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; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.content.Context; |
| 28 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 29 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 30 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 31 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 32 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 33 | import android.content.pm.PackageManager; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 34 | import android.net.NetworkStats; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 35 | import android.net.Uri; |
| 36 | import android.os.AsyncResult; |
| 37 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 38 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 39 | import android.os.Bundle; |
| 40 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 41 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Looper; |
| 43 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.Messenger; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 45 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 46 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 47 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 48 | import android.os.ServiceManager; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 49 | import android.os.ShellCallback; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 50 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 51 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 52 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 53 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 54 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 55 | import android.provider.Settings; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 56 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 57 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 58 | import android.telecom.TelecomManager; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 59 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 60 | import android.telephony.CarrierRestrictionRules; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 61 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 62 | import android.telephony.CellInfoGsm; |
| 63 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 64 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 65 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 66 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 67 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 68 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 69 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 70 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 71 | import android.telephony.NetworkScanRequest; |
Michele | bcb01bc | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 72 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 73 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 74 | import android.telephony.RadioAccessFamily; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 75 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 76 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 77 | import android.telephony.SignalStrength; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 78 | import android.telephony.SmsManager; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 79 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 80 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 81 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 82 | import android.telephony.TelephonyManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 83 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 84 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 85 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 86 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 87 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 88 | import android.telephony.data.ApnSetting; |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 89 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 90 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 91 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 92 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 93 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 94 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 95 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 96 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 97 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 98 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 99 | import android.telephony.ims.feature.MmTelFeature; |
| 100 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 101 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 102 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 103 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 104 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 105 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 106 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 107 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 108 | import com.android.ims.ImsException; |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 109 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 110 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 111 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 112 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 113 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 114 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 115 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 116 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 117 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 118 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 119 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 120 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 121 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 122 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 123 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.Phone; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 128 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.ServiceStateTracker; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 135 | import com.android.internal.telephony.SmsApplication; |
| 136 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 137 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.TelephonyPermissions; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 139 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame^] | 141 | import com.android.internal.telephony.ims.ImsResolver; |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.uicc.IccIoResult; |
| 144 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 147 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 150 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 152 | import com.android.internal.util.HexDump; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 153 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 154 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 155 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 156 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 157 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 158 | import java.io.FileDescriptor; |
| 159 | import java.io.PrintWriter; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 160 | import java.nio.charset.StandardCharsets; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 161 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 162 | import java.util.Arrays; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 163 | import java.util.Collection; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 164 | import java.util.HashMap; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 165 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 166 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 167 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 168 | import java.util.Map; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 169 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 170 | |
| 171 | /** |
| 172 | * Implementation of the ITelephony interface. |
| 173 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 174 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 175 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 176 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 177 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 178 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 179 | |
| 180 | // Message codes used with mMainThreadHandler |
| 181 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 182 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 183 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 184 | private static final int CMD_OPEN_CHANNEL = 9; |
| 185 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 186 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 187 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 188 | private static final int CMD_NV_READ_ITEM = 13; |
| 189 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 190 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 191 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 192 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 193 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 194 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 195 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 196 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 197 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 198 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 199 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 200 | private static final int CMD_SEND_ENVELOPE = 25; |
| 201 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 202 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 203 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 204 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 205 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 206 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 207 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 208 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 209 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 210 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 211 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 212 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 213 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 214 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 215 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 216 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 217 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 218 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 219 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 220 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 221 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 222 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 223 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 224 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 225 | private static final int CMD_SWITCH_SLOTS = 50; |
| 226 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 227 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 228 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 229 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 230 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 231 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 232 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 233 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 234 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 235 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 236 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 237 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 238 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 239 | private static final int CMD_MODEM_REBOOT = 64; |
| 240 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 241 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 242 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 243 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 244 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 245 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 246 | // Parameters of select command. |
| 247 | private static final int SELECT_COMMAND = 0xA4; |
| 248 | private static final int SELECT_P1 = 0x04; |
| 249 | private static final int SELECT_P2 = 0; |
| 250 | private static final int SELECT_P3 = 0x10; |
| 251 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 252 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 253 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 254 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 255 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 256 | /** The singleton instance. */ |
| 257 | private static PhoneInterfaceManager sInstance; |
| 258 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 259 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 260 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 261 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 262 | private AppOpsManager mAppOps; |
| 263 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 264 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 265 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 266 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 267 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 268 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 269 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 270 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 271 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 272 | |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 273 | // String to store multi SIM allowed |
| 274 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 275 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 276 | // The AID of ISD-R. |
| 277 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 278 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 279 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 280 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 281 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 282 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 283 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 284 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 285 | * A request object to use for transmitting data to an ICC. |
| 286 | */ |
| 287 | private static final class IccAPDUArgument { |
| 288 | public int channel, cla, command, p1, p2, p3; |
| 289 | public String data; |
| 290 | |
| 291 | public IccAPDUArgument(int channel, int cla, int command, |
| 292 | int p1, int p2, int p3, String data) { |
| 293 | this.channel = channel; |
| 294 | this.cla = cla; |
| 295 | this.command = command; |
| 296 | this.p1 = p1; |
| 297 | this.p2 = p2; |
| 298 | this.p3 = p3; |
| 299 | this.data = data; |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 304 | * A request object to use for transmitting data to an ICC. |
| 305 | */ |
| 306 | private static final class ManualNetworkSelectionArgument { |
| 307 | public OperatorInfo operatorInfo; |
| 308 | public boolean persistSelection; |
| 309 | |
| 310 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 311 | this.operatorInfo = operatorInfo; |
| 312 | this.persistSelection = persistSelection; |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 317 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 318 | * request after sending. The main thread will notify the request when it is complete. |
| 319 | */ |
| 320 | private static final class MainThreadRequest { |
| 321 | /** The argument to use for the request */ |
| 322 | public Object argument; |
| 323 | /** The result of the request that is run on the main thread */ |
| 324 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 325 | // The subscriber id that this request applies to. Defaults to |
| 326 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 327 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 328 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 329 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 330 | public Phone phone; |
| 331 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 332 | public WorkSource workSource; |
| 333 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 334 | public MainThreadRequest(Object argument) { |
| 335 | this.argument = argument; |
| 336 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 337 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 338 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 339 | this.argument = argument; |
| 340 | if (phone != null) { |
| 341 | this.phone = phone; |
| 342 | } |
| 343 | this.workSource = workSource; |
| 344 | } |
| 345 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 346 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 347 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 348 | if (subId != null) { |
| 349 | this.subId = subId; |
| 350 | } |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 351 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 352 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 355 | private static final class IncomingThirdPartyCallArgs { |
| 356 | public final ComponentName component; |
| 357 | public final String callId; |
| 358 | public final String callerDisplayName; |
| 359 | |
| 360 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 361 | String callerDisplayName) { |
| 362 | this.component = component; |
| 363 | this.callId = callId; |
| 364 | this.callerDisplayName = callerDisplayName; |
| 365 | } |
| 366 | } |
| 367 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 368 | /** |
| 369 | * A handler that processes messages on the main thread in the phone process. Since many |
| 370 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 371 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 372 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 373 | * on, which will be notified when the operation completes and will contain the result of the |
| 374 | * request. |
| 375 | * |
| 376 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 377 | * note that request.result must be set to something non-null for the calling thread to |
| 378 | * unblock. |
| 379 | */ |
| 380 | private final class MainThreadHandler extends Handler { |
| 381 | @Override |
| 382 | public void handleMessage(Message msg) { |
| 383 | MainThreadRequest request; |
| 384 | Message onCompleted; |
| 385 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 386 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 387 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 388 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 389 | |
| 390 | switch (msg.what) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 391 | case CMD_HANDLE_USSD_REQUEST: { |
| 392 | request = (MainThreadRequest) msg.obj; |
| 393 | final Phone phone = getPhoneFromRequest(request); |
| 394 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 395 | String ussdRequest = ussdObject.first; |
| 396 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 397 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 398 | if (!isUssdApiAllowed(request.subId)) { |
| 399 | // Carrier does not support use of this API, return failure. |
| 400 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 401 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 402 | Bundle returnData = new Bundle(); |
| 403 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 404 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 405 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 406 | request.result = true; |
| 407 | notifyRequester(request); |
| 408 | return; |
| 409 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 410 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 411 | try { |
| 412 | request.result = phone != null |
| 413 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 414 | } catch (CallStateException cse) { |
| 415 | request.result = false; |
| 416 | } |
| 417 | // Wake up the requesting thread |
| 418 | notifyRequester(request); |
| 419 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 422 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 423 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 424 | final Phone phone = getPhoneFromRequest(request); |
| 425 | request.result = phone != null ? |
| 426 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 427 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 428 | // Wake up the requesting thread |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 429 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 430 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 431 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 432 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 433 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 434 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 435 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 436 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 437 | if (uiccCard == null) { |
| 438 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 439 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 440 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 441 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 442 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 443 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 444 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 445 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 446 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 447 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 448 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 449 | break; |
| 450 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 451 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 452 | ar = (AsyncResult) msg.obj; |
| 453 | request = (MainThreadRequest) ar.userObj; |
| 454 | if (ar.exception == null && ar.result != null) { |
| 455 | request.result = ar.result; |
| 456 | } else { |
| 457 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 458 | if (ar.result == null) { |
| 459 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 460 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 461 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 462 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 463 | } else { |
| 464 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 465 | } |
| 466 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 467 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 468 | break; |
| 469 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 470 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 471 | request = (MainThreadRequest) msg.obj; |
| 472 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 473 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 474 | if (uiccCard == null) { |
| 475 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 476 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 477 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 478 | } else { |
| 479 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 480 | request); |
| 481 | uiccCard.iccTransmitApduBasicChannel( |
| 482 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 483 | iccArgument.p3, iccArgument.data, onCompleted); |
| 484 | } |
| 485 | break; |
| 486 | |
| 487 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 488 | ar = (AsyncResult) msg.obj; |
| 489 | request = (MainThreadRequest) ar.userObj; |
| 490 | if (ar.exception == null && ar.result != null) { |
| 491 | request.result = ar.result; |
| 492 | } else { |
| 493 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 494 | if (ar.result == null) { |
| 495 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 496 | } else if (ar.exception instanceof CommandException) { |
| 497 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 498 | ar.exception); |
| 499 | } else { |
| 500 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 501 | } |
| 502 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 503 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 504 | break; |
| 505 | |
| 506 | case CMD_EXCHANGE_SIM_IO: |
| 507 | request = (MainThreadRequest) msg.obj; |
| 508 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 509 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 510 | if (uiccCard == null) { |
| 511 | loge("iccExchangeSimIO: No UICC"); |
| 512 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 513 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 514 | } else { |
| 515 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 516 | request); |
| 517 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 518 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 519 | iccArgument.data, onCompleted); |
| 520 | } |
| 521 | break; |
| 522 | |
| 523 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 524 | ar = (AsyncResult) msg.obj; |
| 525 | request = (MainThreadRequest) ar.userObj; |
| 526 | if (ar.exception == null && ar.result != null) { |
| 527 | request.result = ar.result; |
| 528 | } else { |
| 529 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 530 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 531 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 532 | break; |
| 533 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 534 | case CMD_SEND_ENVELOPE: |
| 535 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 536 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 537 | if (uiccCard == null) { |
| 538 | loge("sendEnvelopeWithStatus: No UICC"); |
| 539 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 540 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 541 | } else { |
| 542 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 543 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 544 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 545 | break; |
| 546 | |
| 547 | case EVENT_SEND_ENVELOPE_DONE: |
| 548 | ar = (AsyncResult) msg.obj; |
| 549 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 550 | if (ar.exception == null && ar.result != null) { |
| 551 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 552 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 553 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 554 | if (ar.result == null) { |
| 555 | loge("sendEnvelopeWithStatus: Empty response"); |
| 556 | } else if (ar.exception instanceof CommandException) { |
| 557 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 558 | ar.exception); |
| 559 | } else { |
| 560 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 561 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 562 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 563 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 564 | break; |
| 565 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 566 | case CMD_OPEN_CHANNEL: |
| 567 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 568 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 569 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 570 | if (uiccCard == null) { |
| 571 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 572 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 573 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 574 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 575 | } else { |
| 576 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 577 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 578 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 579 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 580 | break; |
| 581 | |
| 582 | case EVENT_OPEN_CHANNEL_DONE: |
| 583 | ar = (AsyncResult) msg.obj; |
| 584 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 585 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 586 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 587 | int[] result = (int[]) ar.result; |
| 588 | int channelId = result[0]; |
| 589 | byte[] selectResponse = null; |
| 590 | if (result.length > 1) { |
| 591 | selectResponse = new byte[result.length - 1]; |
| 592 | for (int i = 1; i < result.length; ++i) { |
| 593 | selectResponse[i - 1] = (byte) result[i]; |
| 594 | } |
| 595 | } |
| 596 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 597 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 598 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 599 | if (ar.result == null) { |
| 600 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 601 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 602 | if (ar.exception != null) { |
| 603 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 604 | } |
| 605 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 606 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 607 | if (ar.exception instanceof CommandException) { |
| 608 | CommandException.Error error = |
| 609 | ((CommandException) (ar.exception)).getCommandError(); |
| 610 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 611 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 612 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 613 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 614 | } |
| 615 | } |
| 616 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 617 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 618 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 619 | request.result = openChannelResp; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 620 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 621 | break; |
| 622 | |
| 623 | case CMD_CLOSE_CHANNEL: |
| 624 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 625 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 626 | if (uiccCard == null) { |
| 627 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 628 | request.result = false; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 629 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 630 | } else { |
| 631 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 632 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 633 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 634 | break; |
| 635 | |
| 636 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 637 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 638 | break; |
| 639 | |
| 640 | case CMD_NV_READ_ITEM: |
| 641 | request = (MainThreadRequest) msg.obj; |
| 642 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 643 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 644 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 645 | break; |
| 646 | |
| 647 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 648 | ar = (AsyncResult) msg.obj; |
| 649 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 650 | if (ar.exception == null && ar.result != null) { |
| 651 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 652 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 653 | request.result = ""; |
| 654 | if (ar.result == null) { |
| 655 | loge("nvReadItem: Empty response"); |
| 656 | } else if (ar.exception instanceof CommandException) { |
| 657 | loge("nvReadItem: CommandException: " + |
| 658 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 659 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 660 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 661 | } |
| 662 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 663 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 664 | break; |
| 665 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 666 | case CMD_NV_WRITE_ITEM: |
| 667 | request = (MainThreadRequest) msg.obj; |
| 668 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 669 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 670 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 671 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 672 | break; |
| 673 | |
| 674 | case EVENT_NV_WRITE_ITEM_DONE: |
| 675 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 676 | break; |
| 677 | |
| 678 | case CMD_NV_WRITE_CDMA_PRL: |
| 679 | request = (MainThreadRequest) msg.obj; |
| 680 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 681 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 682 | break; |
| 683 | |
| 684 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 685 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 686 | break; |
| 687 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 688 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 689 | request = (MainThreadRequest) msg.obj; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 690 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 691 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 692 | break; |
| 693 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 694 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 695 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 696 | break; |
| 697 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 698 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 699 | request = (MainThreadRequest) msg.obj; |
| 700 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 701 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 702 | break; |
| 703 | |
| 704 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 705 | ar = (AsyncResult) msg.obj; |
| 706 | request = (MainThreadRequest) ar.userObj; |
| 707 | if (ar.exception == null && ar.result != null) { |
| 708 | request.result = ar.result; // Integer |
| 709 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 710 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 711 | if (ar.result == null) { |
| 712 | loge("getPreferredNetworkType: Empty response"); |
| 713 | } else if (ar.exception instanceof CommandException) { |
| 714 | loge("getPreferredNetworkType: CommandException: " + |
| 715 | ar.exception); |
| 716 | } else { |
| 717 | loge("getPreferredNetworkType: Unknown exception"); |
| 718 | } |
| 719 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 720 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 721 | break; |
| 722 | |
| 723 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 724 | request = (MainThreadRequest) msg.obj; |
| 725 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 726 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 727 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 728 | break; |
| 729 | |
| 730 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 731 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 732 | break; |
| 733 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 734 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 735 | request = (MainThreadRequest)msg.obj; |
| 736 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 737 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 738 | break; |
| 739 | |
| 740 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 741 | ar = (AsyncResult)msg.obj; |
| 742 | request = (MainThreadRequest)ar.userObj; |
| 743 | request.result = ar; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 744 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 745 | break; |
| 746 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 747 | case CMD_SET_VOICEMAIL_NUMBER: |
| 748 | request = (MainThreadRequest) msg.obj; |
| 749 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 750 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 751 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 752 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 753 | break; |
| 754 | |
| 755 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 756 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 757 | break; |
| 758 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 759 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 760 | request = (MainThreadRequest) msg.obj; |
| 761 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 762 | request); |
| 763 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 764 | break; |
| 765 | |
| 766 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 767 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 768 | break; |
| 769 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 770 | case CMD_PERFORM_NETWORK_SCAN: |
| 771 | request = (MainThreadRequest) msg.obj; |
| 772 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 773 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 774 | break; |
| 775 | |
| 776 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 777 | ar = (AsyncResult) msg.obj; |
| 778 | request = (MainThreadRequest) ar.userObj; |
| 779 | CellNetworkScanResult cellScanResult; |
| 780 | if (ar.exception == null && ar.result != null) { |
| 781 | cellScanResult = new CellNetworkScanResult( |
| 782 | CellNetworkScanResult.STATUS_SUCCESS, |
| 783 | (List<OperatorInfo>) ar.result); |
| 784 | } else { |
| 785 | if (ar.result == null) { |
| 786 | loge("getCellNetworkScanResults: Empty response"); |
| 787 | } |
| 788 | if (ar.exception != null) { |
| 789 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 790 | } |
| 791 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 792 | if (ar.exception instanceof CommandException) { |
| 793 | CommandException.Error error = |
| 794 | ((CommandException) (ar.exception)).getCommandError(); |
| 795 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 796 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 797 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 798 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 799 | } |
| 800 | } |
| 801 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 802 | } |
| 803 | request.result = cellScanResult; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 804 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 805 | break; |
| 806 | |
| 807 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 808 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 809 | ManualNetworkSelectionArgument selArg = |
| 810 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 811 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 812 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 813 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 814 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 815 | break; |
| 816 | |
| 817 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | dd9ac82 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 818 | ar = (AsyncResult) msg.obj; |
| 819 | request = (MainThreadRequest) ar.userObj; |
| 820 | if (ar.exception == null) { |
| 821 | request.result = true; |
| 822 | } else { |
| 823 | request.result = false; |
| 824 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 825 | } |
| 826 | notifyRequester(request); |
| 827 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 828 | break; |
| 829 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 830 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 831 | request = (MainThreadRequest) msg.obj; |
| 832 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 833 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 834 | break; |
| 835 | |
| 836 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 837 | ar = (AsyncResult) msg.obj; |
| 838 | request = (MainThreadRequest) ar.userObj; |
| 839 | if (ar.exception == null && ar.result != null) { |
| 840 | request.result = ar.result; |
| 841 | } else { |
| 842 | if (ar.result == null) { |
| 843 | loge("queryModemActivityInfo: Empty response"); |
| 844 | } else if (ar.exception instanceof CommandException) { |
| 845 | loge("queryModemActivityInfo: CommandException: " + |
| 846 | ar.exception); |
| 847 | } else { |
| 848 | loge("queryModemActivityInfo: Unknown exception"); |
| 849 | } |
| 850 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 851 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 852 | if (request.result == null) { |
| 853 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 854 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 855 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 856 | break; |
| 857 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 858 | case CMD_SET_ALLOWED_CARRIERS: |
| 859 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 860 | CarrierRestrictionRules argument = |
| 861 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 862 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 863 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 864 | break; |
| 865 | |
| 866 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 867 | ar = (AsyncResult) msg.obj; |
| 868 | request = (MainThreadRequest) ar.userObj; |
| 869 | if (ar.exception == null && ar.result != null) { |
| 870 | request.result = ar.result; |
| 871 | } else { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 872 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 873 | if (ar.exception instanceof CommandException) { |
| 874 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 875 | CommandException.Error error = |
| 876 | ((CommandException) (ar.exception)).getCommandError(); |
| 877 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 878 | request.result = |
| 879 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 880 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 881 | } else { |
| 882 | loge("setAllowedCarriers: Unknown exception"); |
| 883 | } |
| 884 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 885 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 886 | break; |
| 887 | |
| 888 | case CMD_GET_ALLOWED_CARRIERS: |
| 889 | request = (MainThreadRequest) msg.obj; |
| 890 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 891 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 892 | break; |
| 893 | |
| 894 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 895 | ar = (AsyncResult) msg.obj; |
| 896 | request = (MainThreadRequest) ar.userObj; |
| 897 | if (ar.exception == null && ar.result != null) { |
| 898 | request.result = ar.result; |
| 899 | } else { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 900 | request.result = new IllegalStateException( |
| 901 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 902 | if (ar.result == null) { |
| 903 | loge("getAllowedCarriers: Empty response"); |
| 904 | } else if (ar.exception instanceof CommandException) { |
| 905 | loge("getAllowedCarriers: CommandException: " + |
| 906 | ar.exception); |
| 907 | } else { |
| 908 | loge("getAllowedCarriers: Unknown exception"); |
| 909 | } |
| 910 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 911 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 912 | break; |
| 913 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 914 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 915 | ar = (AsyncResult) msg.obj; |
| 916 | request = (MainThreadRequest) ar.userObj; |
| 917 | if (ar.exception == null && ar.result != null) { |
| 918 | request.result = ar.result; |
| 919 | } else { |
| 920 | request.result = new IllegalArgumentException( |
| 921 | "Failed to retrieve Forbidden Plmns"); |
| 922 | if (ar.result == null) { |
| 923 | loge("getForbiddenPlmns: Empty response"); |
| 924 | } else { |
| 925 | loge("getForbiddenPlmns: Unknown exception"); |
| 926 | } |
| 927 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 928 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 929 | break; |
| 930 | |
| 931 | case CMD_GET_FORBIDDEN_PLMNS: |
| 932 | request = (MainThreadRequest) msg.obj; |
| 933 | uiccCard = getUiccCardFromRequest(request); |
| 934 | if (uiccCard == null) { |
| 935 | loge("getForbiddenPlmns() UiccCard is null"); |
| 936 | request.result = new IllegalArgumentException( |
| 937 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 938 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 939 | break; |
| 940 | } |
| 941 | Integer appType = (Integer) request.argument; |
| 942 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 943 | if (uiccApp == null) { |
| 944 | loge("getForbiddenPlmns() no app with specified type -- " |
| 945 | + appType); |
| 946 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 947 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 948 | break; |
| 949 | } else { |
| 950 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 951 | + " specified type -- " + appType); |
| 952 | } |
| 953 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 954 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 955 | onCompleted); |
| 956 | break; |
| 957 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 958 | case CMD_SWITCH_SLOTS: |
| 959 | request = (MainThreadRequest) msg.obj; |
| 960 | int[] physicalSlots = (int[]) request.argument; |
| 961 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 962 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 963 | break; |
| 964 | |
| 965 | case EVENT_SWITCH_SLOTS_DONE: |
| 966 | ar = (AsyncResult) msg.obj; |
| 967 | request = (MainThreadRequest) ar.userObj; |
| 968 | request.result = (ar.exception == null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 969 | notifyRequester(request); |
| 970 | break; |
| 971 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 972 | request = (MainThreadRequest) msg.obj; |
| 973 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 974 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 975 | break; |
| 976 | |
| 977 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 978 | ar = (AsyncResult) msg.obj; |
| 979 | request = (MainThreadRequest) ar.userObj; |
| 980 | if (ar.exception != null) { |
| 981 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 982 | } else { |
| 983 | int mode = ((int[]) ar.result)[0]; |
| 984 | if (mode == 0) { |
| 985 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 986 | } else { |
| 987 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 988 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 989 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 990 | notifyRequester(request); |
| 991 | break; |
| 992 | case CMD_GET_CDMA_ROAMING_MODE: |
| 993 | request = (MainThreadRequest) msg.obj; |
| 994 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 995 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 996 | break; |
| 997 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 998 | ar = (AsyncResult) msg.obj; |
| 999 | request = (MainThreadRequest) ar.userObj; |
| 1000 | if (ar.exception != null) { |
| 1001 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1002 | } else { |
| 1003 | request.result = ((int[]) ar.result)[0]; |
| 1004 | } |
| 1005 | notifyRequester(request); |
| 1006 | break; |
| 1007 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1008 | request = (MainThreadRequest) msg.obj; |
| 1009 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1010 | int mode = (int) request.argument; |
| 1011 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1012 | break; |
| 1013 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1014 | ar = (AsyncResult) msg.obj; |
| 1015 | request = (MainThreadRequest) ar.userObj; |
| 1016 | request.result = ar.exception == null; |
| 1017 | notifyRequester(request); |
| 1018 | break; |
| 1019 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1020 | request = (MainThreadRequest) msg.obj; |
| 1021 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1022 | int subscriptionMode = (int) request.argument; |
| 1023 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1024 | break; |
| 1025 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1026 | ar = (AsyncResult) msg.obj; |
| 1027 | request = (MainThreadRequest) ar.userObj; |
| 1028 | request.result = ar.exception == null; |
| 1029 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1030 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1031 | case CMD_GET_ALL_CELL_INFO: |
| 1032 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1033 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1034 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1035 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1036 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1037 | ar = (AsyncResult) msg.obj; |
| 1038 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1039 | // If a timeout occurs, the response will be null |
| 1040 | request.result = (ar.exception == null && ar.result != null) |
| 1041 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1042 | synchronized (request) { |
| 1043 | request.notifyAll(); |
| 1044 | } |
| 1045 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1046 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1047 | request = (MainThreadRequest) msg.obj; |
| 1048 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1049 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1050 | break; |
| 1051 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1052 | ar = (AsyncResult) msg.obj; |
| 1053 | request = (MainThreadRequest) ar.userObj; |
| 1054 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1055 | try { |
| 1056 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1057 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1058 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1059 | new android.os.ParcelableException(ar.exception)); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1060 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1061 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1062 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1063 | } else { |
| 1064 | // use the result as returned |
| 1065 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1066 | } |
| 1067 | } catch (RemoteException re) { |
| 1068 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1069 | } |
| 1070 | break; |
| 1071 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1072 | request = (MainThreadRequest) msg.obj; |
| 1073 | WorkSource ws = (WorkSource) request.argument; |
| 1074 | Phone phone = getPhoneFromRequest(request); |
| 1075 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1076 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1077 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1078 | ar = (AsyncResult) msg.obj; |
| 1079 | request = (MainThreadRequest) ar.userObj; |
| 1080 | if (ar.exception == null) { |
| 1081 | request.result = ar.result; |
| 1082 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1083 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1084 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1085 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1086 | } |
| 1087 | |
| 1088 | synchronized (request) { |
| 1089 | request.notifyAll(); |
| 1090 | } |
| 1091 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1092 | case CMD_MODEM_REBOOT: |
| 1093 | request = (MainThreadRequest) msg.obj; |
| 1094 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1095 | defaultPhone.rebootModem(onCompleted); |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1096 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1097 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1098 | handleNullReturnEvent(msg, "rebootModem"); |
| 1099 | break; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1100 | case CMD_REQUEST_ENABLE_MODEM: |
| 1101 | request = (MainThreadRequest) msg.obj; |
| 1102 | boolean enable = (boolean) request.argument; |
| 1103 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 9b37957 | 2019-03-01 17:27:47 -0800 | [diff] [blame] | 1104 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1105 | PhoneConfigurationManager.getInstance() |
| 1106 | .enablePhone(request.phone, enable, onCompleted); |
| 1107 | break; |
| 1108 | case EVENT_ENABLE_MODEM_DONE: |
| 1109 | ar = (AsyncResult) msg.obj; |
| 1110 | request = (MainThreadRequest) ar.userObj; |
| 1111 | request.result = (ar.exception == null); |
Nazanin Bakhshi | 9b37957 | 2019-03-01 17:27:47 -0800 | [diff] [blame] | 1112 | //update the cache as modem status has changed |
| 1113 | mPhoneConfigurationManager.addToPhoneStatusCache( |
| 1114 | request.phone.getPhoneId(), msg.arg1 == 1); |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 1115 | updateModemStateMetrics(); |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1116 | notifyRequester(request); |
| 1117 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1118 | default: |
| 1119 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1120 | break; |
| 1121 | } |
| 1122 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1123 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1124 | private void notifyRequester(MainThreadRequest request) { |
| 1125 | synchronized (request) { |
| 1126 | request.notifyAll(); |
| 1127 | } |
| 1128 | } |
| 1129 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1130 | private void handleNullReturnEvent(Message msg, String command) { |
| 1131 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1132 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1133 | if (ar.exception == null) { |
| 1134 | request.result = true; |
| 1135 | } else { |
| 1136 | request.result = false; |
| 1137 | if (ar.exception instanceof CommandException) { |
| 1138 | loge(command + ": CommandException: " + ar.exception); |
| 1139 | } else { |
| 1140 | loge(command + ": Unknown exception"); |
| 1141 | } |
| 1142 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1143 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1144 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | /** |
| 1148 | * Posts the specified command to be executed on the main thread, |
| 1149 | * waits for the request to complete, and returns the result. |
| 1150 | * @see #sendRequestAsync |
| 1151 | */ |
| 1152 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1153 | return sendRequest( |
| 1154 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | /** |
| 1158 | * Posts the specified command to be executed on the main thread, |
| 1159 | * waits for the request to complete, and returns the result. |
| 1160 | * @see #sendRequestAsync |
| 1161 | */ |
| 1162 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1163 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1164 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | /** |
| 1168 | * Posts the specified command to be executed on the main thread, |
| 1169 | * waits for the request to complete, and returns the result. |
| 1170 | * @see #sendRequestAsync |
| 1171 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1172 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1173 | return sendRequest(command, argument, subId, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | /** |
| 1177 | * Posts the specified command to be executed on the main thread, |
| 1178 | * waits for the request to complete, and returns the result. |
| 1179 | * @see #sendRequestAsync |
| 1180 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1181 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1182 | return sendRequest(command, argument, subId, null, workSource); |
| 1183 | } |
| 1184 | |
| 1185 | /** |
| 1186 | * Posts the specified command to be executed on the main thread, |
| 1187 | * waits for the request to complete, and returns the result. |
| 1188 | * @see #sendRequestAsync |
| 1189 | */ |
| 1190 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1191 | return sendRequest( |
| 1192 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1193 | } |
| 1194 | |
| 1195 | /** |
| 1196 | * Posts the specified command to be executed on the main thread, |
| 1197 | * waits for the request to complete, and returns the result. |
| 1198 | * @see #sendRequestAsync |
| 1199 | */ |
| 1200 | private Object sendRequest( |
| 1201 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1202 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1203 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1204 | } |
| 1205 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1206 | MainThreadRequest request = null; |
| 1207 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1208 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1209 | } else if (phone != null) { |
| 1210 | request = new MainThreadRequest(argument, phone, workSource); |
| 1211 | } else { |
| 1212 | request = new MainThreadRequest(argument, subId, workSource); |
| 1213 | } |
| 1214 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1215 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1216 | msg.sendToTarget(); |
| 1217 | |
| 1218 | // Wait for the request to complete |
| 1219 | synchronized (request) { |
| 1220 | while (request.result == null) { |
| 1221 | try { |
| 1222 | request.wait(); |
| 1223 | } catch (InterruptedException e) { |
| 1224 | // Do nothing, go back and wait until the request is complete |
| 1225 | } |
| 1226 | } |
| 1227 | } |
| 1228 | return request.result; |
| 1229 | } |
| 1230 | |
| 1231 | /** |
| 1232 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1233 | * Posts the specified command to be executed on the main thread, and |
| 1234 | * returns immediately. |
| 1235 | * @see #sendRequest |
| 1236 | */ |
| 1237 | private void sendRequestAsync(int command) { |
| 1238 | mMainThreadHandler.sendEmptyMessage(command); |
| 1239 | } |
| 1240 | |
| 1241 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1242 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1243 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1244 | */ |
| 1245 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1246 | sendRequestAsync(command, argument, null, null); |
| 1247 | } |
| 1248 | |
| 1249 | /** |
| 1250 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1251 | * @see {@link #sendRequest(int,Object)} |
| 1252 | */ |
| 1253 | private void sendRequestAsync( |
| 1254 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1255 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1256 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1257 | msg.sendToTarget(); |
| 1258 | } |
| 1259 | |
| 1260 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1261 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1262 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1263 | */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1264 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1265 | synchronized (PhoneInterfaceManager.class) { |
| 1266 | if (sInstance == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1267 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1268 | } else { |
| 1269 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1270 | } |
| 1271 | return sInstance; |
| 1272 | } |
| 1273 | } |
| 1274 | |
| 1275 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1276 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1277 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1278 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1279 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1280 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1281 | mMainThreadHandler = new MainThreadHandler(); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1282 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1283 | mTelephonySharedPreferences = |
| 1284 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1285 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1286 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1287 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1288 | publish(); |
| 1289 | } |
| 1290 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1291 | private Phone getDefaultPhone() { |
| 1292 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1293 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1294 | } |
| 1295 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1296 | private void publish() { |
| 1297 | if (DBG) log("publish: " + this); |
| 1298 | |
| 1299 | ServiceManager.addService("phone", this); |
| 1300 | } |
| 1301 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1302 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 1303 | return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1304 | ? getDefaultPhone() : getPhone(request.subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1305 | } |
| 1306 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1307 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1308 | Phone phone = getPhoneFromRequest(request); |
| 1309 | return phone == null ? null : |
| 1310 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1311 | } |
| 1312 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1313 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1314 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1315 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1316 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1317 | |
| 1318 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1319 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1320 | } |
| 1321 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1322 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1323 | if (DBG) log("dial: " + number); |
| 1324 | // No permission check needed here: This is just a wrapper around the |
| 1325 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1326 | // the UI before it does anything. |
| 1327 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1328 | final long identity = Binder.clearCallingIdentity(); |
| 1329 | try { |
| 1330 | String url = createTelUrl(number); |
| 1331 | if (url == null) { |
| 1332 | return; |
| 1333 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1334 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1335 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1336 | PhoneConstants.State state = mCM.getState(subId); |
| 1337 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1338 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1339 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1340 | mApp.startActivity(intent); |
| 1341 | } |
| 1342 | } finally { |
| 1343 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1344 | } |
| 1345 | } |
| 1346 | |
| 1347 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1348 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1349 | } |
| 1350 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1351 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1352 | if (DBG) log("call: " + number); |
| 1353 | |
| 1354 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1355 | // need to do a permission check since we're calling startActivity() |
| 1356 | // from the context of the phone app. |
| 1357 | enforceCallPermission(); |
| 1358 | |
| 1359 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1360 | != AppOpsManager.MODE_ALLOWED) { |
| 1361 | return; |
| 1362 | } |
| 1363 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1364 | final long identity = Binder.clearCallingIdentity(); |
| 1365 | try { |
| 1366 | String url = createTelUrl(number); |
| 1367 | if (url == null) { |
| 1368 | return; |
| 1369 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1370 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1371 | boolean isValid = false; |
| 1372 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1373 | if (slist != null) { |
| 1374 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1375 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1376 | isValid = true; |
| 1377 | break; |
| 1378 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1379 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1380 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1381 | if (!isValid) { |
| 1382 | return; |
| 1383 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1384 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1385 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1386 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1387 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1388 | mApp.startActivity(intent); |
| 1389 | } finally { |
| 1390 | Binder.restoreCallingIdentity(identity); |
| 1391 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1394 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1395 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1396 | } |
| 1397 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1398 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1399 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1400 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1401 | } |
| 1402 | |
| 1403 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1404 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1405 | } |
| 1406 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1407 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1408 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1409 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1410 | } |
| 1411 | |
| 1412 | /** {@hide} */ |
| 1413 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1414 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), 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 int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1418 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1419 | |
| 1420 | final long identity = Binder.clearCallingIdentity(); |
| 1421 | try { |
| 1422 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1423 | checkSimPin.start(); |
| 1424 | return checkSimPin.unlockSim(null, pin); |
| 1425 | } finally { |
| 1426 | Binder.restoreCallingIdentity(identity); |
| 1427 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1428 | } |
| 1429 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1430 | /** {@hide} */ |
| 1431 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1432 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1433 | } |
| 1434 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1435 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1436 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1437 | |
| 1438 | final long identity = Binder.clearCallingIdentity(); |
| 1439 | try { |
| 1440 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1441 | checkSimPuk.start(); |
| 1442 | return checkSimPuk.unlockSim(puk, pin); |
| 1443 | } finally { |
| 1444 | Binder.restoreCallingIdentity(identity); |
| 1445 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1449 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1450 | * a synchronous one. |
| 1451 | */ |
| 1452 | private static class UnlockSim extends Thread { |
| 1453 | |
| 1454 | private final IccCard mSimCard; |
| 1455 | |
| 1456 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1457 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1458 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1459 | |
| 1460 | // For replies from SimCard interface |
| 1461 | private Handler mHandler; |
| 1462 | |
| 1463 | // For async handler to identify request type |
| 1464 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1465 | |
| 1466 | public UnlockSim(IccCard simCard) { |
| 1467 | mSimCard = simCard; |
| 1468 | } |
| 1469 | |
| 1470 | @Override |
| 1471 | public void run() { |
| 1472 | Looper.prepare(); |
| 1473 | synchronized (UnlockSim.this) { |
| 1474 | mHandler = new Handler() { |
| 1475 | @Override |
| 1476 | public void handleMessage(Message msg) { |
| 1477 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1478 | switch (msg.what) { |
| 1479 | case SUPPLY_PIN_COMPLETE: |
| 1480 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1481 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1482 | mRetryCount = msg.arg1; |
| 1483 | if (ar.exception != null) { |
| 1484 | if (ar.exception instanceof CommandException && |
| 1485 | ((CommandException)(ar.exception)).getCommandError() |
| 1486 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1487 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1488 | } else { |
| 1489 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1490 | } |
| 1491 | } else { |
| 1492 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1493 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1494 | mDone = true; |
| 1495 | UnlockSim.this.notifyAll(); |
| 1496 | } |
| 1497 | break; |
| 1498 | } |
| 1499 | } |
| 1500 | }; |
| 1501 | UnlockSim.this.notifyAll(); |
| 1502 | } |
| 1503 | Looper.loop(); |
| 1504 | } |
| 1505 | |
| 1506 | /* |
| 1507 | * Use PIN or PUK to unlock SIM card |
| 1508 | * |
| 1509 | * If PUK is null, unlock SIM card with PIN |
| 1510 | * |
| 1511 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1512 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1513 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1514 | |
| 1515 | while (mHandler == null) { |
| 1516 | try { |
| 1517 | wait(); |
| 1518 | } catch (InterruptedException e) { |
| 1519 | Thread.currentThread().interrupt(); |
| 1520 | } |
| 1521 | } |
| 1522 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1523 | |
| 1524 | if (puk == null) { |
| 1525 | mSimCard.supplyPin(pin, callback); |
| 1526 | } else { |
| 1527 | mSimCard.supplyPuk(puk, pin, callback); |
| 1528 | } |
| 1529 | |
| 1530 | while (!mDone) { |
| 1531 | try { |
| 1532 | Log.d(LOG_TAG, "wait for done"); |
| 1533 | wait(); |
| 1534 | } catch (InterruptedException e) { |
| 1535 | // Restore the interrupted status |
| 1536 | Thread.currentThread().interrupt(); |
| 1537 | } |
| 1538 | } |
| 1539 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1540 | int[] resultArray = new int[2]; |
| 1541 | resultArray[0] = mResult; |
| 1542 | resultArray[1] = mRetryCount; |
| 1543 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1544 | } |
| 1545 | } |
| 1546 | |
| 1547 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1548 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1549 | |
| 1550 | } |
| 1551 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1552 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1553 | // No permission check needed here: this call is harmless, and it's |
| 1554 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1555 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1556 | final long identity = Binder.clearCallingIdentity(); |
| 1557 | try { |
| 1558 | final Phone phone = getPhone(subId); |
| 1559 | if (phone != null) { |
| 1560 | phone.updateServiceLocation(); |
| 1561 | } |
| 1562 | } finally { |
| 1563 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1564 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1567 | @Override |
| 1568 | public boolean isRadioOn(String callingPackage) { |
| 1569 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1570 | } |
| 1571 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1572 | @Override |
| 1573 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1574 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1575 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1576 | return false; |
| 1577 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1578 | |
| 1579 | final long identity = Binder.clearCallingIdentity(); |
| 1580 | try { |
| 1581 | return isRadioOnForSubscriber(subId); |
| 1582 | } finally { |
| 1583 | Binder.restoreCallingIdentity(identity); |
| 1584 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1588 | final long identity = Binder.clearCallingIdentity(); |
| 1589 | try { |
| 1590 | final Phone phone = getPhone(subId); |
| 1591 | if (phone != null) { |
| 1592 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1593 | } else { |
| 1594 | return false; |
| 1595 | } |
| 1596 | } finally { |
| 1597 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1598 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1602 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1603 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1604 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1605 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1606 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1607 | |
| 1608 | final long identity = Binder.clearCallingIdentity(); |
| 1609 | try { |
| 1610 | final Phone phone = getPhone(subId); |
| 1611 | if (phone != null) { |
| 1612 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1613 | } |
| 1614 | } finally { |
| 1615 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1616 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1617 | } |
| 1618 | |
| 1619 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1620 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1621 | } |
| 1622 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1623 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1624 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1625 | |
| 1626 | final long identity = Binder.clearCallingIdentity(); |
| 1627 | try { |
| 1628 | final Phone phone = getPhone(subId); |
| 1629 | if (phone == null) { |
| 1630 | return false; |
| 1631 | } |
| 1632 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1633 | toggleRadioOnOffForSubscriber(subId); |
| 1634 | } |
| 1635 | return true; |
| 1636 | } finally { |
| 1637 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1638 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1639 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1640 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1641 | public boolean needMobileRadioShutdown() { |
| 1642 | /* |
| 1643 | * If any of the Radios are available, it will need to be |
| 1644 | * shutdown. So return true if any Radio is available. |
| 1645 | */ |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1646 | final long identity = Binder.clearCallingIdentity(); |
| 1647 | try { |
| 1648 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1649 | Phone phone = PhoneFactory.getPhone(i); |
| 1650 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1651 | } |
| 1652 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1653 | return false; |
| 1654 | } finally { |
| 1655 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1656 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1657 | } |
| 1658 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1659 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1660 | public void shutdownMobileRadios() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1661 | enforceModifyPermission(); |
| 1662 | |
| 1663 | final long identity = Binder.clearCallingIdentity(); |
| 1664 | try { |
| 1665 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1666 | logv("Shutting down Phone " + i); |
| 1667 | shutdownRadioUsingPhoneId(i); |
| 1668 | } |
| 1669 | } finally { |
| 1670 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1671 | } |
| 1672 | } |
| 1673 | |
| 1674 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1675 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1676 | if (phone != null && phone.isRadioAvailable()) { |
| 1677 | phone.shutdownRadio(); |
| 1678 | } |
| 1679 | } |
| 1680 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1681 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1682 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1683 | |
| 1684 | final long identity = Binder.clearCallingIdentity(); |
| 1685 | try { |
| 1686 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1687 | if (defaultPhone != null) { |
| 1688 | defaultPhone.setRadioPower(turnOn); |
| 1689 | return true; |
| 1690 | } else { |
| 1691 | loge("There's no default phone."); |
| 1692 | return false; |
| 1693 | } |
| 1694 | } finally { |
| 1695 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1696 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1697 | } |
| 1698 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1699 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1700 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1701 | |
| 1702 | final long identity = Binder.clearCallingIdentity(); |
| 1703 | try { |
| 1704 | final Phone phone = getPhone(subId); |
| 1705 | if (phone != null) { |
| 1706 | phone.setRadioPower(turnOn); |
| 1707 | return true; |
| 1708 | } else { |
| 1709 | return false; |
| 1710 | } |
| 1711 | } finally { |
| 1712 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1713 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1716 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1717 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1718 | public boolean enableDataConnectivity() { |
| 1719 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1720 | |
| 1721 | final long identity = Binder.clearCallingIdentity(); |
| 1722 | try { |
| 1723 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1724 | final Phone phone = getPhone(subId); |
| 1725 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1726 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1727 | return true; |
| 1728 | } else { |
| 1729 | return false; |
| 1730 | } |
| 1731 | } finally { |
| 1732 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1733 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1734 | } |
| 1735 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1736 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1737 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1738 | public boolean disableDataConnectivity() { |
| 1739 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1740 | |
| 1741 | final long identity = Binder.clearCallingIdentity(); |
| 1742 | try { |
| 1743 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1744 | final Phone phone = getPhone(subId); |
| 1745 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1746 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1747 | return true; |
| 1748 | } else { |
| 1749 | return false; |
| 1750 | } |
| 1751 | } finally { |
| 1752 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1753 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1754 | } |
| 1755 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1756 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1757 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1758 | final long identity = Binder.clearCallingIdentity(); |
| 1759 | try { |
| 1760 | final Phone phone = getPhone(subId); |
| 1761 | if (phone != null) { |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1762 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1763 | } else { |
| 1764 | return false; |
| 1765 | } |
| 1766 | } finally { |
| 1767 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1768 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1772 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1775 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1776 | enforceCallPermission(); |
| 1777 | |
| 1778 | final long identity = Binder.clearCallingIdentity(); |
| 1779 | try { |
| 1780 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1781 | return; |
| 1782 | } |
| 1783 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1784 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1785 | } finally { |
| 1786 | Binder.restoreCallingIdentity(identity); |
| 1787 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1788 | }; |
| 1789 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1790 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1791 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1792 | |
| 1793 | final long identity = Binder.clearCallingIdentity(); |
| 1794 | try { |
| 1795 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1796 | return false; |
| 1797 | } |
| 1798 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1799 | } finally { |
| 1800 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1801 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1804 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1805 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1806 | } |
| 1807 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1808 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1809 | final long identity = Binder.clearCallingIdentity(); |
| 1810 | try { |
| 1811 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1812 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1813 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1814 | } finally { |
| 1815 | Binder.restoreCallingIdentity(identity); |
| 1816 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1819 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1820 | public int getDataState() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1821 | final long identity = Binder.clearCallingIdentity(); |
| 1822 | try { |
| 1823 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1824 | if (phone != null) { |
| 1825 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1826 | } else { |
| 1827 | return PhoneConstantConversions.convertDataState( |
| 1828 | PhoneConstants.DataState.DISCONNECTED); |
| 1829 | } |
| 1830 | } finally { |
| 1831 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1832 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1835 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1836 | public int getDataActivity() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1837 | final long identity = Binder.clearCallingIdentity(); |
| 1838 | try { |
| 1839 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1840 | if (phone != null) { |
| 1841 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1842 | } else { |
| 1843 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1844 | } |
| 1845 | } finally { |
| 1846 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1847 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1851 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1852 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1853 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1854 | |
| 1855 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 1856 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 1857 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 1858 | .setCallingPackage(callingPackage) |
| 1859 | .setCallingPid(Binder.getCallingPid()) |
| 1860 | .setCallingUid(Binder.getCallingUid()) |
| 1861 | .setMethod("getCellLocation") |
| 1862 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 1863 | .build()); |
| 1864 | switch (locationResult) { |
| 1865 | case DENIED_HARD: |
| 1866 | throw new SecurityException("Not allowed to access cell location"); |
| 1867 | case DENIED_SOFT: |
| 1868 | return new Bundle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1869 | } |
| 1870 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1871 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1872 | final long identity = Binder.clearCallingIdentity(); |
| 1873 | try { |
| 1874 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1875 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1876 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1877 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1878 | cl.fillInNotifierBundle(data); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1879 | return data; |
| 1880 | } finally { |
| 1881 | Binder.restoreCallingIdentity(identity); |
| 1882 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1883 | } |
| 1884 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1885 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1886 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1887 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1888 | // registered cell info, so return a NULL country instead. |
| 1889 | final long identity = Binder.clearCallingIdentity(); |
| 1890 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1891 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1892 | // Get default phone in this case. |
| 1893 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1894 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1895 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1896 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1897 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1898 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1899 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1900 | return ""; |
| 1901 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1902 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1903 | if (phone != null) { |
| 1904 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 1905 | if (sst != null) { |
| 1906 | LocaleTracker lt = sst.getLocaleTracker(); |
| 1907 | if (lt != null) { |
| 1908 | return lt.getCurrentCountry(); |
| 1909 | } |
| 1910 | } |
| 1911 | } |
| 1912 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1913 | } finally { |
| 1914 | Binder.restoreCallingIdentity(identity); |
| 1915 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1919 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1920 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1921 | } |
| 1922 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1923 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1924 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1925 | mApp.enforceCallingOrSelfPermission( |
| 1926 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1927 | |
| 1928 | final long identity = Binder.clearCallingIdentity(); |
| 1929 | try { |
| 1930 | final Phone phone = getPhone(subId); |
| 1931 | if (phone != null) { |
| 1932 | phone.enableLocationUpdates(); |
| 1933 | } |
| 1934 | } finally { |
| 1935 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1936 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | @Override |
| 1940 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1941 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1942 | } |
| 1943 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1944 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1945 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1946 | mApp.enforceCallingOrSelfPermission( |
| 1947 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1948 | |
| 1949 | final long identity = Binder.clearCallingIdentity(); |
| 1950 | try { |
| 1951 | final Phone phone = getPhone(subId); |
| 1952 | if (phone != null) { |
| 1953 | phone.disableLocationUpdates(); |
| 1954 | } |
| 1955 | } finally { |
| 1956 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1957 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1958 | } |
| 1959 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1960 | /** |
| 1961 | * Returns the target SDK version number for a given package name. |
| 1962 | * |
| 1963 | * @return target SDK if the package is found or INT_MAX. |
| 1964 | */ |
| 1965 | private int getTargetSdk(String packageName) { |
| 1966 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1967 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo( |
| 1968 | packageName, 0); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1969 | if (ai != null) return ai.targetSdkVersion; |
| 1970 | } catch (PackageManager.NameNotFoundException unexpected) { |
| 1971 | } |
| 1972 | return Integer.MAX_VALUE; |
| 1973 | } |
| 1974 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1975 | @Override |
| 1976 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1977 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 1978 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 1979 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 1980 | throw new SecurityException( |
| 1981 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 1982 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 1983 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1984 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 1985 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 1986 | return null; |
| 1987 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1988 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1989 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1990 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1991 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 1992 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1993 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1994 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 1995 | for (CellInfo ci : info) { |
| 1996 | if (ci instanceof CellInfoGsm) { |
| 1997 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 1998 | } else if (ci instanceof CellInfoWcdma) { |
| 1999 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2000 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2001 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2002 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2005 | private List<CellInfo> getCachedCellInfo() { |
| 2006 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2007 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2008 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2009 | if (info != null) cellInfos.addAll(info); |
| 2010 | } |
| 2011 | return cellInfos; |
| 2012 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2013 | |
| 2014 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2015 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2016 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2017 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2018 | |
| 2019 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2020 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2021 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2022 | .setCallingPackage(callingPackage) |
| 2023 | .setCallingPid(Binder.getCallingPid()) |
| 2024 | .setCallingUid(Binder.getCallingUid()) |
| 2025 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2026 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2027 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2028 | .build()); |
| 2029 | switch (locationResult) { |
| 2030 | case DENIED_HARD: |
| 2031 | throw new SecurityException("Not allowed to access cell info"); |
| 2032 | case DENIED_SOFT: |
| 2033 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2034 | } |
| 2035 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2036 | final int targetSdk = getTargetSdk(callingPackage); |
| 2037 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2038 | return getCachedCellInfo(); |
| 2039 | } |
| 2040 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2041 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2042 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2043 | final long identity = Binder.clearCallingIdentity(); |
| 2044 | try { |
| 2045 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2046 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2047 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2048 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2049 | if (info != null) cellInfos.addAll(info); |
| 2050 | } |
| 2051 | return cellInfos; |
| 2052 | } finally { |
| 2053 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2054 | } |
| 2055 | } |
| 2056 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2057 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2058 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2059 | requestCellInfoUpdateInternal( |
| 2060 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2061 | } |
| 2062 | |
| 2063 | @Override |
| 2064 | public void requestCellInfoUpdateWithWorkSource( |
| 2065 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2066 | enforceModifyPermission(); |
| 2067 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2068 | } |
| 2069 | |
| 2070 | private void requestCellInfoUpdateInternal( |
| 2071 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2072 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2073 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2074 | |
| 2075 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2076 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2077 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2078 | .setCallingPackage(callingPackage) |
| 2079 | .setCallingPid(Binder.getCallingPid()) |
| 2080 | .setCallingUid(Binder.getCallingUid()) |
| 2081 | .setMethod("requestCellInfoUpdate") |
| 2082 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2083 | .build()); |
| 2084 | switch (locationResult) { |
| 2085 | case DENIED_HARD: |
| 2086 | throw new SecurityException("Not allowed to access cell info"); |
| 2087 | case DENIED_SOFT: |
| 2088 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2089 | } |
| 2090 | |
| 2091 | final Phone phone = getPhone(subId); |
| 2092 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2093 | |
| 2094 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2095 | } |
| 2096 | |
| 2097 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2098 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2099 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2100 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2101 | |
| 2102 | final long identity = Binder.clearCallingIdentity(); |
| 2103 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2104 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2105 | } finally { |
| 2106 | Binder.restoreCallingIdentity(identity); |
| 2107 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2110 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2111 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2112 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2113 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2114 | return null; |
| 2115 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2116 | int subId = phone.getSubId(); |
| 2117 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2118 | mApp, subId, callingPackage, "getImeiForSlot")) { |
| 2119 | return null; |
| 2120 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2121 | |
| 2122 | final long identity = Binder.clearCallingIdentity(); |
| 2123 | try { |
| 2124 | return phone.getImei(); |
| 2125 | } finally { |
| 2126 | Binder.restoreCallingIdentity(identity); |
| 2127 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2128 | } |
| 2129 | |
| 2130 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2131 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2132 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2133 | String tac = null; |
| 2134 | if (phone != null) { |
| 2135 | String imei = phone.getImei(); |
| 2136 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2137 | } |
| 2138 | return tac; |
| 2139 | } |
| 2140 | |
| 2141 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2142 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2143 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2144 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2145 | return null; |
| 2146 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2147 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2148 | int subId = phone.getSubId(); |
| 2149 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2150 | mApp, subId, callingPackage, "getMeidForSlot")) { |
| 2151 | return null; |
| 2152 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2153 | |
| 2154 | final long identity = Binder.clearCallingIdentity(); |
| 2155 | try { |
| 2156 | return phone.getMeid(); |
| 2157 | } finally { |
| 2158 | Binder.restoreCallingIdentity(identity); |
| 2159 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2163 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2164 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2165 | String manufacturerCode = null; |
| 2166 | if (phone != null) { |
| 2167 | String meid = phone.getMeid(); |
| 2168 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2169 | } |
| 2170 | return manufacturerCode; |
| 2171 | } |
| 2172 | |
| 2173 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2174 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2175 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2176 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2177 | return null; |
| 2178 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2179 | int subId = phone.getSubId(); |
| 2180 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2181 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2182 | return null; |
| 2183 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2184 | |
| 2185 | final long identity = Binder.clearCallingIdentity(); |
| 2186 | try { |
| 2187 | return phone.getDeviceSvn(); |
| 2188 | } finally { |
| 2189 | Binder.restoreCallingIdentity(identity); |
| 2190 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2191 | } |
| 2192 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2193 | @Override |
| 2194 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2195 | final long identity = Binder.clearCallingIdentity(); |
| 2196 | try { |
| 2197 | final Phone phone = getPhone(subId); |
| 2198 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2199 | } finally { |
| 2200 | Binder.restoreCallingIdentity(identity); |
| 2201 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | @Override |
| 2205 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2206 | final long identity = Binder.clearCallingIdentity(); |
| 2207 | try { |
| 2208 | final Phone phone = getPhone(subId); |
| 2209 | return phone == null ? null : phone.getCarrierName(); |
| 2210 | } finally { |
| 2211 | Binder.restoreCallingIdentity(identity); |
| 2212 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2213 | } |
| 2214 | |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2215 | @Override |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2216 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2217 | final long identity = Binder.clearCallingIdentity(); |
| 2218 | try { |
| 2219 | final Phone phone = getPhone(subId); |
| 2220 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2221 | : phone.getSpecificCarrierId(); |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2222 | } finally { |
| 2223 | Binder.restoreCallingIdentity(identity); |
| 2224 | } |
| 2225 | } |
| 2226 | |
| 2227 | @Override |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2228 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2229 | final long identity = Binder.clearCallingIdentity(); |
| 2230 | try { |
| 2231 | final Phone phone = getPhone(subId); |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2232 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2233 | } finally { |
| 2234 | Binder.restoreCallingIdentity(identity); |
| 2235 | } |
| 2236 | } |
| 2237 | |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2238 | @Override |
chen xu | 4ca4e69 | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2239 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2240 | if (!isSubscriptionMccMnc) { |
| 2241 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2242 | } |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2243 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2244 | if (phone == null) { |
| 2245 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2246 | } |
| 2247 | final long identity = Binder.clearCallingIdentity(); |
| 2248 | try { |
| 2249 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2250 | } finally { |
| 2251 | Binder.restoreCallingIdentity(identity); |
| 2252 | } |
| 2253 | } |
| 2254 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2255 | // |
| 2256 | // Internal helper methods. |
| 2257 | // |
| 2258 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2259 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2260 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2261 | * |
| 2262 | * @throws SecurityException if the caller does not have the required permission |
| 2263 | */ |
| 2264 | private void enforceModifyPermission() { |
| 2265 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2266 | } |
| 2267 | |
| 2268 | /** |
| 2269 | * Make sure the caller has the CALL_PHONE permission. |
| 2270 | * |
| 2271 | * @throws SecurityException if the caller does not have the required permission |
| 2272 | */ |
| 2273 | private void enforceCallPermission() { |
| 2274 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2275 | } |
| 2276 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2277 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2278 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2279 | "ConnectivityService"); |
| 2280 | } |
| 2281 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2282 | private String createTelUrl(String number) { |
| 2283 | if (TextUtils.isEmpty(number)) { |
| 2284 | return null; |
| 2285 | } |
| 2286 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2287 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2288 | } |
| 2289 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2290 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2291 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2292 | } |
| 2293 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2294 | private static void logv(String msg) { |
| 2295 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2296 | } |
| 2297 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2298 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2299 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2300 | } |
| 2301 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2302 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2303 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2304 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2305 | } |
| 2306 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2307 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2308 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2309 | final long identity = Binder.clearCallingIdentity(); |
| 2310 | try { |
| 2311 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2312 | if (phone == null) { |
| 2313 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2314 | } else { |
| 2315 | return phone.getPhoneType(); |
| 2316 | } |
| 2317 | } finally { |
| 2318 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2319 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2320 | } |
| 2321 | |
| 2322 | /** |
| 2323 | * Returns the CDMA ERI icon index to display |
| 2324 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2325 | @Override |
| 2326 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2327 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2328 | } |
| 2329 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2330 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2331 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2332 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2333 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2334 | return -1; |
| 2335 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2336 | |
| 2337 | final long identity = Binder.clearCallingIdentity(); |
| 2338 | try { |
| 2339 | final Phone phone = getPhone(subId); |
| 2340 | if (phone != null) { |
| 2341 | return phone.getCdmaEriIconIndex(); |
| 2342 | } else { |
| 2343 | return -1; |
| 2344 | } |
| 2345 | } finally { |
| 2346 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2347 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2348 | } |
| 2349 | |
| 2350 | /** |
| 2351 | * Returns the CDMA ERI icon mode, |
| 2352 | * 0 - ON |
| 2353 | * 1 - FLASHING |
| 2354 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2355 | @Override |
| 2356 | public int getCdmaEriIconMode(String callingPackage) { |
| 2357 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2358 | } |
| 2359 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2360 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2361 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2362 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2363 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2364 | return -1; |
| 2365 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2366 | |
| 2367 | final long identity = Binder.clearCallingIdentity(); |
| 2368 | try { |
| 2369 | final Phone phone = getPhone(subId); |
| 2370 | if (phone != null) { |
| 2371 | return phone.getCdmaEriIconMode(); |
| 2372 | } else { |
| 2373 | return -1; |
| 2374 | } |
| 2375 | } finally { |
| 2376 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2377 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | /** |
| 2381 | * Returns the CDMA ERI text, |
| 2382 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2383 | @Override |
| 2384 | public String getCdmaEriText(String callingPackage) { |
| 2385 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2386 | } |
| 2387 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2388 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2389 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2390 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2391 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2392 | return null; |
| 2393 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2394 | |
| 2395 | final long identity = Binder.clearCallingIdentity(); |
| 2396 | try { |
| 2397 | final Phone phone = getPhone(subId); |
| 2398 | if (phone != null) { |
| 2399 | return phone.getCdmaEriText(); |
| 2400 | } else { |
| 2401 | return null; |
| 2402 | } |
| 2403 | } finally { |
| 2404 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2405 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2406 | } |
| 2407 | |
| 2408 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2409 | * Returns the CDMA MDN. |
| 2410 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2411 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2412 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2413 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2414 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2415 | |
| 2416 | final long identity = Binder.clearCallingIdentity(); |
| 2417 | try { |
| 2418 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2419 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2420 | return phone.getLine1Number(); |
| 2421 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2422 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2423 | return null; |
| 2424 | } |
| 2425 | } finally { |
| 2426 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2427 | } |
| 2428 | } |
| 2429 | |
| 2430 | /** |
| 2431 | * Returns the CDMA MIN. |
| 2432 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2433 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2434 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2435 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2436 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2437 | |
| 2438 | final long identity = Binder.clearCallingIdentity(); |
| 2439 | try { |
| 2440 | final Phone phone = getPhone(subId); |
| 2441 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2442 | return phone.getCdmaMin(); |
| 2443 | } else { |
| 2444 | return null; |
| 2445 | } |
| 2446 | } finally { |
| 2447 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2448 | } |
| 2449 | } |
| 2450 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2451 | @Override |
| 2452 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2453 | INumberVerificationCallback callback, String callingPackage) { |
| 2454 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2455 | != PERMISSION_GRANTED) { |
| 2456 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2457 | } |
| 2458 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2459 | |
| 2460 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2461 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2462 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2463 | } |
| 2464 | |
| 2465 | if (range == null) { |
| 2466 | throw new NullPointerException("Range must be non-null"); |
| 2467 | } |
| 2468 | |
| 2469 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2470 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2471 | |
| 2472 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2473 | } |
| 2474 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2475 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2476 | * Returns true if CDMA provisioning needs to run. |
| 2477 | */ |
| 2478 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2479 | final long identity = Binder.clearCallingIdentity(); |
| 2480 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2481 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2482 | } finally { |
| 2483 | Binder.restoreCallingIdentity(identity); |
| 2484 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2485 | } |
| 2486 | |
| 2487 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2488 | * Sets the voice mail number of a given subId. |
| 2489 | */ |
| 2490 | @Override |
| 2491 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2492 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2493 | |
| 2494 | final long identity = Binder.clearCallingIdentity(); |
| 2495 | try { |
| 2496 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2497 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2498 | return success; |
| 2499 | } finally { |
| 2500 | Binder.restoreCallingIdentity(identity); |
| 2501 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2502 | } |
| 2503 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2504 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2505 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2506 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2507 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2508 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2509 | throw new SecurityException("caller must be system dialer"); |
| 2510 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2511 | |
| 2512 | final long identity = Binder.clearCallingIdentity(); |
| 2513 | try { |
| 2514 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2515 | if (phoneAccountHandle == null) { |
| 2516 | return null; |
| 2517 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2518 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2519 | } finally { |
| 2520 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2521 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2525 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2526 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2527 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2528 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2529 | return null; |
| 2530 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2531 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2532 | final long identity = Binder.clearCallingIdentity(); |
| 2533 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2534 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2535 | } finally { |
| 2536 | Binder.restoreCallingIdentity(identity); |
| 2537 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2541 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2542 | VisualVoicemailSmsFilterSettings settings) { |
| 2543 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2544 | |
| 2545 | final long identity = Binder.clearCallingIdentity(); |
| 2546 | try { |
| 2547 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2548 | mApp, callingPackage, subId, settings); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2549 | } finally { |
| 2550 | Binder.restoreCallingIdentity(identity); |
| 2551 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2552 | } |
| 2553 | |
| 2554 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2555 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2556 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2557 | |
| 2558 | final long identity = Binder.clearCallingIdentity(); |
| 2559 | try { |
| 2560 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2561 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2562 | } finally { |
| 2563 | Binder.restoreCallingIdentity(identity); |
| 2564 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2565 | } |
| 2566 | |
| 2567 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2568 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2569 | String callingPackage, int subId) { |
| 2570 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2571 | |
| 2572 | final long identity = Binder.clearCallingIdentity(); |
| 2573 | try { |
| 2574 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2575 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2576 | } finally { |
| 2577 | Binder.restoreCallingIdentity(identity); |
| 2578 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2579 | } |
| 2580 | |
| 2581 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2582 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2583 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2584 | |
| 2585 | final long identity = Binder.clearCallingIdentity(); |
| 2586 | try { |
| 2587 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2588 | mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2589 | } finally { |
| 2590 | Binder.restoreCallingIdentity(identity); |
| 2591 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2592 | } |
| 2593 | |
| 2594 | @Override |
| 2595 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2596 | String number, int port, String text, PendingIntent sentIntent) { |
| 2597 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2598 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2599 | enforceSendSmsPermission(); |
| 2600 | // Make the calls as the phone process. |
| 2601 | final long identity = Binder.clearCallingIdentity(); |
| 2602 | try { |
| 2603 | SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); |
| 2604 | if (port == 0) { |
| 2605 | smsManager.sendTextMessageWithSelfPermissions(number, null, text, |
| 2606 | sentIntent, null, false); |
| 2607 | } else { |
| 2608 | byte[] data = text.getBytes(StandardCharsets.UTF_8); |
| 2609 | smsManager.sendDataMessageWithSelfPermissions(number, null, |
| 2610 | (short) port, data, sentIntent, null); |
| 2611 | } |
| 2612 | } finally { |
| 2613 | Binder.restoreCallingIdentity(identity); |
| 2614 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2615 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2616 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2617 | * Sets the voice activation state of a given subId. |
| 2618 | */ |
| 2619 | @Override |
| 2620 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2621 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2622 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2623 | |
| 2624 | final long identity = Binder.clearCallingIdentity(); |
| 2625 | try { |
| 2626 | final Phone phone = getPhone(subId); |
| 2627 | if (phone != null) { |
| 2628 | phone.setVoiceActivationState(activationState); |
| 2629 | } else { |
| 2630 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2631 | } |
| 2632 | } finally { |
| 2633 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2634 | } |
| 2635 | } |
| 2636 | |
| 2637 | /** |
| 2638 | * Sets the data activation state of a given subId. |
| 2639 | */ |
| 2640 | @Override |
| 2641 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2642 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2643 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2644 | |
| 2645 | final long identity = Binder.clearCallingIdentity(); |
| 2646 | try { |
| 2647 | final Phone phone = getPhone(subId); |
| 2648 | if (phone != null) { |
| 2649 | phone.setDataActivationState(activationState); |
| 2650 | } else { |
| 2651 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2652 | } |
| 2653 | } finally { |
| 2654 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2655 | } |
| 2656 | } |
| 2657 | |
| 2658 | /** |
| 2659 | * Returns the voice activation state of a given subId. |
| 2660 | */ |
| 2661 | @Override |
| 2662 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2663 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2664 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2665 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2666 | final long identity = Binder.clearCallingIdentity(); |
| 2667 | try { |
| 2668 | if (phone != null) { |
| 2669 | return phone.getVoiceActivationState(); |
| 2670 | } else { |
| 2671 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2672 | } |
| 2673 | } finally { |
| 2674 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2675 | } |
| 2676 | } |
| 2677 | |
| 2678 | /** |
| 2679 | * Returns the data activation state of a given subId. |
| 2680 | */ |
| 2681 | @Override |
| 2682 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2683 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2684 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2685 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2686 | final long identity = Binder.clearCallingIdentity(); |
| 2687 | try { |
| 2688 | if (phone != null) { |
| 2689 | return phone.getDataActivationState(); |
| 2690 | } else { |
| 2691 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2692 | } |
| 2693 | } finally { |
| 2694 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2695 | } |
| 2696 | } |
| 2697 | |
| 2698 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2699 | * Returns the unread count of voicemails for a subId |
| 2700 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2701 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2702 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2703 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2704 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2705 | return 0; |
| 2706 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2707 | final long identity = Binder.clearCallingIdentity(); |
| 2708 | try { |
| 2709 | final Phone phone = getPhone(subId); |
| 2710 | if (phone != null) { |
| 2711 | return phone.getVoiceMessageCount(); |
| 2712 | } else { |
| 2713 | return 0; |
| 2714 | } |
| 2715 | } finally { |
| 2716 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2717 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2718 | } |
| 2719 | |
| 2720 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2721 | * returns true, if the device is in a state where both voice and data |
| 2722 | * are supported simultaneously. This can change based on location or network condition. |
| 2723 | */ |
| 2724 | @Override |
| 2725 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2726 | final long identity = Binder.clearCallingIdentity(); |
| 2727 | try { |
| 2728 | final Phone phone = getPhone(subId); |
| 2729 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2730 | } finally { |
| 2731 | Binder.restoreCallingIdentity(identity); |
| 2732 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2736 | * Send the dialer code if called from the current default dialer or the caller has |
| 2737 | * carrier privilege. |
| 2738 | * @param inputCode The dialer code to send |
| 2739 | */ |
| 2740 | @Override |
| 2741 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2742 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2743 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2744 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2745 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2746 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2747 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2748 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2749 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2750 | |
| 2751 | final long identity = Binder.clearCallingIdentity(); |
| 2752 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2753 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2754 | } finally { |
| 2755 | Binder.restoreCallingIdentity(identity); |
| 2756 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2757 | } |
| 2758 | |
| 2759 | /** |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2760 | * Returns the data network type. |
| 2761 | * Legacy call, permission-free. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2762 | * |
| 2763 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 2764 | */ |
| 2765 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2766 | public int getNetworkType() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2767 | final long identity = Binder.clearCallingIdentity(); |
| 2768 | try { |
| 2769 | final Phone phone = getPhone(getDefaultSubscription()); |
| 2770 | if (phone != null) { |
| 2771 | return phone.getServiceState().getDataNetworkType(); |
| 2772 | } else { |
| 2773 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2774 | } |
| 2775 | } finally { |
| 2776 | Binder.restoreCallingIdentity(identity); |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2777 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2778 | } |
| 2779 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2780 | @Override |
| 2781 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2782 | if (!isActiveSubscription(subId)) { |
| 2783 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2784 | } |
| 2785 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2786 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2787 | } |
| 2788 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2789 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2790 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2791 | throws RemoteException { |
| 2792 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2793 | final long token = Binder.clearCallingIdentity(); |
| 2794 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2795 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2796 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2797 | .addRegistrationCallbackForSubscription(c, subId); |
| 2798 | } finally { |
| 2799 | Binder.restoreCallingIdentity(token); |
| 2800 | } |
| 2801 | } |
| 2802 | |
| 2803 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2804 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2805 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2806 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2807 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2808 | } |
| 2809 | Binder.withCleanCallingIdentity(() -> { |
| 2810 | try { |
| 2811 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2812 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2813 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2814 | } catch (IllegalArgumentException e) { |
| 2815 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2816 | + "is inactive, ignoring unregister."); |
| 2817 | // If the subscription is no longer active, just return, since the callback |
| 2818 | // will already have been removed internally. |
| 2819 | } |
| 2820 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2821 | } |
| 2822 | |
| 2823 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2824 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2825 | throws RemoteException { |
| 2826 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2827 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2828 | final long token = Binder.clearCallingIdentity(); |
| 2829 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2830 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2831 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2832 | } finally { |
| 2833 | Binder.restoreCallingIdentity(token); |
| 2834 | } |
| 2835 | } |
| 2836 | |
| 2837 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2838 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2839 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2840 | |
| 2841 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2842 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2843 | } |
| 2844 | Binder.withCleanCallingIdentity(() -> { |
| 2845 | try { |
| 2846 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2847 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2848 | .removeCapabilitiesCallbackForSubscription(c, subId); |
| 2849 | } catch (IllegalArgumentException e) { |
| 2850 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2851 | + "is inactive, ignoring unregister."); |
| 2852 | // If the subscription is no longer active, just return, since the callback |
| 2853 | // will already have been removed internally. |
| 2854 | } |
| 2855 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2856 | } |
| 2857 | |
| 2858 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2859 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2860 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2861 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2862 | final long token = Binder.clearCallingIdentity(); |
| 2863 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2864 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2865 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2866 | } catch (ImsException e) { |
| 2867 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2868 | return false; |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2869 | } catch (IllegalArgumentException e) { |
| 2870 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 2871 | return false; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2872 | } finally { |
| 2873 | Binder.restoreCallingIdentity(token); |
| 2874 | } |
| 2875 | } |
| 2876 | |
| 2877 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2878 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2879 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2880 | final long token = Binder.clearCallingIdentity(); |
| 2881 | try { |
| 2882 | Phone phone = getPhone(subId); |
| 2883 | if (phone == null) return false; |
| 2884 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2885 | } finally { |
| 2886 | Binder.restoreCallingIdentity(token); |
| 2887 | } |
| 2888 | } |
| 2889 | |
| 2890 | @Override |
| 2891 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2892 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2893 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2894 | final long token = Binder.clearCallingIdentity(); |
| 2895 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2896 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2897 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2898 | } finally { |
| 2899 | Binder.restoreCallingIdentity(token); |
| 2900 | } |
| 2901 | } |
| 2902 | |
| 2903 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2904 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2905 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2906 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2907 | final long identity = Binder.clearCallingIdentity(); |
| 2908 | try { |
| 2909 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2910 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2911 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 2912 | } finally { |
| 2913 | Binder.restoreCallingIdentity(identity); |
| 2914 | } |
| 2915 | } |
| 2916 | |
| 2917 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2918 | public boolean isVtSettingEnabled(int subId) { |
| 2919 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2920 | final long identity = Binder.clearCallingIdentity(); |
| 2921 | try { |
| 2922 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2923 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2924 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2925 | } finally { |
| 2926 | Binder.restoreCallingIdentity(identity); |
| 2927 | } |
| 2928 | } |
| 2929 | |
| 2930 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2931 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2932 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2933 | "setVtSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2934 | final long identity = Binder.clearCallingIdentity(); |
| 2935 | try { |
| 2936 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2937 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2938 | } finally { |
| 2939 | Binder.restoreCallingIdentity(identity); |
| 2940 | } |
| 2941 | } |
| 2942 | |
| 2943 | @Override |
| 2944 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 2945 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 2946 | final long identity = Binder.clearCallingIdentity(); |
| 2947 | try { |
| 2948 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2949 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2950 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 2951 | } finally { |
| 2952 | Binder.restoreCallingIdentity(identity); |
| 2953 | } |
| 2954 | } |
| 2955 | |
| 2956 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2957 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2958 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2959 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2960 | final long identity = Binder.clearCallingIdentity(); |
| 2961 | try { |
| 2962 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2963 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2964 | } finally { |
| 2965 | Binder.restoreCallingIdentity(identity); |
| 2966 | } |
| 2967 | } |
| 2968 | |
| 2969 | @Override |
| 2970 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 2971 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 2972 | final long identity = Binder.clearCallingIdentity(); |
| 2973 | try { |
| 2974 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2975 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2976 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 2977 | } finally { |
| 2978 | Binder.restoreCallingIdentity(identity); |
| 2979 | } |
| 2980 | } |
| 2981 | |
| 2982 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2983 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2984 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2985 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2986 | final long identity = Binder.clearCallingIdentity(); |
| 2987 | try { |
| 2988 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2989 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2990 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 2991 | } finally { |
| 2992 | Binder.restoreCallingIdentity(identity); |
| 2993 | } |
| 2994 | } |
| 2995 | |
| 2996 | @Override |
| 2997 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 2998 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2999 | "setVoWiFiNonPersistent"); |
| 3000 | final long identity = Binder.clearCallingIdentity(); |
| 3001 | try { |
| 3002 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 3003 | boolean isRoaming = TelephonyManager.from( |
| 3004 | getPhone(subId).getContext()).isNetworkRoaming(subId); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3005 | ImsManager.getInstance(mApp, |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 3006 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3007 | } finally { |
| 3008 | Binder.restoreCallingIdentity(identity); |
| 3009 | } |
| 3010 | } |
| 3011 | |
| 3012 | @Override |
| 3013 | public int getVoWiFiModeSetting(int subId) { |
| 3014 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3015 | final long identity = Binder.clearCallingIdentity(); |
| 3016 | try { |
| 3017 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3018 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3019 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 3020 | } finally { |
| 3021 | Binder.restoreCallingIdentity(identity); |
| 3022 | } |
| 3023 | } |
| 3024 | |
| 3025 | @Override |
| 3026 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3027 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3028 | "setVoWiFiModeSetting"); |
| 3029 | final long identity = Binder.clearCallingIdentity(); |
| 3030 | try { |
| 3031 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3032 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3033 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 3034 | } finally { |
| 3035 | Binder.restoreCallingIdentity(identity); |
| 3036 | } |
| 3037 | } |
| 3038 | |
| 3039 | @Override |
| 3040 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3041 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3042 | final long identity = Binder.clearCallingIdentity(); |
| 3043 | try { |
| 3044 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3045 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3046 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 3047 | } finally { |
| 3048 | Binder.restoreCallingIdentity(identity); |
| 3049 | } |
| 3050 | } |
| 3051 | |
| 3052 | @Override |
| 3053 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3054 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3055 | "setVoWiFiRoamingModeSetting"); |
| 3056 | final long identity = Binder.clearCallingIdentity(); |
| 3057 | try { |
| 3058 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3059 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3060 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 3061 | } finally { |
| 3062 | Binder.restoreCallingIdentity(identity); |
| 3063 | } |
| 3064 | } |
| 3065 | |
| 3066 | @Override |
| 3067 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3068 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3069 | "setRttCapabilityEnabled"); |
| 3070 | final long identity = Binder.clearCallingIdentity(); |
| 3071 | try { |
| 3072 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3073 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3074 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3075 | } finally { |
| 3076 | Binder.restoreCallingIdentity(identity); |
| 3077 | } |
| 3078 | } |
| 3079 | |
| 3080 | @Override |
| 3081 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3082 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3083 | final long identity = Binder.clearCallingIdentity(); |
| 3084 | try { |
| 3085 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3086 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3087 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 3088 | } finally { |
| 3089 | Binder.restoreCallingIdentity(identity); |
| 3090 | } |
| 3091 | } |
| 3092 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3093 | @Override |
| 3094 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3095 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3096 | final long identity = Binder.clearCallingIdentity(); |
| 3097 | try { |
| 3098 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3099 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3100 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3101 | } finally { |
| 3102 | Binder.restoreCallingIdentity(identity); |
| 3103 | } |
| 3104 | } |
| 3105 | |
| 3106 | @Override |
| 3107 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3108 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3109 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3110 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3111 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3112 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3113 | try { |
| 3114 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3115 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3116 | .removeProvisioningCallbackForSubscription(callback, subId); |
| 3117 | } catch (IllegalArgumentException e) { |
| 3118 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3119 | + "is inactive, ignoring unregister."); |
| 3120 | // If the subscription is no longer active, just return, since the callback will already |
| 3121 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3122 | } finally { |
| 3123 | Binder.restoreCallingIdentity(identity); |
| 3124 | } |
| 3125 | } |
| 3126 | |
| 3127 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3128 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3129 | boolean isProvisioned) { |
| 3130 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3131 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3132 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3133 | } |
| 3134 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3135 | "setProvisioningStatusForCapability"); |
| 3136 | final long identity = Binder.clearCallingIdentity(); |
| 3137 | try { |
| 3138 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3139 | Phone phone = getPhone(subId); |
| 3140 | if (phone == null) { |
| 3141 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3142 | + subId); |
| 3143 | return; |
| 3144 | } |
| 3145 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3146 | return; |
| 3147 | } |
| 3148 | |
| 3149 | // this capability requires provisioning, route to the correct API. |
| 3150 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3151 | switch (capability) { |
| 3152 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3153 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3154 | ims.setVolteProvisioned(isProvisioned); |
| 3155 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3156 | ims.setWfcProvisioned(isProvisioned); |
| 3157 | } |
| 3158 | break; |
| 3159 | } |
| 3160 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3161 | // There is currently no difference in VT provisioning type. |
| 3162 | ims.setVtProvisioned(isProvisioned); |
| 3163 | break; |
| 3164 | } |
| 3165 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3166 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3167 | // change the capability of the feature instead if needed. |
| 3168 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3169 | == isProvisioned) { |
| 3170 | // No change in provisioning. |
| 3171 | return; |
| 3172 | } |
| 3173 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3174 | try { |
| 3175 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
| 3176 | } catch (ImsException e) { |
| 3177 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3178 | + ", Exception" + e.getMessage()); |
| 3179 | } |
| 3180 | break; |
| 3181 | } |
| 3182 | default: { |
| 3183 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3184 | + capability + "', which does not require provisioning."); |
| 3185 | } |
| 3186 | } |
| 3187 | |
| 3188 | } finally { |
| 3189 | Binder.restoreCallingIdentity(identity); |
| 3190 | } |
| 3191 | } |
| 3192 | |
| 3193 | @Override |
| 3194 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3195 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3196 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3197 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3198 | } |
| 3199 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3200 | final long identity = Binder.clearCallingIdentity(); |
| 3201 | try { |
| 3202 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3203 | Phone phone = getPhone(subId); |
| 3204 | if (phone == null) { |
| 3205 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3206 | + subId); |
| 3207 | // We will fail with "true" as the provisioning status because this is the default |
| 3208 | // if we do not require provisioning. |
| 3209 | return true; |
| 3210 | } |
| 3211 | |
| 3212 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3213 | return true; |
| 3214 | } |
| 3215 | |
| 3216 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3217 | switch (capability) { |
| 3218 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3219 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3220 | return ims.isVolteProvisionedOnDevice(); |
| 3221 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3222 | return ims.isWfcProvisionedOnDevice(); |
| 3223 | } |
| 3224 | // This should never happen, since we are checking tech above to make sure it |
| 3225 | // is either LTE or IWLAN. |
| 3226 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3227 | + "capability."); |
| 3228 | } |
| 3229 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3230 | // There is currently no difference in VT provisioning type. |
| 3231 | return ims.isVtProvisionedOnDevice(); |
| 3232 | } |
| 3233 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3234 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3235 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3236 | } |
| 3237 | default: { |
| 3238 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3239 | + capability + "', which does not require provisioning."); |
| 3240 | } |
| 3241 | } |
| 3242 | |
| 3243 | } finally { |
| 3244 | Binder.restoreCallingIdentity(identity); |
| 3245 | } |
| 3246 | } |
| 3247 | |
| 3248 | @Override |
| 3249 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3250 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3251 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3252 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3253 | } |
| 3254 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3255 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3256 | return (provisionedBits & capability) > 0; |
| 3257 | } |
| 3258 | |
| 3259 | @Override |
| 3260 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3261 | boolean isProvisioned) { |
| 3262 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3263 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3264 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3265 | } |
| 3266 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3267 | "setProvisioningStatusForCapability"); |
| 3268 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3269 | // If the current provisioning status for capability already matches isProvisioned, |
| 3270 | // do nothing. |
| 3271 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3272 | return; |
| 3273 | } |
| 3274 | if (isProvisioned) { |
| 3275 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3276 | } else { |
| 3277 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3278 | } |
| 3279 | } |
| 3280 | |
| 3281 | /** |
| 3282 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3283 | * technology. The bitfield should mirror the bitfield defined by |
| 3284 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3285 | */ |
| 3286 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3287 | String key = getMmTelProvisioningKey(subId, tech); |
| 3288 | // Default is no capabilities are provisioned. |
| 3289 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3290 | } |
| 3291 | |
| 3292 | /** |
| 3293 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3294 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3295 | * technology specified. |
| 3296 | * |
| 3297 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3298 | */ |
| 3299 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3300 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3301 | String key = getMmTelProvisioningKey(subId, tech); |
| 3302 | editor.putInt(key, newField); |
| 3303 | editor.commit(); |
| 3304 | } |
| 3305 | |
| 3306 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3307 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3308 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3309 | } |
| 3310 | |
| 3311 | /** |
| 3312 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3313 | * carrier associated with the subscription id. |
| 3314 | */ |
| 3315 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3316 | int capability) { |
| 3317 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3318 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3319 | boolean requireUtProvisioning = c.getBoolean( |
| 3320 | // By default, this config is true (even if there is no SIM). We also check to make |
| 3321 | // sure the subscription needs provisioning here, so we do not need to check for |
| 3322 | // the no-SIM case, where we would normally shortcut this to false. |
| 3323 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true) |
| 3324 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3325 | false); |
| 3326 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3327 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3328 | |
| 3329 | // First check to make sure that the capability requires provisioning. |
| 3330 | switch (capability) { |
| 3331 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3332 | // intentional fallthrough |
| 3333 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3334 | if (requireVoiceVtProvisioning) { |
| 3335 | // Voice and Video requires provisioning |
| 3336 | return true; |
| 3337 | } |
| 3338 | break; |
| 3339 | } |
| 3340 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3341 | if (requireUtProvisioning) { |
| 3342 | // UT requires provisioning |
| 3343 | return true; |
| 3344 | } |
| 3345 | break; |
| 3346 | } |
| 3347 | } |
| 3348 | return false; |
| 3349 | } |
| 3350 | |
| 3351 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3352 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3353 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3354 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3355 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3356 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3357 | final long identity = Binder.clearCallingIdentity(); |
| 3358 | try { |
| 3359 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3360 | int slotId = getSlotIndex(subId); |
| 3361 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3362 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3363 | + subId + "' for key:" + key); |
| 3364 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3365 | } |
| 3366 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3367 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3368 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3369 | + subId + "' for key:" + key); |
| 3370 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3371 | } finally { |
| 3372 | Binder.restoreCallingIdentity(identity); |
| 3373 | } |
| 3374 | } |
| 3375 | |
| 3376 | @Override |
| 3377 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3378 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3379 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3380 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3381 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3382 | final long identity = Binder.clearCallingIdentity(); |
| 3383 | try { |
| 3384 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3385 | int slotId = getSlotIndex(subId); |
| 3386 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3387 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3388 | + subId + "' for key:" + key); |
| 3389 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3390 | } |
| 3391 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3392 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3393 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3394 | + subId + "' for key:" + key); |
| 3395 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3396 | } finally { |
| 3397 | Binder.restoreCallingIdentity(identity); |
| 3398 | } |
| 3399 | } |
| 3400 | |
| 3401 | @Override |
| 3402 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3403 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3404 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3405 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3406 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3407 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3408 | final long identity = Binder.clearCallingIdentity(); |
| 3409 | try { |
| 3410 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3411 | int slotId = getSlotIndex(subId); |
| 3412 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3413 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3414 | + subId + "' for key:" + key); |
| 3415 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3416 | } |
| 3417 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3418 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3419 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3420 | + "' for key:" + key); |
| 3421 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3422 | } finally { |
| 3423 | Binder.restoreCallingIdentity(identity); |
| 3424 | } |
| 3425 | } |
| 3426 | |
| 3427 | @Override |
| 3428 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3429 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3430 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3431 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3432 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3433 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3434 | final long identity = Binder.clearCallingIdentity(); |
| 3435 | try { |
| 3436 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3437 | int slotId = getSlotIndex(subId); |
| 3438 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3439 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3440 | + subId + "' for key:" + key); |
| 3441 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3442 | } |
| 3443 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3444 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3445 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3446 | + "' for key:" + key); |
| 3447 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3448 | } finally { |
| 3449 | Binder.restoreCallingIdentity(identity); |
| 3450 | } |
| 3451 | } |
| 3452 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3453 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 3454 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3455 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3456 | throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3457 | } |
| 3458 | return slotId; |
| 3459 | } |
| 3460 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3461 | private int getSlotIndex(int subId) { |
| 3462 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3463 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3464 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3465 | } |
| 3466 | return slotId; |
| 3467 | } |
| 3468 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3469 | /** |
| 3470 | * Returns the network type for a subId |
| 3471 | */ |
| 3472 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3473 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3474 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3475 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3476 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3477 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3478 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3479 | final long identity = Binder.clearCallingIdentity(); |
| 3480 | try { |
| 3481 | final Phone phone = getPhone(subId); |
| 3482 | if (phone != null) { |
| 3483 | return phone.getServiceState().getDataNetworkType(); |
| 3484 | } else { |
| 3485 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3486 | } |
| 3487 | } finally { |
| 3488 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3489 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3490 | } |
| 3491 | |
| 3492 | /** |
| 3493 | * Returns the data network type |
| 3494 | */ |
| 3495 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3496 | public int getDataNetworkType(String callingPackage) { |
| 3497 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3498 | } |
| 3499 | |
| 3500 | /** |
| 3501 | * Returns the data network type for a subId |
| 3502 | */ |
| 3503 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3504 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3505 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3506 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3507 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3508 | } |
| 3509 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3510 | final long identity = Binder.clearCallingIdentity(); |
| 3511 | try { |
| 3512 | final Phone phone = getPhone(subId); |
| 3513 | if (phone != null) { |
| 3514 | return phone.getServiceState().getDataNetworkType(); |
| 3515 | } else { |
| 3516 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3517 | } |
| 3518 | } finally { |
| 3519 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3520 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3521 | } |
| 3522 | |
| 3523 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3524 | * Returns the Voice network type for a subId |
| 3525 | */ |
| 3526 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3527 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3528 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3529 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3530 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3531 | } |
| 3532 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3533 | final long identity = Binder.clearCallingIdentity(); |
| 3534 | try { |
| 3535 | final Phone phone = getPhone(subId); |
| 3536 | if (phone != null) { |
| 3537 | return phone.getServiceState().getVoiceNetworkType(); |
| 3538 | } else { |
| 3539 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3540 | } |
| 3541 | } finally { |
| 3542 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3543 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3544 | } |
| 3545 | |
| 3546 | /** |
| 3547 | * @return true if a ICC card is present |
| 3548 | */ |
| 3549 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3550 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3551 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3552 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3553 | } |
| 3554 | |
| 3555 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3556 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3557 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3558 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3559 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3560 | final long identity = Binder.clearCallingIdentity(); |
| 3561 | try { |
| 3562 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3563 | if (phone != null) { |
| 3564 | return phone.getIccCard().hasIccCard(); |
| 3565 | } else { |
| 3566 | return false; |
| 3567 | } |
| 3568 | } finally { |
| 3569 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3570 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3571 | } |
| 3572 | |
| 3573 | /** |
| 3574 | * Return if the current radio is LTE on CDMA. This |
| 3575 | * is a tri-state return value as for a period of time |
| 3576 | * the mode may be unknown. |
| 3577 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3578 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3579 | * @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] | 3580 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3581 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3582 | @Override |
| 3583 | public int getLteOnCdmaMode(String callingPackage) { |
| 3584 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3585 | } |
| 3586 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3587 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3588 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3589 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3590 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3591 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3592 | } |
| 3593 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3594 | final long identity = Binder.clearCallingIdentity(); |
| 3595 | try { |
| 3596 | final Phone phone = getPhone(subId); |
| 3597 | if (phone == null) { |
| 3598 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3599 | } else { |
| 3600 | return phone.getLteOnCdmaMode(); |
| 3601 | } |
| 3602 | } finally { |
| 3603 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3604 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3605 | } |
| 3606 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3607 | /** |
| 3608 | * {@hide} |
| 3609 | * Returns Default subId, 0 in the case of single standby. |
| 3610 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3611 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3612 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3613 | } |
| 3614 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3615 | private int getSlotForDefaultSubscription() { |
| 3616 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3617 | } |
| 3618 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3619 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3620 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3621 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3622 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3623 | private boolean isActiveSubscription(int subId) { |
| 3624 | return mSubscriptionController.isActiveSubId(subId); |
| 3625 | } |
| 3626 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3627 | /** |
| 3628 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3629 | */ |
| 3630 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3631 | final long identity = Binder.clearCallingIdentity(); |
| 3632 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3633 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3634 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3635 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3636 | } finally { |
| 3637 | Binder.restoreCallingIdentity(identity); |
| 3638 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3639 | } |
| 3640 | |
| 3641 | /** |
| 3642 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3643 | */ |
| 3644 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3645 | final long identity = Binder.clearCallingIdentity(); |
| 3646 | try { |
| 3647 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3648 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3649 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3650 | } finally { |
| 3651 | Binder.restoreCallingIdentity(identity); |
| 3652 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3653 | } |
| 3654 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3655 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3656 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3657 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3658 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3659 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3660 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3661 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3662 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3663 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3664 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3665 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3666 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3667 | final long identity = Binder.clearCallingIdentity(); |
| 3668 | try { |
| 3669 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3670 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3671 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3672 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3673 | if (bestComponent == null |
| 3674 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3675 | loge("The calling package is not allowed to access ISD-R."); |
| 3676 | throw new SecurityException( |
| 3677 | "The calling package is not allowed to access ISD-R."); |
| 3678 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3679 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3680 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3681 | if (DBG) { |
| 3682 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3683 | } |
| 3684 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
| 3685 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId); |
| 3686 | if (DBG) log("iccOpenLogicalChannel: " + response); |
| 3687 | return response; |
| 3688 | } finally { |
| 3689 | Binder.restoreCallingIdentity(identity); |
| 3690 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3691 | } |
| 3692 | |
| 3693 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3694 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3695 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3696 | mApp, subId, "iccCloseLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3697 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3698 | final long identity = Binder.clearCallingIdentity(); |
| 3699 | try { |
| 3700 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3701 | if (channel < 0) { |
| 3702 | return false; |
| 3703 | } |
| 3704 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId); |
| 3705 | if (DBG) log("iccCloseLogicalChannel: " + success); |
| 3706 | return success; |
| 3707 | } finally { |
| 3708 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3709 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3710 | } |
| 3711 | |
| 3712 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3713 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3714 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3715 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3716 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3717 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3718 | final long identity = Binder.clearCallingIdentity(); |
| 3719 | try { |
| 3720 | if (DBG) { |
| 3721 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3722 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3723 | + p3 + " data=" + data); |
| 3724 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3725 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3726 | if (channel < 0) { |
| 3727 | return ""; |
| 3728 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3729 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3730 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
| 3731 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId); |
| 3732 | if (DBG) log("iccTransmitApduLogicalChannel: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3733 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3734 | // Append the returned status code to the end of the response payload. |
| 3735 | String s = Integer.toHexString( |
| 3736 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3737 | if (response.payload != null) { |
| 3738 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3739 | } |
| 3740 | return s; |
| 3741 | } finally { |
| 3742 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3743 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3744 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3745 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3746 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3747 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3748 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3749 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3750 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3751 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3752 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3753 | final long identity = Binder.clearCallingIdentity(); |
| 3754 | try { |
| 3755 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3756 | && TextUtils.equals(ISDR_AID, data)) { |
| 3757 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3758 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3759 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3760 | if (bestComponent == null |
| 3761 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3762 | loge("The calling package is not allowed to select ISD-R."); |
| 3763 | throw new SecurityException( |
| 3764 | "The calling package is not allowed to select ISD-R."); |
| 3765 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3766 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3767 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3768 | if (DBG) { |
| 3769 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3770 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3771 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3772 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3773 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
| 3774 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId); |
| 3775 | if (DBG) log("iccTransmitApduBasicChannel: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3776 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3777 | // Append the returned status code to the end of the response payload. |
| 3778 | String s = Integer.toHexString( |
| 3779 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3780 | if (response.payload != null) { |
| 3781 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3782 | } |
| 3783 | return s; |
| 3784 | } finally { |
| 3785 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3786 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3787 | } |
| 3788 | |
| 3789 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3790 | 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] | 3791 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3792 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3793 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3794 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3795 | final long identity = Binder.clearCallingIdentity(); |
| 3796 | try { |
| 3797 | if (DBG) { |
| 3798 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3799 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3800 | } |
| 3801 | |
| 3802 | IccIoResult response = |
| 3803 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3804 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3805 | subId); |
| 3806 | |
| 3807 | if (DBG) { |
| 3808 | log("Exchange SIM_IO [R]" + response); |
| 3809 | } |
| 3810 | |
| 3811 | byte[] result = null; |
| 3812 | int length = 2; |
| 3813 | if (response.payload != null) { |
| 3814 | length = 2 + response.payload.length; |
| 3815 | result = new byte[length]; |
| 3816 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3817 | } else { |
| 3818 | result = new byte[length]; |
| 3819 | } |
| 3820 | |
| 3821 | result[length - 1] = (byte) response.sw2; |
| 3822 | result[length - 2] = (byte) response.sw1; |
| 3823 | return result; |
| 3824 | } finally { |
| 3825 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3826 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3827 | } |
| 3828 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3829 | /** |
| 3830 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 3831 | * on a particular subscription |
| 3832 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3833 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 3834 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3835 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 3836 | return null; |
| 3837 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3838 | |
| 3839 | final long identity = Binder.clearCallingIdentity(); |
| 3840 | try { |
| 3841 | if (appType != TelephonyManager.APPTYPE_USIM |
| 3842 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 3843 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 3844 | return null; |
| 3845 | } |
| 3846 | Object response = sendRequest( |
| 3847 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 3848 | if (response instanceof String[]) { |
| 3849 | return (String[]) response; |
| 3850 | } |
| 3851 | // Response is an Exception of some kind, |
| 3852 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3853 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3854 | } finally { |
| 3855 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3856 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3857 | } |
| 3858 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3859 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3860 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3861 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3862 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3863 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3864 | final long identity = Binder.clearCallingIdentity(); |
| 3865 | try { |
| 3866 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 3867 | if (response.payload == null) { |
| 3868 | return ""; |
| 3869 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3870 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3871 | // Append the returned status code to the end of the response payload. |
| 3872 | String s = Integer.toHexString( |
| 3873 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3874 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3875 | return s; |
| 3876 | } finally { |
| 3877 | Binder.restoreCallingIdentity(identity); |
| 3878 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3879 | } |
| 3880 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3881 | /** |
| 3882 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3883 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3884 | * |
| 3885 | * @param itemID the ID of the item to read |
| 3886 | * @return the NV item as a String, or null on error. |
| 3887 | */ |
| 3888 | @Override |
| 3889 | public String nvReadItem(int itemID) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3890 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3891 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3892 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3893 | |
| 3894 | final long identity = Binder.clearCallingIdentity(); |
| 3895 | try { |
| 3896 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3897 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3898 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 3899 | return value; |
| 3900 | } finally { |
| 3901 | Binder.restoreCallingIdentity(identity); |
| 3902 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3903 | } |
| 3904 | |
| 3905 | /** |
| 3906 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3907 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3908 | * |
| 3909 | * @param itemID the ID of the item to read |
| 3910 | * @param itemValue the value to write, as a String |
| 3911 | * @return true on success; false on any failure |
| 3912 | */ |
| 3913 | @Override |
| 3914 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3915 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3916 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3917 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3918 | |
| 3919 | final long identity = Binder.clearCallingIdentity(); |
| 3920 | try { |
| 3921 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 3922 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3923 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3924 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 3925 | return success; |
| 3926 | } finally { |
| 3927 | Binder.restoreCallingIdentity(identity); |
| 3928 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3929 | } |
| 3930 | |
| 3931 | /** |
| 3932 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 3933 | * Used for device configuration by some CDMA operators. |
| 3934 | * |
| 3935 | * @param preferredRoamingList byte array containing the new PRL |
| 3936 | * @return true on success; false on any failure |
| 3937 | */ |
| 3938 | @Override |
| 3939 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3940 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3941 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3942 | |
| 3943 | final long identity = Binder.clearCallingIdentity(); |
| 3944 | try { |
| 3945 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 3946 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 3947 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 3948 | return success; |
| 3949 | } finally { |
| 3950 | Binder.restoreCallingIdentity(identity); |
| 3951 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3952 | } |
| 3953 | |
| 3954 | /** |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3955 | * 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] | 3956 | * Used for device configuration by some CDMA operators. |
| 3957 | * |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3958 | * @param slotIndex - device slot. |
| 3959 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3960 | * @return true on success; false on any failure |
| 3961 | */ |
| 3962 | @Override |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3963 | public boolean resetModemConfig(int slotIndex) { |
| 3964 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3965 | if (phone != null) { |
| 3966 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3967 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3968 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3969 | final long identity = Binder.clearCallingIdentity(); |
| 3970 | try { |
| 3971 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 3972 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 3973 | return success; |
| 3974 | } finally { |
| 3975 | Binder.restoreCallingIdentity(identity); |
| 3976 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3977 | } |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3978 | return false; |
| 3979 | } |
| 3980 | |
| 3981 | /** |
| 3982 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 3983 | * |
| 3984 | * @param slotIndex - device slot. |
| 3985 | * |
| 3986 | * @return true on success; false on any failure |
| 3987 | */ |
| 3988 | @Override |
| 3989 | public boolean rebootModem(int slotIndex) { |
| 3990 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3991 | if (phone != null) { |
| 3992 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3993 | mApp, phone.getSubId(), "rebootModem"); |
| 3994 | |
| 3995 | final long identity = Binder.clearCallingIdentity(); |
| 3996 | try { |
| 3997 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 3998 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 3999 | return success; |
| 4000 | } finally { |
| 4001 | Binder.restoreCallingIdentity(identity); |
| 4002 | } |
| 4003 | } |
| 4004 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4005 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4006 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4007 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4008 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4009 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4010 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4011 | return new String[0]; |
| 4012 | } |
| 4013 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4014 | final long identity = Binder.clearCallingIdentity(); |
| 4015 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4016 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4017 | } finally { |
| 4018 | Binder.restoreCallingIdentity(identity); |
| 4019 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4020 | } |
| 4021 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4022 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4023 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4024 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4025 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4026 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4027 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4028 | |
| 4029 | final long identity = Binder.clearCallingIdentity(); |
| 4030 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame^] | 4031 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4032 | if (resolver == null) { |
| 4033 | // may happen if the device does not support IMS. |
| 4034 | return; |
| 4035 | } |
| 4036 | resolver.enableIms(slotId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4037 | } finally { |
| 4038 | Binder.restoreCallingIdentity(identity); |
| 4039 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4040 | } |
| 4041 | |
| 4042 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4043 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4044 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4045 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4046 | public void disableIms(int slotId) { |
| 4047 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4048 | |
| 4049 | final long identity = Binder.clearCallingIdentity(); |
| 4050 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame^] | 4051 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4052 | if (resolver == null) { |
| 4053 | // may happen if the device does not support IMS. |
| 4054 | return; |
| 4055 | } |
| 4056 | resolver.disableIms(slotId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4057 | } finally { |
| 4058 | Binder.restoreCallingIdentity(identity); |
| 4059 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4060 | } |
| 4061 | |
| 4062 | /** |
| 4063 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4064 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4065 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4066 | */ |
| 4067 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4068 | IImsServiceFeatureCallback callback) { |
| 4069 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4070 | |
| 4071 | final long identity = Binder.clearCallingIdentity(); |
| 4072 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame^] | 4073 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4074 | if (resolver == null) { |
| 4075 | // may happen if the device does not support IMS. |
| 4076 | return null; |
| 4077 | } |
| 4078 | return resolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4079 | } finally { |
| 4080 | Binder.restoreCallingIdentity(identity); |
| 4081 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4082 | } |
| 4083 | |
| 4084 | /** |
| 4085 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4086 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4087 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4088 | * listener for feature updates. |
| 4089 | */ |
| 4090 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4091 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4092 | |
| 4093 | final long identity = Binder.clearCallingIdentity(); |
| 4094 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame^] | 4095 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4096 | if (resolver == null) { |
| 4097 | // may happen if the device does not support IMS. |
| 4098 | return null; |
| 4099 | } |
| 4100 | return resolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4101 | } finally { |
| 4102 | Binder.restoreCallingIdentity(identity); |
| 4103 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4104 | } |
| 4105 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4106 | /** |
| 4107 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame^] | 4108 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4109 | */ |
| 4110 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4111 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4112 | |
| 4113 | final long identity = Binder.clearCallingIdentity(); |
| 4114 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame^] | 4115 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4116 | if (resolver == null) { |
| 4117 | // may happen if the device does not support IMS. |
| 4118 | return null; |
| 4119 | } |
| 4120 | return resolver.getImsRegistration(slotId, feature); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4121 | } finally { |
| 4122 | Binder.restoreCallingIdentity(identity); |
| 4123 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4124 | } |
| 4125 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4126 | /** |
| 4127 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame^] | 4128 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4129 | */ |
| 4130 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4131 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4132 | |
| 4133 | final long identity = Binder.clearCallingIdentity(); |
| 4134 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame^] | 4135 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4136 | if (resolver == null) { |
| 4137 | // may happen if the device does not support IMS. |
| 4138 | return null; |
| 4139 | } |
| 4140 | return resolver.getImsConfig(slotId, feature); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4141 | } finally { |
| 4142 | Binder.restoreCallingIdentity(identity); |
| 4143 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4144 | } |
| 4145 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4146 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4147 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4148 | * |
| 4149 | * @param slotId the slot ID that the ImsService should bind for. |
| 4150 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4151 | * ImsService is the device default ImsService. |
| 4152 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4153 | * to. |
| 4154 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4155 | * @hide |
| 4156 | */ |
| 4157 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4158 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4159 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4160 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4161 | "setImsService"); |
| 4162 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4163 | final long identity = Binder.clearCallingIdentity(); |
| 4164 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame^] | 4165 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4166 | if (resolver == null) { |
| 4167 | // may happen if the device does not support IMS. |
| 4168 | return false; |
| 4169 | } |
| 4170 | return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService, |
| 4171 | packageName); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4172 | } finally { |
| 4173 | Binder.restoreCallingIdentity(identity); |
| 4174 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | /** |
| 4178 | * Return the ImsService configuration. |
| 4179 | * |
| 4180 | * @param slotId The slot that the ImsService is associated with. |
| 4181 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4182 | * the device default. |
| 4183 | * @return the package name of the ImsService configuration. |
| 4184 | */ |
| 4185 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4186 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4187 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4188 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4189 | "getImsService"); |
| 4190 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4191 | final long identity = Binder.clearCallingIdentity(); |
| 4192 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame^] | 4193 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4194 | if (resolver == null) { |
| 4195 | // may happen if the device does not support IMS. |
| 4196 | return ""; |
| 4197 | } |
| 4198 | return resolver.getImsServiceConfiguration(slotId, isCarrierImsService); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4199 | } finally { |
| 4200 | Binder.restoreCallingIdentity(identity); |
| 4201 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4202 | } |
| 4203 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4204 | public void setImsRegistrationState(boolean registered) { |
| 4205 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4206 | |
| 4207 | final long identity = Binder.clearCallingIdentity(); |
| 4208 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4209 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4210 | } finally { |
| 4211 | Binder.restoreCallingIdentity(identity); |
| 4212 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4213 | } |
| 4214 | |
| 4215 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4216 | * Set the network selection mode to automatic. |
| 4217 | * |
| 4218 | */ |
| 4219 | @Override |
| 4220 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4221 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4222 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4223 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4224 | if (!isActiveSubscription(subId)) { |
| 4225 | return; |
| 4226 | } |
| 4227 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4228 | final long identity = Binder.clearCallingIdentity(); |
| 4229 | try { |
| 4230 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4231 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4232 | } finally { |
| 4233 | Binder.restoreCallingIdentity(identity); |
| 4234 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4235 | } |
| 4236 | |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4237 | /** |
| 4238 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4239 | * |
| 4240 | * @param subId the id of the subscription. |
| 4241 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4242 | * the operator to attach to. |
| 4243 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4244 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4245 | * normal network selection next time. |
| 4246 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4247 | */ |
| 4248 | @Override |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4249 | public boolean setNetworkSelectionModeManual( |
| 4250 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4251 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4252 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4253 | |
| 4254 | if (!isActiveSubscription(subId)) { |
| 4255 | return false; |
| 4256 | } |
| 4257 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4258 | final long identity = Binder.clearCallingIdentity(); |
| 4259 | try { |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4260 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4261 | persistSelection); |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4262 | if (DBG) { |
| 4263 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4264 | + " operator: " + operatorInfo); |
| 4265 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4266 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4267 | } finally { |
| 4268 | Binder.restoreCallingIdentity(identity); |
| 4269 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4270 | } |
| 4271 | |
| 4272 | /** |
| 4273 | * Scans for available networks. |
| 4274 | */ |
| 4275 | @Override |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4276 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4277 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4278 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4279 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4280 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4281 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4282 | .setCallingPackage(callingPackage) |
| 4283 | .setCallingPid(Binder.getCallingPid()) |
| 4284 | .setCallingUid(Binder.getCallingUid()) |
| 4285 | .setMethod("getCellNetworkScanResults") |
| 4286 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4287 | .build()); |
| 4288 | switch (locationResult) { |
| 4289 | case DENIED_HARD: |
| 4290 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4291 | case DENIED_SOFT: |
| 4292 | return null; |
| 4293 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4294 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4295 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4296 | try { |
| 4297 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4298 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4299 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4300 | } finally { |
| 4301 | Binder.restoreCallingIdentity(identity); |
| 4302 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4303 | } |
| 4304 | |
| 4305 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4306 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4307 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4308 | * @param subId id of the subscription |
| 4309 | * @param request contains the radio access networks with bands/channels to scan |
| 4310 | * @param messenger callback messenger for scan results or errors |
| 4311 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4312 | * @return the id of the requested scan which can be used to stop the scan. |
| 4313 | */ |
| 4314 | @Override |
| 4315 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4316 | IBinder binder, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4317 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4318 | mApp, subId, "requestNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4319 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4320 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4321 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4322 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4323 | .setCallingPackage(callingPackage) |
| 4324 | .setCallingPid(Binder.getCallingPid()) |
| 4325 | .setCallingUid(Binder.getCallingUid()) |
| 4326 | .setMethod("requestNetworkScan") |
| 4327 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4328 | .build()); |
| 4329 | switch (locationResult) { |
| 4330 | case DENIED_HARD: |
| 4331 | throw new SecurityException("Not allowed to request network scan -- location"); |
| 4332 | case DENIED_SOFT: |
| 4333 | return -1; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4334 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4335 | |
| 4336 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4337 | request, messenger, binder, getPhone(subId), |
| 4338 | callingPackage); |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4339 | } |
| 4340 | |
| 4341 | /** |
| 4342 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4343 | * |
| 4344 | * @param subId id of the subscription |
| 4345 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4346 | */ |
| 4347 | @Override |
| 4348 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4349 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4350 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4351 | |
| 4352 | final long identity = Binder.clearCallingIdentity(); |
| 4353 | try { |
| 4354 | mNetworkScanRequestTracker.stopNetworkScan(scanId); |
| 4355 | } finally { |
| 4356 | Binder.restoreCallingIdentity(identity); |
| 4357 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4358 | } |
| 4359 | |
| 4360 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4361 | * Get the calculated preferred network type. |
| 4362 | * Used for debugging incorrect network type. |
| 4363 | * |
| 4364 | * @return the preferred network type, defined in RILConstants.java. |
| 4365 | */ |
| 4366 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4367 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4368 | final Phone defaultPhone = getDefaultPhone(); |
| 4369 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4370 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4371 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4372 | } |
| 4373 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4374 | final long identity = Binder.clearCallingIdentity(); |
| 4375 | try { |
| 4376 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4377 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4378 | } finally { |
| 4379 | Binder.restoreCallingIdentity(identity); |
| 4380 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4381 | } |
| 4382 | |
| 4383 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4384 | * Get the preferred network type. |
| 4385 | * Used for device configuration by some CDMA operators. |
| 4386 | * |
| 4387 | * @return the preferred network type, defined in RILConstants.java. |
| 4388 | */ |
| 4389 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4390 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | 4848cd0 | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4391 | TelephonyPermissions |
| 4392 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4393 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4394 | |
| 4395 | final long identity = Binder.clearCallingIdentity(); |
| 4396 | try { |
| 4397 | if (DBG) log("getPreferredNetworkType"); |
| 4398 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4399 | int networkType = (result != null ? result[0] : -1); |
| 4400 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4401 | return networkType; |
| 4402 | } finally { |
| 4403 | Binder.restoreCallingIdentity(identity); |
| 4404 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4405 | } |
| 4406 | |
| 4407 | /** |
| 4408 | * Set the preferred network type. |
| 4409 | * Used for device configuration by some CDMA operators. |
| 4410 | * |
| 4411 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4412 | * @return true on success; false on any failure. |
| 4413 | */ |
| 4414 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4415 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4416 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4417 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4418 | |
| 4419 | final long identity = Binder.clearCallingIdentity(); |
| 4420 | try { |
| 4421 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4422 | Boolean success = (Boolean) sendRequest( |
| 4423 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4424 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4425 | if (success) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4426 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4427 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4428 | } |
| 4429 | return success; |
| 4430 | } finally { |
| 4431 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4432 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4433 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4434 | |
| 4435 | /** |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4436 | * Check whether DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4437 | * |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4438 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4439 | * @hide |
| 4440 | */ |
| 4441 | @Override |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4442 | public boolean getTetherApnRequired() { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4443 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4444 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4445 | final Phone defaultPhone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4446 | try { |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4447 | return defaultPhone.hasMatchedTetherApnSetting(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4448 | } finally { |
| 4449 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4450 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4451 | } |
| 4452 | |
| 4453 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4454 | * Set mobile data enabled |
| 4455 | * Used by the user through settings etc to turn on/off mobile data |
| 4456 | * |
| 4457 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4458 | */ |
| 4459 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4460 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4461 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4462 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4463 | |
| 4464 | final long identity = Binder.clearCallingIdentity(); |
| 4465 | try { |
| 4466 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4467 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4468 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4469 | if (phone != null) { |
| 4470 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4471 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4472 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4473 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4474 | } |
| 4475 | } finally { |
| 4476 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4477 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4478 | } |
| 4479 | |
| 4480 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4481 | * Get the user enabled state of Mobile Data. |
| 4482 | * |
| 4483 | * TODO: remove and use isUserDataEnabled. |
| 4484 | * This can't be removed now because some vendor codes |
| 4485 | * calls through ITelephony directly while they should |
| 4486 | * use TelephonyManager. |
| 4487 | * |
| 4488 | * @return true on enabled |
| 4489 | */ |
| 4490 | @Override |
| 4491 | public boolean getDataEnabled(int subId) { |
| 4492 | return isUserDataEnabled(subId); |
| 4493 | } |
| 4494 | |
| 4495 | /** |
| 4496 | * Get whether mobile data is enabled per user setting. |
| 4497 | * |
| 4498 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4499 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4500 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4501 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4502 | * |
| 4503 | * @return {@code true} if data is enabled else {@code false} |
| 4504 | */ |
| 4505 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4506 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4507 | try { |
| 4508 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4509 | null); |
| 4510 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4511 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4512 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4513 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4514 | |
| 4515 | final long identity = Binder.clearCallingIdentity(); |
| 4516 | try { |
| 4517 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4518 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4519 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4520 | if (phone != null) { |
| 4521 | boolean retVal = phone.isUserDataEnabled(); |
| 4522 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4523 | return retVal; |
| 4524 | } else { |
| 4525 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4526 | return false; |
| 4527 | } |
| 4528 | } finally { |
| 4529 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4530 | } |
| 4531 | } |
| 4532 | |
| 4533 | /** |
| 4534 | * Get whether mobile data is enabled. |
| 4535 | * |
| 4536 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4537 | * whether mobile data is actually enabled. |
| 4538 | * |
| 4539 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4540 | * |
| 4541 | * @return {@code true} if data is enabled else {@code false} |
| 4542 | */ |
| 4543 | @Override |
| 4544 | public boolean isDataEnabled(int subId) { |
| 4545 | try { |
| 4546 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4547 | null); |
| 4548 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4549 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4550 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4551 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4552 | |
| 4553 | final long identity = Binder.clearCallingIdentity(); |
| 4554 | try { |
| 4555 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4556 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4557 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4558 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4559 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4560 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4561 | return retVal; |
| 4562 | } else { |
| 4563 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4564 | return false; |
| 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 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4570 | |
| 4571 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4572 | public int getCarrierPrivilegeStatus(int subId) { |
| 4573 | final Phone phone = getPhone(subId); |
| 4574 | if (phone == null) { |
| 4575 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4576 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4577 | } |
| 4578 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4579 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4580 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4581 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4582 | } |
| 4583 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4584 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4585 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4586 | |
| 4587 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4588 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4589 | final Phone phone = getPhone(subId); |
| 4590 | if (phone == null) { |
| 4591 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4592 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4593 | } |
| 4594 | UiccProfile profile = |
| 4595 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4596 | if (profile == null) { |
| 4597 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4598 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4599 | } |
| 4600 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 4601 | } |
| 4602 | |
| 4603 | @Override |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4604 | public int checkCarrierPrivilegesForPackage(String pkgName) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4605 | final Phone defaultPhone = getDefaultPhone(); |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4606 | if (TextUtils.isEmpty(pkgName)) |
| 4607 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4608 | UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4609 | if (card == null) { |
| 4610 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 4611 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4612 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4613 | return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(), |
| 4614 | pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4615 | } |
| 4616 | |
| 4617 | @Override |
| 4618 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4619 | if (TextUtils.isEmpty(pkgName)) |
| 4620 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4621 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4622 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4623 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4624 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4625 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4626 | continue; |
| 4627 | } |
| 4628 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4629 | result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4630 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4631 | break; |
| 4632 | } |
| 4633 | } |
| 4634 | |
| 4635 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4636 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4637 | |
| 4638 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4639 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4640 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4641 | loge("phoneId " + phoneId + " is not valid."); |
| 4642 | return null; |
| 4643 | } |
| 4644 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4645 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4646 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4647 | return null ; |
| 4648 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4649 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4650 | } |
| 4651 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4652 | @Override |
| 4653 | public List<String> getPackagesWithCarrierPrivileges() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4654 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4655 | List<String> privilegedPackages = new ArrayList<>(); |
| 4656 | List<PackageInfo> packages = null; |
| 4657 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4658 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4659 | if (card == null) { |
| 4660 | // No UICC in that slot. |
| 4661 | continue; |
| 4662 | } |
| 4663 | if (card.hasCarrierPrivilegeRules()) { |
| 4664 | if (packages == null) { |
| 4665 | // Only check packages in user 0 for now |
| 4666 | packages = pm.getInstalledPackagesAsUser( |
| 4667 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4668 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4669 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
| 4670 | } |
| 4671 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4672 | PackageInfo pkgInfo = packages.get(p); |
| 4673 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4674 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| 4675 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4676 | privilegedPackages.add(pkgInfo.packageName); |
| 4677 | } |
| 4678 | } |
| 4679 | } |
| 4680 | } |
| 4681 | return privilegedPackages; |
| 4682 | } |
| 4683 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4684 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4685 | final Phone phone = getPhone(subId); |
| 4686 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4687 | if (card == null) { |
| 4688 | loge("getIccId: No UICC"); |
| 4689 | return null; |
| 4690 | } |
| 4691 | String iccId = card.getIccId(); |
| 4692 | if (TextUtils.isEmpty(iccId)) { |
| 4693 | loge("getIccId: ICC ID is null or empty."); |
| 4694 | return null; |
| 4695 | } |
| 4696 | return iccId; |
| 4697 | } |
| 4698 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4699 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4700 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4701 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4702 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4703 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4704 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4705 | final long identity = Binder.clearCallingIdentity(); |
| 4706 | try { |
| 4707 | final String iccId = getIccId(subId); |
| 4708 | final Phone phone = getPhone(subId); |
| 4709 | if (phone == null) { |
| 4710 | return false; |
| 4711 | } |
| 4712 | final String subscriberId = phone.getSubscriberId(); |
| 4713 | |
| 4714 | if (DBG_MERGE) { |
| 4715 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4716 | + subscriberId + " to " + number); |
| 4717 | } |
| 4718 | |
| 4719 | if (TextUtils.isEmpty(iccId)) { |
| 4720 | return false; |
| 4721 | } |
| 4722 | |
| 4723 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4724 | |
| 4725 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4726 | if (alphaTag == null) { |
| 4727 | editor.remove(alphaTagPrefKey); |
| 4728 | } else { |
| 4729 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4730 | } |
| 4731 | |
| 4732 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4733 | // track all merged IMSIs based on line number |
| 4734 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4735 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4736 | if (number == null) { |
| 4737 | editor.remove(numberPrefKey); |
| 4738 | editor.remove(subscriberPrefKey); |
| 4739 | } else { |
| 4740 | editor.putString(numberPrefKey, number); |
| 4741 | editor.putString(subscriberPrefKey, subscriberId); |
| 4742 | } |
| 4743 | |
| 4744 | editor.commit(); |
| 4745 | return true; |
| 4746 | } finally { |
| 4747 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4748 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4749 | } |
| 4750 | |
| 4751 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4752 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4753 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4754 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4755 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4756 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4757 | return null; |
| 4758 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4759 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4760 | final long identity = Binder.clearCallingIdentity(); |
| 4761 | try { |
| 4762 | String iccId = getIccId(subId); |
| 4763 | if (iccId != null) { |
| 4764 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4765 | if (DBG_MERGE) { |
| 4766 | log("getLine1NumberForDisplay returning " |
| 4767 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 4768 | } |
| 4769 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4770 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4771 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 4772 | return null; |
| 4773 | } finally { |
| 4774 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4775 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4776 | } |
| 4777 | |
| 4778 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4779 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4780 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4781 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4782 | return null; |
| 4783 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4784 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4785 | final long identity = Binder.clearCallingIdentity(); |
| 4786 | try { |
| 4787 | String iccId = getIccId(subId); |
| 4788 | if (iccId != null) { |
| 4789 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4790 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 4791 | } |
| 4792 | return null; |
| 4793 | } finally { |
| 4794 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4795 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4796 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4797 | |
| 4798 | @Override |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4799 | public String[] getMergedSubscriberIds(String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4800 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 4801 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4802 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4803 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 4804 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4805 | return null; |
| 4806 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4807 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4808 | final long identity = Binder.clearCallingIdentity(); |
| 4809 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4810 | final Context context = mApp; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4811 | final TelephonyManager tele = TelephonyManager.from(context); |
| 4812 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 4813 | |
| 4814 | // Figure out what subscribers are currently active |
| 4815 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
| 4816 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 4817 | // the process, where TelephonyManager was instantiated. |
| 4818 | // Otherwise AppOps check will fail. |
| 4819 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4820 | final int[] subIds = sub.getActiveSubscriptionIdList(); |
| 4821 | for (int subId : subIds) { |
| 4822 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 4823 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4824 | |
| 4825 | // First pass, find a number override for an active subscriber |
| 4826 | String mergeNumber = null; |
| 4827 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 4828 | for (String key : prefs.keySet()) { |
| 4829 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 4830 | final String subscriberId = (String) prefs.get(key); |
| 4831 | if (activeSubscriberIds.contains(subscriberId)) { |
| 4832 | final String iccId = key.substring( |
| 4833 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 4834 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4835 | mergeNumber = (String) prefs.get(numberKey); |
| 4836 | if (DBG_MERGE) { |
| 4837 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 4838 | + " for active subscriber " + subscriberId); |
| 4839 | } |
| 4840 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 4841 | break; |
| 4842 | } |
| 4843 | } |
| 4844 | } |
| 4845 | } |
| 4846 | |
| 4847 | // Shortcut when no active merged subscribers |
| 4848 | if (TextUtils.isEmpty(mergeNumber)) { |
| 4849 | return null; |
| 4850 | } |
| 4851 | |
| 4852 | // Second pass, find all subscribers under that line override |
| 4853 | final ArraySet<String> result = new ArraySet<>(); |
| 4854 | for (String key : prefs.keySet()) { |
| 4855 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 4856 | final String number = (String) prefs.get(key); |
| 4857 | if (mergeNumber.equals(number)) { |
| 4858 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 4859 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4860 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 4861 | if (!TextUtils.isEmpty(subscriberId)) { |
| 4862 | result.add(subscriberId); |
| 4863 | } |
| 4864 | } |
| 4865 | } |
| 4866 | } |
| 4867 | |
| 4868 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 4869 | Arrays.sort(resultArray); |
| 4870 | if (DBG_MERGE) { |
| 4871 | Slog.d(LOG_TAG, |
| 4872 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 4873 | } |
| 4874 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4875 | } finally { |
| 4876 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4877 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4878 | } |
| 4879 | |
| 4880 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4881 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4882 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4883 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4884 | |
| 4885 | final long identity = Binder.clearCallingIdentity(); |
| 4886 | try { |
| 4887 | final Phone phone = getPhone(subId); |
| 4888 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 4889 | } finally { |
| 4890 | Binder.restoreCallingIdentity(identity); |
| 4891 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4892 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 4893 | |
| 4894 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4895 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4896 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 4897 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4898 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4899 | |
| 4900 | final long identity = Binder.clearCallingIdentity(); |
| 4901 | try { |
| 4902 | final Phone phone = getPhone(subId); |
| 4903 | if (phone == null) { |
| 4904 | return false; |
| 4905 | } |
| 4906 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 4907 | cdmaNonRoamingList); |
| 4908 | } finally { |
| 4909 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4910 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4911 | } |
| 4912 | |
| 4913 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4914 | @Deprecated |
| 4915 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 4916 | enforceModifyPermission(); |
| 4917 | |
| 4918 | int returnValue = 0; |
| 4919 | try { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4920 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4921 | if(result.exception == null) { |
| 4922 | if (result.result != null) { |
| 4923 | byte[] responseData = (byte[])(result.result); |
| 4924 | if(responseData.length > oemResp.length) { |
| 4925 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 4926 | responseData.length + "bytes. Buffer Size is " + |
| 4927 | oemResp.length + "bytes."); |
| 4928 | } |
| 4929 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 4930 | returnValue = responseData.length; |
| 4931 | } |
| 4932 | } else { |
| 4933 | CommandException ex = (CommandException) result.exception; |
| 4934 | returnValue = ex.getCommandError().ordinal(); |
| 4935 | if(returnValue > 0) returnValue *= -1; |
| 4936 | } |
| 4937 | } catch (RuntimeException e) { |
| 4938 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 4939 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 4940 | if(returnValue > 0) returnValue *= -1; |
| 4941 | } |
| 4942 | |
| 4943 | return returnValue; |
| 4944 | } |
| 4945 | |
| 4946 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4947 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 4948 | try { |
| 4949 | ProxyController.getInstance().setRadioCapability(rafs); |
| 4950 | } catch (RuntimeException e) { |
| 4951 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 4952 | } |
| 4953 | } |
| 4954 | |
| 4955 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4956 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4957 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4958 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4959 | if (phone == null) { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4960 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4961 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4962 | final long identity = Binder.clearCallingIdentity(); |
| 4963 | try { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4964 | TelephonyPermissions |
| 4965 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4966 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 4967 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4968 | } finally { |
| 4969 | Binder.restoreCallingIdentity(identity); |
| 4970 | } |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4971 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4972 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4973 | |
| 4974 | @Override |
| 4975 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4976 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4977 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4978 | |
| 4979 | final long identity = Binder.clearCallingIdentity(); |
| 4980 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4981 | ImsManager.getInstance(defaultPhone.getContext(), |
| 4982 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4983 | } finally { |
| 4984 | Binder.restoreCallingIdentity(identity); |
| 4985 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4986 | } |
| 4987 | |
| 4988 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4989 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4990 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4991 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4992 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4993 | return false; |
| 4994 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4995 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4996 | final long identity = Binder.clearCallingIdentity(); |
| 4997 | try { |
| 4998 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 4999 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5000 | // In the long run, we may instead need to check if there exists a connection service |
| 5001 | // which can support video calling. |
| 5002 | ImsManager imsManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5003 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5004 | return imsManager.isVtEnabledByPlatform() |
| 5005 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5006 | && imsManager.isVtEnabledByUser(); |
| 5007 | } finally { |
| 5008 | Binder.restoreCallingIdentity(identity); |
| 5009 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5010 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5011 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5012 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5013 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 5014 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5015 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5016 | return false; |
| 5017 | } |
| 5018 | |
| 5019 | final long identity = Binder.clearCallingIdentity(); |
| 5020 | try { |
| 5021 | CarrierConfigManager configManager = |
| 5022 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5023 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5024 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5025 | } finally { |
| 5026 | Binder.restoreCallingIdentity(identity); |
| 5027 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5028 | } |
| 5029 | |
| 5030 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5031 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 5032 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5033 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5034 | return false; |
| 5035 | } |
| 5036 | |
| 5037 | final long identity = Binder.clearCallingIdentity(); |
| 5038 | try { |
| 5039 | CarrierConfigManager configManager = |
| 5040 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5041 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5042 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5043 | } finally { |
| 5044 | Binder.restoreCallingIdentity(identity); |
| 5045 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5046 | } |
| 5047 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5048 | @Override |
| 5049 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5050 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5051 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5052 | } |
| 5053 | |
| 5054 | @Override |
| 5055 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5056 | final long identity = Binder.clearCallingIdentity(); |
| 5057 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5058 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5059 | } finally { |
| 5060 | Binder.restoreCallingIdentity(identity); |
| 5061 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5062 | } |
| 5063 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5064 | /** |
| 5065 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5066 | * support for the feature and device firmware support. |
| 5067 | * |
| 5068 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5069 | */ |
| 5070 | @Override |
| 5071 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5072 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5073 | final Phone phone = getPhone(subscriptionId); |
| 5074 | if (phone == null) { |
| 5075 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5076 | return false; |
| 5077 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5078 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5079 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5080 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5081 | boolean isDeviceSupported = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5082 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5083 | return isCarrierSupported && isDeviceSupported; |
| 5084 | } finally { |
| 5085 | Binder.restoreCallingIdentity(identity); |
| 5086 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5087 | } |
| 5088 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5089 | /** |
| 5090 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier |
| 5091 | * both also support RTT. |
| 5092 | */ |
| 5093 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5094 | final long identity = Binder.clearCallingIdentity(); |
| 5095 | try { |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5096 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5097 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5098 | } finally { |
| 5099 | Binder.restoreCallingIdentity(identity); |
| 5100 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5101 | } |
| 5102 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5103 | /** |
| 5104 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5105 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5106 | * |
| 5107 | * <p>Requires Permission: |
| 5108 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5109 | */ |
| 5110 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5111 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5112 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5113 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5114 | return null; |
| 5115 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5116 | int subId = phone.getSubId(); |
| 5117 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5118 | mApp, subId, callingPackage, "getDeviceId")) { |
| 5119 | return null; |
| 5120 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5121 | |
| 5122 | final long identity = Binder.clearCallingIdentity(); |
| 5123 | try { |
| 5124 | return phone.getDeviceId(); |
| 5125 | } finally { |
| 5126 | Binder.restoreCallingIdentity(identity); |
| 5127 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5128 | } |
| 5129 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5130 | /** |
| 5131 | * {@hide} |
| 5132 | * Returns the IMS Registration Status on a particular subid |
| 5133 | * |
| 5134 | * @param subId |
| 5135 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5136 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5137 | Phone phone = getPhone(subId); |
| 5138 | if (phone != null) { |
| 5139 | return phone.isImsRegistered(); |
| 5140 | } else { |
| 5141 | return false; |
| 5142 | } |
| 5143 | } |
| 5144 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5145 | @Override |
| 5146 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5147 | final long identity = Binder.clearCallingIdentity(); |
| 5148 | try { |
| 5149 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5150 | } finally { |
| 5151 | Binder.restoreCallingIdentity(identity); |
| 5152 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5153 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5154 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5155 | /** |
| 5156 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5157 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5158 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5159 | final long identity = Binder.clearCallingIdentity(); |
| 5160 | try { |
| 5161 | Phone phone = getPhone(subId); |
| 5162 | if (phone != null) { |
| 5163 | return phone.isWifiCallingEnabled(); |
| 5164 | } else { |
| 5165 | return false; |
| 5166 | } |
| 5167 | } finally { |
| 5168 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5169 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5170 | } |
| 5171 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5172 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5173 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5174 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5175 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5176 | final long identity = Binder.clearCallingIdentity(); |
| 5177 | try { |
| 5178 | Phone phone = getPhone(subId); |
| 5179 | if (phone != null) { |
| 5180 | return phone.isVideoEnabled(); |
| 5181 | } else { |
| 5182 | return false; |
| 5183 | } |
| 5184 | } finally { |
| 5185 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5186 | } |
| 5187 | } |
| 5188 | |
| 5189 | /** |
| 5190 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5191 | * defined in {@link ImsRegistrationImplBase}. |
| 5192 | */ |
| 5193 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5194 | final long identity = Binder.clearCallingIdentity(); |
| 5195 | try { |
| 5196 | Phone phone = getPhone(subId); |
| 5197 | if (phone != null) { |
| 5198 | return phone.getImsRegistrationTech(); |
| 5199 | } else { |
| 5200 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5201 | } |
| 5202 | } finally { |
| 5203 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5204 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5205 | } |
| 5206 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5207 | @Override |
| 5208 | public void factoryReset(int subId) { |
| 5209 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5210 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5211 | return; |
| 5212 | } |
| 5213 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5214 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5215 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5216 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5217 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5218 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5219 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5220 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5221 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5222 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5223 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5224 | } |
| 5225 | } finally { |
| 5226 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5227 | } |
| 5228 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5229 | |
| 5230 | @Override |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5231 | public String getSimLocaleForSubscriber(int subId) { |
| 5232 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5233 | final Phone phone = getPhone(subId); |
| 5234 | if (phone == null) { |
| 5235 | log("getSimLocaleForSubscriber, invalid subId"); |
Pengquan Meng | 9c29148 | 2019-01-28 16:26:29 -0800 | [diff] [blame] | 5236 | return null; |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5237 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5238 | final long identity = Binder.clearCallingIdentity(); |
| 5239 | try { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5240 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5241 | phone.getContext().getOpPackageName()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5242 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5243 | // preferences (EF-PL and EF-LI)... |
| 5244 | final int mcc = info.getMcc(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5245 | String simLanguage = null; |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5246 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5247 | if (localeFromDefaultSim != null) { |
| 5248 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5249 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5250 | + localeFromDefaultSim); |
| 5251 | return localeFromDefaultSim.toLanguageTag(); |
| 5252 | } else { |
| 5253 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5254 | } |
| 5255 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5256 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5257 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5258 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5259 | // the SIM and carrier preferences does not include a country we add the country |
| 5260 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5261 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5262 | if (mccLocale != null) { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5263 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5264 | return mccLocale.toLanguageTag(); |
| 5265 | } |
| 5266 | |
| 5267 | if (DBG) log("No locale found - returning null"); |
| 5268 | return null; |
| 5269 | } finally { |
| 5270 | Binder.restoreCallingIdentity(identity); |
| 5271 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5272 | } |
| 5273 | |
| 5274 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5275 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5276 | } |
| 5277 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5278 | /** |
| 5279 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5280 | */ |
| 5281 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5282 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5283 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5284 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5285 | private final ModemActivityInfo mLastModemActivityInfo = |
| 5286 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 5287 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5288 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5289 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5290 | * representing the state of the modem. |
| 5291 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5292 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5293 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5294 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5295 | */ |
| 5296 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5297 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5298 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5299 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5300 | |
| 5301 | final long identity = Binder.clearCallingIdentity(); |
| 5302 | try { |
| 5303 | ModemActivityInfo ret = null; |
| 5304 | synchronized (mLastModemActivityInfo) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5305 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5306 | CMD_GET_MODEM_ACTIVITY_INFO, |
| 5307 | null, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5308 | if (isModemActivityInfoValid(info)) { |
| 5309 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 5310 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 5311 | mergedTxTimeMs[i] = |
| 5312 | info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i]; |
| 5313 | } |
| 5314 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 5315 | mLastModemActivityInfo.setSleepTimeMillis( |
| 5316 | info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis()); |
| 5317 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5318 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 5319 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 5320 | mLastModemActivityInfo.setRxTimeMillis( |
| 5321 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 5322 | mLastModemActivityInfo.setEnergyUsed( |
| 5323 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5324 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5325 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5326 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5327 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 5328 | mLastModemActivityInfo.getTxTimeMillis(), |
| 5329 | mLastModemActivityInfo.getRxTimeMillis(), |
| 5330 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5331 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5332 | Bundle bundle = new Bundle(); |
| 5333 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 5334 | result.send(0, bundle); |
| 5335 | } finally { |
| 5336 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5337 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5338 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5339 | |
Siddharth Ray | f5d2955 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5340 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 5341 | // less than total activity duration. |
| 5342 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 5343 | if (info == null) { |
| 5344 | return false; |
| 5345 | } |
| 5346 | int activityDurationMs = |
| 5347 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 5348 | int totalTxTimeMs = 0; |
| 5349 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 5350 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 5351 | } |
| 5352 | return (info.isValid() |
| 5353 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 5354 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 5355 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 5356 | && (totalTxTimeMs <= activityDurationMs)); |
| 5357 | } |
| 5358 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5359 | /** |
| 5360 | * {@hide} |
| 5361 | * Returns the service state information on specified subscription. |
| 5362 | */ |
| 5363 | @Override |
| 5364 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5365 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5366 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5367 | return null; |
| 5368 | } |
| 5369 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5370 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 5371 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5372 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5373 | .setCallingPackage(callingPackage) |
| 5374 | .setCallingPid(Binder.getCallingPid()) |
| 5375 | .setCallingUid(Binder.getCallingUid()) |
| 5376 | .setMethod("getServiceStateForSubscriber") |
| 5377 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5378 | .build()); |
| 5379 | |
| 5380 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 5381 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5382 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5383 | .setCallingPackage(callingPackage) |
| 5384 | .setCallingPid(Binder.getCallingPid()) |
| 5385 | .setCallingUid(Binder.getCallingUid()) |
| 5386 | .setMethod("getServiceStateForSubscriber") |
| 5387 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5388 | .build()); |
| 5389 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 5390 | boolean hasFinePermission = |
| 5391 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5392 | boolean hasCoarsePermission = |
| 5393 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5394 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5395 | final long identity = Binder.clearCallingIdentity(); |
| 5396 | try { |
| 5397 | final Phone phone = getPhone(subId); |
| 5398 | if (phone == null) { |
| 5399 | return null; |
| 5400 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5401 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5402 | ServiceState ss = phone.getServiceState(); |
| 5403 | |
| 5404 | // Scrub out the location info in ServiceState depending on what level of access |
| 5405 | // the caller has. |
| 5406 | if (hasFinePermission) return ss; |
| 5407 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 5408 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5409 | } finally { |
| 5410 | Binder.restoreCallingIdentity(identity); |
| 5411 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5412 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5413 | |
| 5414 | /** |
| 5415 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5416 | * |
| 5417 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5418 | * voicemail ringtone. |
| 5419 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5420 | * PhoneAccount. |
| 5421 | */ |
| 5422 | @Override |
| 5423 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5424 | final long identity = Binder.clearCallingIdentity(); |
| 5425 | try { |
| 5426 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5427 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5428 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5429 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5430 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5431 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5432 | } finally { |
| 5433 | Binder.restoreCallingIdentity(identity); |
| 5434 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5435 | } |
| 5436 | |
| 5437 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5438 | * Sets the per-account voicemail ringtone. |
| 5439 | * |
| 5440 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5441 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5442 | * |
| 5443 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5444 | * voicemail ringtone. |
| 5445 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5446 | * PhoneAccount. |
| 5447 | */ |
| 5448 | @Override |
| 5449 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5450 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5451 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5452 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5453 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5454 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5455 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5456 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5457 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5458 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5459 | |
| 5460 | final long identity = Binder.clearCallingIdentity(); |
| 5461 | try { |
| 5462 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5463 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5464 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5465 | } |
| 5466 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5467 | } finally { |
| 5468 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5469 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5470 | } |
| 5471 | |
| 5472 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5473 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5474 | * |
| 5475 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5476 | * voicemail vibration setting. |
| 5477 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5478 | */ |
| 5479 | @Override |
| 5480 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5481 | final long identity = Binder.clearCallingIdentity(); |
| 5482 | try { |
| 5483 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5484 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5485 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5486 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5487 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5488 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5489 | } finally { |
| 5490 | Binder.restoreCallingIdentity(identity); |
| 5491 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5492 | } |
| 5493 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5494 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5495 | * Sets the per-account voicemail vibration. |
| 5496 | * |
| 5497 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5498 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5499 | * |
| 5500 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5501 | * voicemail vibration setting. |
| 5502 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5503 | * specific PhoneAccount. |
| 5504 | */ |
| 5505 | @Override |
| 5506 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5507 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5508 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5509 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5510 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5511 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5512 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5513 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5514 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5515 | } |
| 5516 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5517 | final long identity = Binder.clearCallingIdentity(); |
| 5518 | try { |
| 5519 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5520 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5521 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5522 | } |
| 5523 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5524 | } finally { |
| 5525 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5526 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5527 | } |
| 5528 | |
| 5529 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5530 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5531 | * |
| 5532 | * @throws SecurityException if the caller does not have the required permission |
| 5533 | */ |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5534 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5535 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5536 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5537 | } |
| 5538 | |
| 5539 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5540 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5541 | * permission. |
| 5542 | * |
| 5543 | * @throws SecurityException if the caller does not have the required permission |
| 5544 | */ |
| 5545 | private void enforceSendSmsPermission() { |
| 5546 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5547 | } |
| 5548 | |
| 5549 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5550 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5551 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5552 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5553 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5554 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5555 | final long identity = Binder.clearCallingIdentity(); |
| 5556 | try { |
| 5557 | ComponentName componentName = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5558 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5559 | if (componentName == null) { |
| 5560 | throw new SecurityException( |
| 5561 | "Caller not current active visual voicemail package[null]"); |
| 5562 | } |
| 5563 | String vvmPackage = componentName.getPackageName(); |
| 5564 | if (!callingPackage.equals(vvmPackage)) { |
| 5565 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5566 | + vvmPackage + "]"); |
| 5567 | } |
| 5568 | } finally { |
| 5569 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5570 | } |
| 5571 | } |
| 5572 | |
| 5573 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5574 | * Return the application ID for the app type. |
| 5575 | * |
| 5576 | * @param subId the subscription ID that this request applies to. |
| 5577 | * @param appType the uicc app type. |
| 5578 | * @return Application ID for specificied app type, or null if no uicc. |
| 5579 | */ |
| 5580 | @Override |
| 5581 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5582 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5583 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5584 | |
| 5585 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5586 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5587 | if (phone == null) { |
| 5588 | return null; |
| 5589 | } |
| 5590 | String aid = null; |
| 5591 | try { |
| 5592 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5593 | .getApplicationByType(appType).getAid(); |
| 5594 | } catch (Exception e) { |
| 5595 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5596 | } |
| 5597 | return aid; |
| 5598 | } finally { |
| 5599 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5600 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5601 | } |
| 5602 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5603 | /** |
| 5604 | * Return the Electronic Serial Number. |
| 5605 | * |
| 5606 | * @param subId the subscription ID that this request applies to. |
| 5607 | * @return ESN or null if error. |
| 5608 | */ |
| 5609 | @Override |
| 5610 | public String getEsn(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5611 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5612 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5613 | |
| 5614 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5615 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5616 | if (phone == null) { |
| 5617 | return null; |
| 5618 | } |
| 5619 | String esn = null; |
| 5620 | try { |
| 5621 | esn = phone.getEsn(); |
| 5622 | } catch (Exception e) { |
| 5623 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5624 | } |
| 5625 | return esn; |
| 5626 | } finally { |
| 5627 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5628 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5629 | } |
| 5630 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5631 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5632 | * Return the Preferred Roaming List Version. |
| 5633 | * |
| 5634 | * @param subId the subscription ID that this request applies to. |
| 5635 | * @return PRLVersion or null if error. |
| 5636 | */ |
| 5637 | @Override |
| 5638 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5639 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5640 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5641 | |
| 5642 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5643 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5644 | if (phone == null) { |
| 5645 | return null; |
| 5646 | } |
| 5647 | String cdmaPrlVersion = null; |
| 5648 | try { |
| 5649 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 5650 | } catch (Exception e) { |
| 5651 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 5652 | } |
| 5653 | return cdmaPrlVersion; |
| 5654 | } finally { |
| 5655 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5656 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5657 | } |
| 5658 | |
| 5659 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5660 | * Get snapshot of Telephony histograms |
| 5661 | * @return List of Telephony histograms |
| 5662 | * @hide |
| 5663 | */ |
| 5664 | @Override |
| 5665 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5666 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5667 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5668 | |
| 5669 | final long identity = Binder.clearCallingIdentity(); |
| 5670 | try { |
| 5671 | return RIL.getTelephonyRILTimingHistograms(); |
| 5672 | } finally { |
| 5673 | Binder.restoreCallingIdentity(identity); |
| 5674 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5675 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5676 | |
| 5677 | /** |
| 5678 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5679 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 5680 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5681 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5682 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5683 | * @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] | 5684 | */ |
| 5685 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5686 | @TelephonyManager.SetCarrierRestrictionResult |
| 5687 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5688 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5689 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5690 | |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5691 | if (carrierRestrictionRules == null) { |
| 5692 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5693 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5694 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5695 | final long identity = Binder.clearCallingIdentity(); |
| 5696 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5697 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5698 | workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5699 | } finally { |
| 5700 | Binder.restoreCallingIdentity(identity); |
| 5701 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5702 | } |
| 5703 | |
| 5704 | /** |
| 5705 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5706 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 5707 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5708 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5709 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5710 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5711 | */ |
| 5712 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5713 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5714 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5715 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5716 | |
| 5717 | final long identity = Binder.clearCallingIdentity(); |
| 5718 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5719 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 5720 | if (response instanceof CarrierRestrictionRules) { |
| 5721 | return (CarrierRestrictionRules) response; |
| 5722 | } |
| 5723 | // Response is an Exception of some kind, |
| 5724 | // which is signalled to the user as a NULL retval |
| 5725 | return null; |
| 5726 | } catch (Exception e) { |
| 5727 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 5728 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5729 | } finally { |
| 5730 | Binder.restoreCallingIdentity(identity); |
| 5731 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5732 | } |
| 5733 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5734 | /** |
| 5735 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 5736 | * @param subId the subscription ID that this action applies to. |
| 5737 | * @param enabled control enable or disable metered apns. |
| 5738 | * {@hide} |
| 5739 | */ |
| 5740 | @Override |
| 5741 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 5742 | enforceModifyPermission(); |
| 5743 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5744 | |
| 5745 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5746 | if (phone == null) { |
| 5747 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 5748 | return; |
| 5749 | } |
| 5750 | try { |
| 5751 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 5752 | } catch (Exception e) { |
| 5753 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5754 | } finally { |
| 5755 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5756 | } |
| 5757 | } |
| 5758 | |
| 5759 | /** |
| 5760 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 5761 | * @param subId the subscription ID that this action applies to. |
| 5762 | * @param enabled control enable or disable radio. |
| 5763 | * {@hide} |
| 5764 | */ |
| 5765 | @Override |
| 5766 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 5767 | enforceModifyPermission(); |
| 5768 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5769 | |
| 5770 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5771 | if (phone == null) { |
| 5772 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 5773 | return; |
| 5774 | } |
| 5775 | try { |
| 5776 | phone.carrierActionSetRadioEnabled(enabled); |
| 5777 | } catch (Exception e) { |
| 5778 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5779 | } finally { |
| 5780 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5781 | } |
| 5782 | } |
| 5783 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5784 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5785 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 5786 | * network status based on which carrier apps could apply actions accordingly, |
| 5787 | * enable/disable default url handler for example. |
| 5788 | * |
| 5789 | * @param subId the subscription ID that this action applies to. |
| 5790 | * @param report control start/stop reporting the default network status. |
| 5791 | * {@hide} |
| 5792 | */ |
| 5793 | @Override |
| 5794 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 5795 | enforceModifyPermission(); |
| 5796 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5797 | |
| 5798 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5799 | if (phone == null) { |
| 5800 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 5801 | return; |
| 5802 | } |
| 5803 | try { |
| 5804 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 5805 | } catch (Exception e) { |
| 5806 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5807 | } finally { |
| 5808 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5809 | } |
| 5810 | } |
| 5811 | |
| 5812 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5813 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 5814 | * bug report is being generated. |
| 5815 | */ |
| 5816 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 5817 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5818 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 5819 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 5820 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 5821 | + Binder.getCallingPid() |
| 5822 | + ", uid=" + Binder.getCallingUid() |
| 5823 | + "without permission " |
| 5824 | + android.Manifest.permission.DUMP); |
| 5825 | return; |
| 5826 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5827 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5828 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5829 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5830 | @Override |
| 5831 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 5832 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 5833 | throws RemoteException { |
| 5834 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 5835 | } |
| 5836 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5837 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5838 | * Get aggregated video call data usage since boot. |
| 5839 | * |
| 5840 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 5841 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5842 | * {@hide} |
| 5843 | */ |
| 5844 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5845 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5846 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 5847 | null); |
| 5848 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5849 | final long identity = Binder.clearCallingIdentity(); |
| 5850 | try { |
| 5851 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 5852 | // records the delta with the corresponding network identity. |
| 5853 | // We just return the total video call data usage snapshot since boot. |
| 5854 | Phone phone = getPhone(subId); |
| 5855 | if (phone != null) { |
| 5856 | return phone.getVtDataUsage(perUidStats); |
| 5857 | } |
| 5858 | return null; |
| 5859 | } finally { |
| 5860 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5861 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5862 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5863 | |
| 5864 | /** |
| 5865 | * Policy control of data connection. Usually used when data limit is passed. |
| 5866 | * @param enabled True if enabling the data, otherwise disabling. |
| 5867 | * @param subId Subscription index |
| 5868 | * {@hide} |
| 5869 | */ |
| 5870 | @Override |
| 5871 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 5872 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5873 | |
| 5874 | final long identity = Binder.clearCallingIdentity(); |
| 5875 | try { |
| 5876 | Phone phone = getPhone(subId); |
| 5877 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5878 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5879 | } |
| 5880 | } finally { |
| 5881 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5882 | } |
| 5883 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5884 | |
| 5885 | /** |
| 5886 | * Get Client request stats |
| 5887 | * @return List of Client Request Stats |
| 5888 | * @hide |
| 5889 | */ |
| 5890 | @Override |
| 5891 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5892 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5893 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5894 | return null; |
| 5895 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5896 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5897 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5898 | final long identity = Binder.clearCallingIdentity(); |
| 5899 | try { |
| 5900 | if (phone != null) { |
| 5901 | return phone.getClientRequestStats(); |
| 5902 | } |
| 5903 | |
| 5904 | return null; |
| 5905 | } finally { |
| 5906 | Binder.restoreCallingIdentity(identity); |
| 5907 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5908 | } |
| 5909 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5910 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5911 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5912 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5913 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5914 | |
| 5915 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5916 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5917 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5918 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5919 | * @param state State of SIM (power down, power up, pass through) |
| 5920 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 5921 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 5922 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5923 | * |
| 5924 | **/ |
| 5925 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5926 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5927 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5928 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5929 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5930 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5931 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5932 | final long identity = Binder.clearCallingIdentity(); |
| 5933 | try { |
| 5934 | if (phone != null) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5935 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5936 | } |
| 5937 | } finally { |
| 5938 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5939 | } |
| 5940 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5941 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5942 | private boolean isUssdApiAllowed(int subId) { |
| 5943 | CarrierConfigManager configManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5944 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5945 | if (configManager == null) { |
| 5946 | return false; |
| 5947 | } |
| 5948 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 5949 | if (pb == null) { |
| 5950 | return false; |
| 5951 | } |
| 5952 | return pb.getBoolean( |
| 5953 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 5954 | } |
| 5955 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5956 | /** |
| 5957 | * Check if phone is in emergency callback mode |
| 5958 | * @return true if phone is in emergency callback mode |
| 5959 | * @param subId sub id |
| 5960 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 5961 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5962 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5963 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5964 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5965 | |
| 5966 | final long identity = Binder.clearCallingIdentity(); |
| 5967 | try { |
| 5968 | if (phone != null) { |
| 5969 | return phone.isInEcm(); |
| 5970 | } else { |
| 5971 | return false; |
| 5972 | } |
| 5973 | } finally { |
| 5974 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5975 | } |
| 5976 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5977 | |
| 5978 | /** |
| 5979 | * Get the current signal strength information for the given subscription. |
| 5980 | * Because this information is not updated when the device is in a low power state |
| 5981 | * it should not be relied-upon to be current. |
| 5982 | * @param subId Subscription index |
| 5983 | * @return the most recent cached signal strength info from the modem |
| 5984 | */ |
| 5985 | @Override |
| 5986 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5987 | final long identity = Binder.clearCallingIdentity(); |
| 5988 | try { |
| 5989 | Phone p = getPhone(subId); |
| 5990 | if (p == null) { |
| 5991 | return null; |
| 5992 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5993 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5994 | return p.getSignalStrength(); |
| 5995 | } finally { |
| 5996 | Binder.restoreCallingIdentity(identity); |
| 5997 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5998 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5999 | |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6000 | /** |
chen xu | 907e5a2 | 2018-10-11 13:21:04 -0700 | [diff] [blame] | 6001 | * Get the current modem radio state for the given slot. |
| 6002 | * @param slotIndex slot index. |
| 6003 | * @param callingPackage the name of the package making the call. |
| 6004 | * @return the current radio power state from the modem |
| 6005 | */ |
| 6006 | @Override |
| 6007 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 6008 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6009 | if (phone != null) { |
| 6010 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6011 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 6012 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6013 | } |
| 6014 | |
| 6015 | final long identity = Binder.clearCallingIdentity(); |
| 6016 | try { |
| 6017 | return phone.getRadioPowerState(); |
| 6018 | } finally { |
| 6019 | Binder.restoreCallingIdentity(identity); |
| 6020 | } |
| 6021 | } |
| 6022 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6023 | } |
| 6024 | |
| 6025 | /** |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6026 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6027 | * |
| 6028 | * <p>Requires one of the following permissions: |
| 6029 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6030 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6031 | * privileges. |
| 6032 | * |
| 6033 | * @param subId subscription id |
| 6034 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6035 | * {@code false}. |
| 6036 | */ |
| 6037 | @Override |
| 6038 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6039 | boolean isEnabled = false; |
| 6040 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6041 | try { |
| 6042 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6043 | null /* message */); |
| 6044 | Phone phone = getPhone(subId); |
| 6045 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6046 | } catch (Exception e) { |
| 6047 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6048 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6049 | } finally { |
| 6050 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6051 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6052 | return isEnabled; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6053 | } |
| 6054 | |
| 6055 | |
| 6056 | /** |
| 6057 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6058 | * |
| 6059 | * <p> Requires permission: |
| 6060 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6061 | * privileges. |
| 6062 | * |
| 6063 | * @param subId subscription id |
| 6064 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6065 | */ |
| 6066 | @Override |
| 6067 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6068 | final long identity = Binder.clearCallingIdentity(); |
| 6069 | try { |
| 6070 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6071 | mApp, subId, "setDataRoamingEnabled"); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6072 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6073 | Phone phone = getPhone(subId); |
| 6074 | if (phone != null) { |
| 6075 | phone.setDataRoamingEnabled(isEnabled); |
| 6076 | } |
| 6077 | } finally { |
| 6078 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6079 | } |
| 6080 | } |
| 6081 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6082 | @Override |
Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6083 | public boolean isManualNetworkSelectionAllowed(int subId) { |
| 6084 | boolean isAllowed = true; |
| 6085 | final long identity = Binder.clearCallingIdentity(); |
| 6086 | try { |
| 6087 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6088 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6089 | Phone phone = getPhone(subId); |
| 6090 | if (phone != null) { |
| 6091 | isAllowed = phone.isCspPlmnEnabled(); |
| 6092 | } |
| 6093 | } finally { |
| 6094 | Binder.restoreCallingIdentity(identity); |
| 6095 | } |
| 6096 | return isAllowed; |
| 6097 | } |
| 6098 | |
| 6099 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6100 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 53fdb78 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6101 | try { |
| 6102 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
| 6103 | } catch (SecurityException e) { |
| 6104 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6105 | // has carrier privileges on an active UICC |
| 6106 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6107 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6108 | throw new SecurityException("Caller does not have carrier privileges on any UICC"); |
| 6109 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6110 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6111 | |
| 6112 | final long identity = Binder.clearCallingIdentity(); |
| 6113 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6114 | UiccController uiccController = UiccController.getInstance(); |
| 6115 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
| 6116 | |
| 6117 | ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0); |
| 6118 | if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 6119 | // Remove private info if the caller doesn't have access |
| 6120 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6121 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6122 | UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex()); |
| 6123 | UiccProfile profile = card.getUiccProfile(); |
| 6124 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6125 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6126 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6127 | } else { |
| 6128 | filteredInfos.add(cardInfo); |
| 6129 | } |
| 6130 | } |
| 6131 | return filteredInfos; |
| 6132 | } |
| 6133 | return cardInfos; |
| 6134 | } catch (PackageManager.NameNotFoundException e) { |
| 6135 | // This should not happen since we pass the package info in from TelephonyManager |
| 6136 | throw new SecurityException("Invalid calling package."); |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6137 | } finally { |
| 6138 | Binder.restoreCallingIdentity(identity); |
| 6139 | } |
| 6140 | } |
| 6141 | |
| 6142 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6143 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6144 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6145 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6146 | final long identity = Binder.clearCallingIdentity(); |
| 6147 | try { |
| 6148 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6149 | if (slots == null) { |
| 6150 | Rlog.i(LOG_TAG, "slots is null."); |
| 6151 | return null; |
| 6152 | } |
| 6153 | |
| 6154 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6155 | for (int i = 0; i < slots.length; i++) { |
| 6156 | UiccSlot slot = slots[i]; |
| 6157 | if (slot == null) { |
| 6158 | continue; |
| 6159 | } |
| 6160 | |
| 6161 | String cardId; |
| 6162 | UiccCard card = slot.getUiccCard(); |
| 6163 | if (card != null) { |
| 6164 | cardId = card.getCardId(); |
| 6165 | } else { |
| 6166 | cardId = slot.getIccId(); |
| 6167 | } |
| 6168 | |
| 6169 | int cardState = 0; |
| 6170 | switch (slot.getCardState()) { |
| 6171 | case CARDSTATE_ABSENT: |
| 6172 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6173 | break; |
| 6174 | case CARDSTATE_PRESENT: |
| 6175 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6176 | break; |
| 6177 | case CARDSTATE_ERROR: |
| 6178 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6179 | break; |
| 6180 | case CARDSTATE_RESTRICTED: |
| 6181 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6182 | break; |
| 6183 | default: |
| 6184 | break; |
| 6185 | |
| 6186 | } |
| 6187 | |
| 6188 | infos[i] = new UiccSlotInfo( |
| 6189 | slot.isActive(), |
| 6190 | slot.isEuicc(), |
| 6191 | cardId, |
| 6192 | cardState, |
| 6193 | slot.getPhoneId(), |
Jordan Liu | ef65d87 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6194 | slot.isExtendedApduSupported(), |
| 6195 | slot.isRemovable()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6196 | } |
| 6197 | return infos; |
| 6198 | } finally { |
| 6199 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6200 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6201 | } |
| 6202 | |
| 6203 | @Override |
| 6204 | public boolean switchSlots(int[] physicalSlots) { |
| 6205 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6206 | |
| 6207 | final long identity = Binder.clearCallingIdentity(); |
| 6208 | try { |
| 6209 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6210 | } finally { |
| 6211 | Binder.restoreCallingIdentity(identity); |
| 6212 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6213 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6214 | |
| 6215 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6216 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6217 | final long identity = Binder.clearCallingIdentity(); |
| 6218 | try { |
| 6219 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6220 | } finally { |
| 6221 | Binder.restoreCallingIdentity(identity); |
| 6222 | } |
| 6223 | } |
| 6224 | |
| 6225 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6226 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6227 | enforceModifyPermission(); |
| 6228 | final Phone phone = getPhone(subId); |
| 6229 | if (phone == null) { |
| 6230 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6231 | return; |
| 6232 | } |
| 6233 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6234 | final long identity = Binder.clearCallingIdentity(); |
| 6235 | try { |
| 6236 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6237 | } finally { |
| 6238 | Binder.restoreCallingIdentity(identity); |
| 6239 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6240 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6241 | |
| 6242 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6243 | * A test API to reload the UICC profile. |
| 6244 | * |
| 6245 | * <p>Requires that the calling app has permission |
| 6246 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6247 | * @hide |
| 6248 | */ |
| 6249 | @Override |
| 6250 | public void refreshUiccProfile(int subId) { |
| 6251 | enforceModifyPermission(); |
| 6252 | |
| 6253 | final long identity = Binder.clearCallingIdentity(); |
| 6254 | try { |
| 6255 | Phone phone = getPhone(subId); |
| 6256 | if (phone == null) { |
| 6257 | return; |
| 6258 | } |
| 6259 | UiccCard uiccCard = phone.getUiccCard(); |
| 6260 | if (uiccCard == null) { |
| 6261 | return; |
| 6262 | } |
| 6263 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6264 | if (uiccProfile == null) { |
| 6265 | return; |
| 6266 | } |
| 6267 | uiccProfile.refresh(); |
| 6268 | } finally { |
| 6269 | Binder.restoreCallingIdentity(identity); |
| 6270 | } |
| 6271 | } |
| 6272 | |
| 6273 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6274 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6275 | */ |
| 6276 | private boolean getDefaultDataEnabled() { |
| 6277 | return "true".equalsIgnoreCase( |
| 6278 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6279 | } |
| 6280 | |
| 6281 | /** |
| 6282 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6283 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6284 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6285 | */ |
| 6286 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6287 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6288 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6289 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6290 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6291 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6292 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 6293 | return isDataRoamingEnabled; |
| 6294 | } |
| 6295 | |
| 6296 | /** |
| 6297 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 6298 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 6299 | */ |
| 6300 | private int getDefaultNetworkType(int subId) { |
| 6301 | return Integer.parseInt( |
| 6302 | TelephonyManager.getTelephonyProperty( |
| 6303 | mSubscriptionController.getPhoneId(subId), |
| 6304 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 6305 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 6306 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6307 | |
| 6308 | @Override |
| 6309 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
| 6310 | gid1, String gid2, String plmn, String spn) { |
| 6311 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6312 | |
| 6313 | final long identity = Binder.clearCallingIdentity(); |
| 6314 | try { |
| 6315 | final Phone phone = getPhone(subId); |
| 6316 | if (phone == null) { |
| 6317 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 6318 | return; |
| 6319 | } |
| 6320 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn); |
| 6321 | } finally { |
| 6322 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6323 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6324 | } |
| 6325 | |
| 6326 | @Override |
| 6327 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6328 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6329 | |
| 6330 | final long identity = Binder.clearCallingIdentity(); |
| 6331 | try { |
| 6332 | final Phone phone = getPhone(subId); |
| 6333 | if (phone == null) { |
| 6334 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 6335 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 6336 | } |
| 6337 | return phone.getCarrierIdListVersion(); |
| 6338 | } finally { |
| 6339 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6340 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6341 | } |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6342 | |
| 6343 | @Override |
| 6344 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 6345 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6346 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 6347 | return -1; |
| 6348 | } |
| 6349 | |
| 6350 | final long identity = Binder.clearCallingIdentity(); |
| 6351 | try { |
| 6352 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 6353 | } finally { |
| 6354 | Binder.restoreCallingIdentity(identity); |
| 6355 | } |
| 6356 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6357 | |
| 6358 | @Override |
| 6359 | public int getCdmaRoamingMode(int subId) { |
| 6360 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6361 | mApp, subId, "getCdmaRoamingMode"); |
| 6362 | |
| 6363 | final long identity = Binder.clearCallingIdentity(); |
| 6364 | try { |
| 6365 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 6366 | } finally { |
| 6367 | Binder.restoreCallingIdentity(identity); |
| 6368 | } |
| 6369 | } |
| 6370 | |
| 6371 | @Override |
| 6372 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 6373 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6374 | mApp, subId, "setCdmaRoamingMode"); |
| 6375 | |
| 6376 | final long identity = Binder.clearCallingIdentity(); |
| 6377 | try { |
| 6378 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 6379 | } finally { |
| 6380 | Binder.restoreCallingIdentity(identity); |
| 6381 | } |
| 6382 | } |
| 6383 | |
| 6384 | @Override |
| 6385 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 6386 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6387 | mApp, subId, "setCdmaSubscriptionMode"); |
| 6388 | |
| 6389 | final long identity = Binder.clearCallingIdentity(); |
| 6390 | try { |
| 6391 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 6392 | } finally { |
| 6393 | Binder.restoreCallingIdentity(identity); |
| 6394 | } |
| 6395 | } |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6396 | |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 6397 | private void ensureUserRunning(int userId) { |
| 6398 | if (!mUserManager.isUserRunning(userId)) { |
| 6399 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 6400 | } |
| 6401 | } |
| 6402 | |
| 6403 | /** |
| 6404 | * Returns a list of SMS apps on a given user. |
| 6405 | * |
| 6406 | * Only the shell user (UID 2000 or 0) can call it. |
| 6407 | * Target user must be running. |
| 6408 | */ |
| 6409 | @Override |
| 6410 | public String[] getSmsApps(int userId) { |
| 6411 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 6412 | ensureUserRunning(userId); |
| 6413 | |
| 6414 | final Collection<SmsApplicationData> apps = |
| 6415 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 6416 | |
| 6417 | String[] ret = new String[apps.size()]; |
| 6418 | int i = 0; |
| 6419 | for (SmsApplicationData app : apps) { |
| 6420 | ret[i++] = app.mPackageName; |
| 6421 | } |
| 6422 | return ret; |
| 6423 | } |
| 6424 | |
| 6425 | /** |
| 6426 | * Returns the default SMS app package name on a given user. |
| 6427 | * |
| 6428 | * Only the shell user (UID 2000 or 0) can call it. |
| 6429 | * Target user must be running. |
| 6430 | */ |
| 6431 | @Override |
| 6432 | public String getDefaultSmsApp(int userId) { |
| 6433 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 6434 | ensureUserRunning(userId); |
| 6435 | |
| 6436 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 6437 | /* updateIfNeeded= */ true, userId); |
| 6438 | return cn == null ? null : cn.getPackageName(); |
| 6439 | } |
| 6440 | |
| 6441 | /** |
| 6442 | * Set a package as the default SMS app on a given user. |
| 6443 | * |
| 6444 | * Only the shell user (UID 2000 or 0) can call it. |
| 6445 | * Target user must be running. |
| 6446 | */ |
| 6447 | @Override |
| 6448 | public void setDefaultSmsApp(int userId, String packageName) { |
| 6449 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6450 | ensureUserRunning(userId); |
| 6451 | |
| 6452 | boolean found = false; |
| 6453 | for (String pkg : getSmsApps(userId)) { |
| 6454 | if (TextUtils.equals(packageName, pkg)) { |
| 6455 | found = true; |
| 6456 | break; |
| 6457 | } |
| 6458 | } |
| 6459 | if (!found) { |
| 6460 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6461 | } |
| 6462 | |
| 6463 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6464 | } |
| 6465 | |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6466 | @Override |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6467 | public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList( |
| 6468 | String callingPackage) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6469 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6470 | mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) { |
| 6471 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6472 | } |
| 6473 | final long identity = Binder.clearCallingIdentity(); |
| 6474 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6475 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6476 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6477 | if (phone.getEmergencyNumberTracker() != null |
| 6478 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6479 | emergencyNumberListInternal.put( |
| 6480 | phone.getSubId(), |
| 6481 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6482 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6483 | } |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6484 | return emergencyNumberListInternal; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6485 | } finally { |
| 6486 | Binder.restoreCallingIdentity(identity); |
| 6487 | } |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6488 | } |
| 6489 | |
| 6490 | @Override |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6491 | public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) { |
| 6492 | final Phone defaultPhone = getDefaultPhone(); |
| 6493 | if (!exactMatch) { |
| 6494 | TelephonyPermissions |
| 6495 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6496 | mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)"); |
| 6497 | } |
| 6498 | final long identity = Binder.clearCallingIdentity(); |
| 6499 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6500 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6501 | if (phone.getEmergencyNumberTracker() != null |
| 6502 | && phone.getEmergencyNumberTracker() != null) { |
| 6503 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 6504 | number, exactMatch)) { |
| 6505 | return true; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6506 | } |
| 6507 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6508 | } |
| 6509 | return false; |
| 6510 | } finally { |
| 6511 | Binder.restoreCallingIdentity(identity); |
| 6512 | } |
| 6513 | } |
| 6514 | |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6515 | /** |
| 6516 | * Update emergency number list for test mode. |
| 6517 | */ |
| 6518 | @Override |
| 6519 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 6520 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6521 | "updateEmergencyNumberListTestMode"); |
| 6522 | |
| 6523 | final long identity = Binder.clearCallingIdentity(); |
| 6524 | try { |
| 6525 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6526 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6527 | if (tracker != null) { |
| 6528 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 6529 | } |
| 6530 | } |
| 6531 | } finally { |
| 6532 | Binder.restoreCallingIdentity(identity); |
| 6533 | } |
| 6534 | } |
| 6535 | |
| 6536 | /** |
| 6537 | * Get the full emergency number list for test mode. |
| 6538 | */ |
| 6539 | @Override |
| 6540 | public List<String> getEmergencyNumberListTestMode() { |
| 6541 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6542 | "getEmergencyNumberListTestMode"); |
| 6543 | |
| 6544 | final long identity = Binder.clearCallingIdentity(); |
| 6545 | try { |
| 6546 | Set<String> emergencyNumbers = new HashSet<>(); |
| 6547 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6548 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6549 | if (tracker != null) { |
| 6550 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 6551 | emergencyNumbers.add(num.getNumber()); |
| 6552 | } |
| 6553 | } |
| 6554 | } |
| 6555 | return new ArrayList<>(emergencyNumbers); |
| 6556 | } finally { |
| 6557 | Binder.restoreCallingIdentity(identity); |
| 6558 | } |
| 6559 | } |
| 6560 | |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6561 | @Override |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6562 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6563 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6564 | Phone phone = getPhone(subId); |
| 6565 | if (phone == null) { |
| 6566 | return null; |
| 6567 | } |
| 6568 | final long identity = Binder.clearCallingIdentity(); |
| 6569 | try { |
| 6570 | UiccProfile profile = UiccController.getInstance() |
| 6571 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6572 | if (profile != null) { |
| 6573 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6574 | } |
| 6575 | } finally { |
| 6576 | Binder.restoreCallingIdentity(identity); |
| 6577 | } |
| 6578 | return null; |
| 6579 | } |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6580 | |
| 6581 | /** |
| 6582 | * Enable or disable a modem stack. |
| 6583 | */ |
| 6584 | @Override |
| 6585 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 6586 | enforceModifyPermission(); |
| 6587 | |
| 6588 | final long identity = Binder.clearCallingIdentity(); |
| 6589 | try { |
| 6590 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6591 | if (phone == null) { |
| 6592 | return false; |
| 6593 | } else { |
| 6594 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 6595 | } |
| 6596 | } finally { |
| 6597 | Binder.restoreCallingIdentity(identity); |
| 6598 | } |
| 6599 | } |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6600 | |
| 6601 | @Override |
| 6602 | public void setMultisimCarrierRestriction(boolean isMultisimCarrierRestricted) { |
| 6603 | enforceModifyPermission(); |
| 6604 | |
| 6605 | final long identity = Binder.clearCallingIdentity(); |
| 6606 | try { |
| 6607 | mTelephonySharedPreferences.edit() |
| 6608 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultisimCarrierRestricted) |
| 6609 | .commit(); |
| 6610 | } finally { |
| 6611 | Binder.restoreCallingIdentity(identity); |
| 6612 | } |
| 6613 | } |
| 6614 | |
| 6615 | @Override |
Michele | bcb01bc | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6616 | public boolean isMultisimSupported(String callingPackage) { |
| 6617 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
| 6618 | getDefaultPhone().getSubId(), callingPackage, "isMultisimSupported")) { |
| 6619 | return false; |
| 6620 | } |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6621 | |
| 6622 | final long identity = Binder.clearCallingIdentity(); |
| 6623 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6624 | return isMultisimSupportedInternal(); |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6625 | } finally { |
| 6626 | Binder.restoreCallingIdentity(identity); |
| 6627 | } |
| 6628 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6629 | |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6630 | private boolean isMultisimSupportedInternal() { |
| 6631 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 6632 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 6633 | if (numPhysicalSlots < 2) { |
| 6634 | loge("isMultisimSupportedInternal: requires at least 2 cards"); |
| 6635 | return false; |
| 6636 | } |
| 6637 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 6638 | // supported by the modem, indicate that it is restricted. |
| 6639 | PhoneCapability staticCapability = |
| 6640 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 6641 | if (staticCapability == null) { |
| 6642 | loge("isMultisimSupportedInternal: no static configuration available"); |
| 6643 | return false; |
| 6644 | } |
| 6645 | if (staticCapability.logicalModemList.size() < 2) { |
| 6646 | loge("isMultisimSupportedInternal: maximum number of modem is < 2"); |
| 6647 | return false; |
| 6648 | } |
| 6649 | // Check if support of multiple SIMs is restricted by carrier |
| 6650 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
| 6651 | return false; |
| 6652 | } |
| 6653 | |
| 6654 | return true; |
| 6655 | } |
| 6656 | |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6657 | /** |
| 6658 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 814dc22 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6659 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 6660 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 6661 | * or carrier privileges |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6662 | * @param numOfSims number of active sims we want to switch to |
| 6663 | */ |
| 6664 | @Override |
| 6665 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 814dc22 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6666 | if (numOfSims == 1) { |
| 6667 | enforceModifyPermission(); |
| 6668 | } else { |
| 6669 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6670 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 6671 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6672 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6673 | |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6674 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6675 | //only proceed if multi-sim is not restricted |
| 6676 | if (!isMultisimSupportedInternal()) { |
| 6677 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 6678 | return; |
| 6679 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6680 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 6681 | } finally { |
| 6682 | Binder.restoreCallingIdentity(identity); |
| 6683 | } |
| 6684 | } |
| 6685 | |
| 6686 | /** |
Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6687 | * 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] | 6688 | * Return value defaults to true |
Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6689 | */ |
| 6690 | @Override |
| 6691 | public boolean isRebootRequiredForModemConfigChange() { |
| 6692 | enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange"); |
| 6693 | final long identity = Binder.clearCallingIdentity(); |
| 6694 | try { |
| 6695 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 6696 | } finally { |
| 6697 | Binder.restoreCallingIdentity(identity); |
| 6698 | } |
| 6699 | } |
| 6700 | |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 6701 | private void updateModemStateMetrics() { |
| 6702 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 6703 | // TODO: check the state for each modem if the api is ready. |
| 6704 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 6705 | } |
| 6706 | |
Pengquan Meng | 3aceaec | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 6707 | @Override |
| 6708 | public int[] getSlotsMapping() { |
| 6709 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 6710 | |
| 6711 | final long identity = Binder.clearCallingIdentity(); |
| 6712 | try { |
| 6713 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 6714 | // All logical slots should have a mapping to a physical slot. |
| 6715 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 6716 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 6717 | for (int i = 0; i < slotInfos.length; i++) { |
| 6718 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 6719 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 6720 | } |
| 6721 | } |
| 6722 | return logicalSlotsMapping; |
| 6723 | } finally { |
| 6724 | Binder.restoreCallingIdentity(identity); |
| 6725 | } |
| 6726 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 6727 | |
| 6728 | /** |
| 6729 | * Get the IRadio HAL Version |
| 6730 | */ |
| 6731 | @Override |
| 6732 | public int getRadioHalVersion() { |
| 6733 | Phone phone = getDefaultPhone(); |
| 6734 | if (phone == null) return -1; |
| 6735 | HalVersion hv = phone.getHalVersion(); |
| 6736 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 6737 | return hv.major * 100 + hv.minor; |
| 6738 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6739 | } |