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; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 72 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 73 | import android.telephony.RadioAccessFamily; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 74 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 75 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 76 | import android.telephony.SignalStrength; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 77 | import android.telephony.SmsManager; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 78 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 79 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 80 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 81 | import android.telephony.TelephonyManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 82 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 83 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 84 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 85 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 86 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 87 | import android.telephony.data.ApnSetting; |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 88 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 89 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 90 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 91 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 92 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 93 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 94 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 95 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 96 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 97 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 98 | import android.telephony.ims.feature.MmTelFeature; |
| 99 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 100 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 101 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 102 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 103 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 104 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 105 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 106 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 107 | import com.android.ims.ImsException; |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 108 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 109 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 110 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 111 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 112 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 113 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 114 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 115 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 116 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 117 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 118 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 119 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 120 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 121 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 122 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.Phone; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 127 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.ServiceStateTracker; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.SmsApplication; |
| 135 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 137 | import com.android.internal.telephony.TelephonyPermissions; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.euicc.EuiccConnector; |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 140 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.uicc.IccIoResult; |
| 142 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 147 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 148 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 150 | import com.android.internal.util.HexDump; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 151 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 152 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 153 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 154 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 155 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 156 | import java.io.FileDescriptor; |
| 157 | import java.io.PrintWriter; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 158 | import java.nio.charset.StandardCharsets; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 159 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 160 | import java.util.Arrays; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 161 | import java.util.Collection; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 162 | import java.util.HashMap; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 163 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 164 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 165 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 166 | import java.util.Map; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 167 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 168 | |
| 169 | /** |
| 170 | * Implementation of the ITelephony interface. |
| 171 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 172 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 173 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 174 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 175 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 176 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 177 | |
| 178 | // Message codes used with mMainThreadHandler |
| 179 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 180 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 181 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 182 | private static final int CMD_OPEN_CHANNEL = 9; |
| 183 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 184 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 185 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 186 | private static final int CMD_NV_READ_ITEM = 13; |
| 187 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 188 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 189 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 190 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 191 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 192 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 193 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 194 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 195 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 196 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 197 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 198 | private static final int CMD_SEND_ENVELOPE = 25; |
| 199 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 200 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 201 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 202 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 203 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 204 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 205 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 206 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 207 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 208 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 209 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 210 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 211 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 212 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 213 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 214 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 215 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 216 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 217 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 218 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 219 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 220 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 221 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 222 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 223 | private static final int CMD_SWITCH_SLOTS = 50; |
| 224 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 225 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 226 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 227 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 228 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 229 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 230 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 231 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 232 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 233 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 234 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 235 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 236 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 237 | private static final int CMD_MODEM_REBOOT = 64; |
| 238 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 239 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 240 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 241 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 242 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 243 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 244 | // Parameters of select command. |
| 245 | private static final int SELECT_COMMAND = 0xA4; |
| 246 | private static final int SELECT_P1 = 0x04; |
| 247 | private static final int SELECT_P2 = 0; |
| 248 | private static final int SELECT_P3 = 0x10; |
| 249 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 250 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 251 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 252 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 253 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 254 | /** The singleton instance. */ |
| 255 | private static PhoneInterfaceManager sInstance; |
| 256 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 257 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 258 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 259 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 260 | private AppOpsManager mAppOps; |
| 261 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 262 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 263 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 264 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 265 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 266 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 267 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 268 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 269 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 270 | |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 271 | // String to store multi SIM allowed |
| 272 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 273 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 274 | // The AID of ISD-R. |
| 275 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 276 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 277 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 278 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 279 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 280 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 281 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 282 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 283 | * A request object to use for transmitting data to an ICC. |
| 284 | */ |
| 285 | private static final class IccAPDUArgument { |
| 286 | public int channel, cla, command, p1, p2, p3; |
| 287 | public String data; |
| 288 | |
| 289 | public IccAPDUArgument(int channel, int cla, int command, |
| 290 | int p1, int p2, int p3, String data) { |
| 291 | this.channel = channel; |
| 292 | this.cla = cla; |
| 293 | this.command = command; |
| 294 | this.p1 = p1; |
| 295 | this.p2 = p2; |
| 296 | this.p3 = p3; |
| 297 | this.data = data; |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 302 | * A request object to use for transmitting data to an ICC. |
| 303 | */ |
| 304 | private static final class ManualNetworkSelectionArgument { |
| 305 | public OperatorInfo operatorInfo; |
| 306 | public boolean persistSelection; |
| 307 | |
| 308 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 309 | this.operatorInfo = operatorInfo; |
| 310 | this.persistSelection = persistSelection; |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 315 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 316 | * request after sending. The main thread will notify the request when it is complete. |
| 317 | */ |
| 318 | private static final class MainThreadRequest { |
| 319 | /** The argument to use for the request */ |
| 320 | public Object argument; |
| 321 | /** The result of the request that is run on the main thread */ |
| 322 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 323 | // The subscriber id that this request applies to. Defaults to |
| 324 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 325 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 326 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 327 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 328 | public Phone phone; |
| 329 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 330 | public WorkSource workSource; |
| 331 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 332 | public MainThreadRequest(Object argument) { |
| 333 | this.argument = argument; |
| 334 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 335 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 336 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 337 | this.argument = argument; |
| 338 | if (phone != null) { |
| 339 | this.phone = phone; |
| 340 | } |
| 341 | this.workSource = workSource; |
| 342 | } |
| 343 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 344 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 345 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 346 | if (subId != null) { |
| 347 | this.subId = subId; |
| 348 | } |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 349 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 350 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 353 | private static final class IncomingThirdPartyCallArgs { |
| 354 | public final ComponentName component; |
| 355 | public final String callId; |
| 356 | public final String callerDisplayName; |
| 357 | |
| 358 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 359 | String callerDisplayName) { |
| 360 | this.component = component; |
| 361 | this.callId = callId; |
| 362 | this.callerDisplayName = callerDisplayName; |
| 363 | } |
| 364 | } |
| 365 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 366 | /** |
| 367 | * A handler that processes messages on the main thread in the phone process. Since many |
| 368 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 369 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 370 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 371 | * on, which will be notified when the operation completes and will contain the result of the |
| 372 | * request. |
| 373 | * |
| 374 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 375 | * note that request.result must be set to something non-null for the calling thread to |
| 376 | * unblock. |
| 377 | */ |
| 378 | private final class MainThreadHandler extends Handler { |
| 379 | @Override |
| 380 | public void handleMessage(Message msg) { |
| 381 | MainThreadRequest request; |
| 382 | Message onCompleted; |
| 383 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 384 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 385 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 386 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 387 | |
| 388 | switch (msg.what) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 389 | case CMD_HANDLE_USSD_REQUEST: { |
| 390 | request = (MainThreadRequest) msg.obj; |
| 391 | final Phone phone = getPhoneFromRequest(request); |
| 392 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 393 | String ussdRequest = ussdObject.first; |
| 394 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 395 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 396 | if (!isUssdApiAllowed(request.subId)) { |
| 397 | // Carrier does not support use of this API, return failure. |
| 398 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 399 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 400 | Bundle returnData = new Bundle(); |
| 401 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 402 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 403 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 404 | request.result = true; |
| 405 | notifyRequester(request); |
| 406 | return; |
| 407 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 408 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 409 | try { |
| 410 | request.result = phone != null |
| 411 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 412 | } catch (CallStateException cse) { |
| 413 | request.result = false; |
| 414 | } |
| 415 | // Wake up the requesting thread |
| 416 | notifyRequester(request); |
| 417 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 420 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 421 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 422 | final Phone phone = getPhoneFromRequest(request); |
| 423 | request.result = phone != null ? |
| 424 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 425 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 426 | // Wake up the requesting thread |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 427 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 428 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 429 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 430 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 431 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 432 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 433 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 434 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 435 | if (uiccCard == null) { |
| 436 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 437 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 438 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 439 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 440 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 441 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 442 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 443 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 444 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 445 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 446 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 447 | break; |
| 448 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 449 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 450 | ar = (AsyncResult) msg.obj; |
| 451 | request = (MainThreadRequest) ar.userObj; |
| 452 | if (ar.exception == null && ar.result != null) { |
| 453 | request.result = ar.result; |
| 454 | } else { |
| 455 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 456 | if (ar.result == null) { |
| 457 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 458 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 459 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 460 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 461 | } else { |
| 462 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 463 | } |
| 464 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 465 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 466 | break; |
| 467 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 468 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 469 | request = (MainThreadRequest) msg.obj; |
| 470 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 471 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 472 | if (uiccCard == null) { |
| 473 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 474 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 475 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 476 | } else { |
| 477 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 478 | request); |
| 479 | uiccCard.iccTransmitApduBasicChannel( |
| 480 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 481 | iccArgument.p3, iccArgument.data, onCompleted); |
| 482 | } |
| 483 | break; |
| 484 | |
| 485 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 486 | ar = (AsyncResult) msg.obj; |
| 487 | request = (MainThreadRequest) ar.userObj; |
| 488 | if (ar.exception == null && ar.result != null) { |
| 489 | request.result = ar.result; |
| 490 | } else { |
| 491 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 492 | if (ar.result == null) { |
| 493 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 494 | } else if (ar.exception instanceof CommandException) { |
| 495 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 496 | ar.exception); |
| 497 | } else { |
| 498 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 499 | } |
| 500 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 501 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 502 | break; |
| 503 | |
| 504 | case CMD_EXCHANGE_SIM_IO: |
| 505 | request = (MainThreadRequest) msg.obj; |
| 506 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 507 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 508 | if (uiccCard == null) { |
| 509 | loge("iccExchangeSimIO: No UICC"); |
| 510 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 511 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 512 | } else { |
| 513 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 514 | request); |
| 515 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 516 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 517 | iccArgument.data, onCompleted); |
| 518 | } |
| 519 | break; |
| 520 | |
| 521 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 522 | ar = (AsyncResult) msg.obj; |
| 523 | request = (MainThreadRequest) ar.userObj; |
| 524 | if (ar.exception == null && ar.result != null) { |
| 525 | request.result = ar.result; |
| 526 | } else { |
| 527 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 528 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 529 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 530 | break; |
| 531 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 532 | case CMD_SEND_ENVELOPE: |
| 533 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 534 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 535 | if (uiccCard == null) { |
| 536 | loge("sendEnvelopeWithStatus: No UICC"); |
| 537 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 538 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 539 | } else { |
| 540 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 541 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 542 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 543 | break; |
| 544 | |
| 545 | case EVENT_SEND_ENVELOPE_DONE: |
| 546 | ar = (AsyncResult) msg.obj; |
| 547 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 548 | if (ar.exception == null && ar.result != null) { |
| 549 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 550 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 551 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 552 | if (ar.result == null) { |
| 553 | loge("sendEnvelopeWithStatus: Empty response"); |
| 554 | } else if (ar.exception instanceof CommandException) { |
| 555 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 556 | ar.exception); |
| 557 | } else { |
| 558 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 559 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 560 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 561 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 562 | break; |
| 563 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 564 | case CMD_OPEN_CHANNEL: |
| 565 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 566 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 567 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 568 | if (uiccCard == null) { |
| 569 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 570 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 571 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 572 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 573 | } else { |
| 574 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 575 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 576 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 577 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 578 | break; |
| 579 | |
| 580 | case EVENT_OPEN_CHANNEL_DONE: |
| 581 | ar = (AsyncResult) msg.obj; |
| 582 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 583 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 584 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 585 | int[] result = (int[]) ar.result; |
| 586 | int channelId = result[0]; |
| 587 | byte[] selectResponse = null; |
| 588 | if (result.length > 1) { |
| 589 | selectResponse = new byte[result.length - 1]; |
| 590 | for (int i = 1; i < result.length; ++i) { |
| 591 | selectResponse[i - 1] = (byte) result[i]; |
| 592 | } |
| 593 | } |
| 594 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 595 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 596 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 597 | if (ar.result == null) { |
| 598 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 599 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 600 | if (ar.exception != null) { |
| 601 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 602 | } |
| 603 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 604 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 605 | if (ar.exception instanceof CommandException) { |
| 606 | CommandException.Error error = |
| 607 | ((CommandException) (ar.exception)).getCommandError(); |
| 608 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 609 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 610 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 611 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 612 | } |
| 613 | } |
| 614 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 615 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 616 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 617 | request.result = openChannelResp; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 618 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 619 | break; |
| 620 | |
| 621 | case CMD_CLOSE_CHANNEL: |
| 622 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 623 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 624 | if (uiccCard == null) { |
| 625 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 626 | request.result = false; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 627 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 628 | } else { |
| 629 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 630 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 631 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 632 | break; |
| 633 | |
| 634 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 635 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 636 | break; |
| 637 | |
| 638 | case CMD_NV_READ_ITEM: |
| 639 | request = (MainThreadRequest) msg.obj; |
| 640 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 641 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 642 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 643 | break; |
| 644 | |
| 645 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 646 | ar = (AsyncResult) msg.obj; |
| 647 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 648 | if (ar.exception == null && ar.result != null) { |
| 649 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 650 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 651 | request.result = ""; |
| 652 | if (ar.result == null) { |
| 653 | loge("nvReadItem: Empty response"); |
| 654 | } else if (ar.exception instanceof CommandException) { |
| 655 | loge("nvReadItem: CommandException: " + |
| 656 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 657 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 658 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 659 | } |
| 660 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 661 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 662 | break; |
| 663 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 664 | case CMD_NV_WRITE_ITEM: |
| 665 | request = (MainThreadRequest) msg.obj; |
| 666 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 667 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 668 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 669 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 670 | break; |
| 671 | |
| 672 | case EVENT_NV_WRITE_ITEM_DONE: |
| 673 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 674 | break; |
| 675 | |
| 676 | case CMD_NV_WRITE_CDMA_PRL: |
| 677 | request = (MainThreadRequest) msg.obj; |
| 678 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 679 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 680 | break; |
| 681 | |
| 682 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 683 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 684 | break; |
| 685 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 686 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 687 | request = (MainThreadRequest) msg.obj; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 688 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 689 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 690 | break; |
| 691 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 692 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 693 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 694 | break; |
| 695 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 696 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 697 | request = (MainThreadRequest) msg.obj; |
| 698 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 699 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 700 | break; |
| 701 | |
| 702 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 703 | ar = (AsyncResult) msg.obj; |
| 704 | request = (MainThreadRequest) ar.userObj; |
| 705 | if (ar.exception == null && ar.result != null) { |
| 706 | request.result = ar.result; // Integer |
| 707 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 708 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 709 | if (ar.result == null) { |
| 710 | loge("getPreferredNetworkType: Empty response"); |
| 711 | } else if (ar.exception instanceof CommandException) { |
| 712 | loge("getPreferredNetworkType: CommandException: " + |
| 713 | ar.exception); |
| 714 | } else { |
| 715 | loge("getPreferredNetworkType: Unknown exception"); |
| 716 | } |
| 717 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 718 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 719 | break; |
| 720 | |
| 721 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 722 | request = (MainThreadRequest) msg.obj; |
| 723 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 724 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 725 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 726 | break; |
| 727 | |
| 728 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 729 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 730 | break; |
| 731 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 732 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 733 | request = (MainThreadRequest)msg.obj; |
| 734 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 735 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 736 | break; |
| 737 | |
| 738 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 739 | ar = (AsyncResult)msg.obj; |
| 740 | request = (MainThreadRequest)ar.userObj; |
| 741 | request.result = ar; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 742 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 743 | break; |
| 744 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 745 | case CMD_SET_VOICEMAIL_NUMBER: |
| 746 | request = (MainThreadRequest) msg.obj; |
| 747 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 748 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 749 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 750 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 751 | break; |
| 752 | |
| 753 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 754 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 755 | break; |
| 756 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 757 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 758 | request = (MainThreadRequest) msg.obj; |
| 759 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 760 | request); |
| 761 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 762 | break; |
| 763 | |
| 764 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 765 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 766 | break; |
| 767 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 768 | case CMD_PERFORM_NETWORK_SCAN: |
| 769 | request = (MainThreadRequest) msg.obj; |
| 770 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 771 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 772 | break; |
| 773 | |
| 774 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 775 | ar = (AsyncResult) msg.obj; |
| 776 | request = (MainThreadRequest) ar.userObj; |
| 777 | CellNetworkScanResult cellScanResult; |
| 778 | if (ar.exception == null && ar.result != null) { |
| 779 | cellScanResult = new CellNetworkScanResult( |
| 780 | CellNetworkScanResult.STATUS_SUCCESS, |
| 781 | (List<OperatorInfo>) ar.result); |
| 782 | } else { |
| 783 | if (ar.result == null) { |
| 784 | loge("getCellNetworkScanResults: Empty response"); |
| 785 | } |
| 786 | if (ar.exception != null) { |
| 787 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 788 | } |
| 789 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 790 | if (ar.exception instanceof CommandException) { |
| 791 | CommandException.Error error = |
| 792 | ((CommandException) (ar.exception)).getCommandError(); |
| 793 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 794 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 795 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 796 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 797 | } |
| 798 | } |
| 799 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 800 | } |
| 801 | request.result = cellScanResult; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 802 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 803 | break; |
| 804 | |
| 805 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 806 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 807 | ManualNetworkSelectionArgument selArg = |
| 808 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 809 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 810 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 811 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 812 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 813 | break; |
| 814 | |
| 815 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | dd9ac82 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 816 | ar = (AsyncResult) msg.obj; |
| 817 | request = (MainThreadRequest) ar.userObj; |
| 818 | if (ar.exception == null) { |
| 819 | request.result = true; |
| 820 | } else { |
| 821 | request.result = false; |
| 822 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 823 | } |
| 824 | notifyRequester(request); |
| 825 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 826 | break; |
| 827 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 828 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 829 | request = (MainThreadRequest) msg.obj; |
| 830 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 831 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 832 | break; |
| 833 | |
| 834 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 835 | ar = (AsyncResult) msg.obj; |
| 836 | request = (MainThreadRequest) ar.userObj; |
| 837 | if (ar.exception == null && ar.result != null) { |
| 838 | request.result = ar.result; |
| 839 | } else { |
| 840 | if (ar.result == null) { |
| 841 | loge("queryModemActivityInfo: Empty response"); |
| 842 | } else if (ar.exception instanceof CommandException) { |
| 843 | loge("queryModemActivityInfo: CommandException: " + |
| 844 | ar.exception); |
| 845 | } else { |
| 846 | loge("queryModemActivityInfo: Unknown exception"); |
| 847 | } |
| 848 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 849 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 850 | if (request.result == null) { |
| 851 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 852 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 853 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 854 | break; |
| 855 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 856 | case CMD_SET_ALLOWED_CARRIERS: |
| 857 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 858 | CarrierRestrictionRules argument = |
| 859 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 860 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 861 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 862 | break; |
| 863 | |
| 864 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 865 | ar = (AsyncResult) msg.obj; |
| 866 | request = (MainThreadRequest) ar.userObj; |
| 867 | if (ar.exception == null && ar.result != null) { |
| 868 | request.result = ar.result; |
| 869 | } else { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 870 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 871 | if (ar.exception instanceof CommandException) { |
| 872 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 873 | CommandException.Error error = |
| 874 | ((CommandException) (ar.exception)).getCommandError(); |
| 875 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 876 | request.result = |
| 877 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 878 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 879 | } else { |
| 880 | loge("setAllowedCarriers: Unknown exception"); |
| 881 | } |
| 882 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 883 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 884 | break; |
| 885 | |
| 886 | case CMD_GET_ALLOWED_CARRIERS: |
| 887 | request = (MainThreadRequest) msg.obj; |
| 888 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 889 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 890 | break; |
| 891 | |
| 892 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 893 | ar = (AsyncResult) msg.obj; |
| 894 | request = (MainThreadRequest) ar.userObj; |
| 895 | if (ar.exception == null && ar.result != null) { |
| 896 | request.result = ar.result; |
| 897 | } else { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 898 | request.result = new IllegalStateException( |
| 899 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 900 | if (ar.result == null) { |
| 901 | loge("getAllowedCarriers: Empty response"); |
| 902 | } else if (ar.exception instanceof CommandException) { |
| 903 | loge("getAllowedCarriers: CommandException: " + |
| 904 | ar.exception); |
| 905 | } else { |
| 906 | loge("getAllowedCarriers: Unknown exception"); |
| 907 | } |
| 908 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 909 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 910 | break; |
| 911 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 912 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 913 | ar = (AsyncResult) msg.obj; |
| 914 | request = (MainThreadRequest) ar.userObj; |
| 915 | if (ar.exception == null && ar.result != null) { |
| 916 | request.result = ar.result; |
| 917 | } else { |
| 918 | request.result = new IllegalArgumentException( |
| 919 | "Failed to retrieve Forbidden Plmns"); |
| 920 | if (ar.result == null) { |
| 921 | loge("getForbiddenPlmns: Empty response"); |
| 922 | } else { |
| 923 | loge("getForbiddenPlmns: Unknown exception"); |
| 924 | } |
| 925 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 926 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 927 | break; |
| 928 | |
| 929 | case CMD_GET_FORBIDDEN_PLMNS: |
| 930 | request = (MainThreadRequest) msg.obj; |
| 931 | uiccCard = getUiccCardFromRequest(request); |
| 932 | if (uiccCard == null) { |
| 933 | loge("getForbiddenPlmns() UiccCard is null"); |
| 934 | request.result = new IllegalArgumentException( |
| 935 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 936 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 937 | break; |
| 938 | } |
| 939 | Integer appType = (Integer) request.argument; |
| 940 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 941 | if (uiccApp == null) { |
| 942 | loge("getForbiddenPlmns() no app with specified type -- " |
| 943 | + appType); |
| 944 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 945 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 946 | break; |
| 947 | } else { |
| 948 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 949 | + " specified type -- " + appType); |
| 950 | } |
| 951 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 952 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 953 | onCompleted); |
| 954 | break; |
| 955 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 956 | case CMD_SWITCH_SLOTS: |
| 957 | request = (MainThreadRequest) msg.obj; |
| 958 | int[] physicalSlots = (int[]) request.argument; |
| 959 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 960 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 961 | break; |
| 962 | |
| 963 | case EVENT_SWITCH_SLOTS_DONE: |
| 964 | ar = (AsyncResult) msg.obj; |
| 965 | request = (MainThreadRequest) ar.userObj; |
| 966 | request.result = (ar.exception == null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 967 | notifyRequester(request); |
| 968 | break; |
| 969 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 970 | request = (MainThreadRequest) msg.obj; |
| 971 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 972 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 973 | break; |
| 974 | |
| 975 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 976 | ar = (AsyncResult) msg.obj; |
| 977 | request = (MainThreadRequest) ar.userObj; |
| 978 | if (ar.exception != null) { |
| 979 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 980 | } else { |
| 981 | int mode = ((int[]) ar.result)[0]; |
| 982 | if (mode == 0) { |
| 983 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 984 | } else { |
| 985 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 986 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 987 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 988 | notifyRequester(request); |
| 989 | break; |
| 990 | case CMD_GET_CDMA_ROAMING_MODE: |
| 991 | request = (MainThreadRequest) msg.obj; |
| 992 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 993 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 994 | break; |
| 995 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 996 | ar = (AsyncResult) msg.obj; |
| 997 | request = (MainThreadRequest) ar.userObj; |
| 998 | if (ar.exception != null) { |
| 999 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1000 | } else { |
| 1001 | request.result = ((int[]) ar.result)[0]; |
| 1002 | } |
| 1003 | notifyRequester(request); |
| 1004 | break; |
| 1005 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1006 | request = (MainThreadRequest) msg.obj; |
| 1007 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1008 | int mode = (int) request.argument; |
| 1009 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1010 | break; |
| 1011 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1012 | ar = (AsyncResult) msg.obj; |
| 1013 | request = (MainThreadRequest) ar.userObj; |
| 1014 | request.result = ar.exception == null; |
| 1015 | notifyRequester(request); |
| 1016 | break; |
| 1017 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1018 | request = (MainThreadRequest) msg.obj; |
| 1019 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1020 | int subscriptionMode = (int) request.argument; |
| 1021 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1022 | break; |
| 1023 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1024 | ar = (AsyncResult) msg.obj; |
| 1025 | request = (MainThreadRequest) ar.userObj; |
| 1026 | request.result = ar.exception == null; |
| 1027 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1028 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1029 | case CMD_GET_ALL_CELL_INFO: |
| 1030 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1031 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1032 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1033 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1034 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1035 | ar = (AsyncResult) msg.obj; |
| 1036 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1037 | // If a timeout occurs, the response will be null |
| 1038 | request.result = (ar.exception == null && ar.result != null) |
| 1039 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1040 | synchronized (request) { |
| 1041 | request.notifyAll(); |
| 1042 | } |
| 1043 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1044 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1045 | request = (MainThreadRequest) msg.obj; |
| 1046 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1047 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1048 | break; |
| 1049 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1050 | ar = (AsyncResult) msg.obj; |
| 1051 | request = (MainThreadRequest) ar.userObj; |
| 1052 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1053 | try { |
| 1054 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1055 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1056 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1057 | new android.os.ParcelableException(ar.exception)); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1058 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1059 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1060 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1061 | } else { |
| 1062 | // use the result as returned |
| 1063 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1064 | } |
| 1065 | } catch (RemoteException re) { |
| 1066 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1067 | } |
| 1068 | break; |
| 1069 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1070 | request = (MainThreadRequest) msg.obj; |
| 1071 | WorkSource ws = (WorkSource) request.argument; |
| 1072 | Phone phone = getPhoneFromRequest(request); |
| 1073 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1074 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1075 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1076 | ar = (AsyncResult) msg.obj; |
| 1077 | request = (MainThreadRequest) ar.userObj; |
| 1078 | if (ar.exception == null) { |
| 1079 | request.result = ar.result; |
| 1080 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1081 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1082 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1083 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1084 | } |
| 1085 | |
| 1086 | synchronized (request) { |
| 1087 | request.notifyAll(); |
| 1088 | } |
| 1089 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1090 | case CMD_MODEM_REBOOT: |
| 1091 | request = (MainThreadRequest) msg.obj; |
| 1092 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1093 | defaultPhone.rebootModem(onCompleted); |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1094 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1095 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1096 | handleNullReturnEvent(msg, "rebootModem"); |
| 1097 | break; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1098 | case CMD_REQUEST_ENABLE_MODEM: |
| 1099 | request = (MainThreadRequest) msg.obj; |
| 1100 | boolean enable = (boolean) request.argument; |
| 1101 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
| 1102 | PhoneConfigurationManager.getInstance() |
| 1103 | .enablePhone(request.phone, enable, onCompleted); |
| 1104 | break; |
| 1105 | case EVENT_ENABLE_MODEM_DONE: |
| 1106 | ar = (AsyncResult) msg.obj; |
| 1107 | request = (MainThreadRequest) ar.userObj; |
| 1108 | request.result = (ar.exception == null); |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 1109 | updateModemStateMetrics(); |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1110 | notifyRequester(request); |
| 1111 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1112 | default: |
| 1113 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1114 | break; |
| 1115 | } |
| 1116 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1117 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1118 | private void notifyRequester(MainThreadRequest request) { |
| 1119 | synchronized (request) { |
| 1120 | request.notifyAll(); |
| 1121 | } |
| 1122 | } |
| 1123 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1124 | private void handleNullReturnEvent(Message msg, String command) { |
| 1125 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1126 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1127 | if (ar.exception == null) { |
| 1128 | request.result = true; |
| 1129 | } else { |
| 1130 | request.result = false; |
| 1131 | if (ar.exception instanceof CommandException) { |
| 1132 | loge(command + ": CommandException: " + ar.exception); |
| 1133 | } else { |
| 1134 | loge(command + ": Unknown exception"); |
| 1135 | } |
| 1136 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1137 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1138 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | /** |
| 1142 | * Posts the specified command to be executed on the main thread, |
| 1143 | * waits for the request to complete, and returns the result. |
| 1144 | * @see #sendRequestAsync |
| 1145 | */ |
| 1146 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1147 | return sendRequest( |
| 1148 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | /** |
| 1152 | * Posts the specified command to be executed on the main thread, |
| 1153 | * waits for the request to complete, and returns the result. |
| 1154 | * @see #sendRequestAsync |
| 1155 | */ |
| 1156 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1157 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1158 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | /** |
| 1162 | * Posts the specified command to be executed on the main thread, |
| 1163 | * waits for the request to complete, and returns the result. |
| 1164 | * @see #sendRequestAsync |
| 1165 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1166 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1167 | return sendRequest(command, argument, subId, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | /** |
| 1171 | * Posts the specified command to be executed on the main thread, |
| 1172 | * waits for the request to complete, and returns the result. |
| 1173 | * @see #sendRequestAsync |
| 1174 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1175 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1176 | return sendRequest(command, argument, subId, null, workSource); |
| 1177 | } |
| 1178 | |
| 1179 | /** |
| 1180 | * Posts the specified command to be executed on the main thread, |
| 1181 | * waits for the request to complete, and returns the result. |
| 1182 | * @see #sendRequestAsync |
| 1183 | */ |
| 1184 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1185 | return sendRequest( |
| 1186 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1187 | } |
| 1188 | |
| 1189 | /** |
| 1190 | * Posts the specified command to be executed on the main thread, |
| 1191 | * waits for the request to complete, and returns the result. |
| 1192 | * @see #sendRequestAsync |
| 1193 | */ |
| 1194 | private Object sendRequest( |
| 1195 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1196 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1197 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1198 | } |
| 1199 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1200 | MainThreadRequest request = null; |
| 1201 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1202 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1203 | } else if (phone != null) { |
| 1204 | request = new MainThreadRequest(argument, phone, workSource); |
| 1205 | } else { |
| 1206 | request = new MainThreadRequest(argument, subId, workSource); |
| 1207 | } |
| 1208 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1209 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1210 | msg.sendToTarget(); |
| 1211 | |
| 1212 | // Wait for the request to complete |
| 1213 | synchronized (request) { |
| 1214 | while (request.result == null) { |
| 1215 | try { |
| 1216 | request.wait(); |
| 1217 | } catch (InterruptedException e) { |
| 1218 | // Do nothing, go back and wait until the request is complete |
| 1219 | } |
| 1220 | } |
| 1221 | } |
| 1222 | return request.result; |
| 1223 | } |
| 1224 | |
| 1225 | /** |
| 1226 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1227 | * Posts the specified command to be executed on the main thread, and |
| 1228 | * returns immediately. |
| 1229 | * @see #sendRequest |
| 1230 | */ |
| 1231 | private void sendRequestAsync(int command) { |
| 1232 | mMainThreadHandler.sendEmptyMessage(command); |
| 1233 | } |
| 1234 | |
| 1235 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1236 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1237 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1238 | */ |
| 1239 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1240 | sendRequestAsync(command, argument, null, null); |
| 1241 | } |
| 1242 | |
| 1243 | /** |
| 1244 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1245 | * @see {@link #sendRequest(int,Object)} |
| 1246 | */ |
| 1247 | private void sendRequestAsync( |
| 1248 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1249 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1250 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1251 | msg.sendToTarget(); |
| 1252 | } |
| 1253 | |
| 1254 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1255 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1256 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1257 | */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1258 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1259 | synchronized (PhoneInterfaceManager.class) { |
| 1260 | if (sInstance == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1261 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1262 | } else { |
| 1263 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1264 | } |
| 1265 | return sInstance; |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1270 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1271 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1272 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1273 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1274 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1275 | mMainThreadHandler = new MainThreadHandler(); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1276 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1277 | mTelephonySharedPreferences = |
| 1278 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1279 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1280 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1281 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1282 | publish(); |
| 1283 | } |
| 1284 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1285 | private Phone getDefaultPhone() { |
| 1286 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1287 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1288 | } |
| 1289 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1290 | private void publish() { |
| 1291 | if (DBG) log("publish: " + this); |
| 1292 | |
| 1293 | ServiceManager.addService("phone", this); |
| 1294 | } |
| 1295 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1296 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 1297 | return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1298 | ? getDefaultPhone() : getPhone(request.subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1299 | } |
| 1300 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1301 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1302 | Phone phone = getPhoneFromRequest(request); |
| 1303 | return phone == null ? null : |
| 1304 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1305 | } |
| 1306 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1307 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1308 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1309 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1310 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1311 | |
| 1312 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1313 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1316 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1317 | if (DBG) log("dial: " + number); |
| 1318 | // No permission check needed here: This is just a wrapper around the |
| 1319 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1320 | // the UI before it does anything. |
| 1321 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1322 | final long identity = Binder.clearCallingIdentity(); |
| 1323 | try { |
| 1324 | String url = createTelUrl(number); |
| 1325 | if (url == null) { |
| 1326 | return; |
| 1327 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1328 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1329 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1330 | PhoneConstants.State state = mCM.getState(subId); |
| 1331 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1332 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1333 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1334 | mApp.startActivity(intent); |
| 1335 | } |
| 1336 | } finally { |
| 1337 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1338 | } |
| 1339 | } |
| 1340 | |
| 1341 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1342 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1343 | } |
| 1344 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1345 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1346 | if (DBG) log("call: " + number); |
| 1347 | |
| 1348 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1349 | // need to do a permission check since we're calling startActivity() |
| 1350 | // from the context of the phone app. |
| 1351 | enforceCallPermission(); |
| 1352 | |
| 1353 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1354 | != AppOpsManager.MODE_ALLOWED) { |
| 1355 | return; |
| 1356 | } |
| 1357 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1358 | final long identity = Binder.clearCallingIdentity(); |
| 1359 | try { |
| 1360 | String url = createTelUrl(number); |
| 1361 | if (url == null) { |
| 1362 | return; |
| 1363 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1364 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1365 | boolean isValid = false; |
| 1366 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1367 | if (slist != null) { |
| 1368 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1369 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1370 | isValid = true; |
| 1371 | break; |
| 1372 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1373 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1374 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1375 | if (!isValid) { |
| 1376 | return; |
| 1377 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1378 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1379 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1380 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1381 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1382 | mApp.startActivity(intent); |
| 1383 | } finally { |
| 1384 | Binder.restoreCallingIdentity(identity); |
| 1385 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1386 | } |
| 1387 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1388 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1389 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1390 | } |
| 1391 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1392 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1393 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1394 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1395 | } |
| 1396 | |
| 1397 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1398 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1399 | } |
| 1400 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1401 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1402 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1403 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1404 | } |
| 1405 | |
| 1406 | /** {@hide} */ |
| 1407 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1408 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1409 | } |
| 1410 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1411 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1412 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1413 | |
| 1414 | final long identity = Binder.clearCallingIdentity(); |
| 1415 | try { |
| 1416 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1417 | checkSimPin.start(); |
| 1418 | return checkSimPin.unlockSim(null, pin); |
| 1419 | } finally { |
| 1420 | Binder.restoreCallingIdentity(identity); |
| 1421 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1424 | /** {@hide} */ |
| 1425 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1426 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1427 | } |
| 1428 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1429 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1430 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1431 | |
| 1432 | final long identity = Binder.clearCallingIdentity(); |
| 1433 | try { |
| 1434 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1435 | checkSimPuk.start(); |
| 1436 | return checkSimPuk.unlockSim(puk, pin); |
| 1437 | } finally { |
| 1438 | Binder.restoreCallingIdentity(identity); |
| 1439 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1440 | } |
| 1441 | |
| 1442 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1443 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1444 | * a synchronous one. |
| 1445 | */ |
| 1446 | private static class UnlockSim extends Thread { |
| 1447 | |
| 1448 | private final IccCard mSimCard; |
| 1449 | |
| 1450 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1451 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1452 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1453 | |
| 1454 | // For replies from SimCard interface |
| 1455 | private Handler mHandler; |
| 1456 | |
| 1457 | // For async handler to identify request type |
| 1458 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1459 | |
| 1460 | public UnlockSim(IccCard simCard) { |
| 1461 | mSimCard = simCard; |
| 1462 | } |
| 1463 | |
| 1464 | @Override |
| 1465 | public void run() { |
| 1466 | Looper.prepare(); |
| 1467 | synchronized (UnlockSim.this) { |
| 1468 | mHandler = new Handler() { |
| 1469 | @Override |
| 1470 | public void handleMessage(Message msg) { |
| 1471 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1472 | switch (msg.what) { |
| 1473 | case SUPPLY_PIN_COMPLETE: |
| 1474 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1475 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1476 | mRetryCount = msg.arg1; |
| 1477 | if (ar.exception != null) { |
| 1478 | if (ar.exception instanceof CommandException && |
| 1479 | ((CommandException)(ar.exception)).getCommandError() |
| 1480 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1481 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1482 | } else { |
| 1483 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1484 | } |
| 1485 | } else { |
| 1486 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1487 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1488 | mDone = true; |
| 1489 | UnlockSim.this.notifyAll(); |
| 1490 | } |
| 1491 | break; |
| 1492 | } |
| 1493 | } |
| 1494 | }; |
| 1495 | UnlockSim.this.notifyAll(); |
| 1496 | } |
| 1497 | Looper.loop(); |
| 1498 | } |
| 1499 | |
| 1500 | /* |
| 1501 | * Use PIN or PUK to unlock SIM card |
| 1502 | * |
| 1503 | * If PUK is null, unlock SIM card with PIN |
| 1504 | * |
| 1505 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1506 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1507 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1508 | |
| 1509 | while (mHandler == null) { |
| 1510 | try { |
| 1511 | wait(); |
| 1512 | } catch (InterruptedException e) { |
| 1513 | Thread.currentThread().interrupt(); |
| 1514 | } |
| 1515 | } |
| 1516 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1517 | |
| 1518 | if (puk == null) { |
| 1519 | mSimCard.supplyPin(pin, callback); |
| 1520 | } else { |
| 1521 | mSimCard.supplyPuk(puk, pin, callback); |
| 1522 | } |
| 1523 | |
| 1524 | while (!mDone) { |
| 1525 | try { |
| 1526 | Log.d(LOG_TAG, "wait for done"); |
| 1527 | wait(); |
| 1528 | } catch (InterruptedException e) { |
| 1529 | // Restore the interrupted status |
| 1530 | Thread.currentThread().interrupt(); |
| 1531 | } |
| 1532 | } |
| 1533 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1534 | int[] resultArray = new int[2]; |
| 1535 | resultArray[0] = mResult; |
| 1536 | resultArray[1] = mRetryCount; |
| 1537 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1538 | } |
| 1539 | } |
| 1540 | |
| 1541 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1542 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1543 | |
| 1544 | } |
| 1545 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1546 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1547 | // No permission check needed here: this call is harmless, and it's |
| 1548 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1549 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1550 | final long identity = Binder.clearCallingIdentity(); |
| 1551 | try { |
| 1552 | final Phone phone = getPhone(subId); |
| 1553 | if (phone != null) { |
| 1554 | phone.updateServiceLocation(); |
| 1555 | } |
| 1556 | } finally { |
| 1557 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1558 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1559 | } |
| 1560 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1561 | @Override |
| 1562 | public boolean isRadioOn(String callingPackage) { |
| 1563 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1564 | } |
| 1565 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1566 | @Override |
| 1567 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1568 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1569 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1570 | return false; |
| 1571 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1572 | |
| 1573 | final long identity = Binder.clearCallingIdentity(); |
| 1574 | try { |
| 1575 | return isRadioOnForSubscriber(subId); |
| 1576 | } finally { |
| 1577 | Binder.restoreCallingIdentity(identity); |
| 1578 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1582 | final long identity = Binder.clearCallingIdentity(); |
| 1583 | try { |
| 1584 | final Phone phone = getPhone(subId); |
| 1585 | if (phone != null) { |
| 1586 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1587 | } else { |
| 1588 | return false; |
| 1589 | } |
| 1590 | } finally { |
| 1591 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1592 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1596 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1597 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1598 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1599 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1600 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1601 | |
| 1602 | final long identity = Binder.clearCallingIdentity(); |
| 1603 | try { |
| 1604 | final Phone phone = getPhone(subId); |
| 1605 | if (phone != null) { |
| 1606 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1607 | } |
| 1608 | } finally { |
| 1609 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1610 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1611 | } |
| 1612 | |
| 1613 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1614 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1615 | } |
| 1616 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1617 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1618 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1619 | |
| 1620 | final long identity = Binder.clearCallingIdentity(); |
| 1621 | try { |
| 1622 | final Phone phone = getPhone(subId); |
| 1623 | if (phone == null) { |
| 1624 | return false; |
| 1625 | } |
| 1626 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1627 | toggleRadioOnOffForSubscriber(subId); |
| 1628 | } |
| 1629 | return true; |
| 1630 | } finally { |
| 1631 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1632 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1633 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1634 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1635 | public boolean needMobileRadioShutdown() { |
| 1636 | /* |
| 1637 | * If any of the Radios are available, it will need to be |
| 1638 | * shutdown. So return true if any Radio is available. |
| 1639 | */ |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1640 | final long identity = Binder.clearCallingIdentity(); |
| 1641 | try { |
| 1642 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1643 | Phone phone = PhoneFactory.getPhone(i); |
| 1644 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1645 | } |
| 1646 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1647 | return false; |
| 1648 | } finally { |
| 1649 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1650 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1651 | } |
| 1652 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1653 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1654 | public void shutdownMobileRadios() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1655 | enforceModifyPermission(); |
| 1656 | |
| 1657 | final long identity = Binder.clearCallingIdentity(); |
| 1658 | try { |
| 1659 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1660 | logv("Shutting down Phone " + i); |
| 1661 | shutdownRadioUsingPhoneId(i); |
| 1662 | } |
| 1663 | } finally { |
| 1664 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1665 | } |
| 1666 | } |
| 1667 | |
| 1668 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1669 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1670 | if (phone != null && phone.isRadioAvailable()) { |
| 1671 | phone.shutdownRadio(); |
| 1672 | } |
| 1673 | } |
| 1674 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1675 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1676 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1677 | |
| 1678 | final long identity = Binder.clearCallingIdentity(); |
| 1679 | try { |
| 1680 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1681 | if (defaultPhone != null) { |
| 1682 | defaultPhone.setRadioPower(turnOn); |
| 1683 | return true; |
| 1684 | } else { |
| 1685 | loge("There's no default phone."); |
| 1686 | return false; |
| 1687 | } |
| 1688 | } finally { |
| 1689 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1690 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1693 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1694 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1695 | |
| 1696 | final long identity = Binder.clearCallingIdentity(); |
| 1697 | try { |
| 1698 | final Phone phone = getPhone(subId); |
| 1699 | if (phone != null) { |
| 1700 | phone.setRadioPower(turnOn); |
| 1701 | return true; |
| 1702 | } else { |
| 1703 | return false; |
| 1704 | } |
| 1705 | } finally { |
| 1706 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1707 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1708 | } |
| 1709 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1710 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1711 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1712 | public boolean enableDataConnectivity() { |
| 1713 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1714 | |
| 1715 | final long identity = Binder.clearCallingIdentity(); |
| 1716 | try { |
| 1717 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1718 | final Phone phone = getPhone(subId); |
| 1719 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1720 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1721 | return true; |
| 1722 | } else { |
| 1723 | return false; |
| 1724 | } |
| 1725 | } finally { |
| 1726 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1727 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1728 | } |
| 1729 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1730 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1731 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1732 | public boolean disableDataConnectivity() { |
| 1733 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1734 | |
| 1735 | final long identity = Binder.clearCallingIdentity(); |
| 1736 | try { |
| 1737 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1738 | final Phone phone = getPhone(subId); |
| 1739 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1740 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1741 | return true; |
| 1742 | } else { |
| 1743 | return false; |
| 1744 | } |
| 1745 | } finally { |
| 1746 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1747 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1748 | } |
| 1749 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1750 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1751 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1752 | final long identity = Binder.clearCallingIdentity(); |
| 1753 | try { |
| 1754 | final Phone phone = getPhone(subId); |
| 1755 | if (phone != null) { |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1756 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1757 | } else { |
| 1758 | return false; |
| 1759 | } |
| 1760 | } finally { |
| 1761 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1762 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1766 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1769 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1770 | enforceCallPermission(); |
| 1771 | |
| 1772 | final long identity = Binder.clearCallingIdentity(); |
| 1773 | try { |
| 1774 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1775 | return; |
| 1776 | } |
| 1777 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1778 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1779 | } finally { |
| 1780 | Binder.restoreCallingIdentity(identity); |
| 1781 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1782 | }; |
| 1783 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1784 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1785 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1786 | |
| 1787 | final long identity = Binder.clearCallingIdentity(); |
| 1788 | try { |
| 1789 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1790 | return false; |
| 1791 | } |
| 1792 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1793 | } finally { |
| 1794 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1795 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1796 | } |
| 1797 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1798 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1799 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1802 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1803 | final long identity = Binder.clearCallingIdentity(); |
| 1804 | try { |
| 1805 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1806 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1807 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1808 | } finally { |
| 1809 | Binder.restoreCallingIdentity(identity); |
| 1810 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1813 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1814 | public int getDataState() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1815 | final long identity = Binder.clearCallingIdentity(); |
| 1816 | try { |
| 1817 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1818 | if (phone != null) { |
| 1819 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1820 | } else { |
| 1821 | return PhoneConstantConversions.convertDataState( |
| 1822 | PhoneConstants.DataState.DISCONNECTED); |
| 1823 | } |
| 1824 | } finally { |
| 1825 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1826 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1829 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1830 | public int getDataActivity() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1831 | final long identity = Binder.clearCallingIdentity(); |
| 1832 | try { |
| 1833 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1834 | if (phone != null) { |
| 1835 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1836 | } else { |
| 1837 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1838 | } |
| 1839 | } finally { |
| 1840 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1841 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1845 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1846 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1847 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1848 | |
| 1849 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 1850 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 1851 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 1852 | .setCallingPackage(callingPackage) |
| 1853 | .setCallingPid(Binder.getCallingPid()) |
| 1854 | .setCallingUid(Binder.getCallingUid()) |
| 1855 | .setMethod("getCellLocation") |
| 1856 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 1857 | .build()); |
| 1858 | switch (locationResult) { |
| 1859 | case DENIED_HARD: |
| 1860 | throw new SecurityException("Not allowed to access cell location"); |
| 1861 | case DENIED_SOFT: |
| 1862 | return new Bundle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1863 | } |
| 1864 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1865 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1866 | final long identity = Binder.clearCallingIdentity(); |
| 1867 | try { |
| 1868 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1869 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1870 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1871 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1872 | cl.fillInNotifierBundle(data); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1873 | return data; |
| 1874 | } finally { |
| 1875 | Binder.restoreCallingIdentity(identity); |
| 1876 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1877 | } |
| 1878 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1879 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1880 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1881 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1882 | // registered cell info, so return a NULL country instead. |
| 1883 | final long identity = Binder.clearCallingIdentity(); |
| 1884 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1885 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1886 | // Get default phone in this case. |
| 1887 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1888 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1889 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1890 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1891 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1892 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1893 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1894 | return ""; |
| 1895 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1896 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1897 | if (phone != null) { |
| 1898 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 1899 | if (sst != null) { |
| 1900 | LocaleTracker lt = sst.getLocaleTracker(); |
| 1901 | if (lt != null) { |
| 1902 | return lt.getCurrentCountry(); |
| 1903 | } |
| 1904 | } |
| 1905 | } |
| 1906 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1907 | } finally { |
| 1908 | Binder.restoreCallingIdentity(identity); |
| 1909 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1910 | } |
| 1911 | |
| 1912 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1913 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1914 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1915 | } |
| 1916 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1917 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1918 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1919 | mApp.enforceCallingOrSelfPermission( |
| 1920 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1921 | |
| 1922 | final long identity = Binder.clearCallingIdentity(); |
| 1923 | try { |
| 1924 | final Phone phone = getPhone(subId); |
| 1925 | if (phone != null) { |
| 1926 | phone.enableLocationUpdates(); |
| 1927 | } |
| 1928 | } finally { |
| 1929 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1930 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | @Override |
| 1934 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1935 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1936 | } |
| 1937 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1938 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1939 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1940 | mApp.enforceCallingOrSelfPermission( |
| 1941 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1942 | |
| 1943 | final long identity = Binder.clearCallingIdentity(); |
| 1944 | try { |
| 1945 | final Phone phone = getPhone(subId); |
| 1946 | if (phone != null) { |
| 1947 | phone.disableLocationUpdates(); |
| 1948 | } |
| 1949 | } finally { |
| 1950 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1951 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1952 | } |
| 1953 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1954 | /** |
| 1955 | * Returns the target SDK version number for a given package name. |
| 1956 | * |
| 1957 | * @return target SDK if the package is found or INT_MAX. |
| 1958 | */ |
| 1959 | private int getTargetSdk(String packageName) { |
| 1960 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1961 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo( |
| 1962 | packageName, 0); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1963 | if (ai != null) return ai.targetSdkVersion; |
| 1964 | } catch (PackageManager.NameNotFoundException unexpected) { |
| 1965 | } |
| 1966 | return Integer.MAX_VALUE; |
| 1967 | } |
| 1968 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1969 | @Override |
| 1970 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1971 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 1972 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 1973 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 1974 | throw new SecurityException( |
| 1975 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 1976 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 1977 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1978 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 1979 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 1980 | return null; |
| 1981 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1982 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1983 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1984 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1985 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 1986 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1987 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1988 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 1989 | for (CellInfo ci : info) { |
| 1990 | if (ci instanceof CellInfoGsm) { |
| 1991 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 1992 | } else if (ci instanceof CellInfoWcdma) { |
| 1993 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 1994 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1995 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1996 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1997 | } |
| 1998 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1999 | private List<CellInfo> getCachedCellInfo() { |
| 2000 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2001 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2002 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2003 | if (info != null) cellInfos.addAll(info); |
| 2004 | } |
| 2005 | return cellInfos; |
| 2006 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2007 | |
| 2008 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2009 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2010 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2011 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2012 | |
| 2013 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2014 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2015 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2016 | .setCallingPackage(callingPackage) |
| 2017 | .setCallingPid(Binder.getCallingPid()) |
| 2018 | .setCallingUid(Binder.getCallingUid()) |
| 2019 | .setMethod("getAllCellInfo") |
| 2020 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2021 | .build()); |
| 2022 | switch (locationResult) { |
| 2023 | case DENIED_HARD: |
| 2024 | throw new SecurityException("Not allowed to access cell info"); |
| 2025 | case DENIED_SOFT: |
| 2026 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2027 | } |
| 2028 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2029 | final int targetSdk = getTargetSdk(callingPackage); |
| 2030 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2031 | return getCachedCellInfo(); |
| 2032 | } |
| 2033 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2034 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2035 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2036 | final long identity = Binder.clearCallingIdentity(); |
| 2037 | try { |
| 2038 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2039 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2040 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2041 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2042 | if (info != null) cellInfos.addAll(info); |
| 2043 | } |
| 2044 | return cellInfos; |
| 2045 | } finally { |
| 2046 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2047 | } |
| 2048 | } |
| 2049 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2050 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2051 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2052 | requestCellInfoUpdateInternal( |
| 2053 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2054 | } |
| 2055 | |
| 2056 | @Override |
| 2057 | public void requestCellInfoUpdateWithWorkSource( |
| 2058 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2059 | enforceModifyPermission(); |
| 2060 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2061 | } |
| 2062 | |
| 2063 | private void requestCellInfoUpdateInternal( |
| 2064 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2065 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2066 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2067 | |
| 2068 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2069 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2070 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2071 | .setCallingPackage(callingPackage) |
| 2072 | .setCallingPid(Binder.getCallingPid()) |
| 2073 | .setCallingUid(Binder.getCallingUid()) |
| 2074 | .setMethod("requestCellInfoUpdate") |
| 2075 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2076 | .build()); |
| 2077 | switch (locationResult) { |
| 2078 | case DENIED_HARD: |
| 2079 | throw new SecurityException("Not allowed to access cell info"); |
| 2080 | case DENIED_SOFT: |
| 2081 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2082 | } |
| 2083 | |
| 2084 | final Phone phone = getPhone(subId); |
| 2085 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2086 | |
| 2087 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2088 | } |
| 2089 | |
| 2090 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2091 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2092 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2093 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2094 | |
| 2095 | final long identity = Binder.clearCallingIdentity(); |
| 2096 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2097 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2098 | } finally { |
| 2099 | Binder.restoreCallingIdentity(identity); |
| 2100 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2101 | } |
| 2102 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2103 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2104 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2105 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2106 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2107 | return null; |
| 2108 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2109 | int subId = phone.getSubId(); |
| 2110 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2111 | mApp, subId, callingPackage, "getImeiForSlot")) { |
| 2112 | return null; |
| 2113 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2114 | |
| 2115 | final long identity = Binder.clearCallingIdentity(); |
| 2116 | try { |
| 2117 | return phone.getImei(); |
| 2118 | } finally { |
| 2119 | Binder.restoreCallingIdentity(identity); |
| 2120 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2124 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2125 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2126 | String tac = null; |
| 2127 | if (phone != null) { |
| 2128 | String imei = phone.getImei(); |
| 2129 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2130 | } |
| 2131 | return tac; |
| 2132 | } |
| 2133 | |
| 2134 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2135 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2136 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2137 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2138 | return null; |
| 2139 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2140 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2141 | int subId = phone.getSubId(); |
| 2142 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2143 | mApp, subId, callingPackage, "getMeidForSlot")) { |
| 2144 | return null; |
| 2145 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2146 | |
| 2147 | final long identity = Binder.clearCallingIdentity(); |
| 2148 | try { |
| 2149 | return phone.getMeid(); |
| 2150 | } finally { |
| 2151 | Binder.restoreCallingIdentity(identity); |
| 2152 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2153 | } |
| 2154 | |
| 2155 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2156 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2157 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2158 | String manufacturerCode = null; |
| 2159 | if (phone != null) { |
| 2160 | String meid = phone.getMeid(); |
| 2161 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2162 | } |
| 2163 | return manufacturerCode; |
| 2164 | } |
| 2165 | |
| 2166 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2167 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2168 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2169 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2170 | return null; |
| 2171 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2172 | int subId = phone.getSubId(); |
| 2173 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2174 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2175 | return null; |
| 2176 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2177 | |
| 2178 | final long identity = Binder.clearCallingIdentity(); |
| 2179 | try { |
| 2180 | return phone.getDeviceSvn(); |
| 2181 | } finally { |
| 2182 | Binder.restoreCallingIdentity(identity); |
| 2183 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2184 | } |
| 2185 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2186 | @Override |
| 2187 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2188 | final long identity = Binder.clearCallingIdentity(); |
| 2189 | try { |
| 2190 | final Phone phone = getPhone(subId); |
| 2191 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2192 | } finally { |
| 2193 | Binder.restoreCallingIdentity(identity); |
| 2194 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2195 | } |
| 2196 | |
| 2197 | @Override |
| 2198 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2199 | final long identity = Binder.clearCallingIdentity(); |
| 2200 | try { |
| 2201 | final Phone phone = getPhone(subId); |
| 2202 | return phone == null ? null : phone.getCarrierName(); |
| 2203 | } finally { |
| 2204 | Binder.restoreCallingIdentity(identity); |
| 2205 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2206 | } |
| 2207 | |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2208 | @Override |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2209 | public int getSubscriptionPreciseCarrierId(int subId) { |
| 2210 | final long identity = Binder.clearCallingIdentity(); |
| 2211 | try { |
| 2212 | final Phone phone = getPhone(subId); |
| 2213 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
| 2214 | : phone.getPreciseCarrierId(); |
| 2215 | } finally { |
| 2216 | Binder.restoreCallingIdentity(identity); |
| 2217 | } |
| 2218 | } |
| 2219 | |
| 2220 | @Override |
| 2221 | public String getSubscriptionPreciseCarrierName(int subId) { |
| 2222 | final long identity = Binder.clearCallingIdentity(); |
| 2223 | try { |
| 2224 | final Phone phone = getPhone(subId); |
| 2225 | return phone == null ? null : phone.getPreciseCarrierName(); |
| 2226 | } finally { |
| 2227 | Binder.restoreCallingIdentity(identity); |
| 2228 | } |
| 2229 | } |
| 2230 | |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2231 | @Override |
chen xu | 4ca4e69 | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2232 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2233 | if (!isSubscriptionMccMnc) { |
| 2234 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2235 | } |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2236 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2237 | if (phone == null) { |
| 2238 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2239 | } |
| 2240 | final long identity = Binder.clearCallingIdentity(); |
| 2241 | try { |
| 2242 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2243 | } finally { |
| 2244 | Binder.restoreCallingIdentity(identity); |
| 2245 | } |
| 2246 | } |
| 2247 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2248 | // |
| 2249 | // Internal helper methods. |
| 2250 | // |
| 2251 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2252 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2253 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2254 | * |
| 2255 | * @throws SecurityException if the caller does not have the required permission |
| 2256 | */ |
| 2257 | private void enforceModifyPermission() { |
| 2258 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2259 | } |
| 2260 | |
| 2261 | /** |
| 2262 | * Make sure the caller has the CALL_PHONE permission. |
| 2263 | * |
| 2264 | * @throws SecurityException if the caller does not have the required permission |
| 2265 | */ |
| 2266 | private void enforceCallPermission() { |
| 2267 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2268 | } |
| 2269 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2270 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2271 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2272 | "ConnectivityService"); |
| 2273 | } |
| 2274 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2275 | private String createTelUrl(String number) { |
| 2276 | if (TextUtils.isEmpty(number)) { |
| 2277 | return null; |
| 2278 | } |
| 2279 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2280 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2281 | } |
| 2282 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2283 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2284 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2285 | } |
| 2286 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2287 | private static void logv(String msg) { |
| 2288 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2289 | } |
| 2290 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2291 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2292 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2293 | } |
| 2294 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2295 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2296 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2297 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2298 | } |
| 2299 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2300 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2301 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2302 | final long identity = Binder.clearCallingIdentity(); |
| 2303 | try { |
| 2304 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2305 | if (phone == null) { |
| 2306 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2307 | } else { |
| 2308 | return phone.getPhoneType(); |
| 2309 | } |
| 2310 | } finally { |
| 2311 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2312 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2313 | } |
| 2314 | |
| 2315 | /** |
| 2316 | * Returns the CDMA ERI icon index to display |
| 2317 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2318 | @Override |
| 2319 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2320 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2321 | } |
| 2322 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2323 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2324 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2325 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2326 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2327 | return -1; |
| 2328 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2329 | |
| 2330 | final long identity = Binder.clearCallingIdentity(); |
| 2331 | try { |
| 2332 | final Phone phone = getPhone(subId); |
| 2333 | if (phone != null) { |
| 2334 | return phone.getCdmaEriIconIndex(); |
| 2335 | } else { |
| 2336 | return -1; |
| 2337 | } |
| 2338 | } finally { |
| 2339 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2340 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | /** |
| 2344 | * Returns the CDMA ERI icon mode, |
| 2345 | * 0 - ON |
| 2346 | * 1 - FLASHING |
| 2347 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2348 | @Override |
| 2349 | public int getCdmaEriIconMode(String callingPackage) { |
| 2350 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2351 | } |
| 2352 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2353 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2354 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2355 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2356 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2357 | return -1; |
| 2358 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2359 | |
| 2360 | final long identity = Binder.clearCallingIdentity(); |
| 2361 | try { |
| 2362 | final Phone phone = getPhone(subId); |
| 2363 | if (phone != null) { |
| 2364 | return phone.getCdmaEriIconMode(); |
| 2365 | } else { |
| 2366 | return -1; |
| 2367 | } |
| 2368 | } finally { |
| 2369 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2370 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | /** |
| 2374 | * Returns the CDMA ERI text, |
| 2375 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2376 | @Override |
| 2377 | public String getCdmaEriText(String callingPackage) { |
| 2378 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2379 | } |
| 2380 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2381 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2382 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2383 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2384 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2385 | return null; |
| 2386 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2387 | |
| 2388 | final long identity = Binder.clearCallingIdentity(); |
| 2389 | try { |
| 2390 | final Phone phone = getPhone(subId); |
| 2391 | if (phone != null) { |
| 2392 | return phone.getCdmaEriText(); |
| 2393 | } else { |
| 2394 | return null; |
| 2395 | } |
| 2396 | } finally { |
| 2397 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2398 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2402 | * Returns the CDMA MDN. |
| 2403 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2404 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2405 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2406 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2407 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2408 | |
| 2409 | final long identity = Binder.clearCallingIdentity(); |
| 2410 | try { |
| 2411 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2412 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2413 | return phone.getLine1Number(); |
| 2414 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2415 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2416 | return null; |
| 2417 | } |
| 2418 | } finally { |
| 2419 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2420 | } |
| 2421 | } |
| 2422 | |
| 2423 | /** |
| 2424 | * Returns the CDMA MIN. |
| 2425 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2426 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2427 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2428 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2429 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2430 | |
| 2431 | final long identity = Binder.clearCallingIdentity(); |
| 2432 | try { |
| 2433 | final Phone phone = getPhone(subId); |
| 2434 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2435 | return phone.getCdmaMin(); |
| 2436 | } else { |
| 2437 | return null; |
| 2438 | } |
| 2439 | } finally { |
| 2440 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2441 | } |
| 2442 | } |
| 2443 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2444 | @Override |
| 2445 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2446 | INumberVerificationCallback callback, String callingPackage) { |
| 2447 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2448 | != PERMISSION_GRANTED) { |
| 2449 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2450 | } |
| 2451 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2452 | |
| 2453 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2454 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2455 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2456 | } |
| 2457 | |
| 2458 | if (range == null) { |
| 2459 | throw new NullPointerException("Range must be non-null"); |
| 2460 | } |
| 2461 | |
| 2462 | timeoutMillis = Math.min(timeoutMillis, |
| 2463 | TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS); |
| 2464 | |
| 2465 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2466 | } |
| 2467 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2468 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2469 | * Returns true if CDMA provisioning needs to run. |
| 2470 | */ |
| 2471 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2472 | final long identity = Binder.clearCallingIdentity(); |
| 2473 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2474 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2475 | } finally { |
| 2476 | Binder.restoreCallingIdentity(identity); |
| 2477 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2478 | } |
| 2479 | |
| 2480 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2481 | * Sets the voice mail number of a given subId. |
| 2482 | */ |
| 2483 | @Override |
| 2484 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2485 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2486 | |
| 2487 | final long identity = Binder.clearCallingIdentity(); |
| 2488 | try { |
| 2489 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2490 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2491 | return success; |
| 2492 | } finally { |
| 2493 | Binder.restoreCallingIdentity(identity); |
| 2494 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2495 | } |
| 2496 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2497 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2498 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2499 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2500 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2501 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2502 | throw new SecurityException("caller must be system dialer"); |
| 2503 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2504 | |
| 2505 | final long identity = Binder.clearCallingIdentity(); |
| 2506 | try { |
| 2507 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2508 | if (phoneAccountHandle == null) { |
| 2509 | return null; |
| 2510 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2511 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2512 | } finally { |
| 2513 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2514 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2518 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2519 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2520 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2521 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2522 | return null; |
| 2523 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2524 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2525 | final long identity = Binder.clearCallingIdentity(); |
| 2526 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2527 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2528 | } finally { |
| 2529 | Binder.restoreCallingIdentity(identity); |
| 2530 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2534 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2535 | VisualVoicemailSmsFilterSettings settings) { |
| 2536 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2537 | |
| 2538 | final long identity = Binder.clearCallingIdentity(); |
| 2539 | try { |
| 2540 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2541 | mApp, callingPackage, subId, settings); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2542 | } finally { |
| 2543 | Binder.restoreCallingIdentity(identity); |
| 2544 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2545 | } |
| 2546 | |
| 2547 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2548 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2549 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2550 | |
| 2551 | final long identity = Binder.clearCallingIdentity(); |
| 2552 | try { |
| 2553 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2554 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2555 | } finally { |
| 2556 | Binder.restoreCallingIdentity(identity); |
| 2557 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2558 | } |
| 2559 | |
| 2560 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2561 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2562 | String callingPackage, int subId) { |
| 2563 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2564 | |
| 2565 | final long identity = Binder.clearCallingIdentity(); |
| 2566 | try { |
| 2567 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2568 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2569 | } finally { |
| 2570 | Binder.restoreCallingIdentity(identity); |
| 2571 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2572 | } |
| 2573 | |
| 2574 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2575 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2576 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2577 | |
| 2578 | final long identity = Binder.clearCallingIdentity(); |
| 2579 | try { |
| 2580 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2581 | mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2582 | } finally { |
| 2583 | Binder.restoreCallingIdentity(identity); |
| 2584 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2585 | } |
| 2586 | |
| 2587 | @Override |
| 2588 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2589 | String number, int port, String text, PendingIntent sentIntent) { |
| 2590 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2591 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2592 | enforceSendSmsPermission(); |
| 2593 | // Make the calls as the phone process. |
| 2594 | final long identity = Binder.clearCallingIdentity(); |
| 2595 | try { |
| 2596 | SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); |
| 2597 | if (port == 0) { |
| 2598 | smsManager.sendTextMessageWithSelfPermissions(number, null, text, |
| 2599 | sentIntent, null, false); |
| 2600 | } else { |
| 2601 | byte[] data = text.getBytes(StandardCharsets.UTF_8); |
| 2602 | smsManager.sendDataMessageWithSelfPermissions(number, null, |
| 2603 | (short) port, data, sentIntent, null); |
| 2604 | } |
| 2605 | } finally { |
| 2606 | Binder.restoreCallingIdentity(identity); |
| 2607 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2608 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2609 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2610 | * Sets the voice activation state of a given subId. |
| 2611 | */ |
| 2612 | @Override |
| 2613 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2614 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2615 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2616 | |
| 2617 | final long identity = Binder.clearCallingIdentity(); |
| 2618 | try { |
| 2619 | final Phone phone = getPhone(subId); |
| 2620 | if (phone != null) { |
| 2621 | phone.setVoiceActivationState(activationState); |
| 2622 | } else { |
| 2623 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2624 | } |
| 2625 | } finally { |
| 2626 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2627 | } |
| 2628 | } |
| 2629 | |
| 2630 | /** |
| 2631 | * Sets the data activation state of a given subId. |
| 2632 | */ |
| 2633 | @Override |
| 2634 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2635 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2636 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2637 | |
| 2638 | final long identity = Binder.clearCallingIdentity(); |
| 2639 | try { |
| 2640 | final Phone phone = getPhone(subId); |
| 2641 | if (phone != null) { |
| 2642 | phone.setDataActivationState(activationState); |
| 2643 | } else { |
| 2644 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2645 | } |
| 2646 | } finally { |
| 2647 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2648 | } |
| 2649 | } |
| 2650 | |
| 2651 | /** |
| 2652 | * Returns the voice activation state of a given subId. |
| 2653 | */ |
| 2654 | @Override |
| 2655 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2656 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2657 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2658 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2659 | final long identity = Binder.clearCallingIdentity(); |
| 2660 | try { |
| 2661 | if (phone != null) { |
| 2662 | return phone.getVoiceActivationState(); |
| 2663 | } else { |
| 2664 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2665 | } |
| 2666 | } finally { |
| 2667 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2668 | } |
| 2669 | } |
| 2670 | |
| 2671 | /** |
| 2672 | * Returns the data activation state of a given subId. |
| 2673 | */ |
| 2674 | @Override |
| 2675 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2676 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2677 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2678 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2679 | final long identity = Binder.clearCallingIdentity(); |
| 2680 | try { |
| 2681 | if (phone != null) { |
| 2682 | return phone.getDataActivationState(); |
| 2683 | } else { |
| 2684 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2685 | } |
| 2686 | } finally { |
| 2687 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2688 | } |
| 2689 | } |
| 2690 | |
| 2691 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2692 | * Returns the unread count of voicemails for a subId |
| 2693 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2694 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2695 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2696 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2697 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2698 | return 0; |
| 2699 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2700 | final long identity = Binder.clearCallingIdentity(); |
| 2701 | try { |
| 2702 | final Phone phone = getPhone(subId); |
| 2703 | if (phone != null) { |
| 2704 | return phone.getVoiceMessageCount(); |
| 2705 | } else { |
| 2706 | return 0; |
| 2707 | } |
| 2708 | } finally { |
| 2709 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2710 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2711 | } |
| 2712 | |
| 2713 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2714 | * returns true, if the device is in a state where both voice and data |
| 2715 | * are supported simultaneously. This can change based on location or network condition. |
| 2716 | */ |
| 2717 | @Override |
| 2718 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2719 | final long identity = Binder.clearCallingIdentity(); |
| 2720 | try { |
| 2721 | final Phone phone = getPhone(subId); |
| 2722 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2723 | } finally { |
| 2724 | Binder.restoreCallingIdentity(identity); |
| 2725 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2726 | } |
| 2727 | |
| 2728 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2729 | * Send the dialer code if called from the current default dialer or the caller has |
| 2730 | * carrier privilege. |
| 2731 | * @param inputCode The dialer code to send |
| 2732 | */ |
| 2733 | @Override |
| 2734 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2735 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2736 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2737 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2738 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2739 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2740 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2741 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2742 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2743 | |
| 2744 | final long identity = Binder.clearCallingIdentity(); |
| 2745 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2746 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2747 | } finally { |
| 2748 | Binder.restoreCallingIdentity(identity); |
| 2749 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2750 | } |
| 2751 | |
| 2752 | /** |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2753 | * Returns the data network type. |
| 2754 | * Legacy call, permission-free. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2755 | * |
| 2756 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 2757 | */ |
| 2758 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2759 | public int getNetworkType() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2760 | final long identity = Binder.clearCallingIdentity(); |
| 2761 | try { |
| 2762 | final Phone phone = getPhone(getDefaultSubscription()); |
| 2763 | if (phone != null) { |
| 2764 | return phone.getServiceState().getDataNetworkType(); |
| 2765 | } else { |
| 2766 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2767 | } |
| 2768 | } finally { |
| 2769 | Binder.restoreCallingIdentity(identity); |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2770 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2771 | } |
| 2772 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2773 | @Override |
| 2774 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2775 | if (!isActiveSubscription(subId)) { |
| 2776 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2777 | } |
| 2778 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2779 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2780 | } |
| 2781 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2782 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2783 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2784 | throws RemoteException { |
| 2785 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2786 | final long token = Binder.clearCallingIdentity(); |
| 2787 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2788 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2789 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2790 | .addRegistrationCallbackForSubscription(c, subId); |
| 2791 | } finally { |
| 2792 | Binder.restoreCallingIdentity(token); |
| 2793 | } |
| 2794 | } |
| 2795 | |
| 2796 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2797 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2798 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2799 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2800 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2801 | } |
| 2802 | Binder.withCleanCallingIdentity(() -> { |
| 2803 | try { |
| 2804 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2805 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2806 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2807 | } catch (IllegalArgumentException e) { |
| 2808 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2809 | + "is inactive, ignoring unregister."); |
| 2810 | // If the subscription is no longer active, just return, since the callback |
| 2811 | // will already have been removed internally. |
| 2812 | } |
| 2813 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2814 | } |
| 2815 | |
| 2816 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2817 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2818 | throws RemoteException { |
| 2819 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2820 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2821 | final long token = Binder.clearCallingIdentity(); |
| 2822 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2823 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2824 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2825 | } finally { |
| 2826 | Binder.restoreCallingIdentity(token); |
| 2827 | } |
| 2828 | } |
| 2829 | |
| 2830 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2831 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2832 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2833 | |
| 2834 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2835 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2836 | } |
| 2837 | Binder.withCleanCallingIdentity(() -> { |
| 2838 | try { |
| 2839 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2840 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2841 | .removeCapabilitiesCallbackForSubscription(c, subId); |
| 2842 | } catch (IllegalArgumentException e) { |
| 2843 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2844 | + "is inactive, ignoring unregister."); |
| 2845 | // If the subscription is no longer active, just return, since the callback |
| 2846 | // will already have been removed internally. |
| 2847 | } |
| 2848 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2852 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2853 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2854 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2855 | final long token = Binder.clearCallingIdentity(); |
| 2856 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2857 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2858 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2859 | } catch (ImsException e) { |
| 2860 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2861 | return false; |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2862 | } catch (IllegalArgumentException e) { |
| 2863 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 2864 | return false; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2865 | } finally { |
| 2866 | Binder.restoreCallingIdentity(token); |
| 2867 | } |
| 2868 | } |
| 2869 | |
| 2870 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2871 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2872 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2873 | final long token = Binder.clearCallingIdentity(); |
| 2874 | try { |
| 2875 | Phone phone = getPhone(subId); |
| 2876 | if (phone == null) return false; |
| 2877 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2878 | } finally { |
| 2879 | Binder.restoreCallingIdentity(token); |
| 2880 | } |
| 2881 | } |
| 2882 | |
| 2883 | @Override |
| 2884 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2885 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2886 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2887 | final long token = Binder.clearCallingIdentity(); |
| 2888 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2889 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2890 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2891 | } finally { |
| 2892 | Binder.restoreCallingIdentity(token); |
| 2893 | } |
| 2894 | } |
| 2895 | |
| 2896 | @Override |
| 2897 | public void setAdvancedCallingSetting(int subId, boolean isEnabled) { |
| 2898 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2899 | "setAdvancedCallingSetting"); |
| 2900 | final long identity = Binder.clearCallingIdentity(); |
| 2901 | try { |
| 2902 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2903 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2904 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 2905 | } finally { |
| 2906 | Binder.restoreCallingIdentity(identity); |
| 2907 | } |
| 2908 | } |
| 2909 | |
| 2910 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2911 | public boolean isVtSettingEnabled(int subId) { |
| 2912 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2913 | final long identity = Binder.clearCallingIdentity(); |
| 2914 | try { |
| 2915 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2916 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2917 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2918 | } finally { |
| 2919 | Binder.restoreCallingIdentity(identity); |
| 2920 | } |
| 2921 | } |
| 2922 | |
| 2923 | @Override |
| 2924 | public void setVtSetting(int subId, boolean isEnabled) { |
| 2925 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2926 | "setVtSetting"); |
| 2927 | final long identity = Binder.clearCallingIdentity(); |
| 2928 | try { |
| 2929 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2930 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2931 | } finally { |
| 2932 | Binder.restoreCallingIdentity(identity); |
| 2933 | } |
| 2934 | } |
| 2935 | |
| 2936 | @Override |
| 2937 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 2938 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 2939 | final long identity = Binder.clearCallingIdentity(); |
| 2940 | try { |
| 2941 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2942 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2943 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 2944 | } finally { |
| 2945 | Binder.restoreCallingIdentity(identity); |
| 2946 | } |
| 2947 | } |
| 2948 | |
| 2949 | @Override |
| 2950 | public void setVoWiFiSetting(int subId, boolean isEnabled) { |
| 2951 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2952 | "setVoWiFiSetting"); |
| 2953 | final long identity = Binder.clearCallingIdentity(); |
| 2954 | try { |
| 2955 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2956 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2957 | } finally { |
| 2958 | Binder.restoreCallingIdentity(identity); |
| 2959 | } |
| 2960 | } |
| 2961 | |
| 2962 | @Override |
| 2963 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 2964 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 2965 | final long identity = Binder.clearCallingIdentity(); |
| 2966 | try { |
| 2967 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2968 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2969 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 2970 | } finally { |
| 2971 | Binder.restoreCallingIdentity(identity); |
| 2972 | } |
| 2973 | } |
| 2974 | |
| 2975 | @Override |
| 2976 | public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) { |
| 2977 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2978 | "setVoWiFiRoamingSetting"); |
| 2979 | final long identity = Binder.clearCallingIdentity(); |
| 2980 | try { |
| 2981 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2982 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2983 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 2984 | } finally { |
| 2985 | Binder.restoreCallingIdentity(identity); |
| 2986 | } |
| 2987 | } |
| 2988 | |
| 2989 | @Override |
| 2990 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 2991 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2992 | "setVoWiFiNonPersistent"); |
| 2993 | final long identity = Binder.clearCallingIdentity(); |
| 2994 | try { |
| 2995 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 2996 | boolean isRoaming = TelephonyManager.from( |
| 2997 | getPhone(subId).getContext()).isNetworkRoaming(subId); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2998 | ImsManager.getInstance(mApp, |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 2999 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3000 | } finally { |
| 3001 | Binder.restoreCallingIdentity(identity); |
| 3002 | } |
| 3003 | } |
| 3004 | |
| 3005 | @Override |
| 3006 | public int getVoWiFiModeSetting(int subId) { |
| 3007 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3008 | final long identity = Binder.clearCallingIdentity(); |
| 3009 | try { |
| 3010 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3011 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3012 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 3013 | } finally { |
| 3014 | Binder.restoreCallingIdentity(identity); |
| 3015 | } |
| 3016 | } |
| 3017 | |
| 3018 | @Override |
| 3019 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3020 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3021 | "setVoWiFiModeSetting"); |
| 3022 | final long identity = Binder.clearCallingIdentity(); |
| 3023 | try { |
| 3024 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3025 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3026 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 3027 | } finally { |
| 3028 | Binder.restoreCallingIdentity(identity); |
| 3029 | } |
| 3030 | } |
| 3031 | |
| 3032 | @Override |
| 3033 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3034 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3035 | final long identity = Binder.clearCallingIdentity(); |
| 3036 | try { |
| 3037 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3038 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3039 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 3040 | } finally { |
| 3041 | Binder.restoreCallingIdentity(identity); |
| 3042 | } |
| 3043 | } |
| 3044 | |
| 3045 | @Override |
| 3046 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3047 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3048 | "setVoWiFiRoamingModeSetting"); |
| 3049 | final long identity = Binder.clearCallingIdentity(); |
| 3050 | try { |
| 3051 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3052 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3053 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 3054 | } finally { |
| 3055 | Binder.restoreCallingIdentity(identity); |
| 3056 | } |
| 3057 | } |
| 3058 | |
| 3059 | @Override |
| 3060 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3061 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3062 | "setRttCapabilityEnabled"); |
| 3063 | final long identity = Binder.clearCallingIdentity(); |
| 3064 | try { |
| 3065 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3066 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3067 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3068 | } finally { |
| 3069 | Binder.restoreCallingIdentity(identity); |
| 3070 | } |
| 3071 | } |
| 3072 | |
| 3073 | @Override |
| 3074 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3075 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3076 | final long identity = Binder.clearCallingIdentity(); |
| 3077 | try { |
| 3078 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3079 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3080 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 3081 | } finally { |
| 3082 | Binder.restoreCallingIdentity(identity); |
| 3083 | } |
| 3084 | } |
| 3085 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3086 | @Override |
| 3087 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3088 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3089 | final long identity = Binder.clearCallingIdentity(); |
| 3090 | try { |
| 3091 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3092 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3093 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3094 | } finally { |
| 3095 | Binder.restoreCallingIdentity(identity); |
| 3096 | } |
| 3097 | } |
| 3098 | |
| 3099 | @Override |
| 3100 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3101 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3102 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3103 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3104 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3105 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3106 | try { |
| 3107 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3108 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3109 | .removeProvisioningCallbackForSubscription(callback, subId); |
| 3110 | } catch (IllegalArgumentException e) { |
| 3111 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3112 | + "is inactive, ignoring unregister."); |
| 3113 | // If the subscription is no longer active, just return, since the callback will already |
| 3114 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3115 | } finally { |
| 3116 | Binder.restoreCallingIdentity(identity); |
| 3117 | } |
| 3118 | } |
| 3119 | |
| 3120 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3121 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3122 | boolean isProvisioned) { |
| 3123 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3124 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3125 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3126 | } |
| 3127 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3128 | "setProvisioningStatusForCapability"); |
| 3129 | final long identity = Binder.clearCallingIdentity(); |
| 3130 | try { |
| 3131 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3132 | Phone phone = getPhone(subId); |
| 3133 | if (phone == null) { |
| 3134 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3135 | + subId); |
| 3136 | return; |
| 3137 | } |
| 3138 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3139 | return; |
| 3140 | } |
| 3141 | |
| 3142 | // this capability requires provisioning, route to the correct API. |
| 3143 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3144 | switch (capability) { |
| 3145 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3146 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3147 | ims.setVolteProvisioned(isProvisioned); |
| 3148 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3149 | ims.setWfcProvisioned(isProvisioned); |
| 3150 | } |
| 3151 | break; |
| 3152 | } |
| 3153 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3154 | // There is currently no difference in VT provisioning type. |
| 3155 | ims.setVtProvisioned(isProvisioned); |
| 3156 | break; |
| 3157 | } |
| 3158 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3159 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3160 | // change the capability of the feature instead if needed. |
| 3161 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3162 | == isProvisioned) { |
| 3163 | // No change in provisioning. |
| 3164 | return; |
| 3165 | } |
| 3166 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3167 | try { |
| 3168 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
| 3169 | } catch (ImsException e) { |
| 3170 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3171 | + ", Exception" + e.getMessage()); |
| 3172 | } |
| 3173 | break; |
| 3174 | } |
| 3175 | default: { |
| 3176 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3177 | + capability + "', which does not require provisioning."); |
| 3178 | } |
| 3179 | } |
| 3180 | |
| 3181 | } finally { |
| 3182 | Binder.restoreCallingIdentity(identity); |
| 3183 | } |
| 3184 | } |
| 3185 | |
| 3186 | @Override |
| 3187 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3188 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3189 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3190 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3191 | } |
| 3192 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3193 | final long identity = Binder.clearCallingIdentity(); |
| 3194 | try { |
| 3195 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3196 | Phone phone = getPhone(subId); |
| 3197 | if (phone == null) { |
| 3198 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3199 | + subId); |
| 3200 | // We will fail with "true" as the provisioning status because this is the default |
| 3201 | // if we do not require provisioning. |
| 3202 | return true; |
| 3203 | } |
| 3204 | |
| 3205 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3206 | return true; |
| 3207 | } |
| 3208 | |
| 3209 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3210 | switch (capability) { |
| 3211 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3212 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3213 | return ims.isVolteProvisionedOnDevice(); |
| 3214 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3215 | return ims.isWfcProvisionedOnDevice(); |
| 3216 | } |
| 3217 | // This should never happen, since we are checking tech above to make sure it |
| 3218 | // is either LTE or IWLAN. |
| 3219 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3220 | + "capability."); |
| 3221 | } |
| 3222 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3223 | // There is currently no difference in VT provisioning type. |
| 3224 | return ims.isVtProvisionedOnDevice(); |
| 3225 | } |
| 3226 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3227 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3228 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3229 | } |
| 3230 | default: { |
| 3231 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3232 | + capability + "', which does not require provisioning."); |
| 3233 | } |
| 3234 | } |
| 3235 | |
| 3236 | } finally { |
| 3237 | Binder.restoreCallingIdentity(identity); |
| 3238 | } |
| 3239 | } |
| 3240 | |
| 3241 | @Override |
| 3242 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3243 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3244 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3245 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3246 | } |
| 3247 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3248 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3249 | return (provisionedBits & capability) > 0; |
| 3250 | } |
| 3251 | |
| 3252 | @Override |
| 3253 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3254 | boolean isProvisioned) { |
| 3255 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3256 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3257 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3258 | } |
| 3259 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3260 | "setProvisioningStatusForCapability"); |
| 3261 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3262 | // If the current provisioning status for capability already matches isProvisioned, |
| 3263 | // do nothing. |
| 3264 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3265 | return; |
| 3266 | } |
| 3267 | if (isProvisioned) { |
| 3268 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3269 | } else { |
| 3270 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3271 | } |
| 3272 | } |
| 3273 | |
| 3274 | /** |
| 3275 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3276 | * technology. The bitfield should mirror the bitfield defined by |
| 3277 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3278 | */ |
| 3279 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3280 | String key = getMmTelProvisioningKey(subId, tech); |
| 3281 | // Default is no capabilities are provisioned. |
| 3282 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3283 | } |
| 3284 | |
| 3285 | /** |
| 3286 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3287 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3288 | * technology specified. |
| 3289 | * |
| 3290 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3291 | */ |
| 3292 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3293 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3294 | String key = getMmTelProvisioningKey(subId, tech); |
| 3295 | editor.putInt(key, newField); |
| 3296 | editor.commit(); |
| 3297 | } |
| 3298 | |
| 3299 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3300 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3301 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3302 | } |
| 3303 | |
| 3304 | /** |
| 3305 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3306 | * carrier associated with the subscription id. |
| 3307 | */ |
| 3308 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3309 | int capability) { |
| 3310 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3311 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3312 | boolean requireUtProvisioning = c.getBoolean( |
| 3313 | // By default, this config is true (even if there is no SIM). We also check to make |
| 3314 | // sure the subscription needs provisioning here, so we do not need to check for |
| 3315 | // the no-SIM case, where we would normally shortcut this to false. |
| 3316 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true) |
| 3317 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3318 | false); |
| 3319 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3320 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3321 | |
| 3322 | // First check to make sure that the capability requires provisioning. |
| 3323 | switch (capability) { |
| 3324 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3325 | // intentional fallthrough |
| 3326 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3327 | if (requireVoiceVtProvisioning) { |
| 3328 | // Voice and Video requires provisioning |
| 3329 | return true; |
| 3330 | } |
| 3331 | break; |
| 3332 | } |
| 3333 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3334 | if (requireUtProvisioning) { |
| 3335 | // UT requires provisioning |
| 3336 | return true; |
| 3337 | } |
| 3338 | break; |
| 3339 | } |
| 3340 | } |
| 3341 | return false; |
| 3342 | } |
| 3343 | |
| 3344 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3345 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3346 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3347 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3348 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3349 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3350 | final long identity = Binder.clearCallingIdentity(); |
| 3351 | try { |
| 3352 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3353 | int slotId = getSlotIndex(subId); |
| 3354 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3355 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3356 | + subId + "' for key:" + key); |
| 3357 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3358 | } |
| 3359 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3360 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3361 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3362 | + subId + "' for key:" + key); |
| 3363 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3364 | } finally { |
| 3365 | Binder.restoreCallingIdentity(identity); |
| 3366 | } |
| 3367 | } |
| 3368 | |
| 3369 | @Override |
| 3370 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3371 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3372 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3373 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3374 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3375 | final long identity = Binder.clearCallingIdentity(); |
| 3376 | try { |
| 3377 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3378 | int slotId = getSlotIndex(subId); |
| 3379 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3380 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3381 | + subId + "' for key:" + key); |
| 3382 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3383 | } |
| 3384 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3385 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3386 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3387 | + subId + "' for key:" + key); |
| 3388 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3389 | } finally { |
| 3390 | Binder.restoreCallingIdentity(identity); |
| 3391 | } |
| 3392 | } |
| 3393 | |
| 3394 | @Override |
| 3395 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3396 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3397 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3398 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3399 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3400 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3401 | final long identity = Binder.clearCallingIdentity(); |
| 3402 | try { |
| 3403 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3404 | int slotId = getSlotIndex(subId); |
| 3405 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3406 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3407 | + subId + "' for key:" + key); |
| 3408 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3409 | } |
| 3410 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3411 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3412 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3413 | + "' for key:" + key); |
| 3414 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3415 | } finally { |
| 3416 | Binder.restoreCallingIdentity(identity); |
| 3417 | } |
| 3418 | } |
| 3419 | |
| 3420 | @Override |
| 3421 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3422 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3423 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3424 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3425 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3426 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3427 | final long identity = Binder.clearCallingIdentity(); |
| 3428 | try { |
| 3429 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3430 | int slotId = getSlotIndex(subId); |
| 3431 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3432 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3433 | + subId + "' for key:" + key); |
| 3434 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3435 | } |
| 3436 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3437 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3438 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3439 | + "' for key:" + key); |
| 3440 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3441 | } finally { |
| 3442 | Binder.restoreCallingIdentity(identity); |
| 3443 | } |
| 3444 | } |
| 3445 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3446 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 3447 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3448 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3449 | throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3450 | } |
| 3451 | return slotId; |
| 3452 | } |
| 3453 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3454 | private int getSlotIndex(int subId) { |
| 3455 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3456 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3457 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3458 | } |
| 3459 | return slotId; |
| 3460 | } |
| 3461 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3462 | /** |
| 3463 | * Returns the network type for a subId |
| 3464 | */ |
| 3465 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3466 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3467 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3468 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3469 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3470 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3471 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3472 | final long identity = Binder.clearCallingIdentity(); |
| 3473 | try { |
| 3474 | final Phone phone = getPhone(subId); |
| 3475 | if (phone != null) { |
| 3476 | return phone.getServiceState().getDataNetworkType(); |
| 3477 | } else { |
| 3478 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3479 | } |
| 3480 | } finally { |
| 3481 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3482 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3483 | } |
| 3484 | |
| 3485 | /** |
| 3486 | * Returns the data network type |
| 3487 | */ |
| 3488 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3489 | public int getDataNetworkType(String callingPackage) { |
| 3490 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3491 | } |
| 3492 | |
| 3493 | /** |
| 3494 | * Returns the data network type for a subId |
| 3495 | */ |
| 3496 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3497 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3498 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3499 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3500 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3501 | } |
| 3502 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3503 | final long identity = Binder.clearCallingIdentity(); |
| 3504 | try { |
| 3505 | final Phone phone = getPhone(subId); |
| 3506 | if (phone != null) { |
| 3507 | return phone.getServiceState().getDataNetworkType(); |
| 3508 | } else { |
| 3509 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3510 | } |
| 3511 | } finally { |
| 3512 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3513 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3514 | } |
| 3515 | |
| 3516 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3517 | * Returns the Voice network type for a subId |
| 3518 | */ |
| 3519 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3520 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3521 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3522 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3523 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3524 | } |
| 3525 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3526 | final long identity = Binder.clearCallingIdentity(); |
| 3527 | try { |
| 3528 | final Phone phone = getPhone(subId); |
| 3529 | if (phone != null) { |
| 3530 | return phone.getServiceState().getVoiceNetworkType(); |
| 3531 | } else { |
| 3532 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3533 | } |
| 3534 | } finally { |
| 3535 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3536 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3537 | } |
| 3538 | |
| 3539 | /** |
| 3540 | * @return true if a ICC card is present |
| 3541 | */ |
| 3542 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3543 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3544 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3545 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3546 | } |
| 3547 | |
| 3548 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3549 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3550 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3551 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3552 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3553 | final long identity = Binder.clearCallingIdentity(); |
| 3554 | try { |
| 3555 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3556 | if (phone != null) { |
| 3557 | return phone.getIccCard().hasIccCard(); |
| 3558 | } else { |
| 3559 | return false; |
| 3560 | } |
| 3561 | } finally { |
| 3562 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3563 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | /** |
| 3567 | * Return if the current radio is LTE on CDMA. This |
| 3568 | * is a tri-state return value as for a period of time |
| 3569 | * the mode may be unknown. |
| 3570 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3571 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3572 | * @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] | 3573 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3574 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3575 | @Override |
| 3576 | public int getLteOnCdmaMode(String callingPackage) { |
| 3577 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3578 | } |
| 3579 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3580 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3581 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3582 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3583 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3584 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3585 | } |
| 3586 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3587 | final long identity = Binder.clearCallingIdentity(); |
| 3588 | try { |
| 3589 | final Phone phone = getPhone(subId); |
| 3590 | if (phone == null) { |
| 3591 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3592 | } else { |
| 3593 | return phone.getLteOnCdmaMode(); |
| 3594 | } |
| 3595 | } finally { |
| 3596 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3597 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3598 | } |
| 3599 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3600 | /** |
| 3601 | * {@hide} |
| 3602 | * Returns Default subId, 0 in the case of single standby. |
| 3603 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3604 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3605 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3606 | } |
| 3607 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3608 | private int getSlotForDefaultSubscription() { |
| 3609 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3610 | } |
| 3611 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3612 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3613 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3614 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3615 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3616 | private boolean isActiveSubscription(int subId) { |
| 3617 | return mSubscriptionController.isActiveSubId(subId); |
| 3618 | } |
| 3619 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3620 | /** |
| 3621 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3622 | */ |
| 3623 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3624 | final long identity = Binder.clearCallingIdentity(); |
| 3625 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3626 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3627 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3628 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3629 | } finally { |
| 3630 | Binder.restoreCallingIdentity(identity); |
| 3631 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3632 | } |
| 3633 | |
| 3634 | /** |
| 3635 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3636 | */ |
| 3637 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3638 | final long identity = Binder.clearCallingIdentity(); |
| 3639 | try { |
| 3640 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3641 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3642 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3643 | } finally { |
| 3644 | Binder.restoreCallingIdentity(identity); |
| 3645 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3646 | } |
| 3647 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3648 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3649 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3650 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3651 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3652 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3653 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3654 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3655 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3656 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3657 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3658 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3659 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3660 | final long identity = Binder.clearCallingIdentity(); |
| 3661 | try { |
| 3662 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3663 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3664 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3665 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3666 | if (bestComponent == null |
| 3667 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3668 | loge("The calling package is not allowed to access ISD-R."); |
| 3669 | throw new SecurityException( |
| 3670 | "The calling package is not allowed to access ISD-R."); |
| 3671 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3672 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3673 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3674 | if (DBG) { |
| 3675 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3676 | } |
| 3677 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
| 3678 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId); |
| 3679 | if (DBG) log("iccOpenLogicalChannel: " + response); |
| 3680 | return response; |
| 3681 | } finally { |
| 3682 | Binder.restoreCallingIdentity(identity); |
| 3683 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3684 | } |
| 3685 | |
| 3686 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3687 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3688 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3689 | mApp, subId, "iccCloseLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3690 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3691 | final long identity = Binder.clearCallingIdentity(); |
| 3692 | try { |
| 3693 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3694 | if (channel < 0) { |
| 3695 | return false; |
| 3696 | } |
| 3697 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId); |
| 3698 | if (DBG) log("iccCloseLogicalChannel: " + success); |
| 3699 | return success; |
| 3700 | } finally { |
| 3701 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3702 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3703 | } |
| 3704 | |
| 3705 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3706 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3707 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3708 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3709 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3710 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3711 | final long identity = Binder.clearCallingIdentity(); |
| 3712 | try { |
| 3713 | if (DBG) { |
| 3714 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3715 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3716 | + p3 + " data=" + data); |
| 3717 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3718 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3719 | if (channel < 0) { |
| 3720 | return ""; |
| 3721 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3722 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3723 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
| 3724 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId); |
| 3725 | if (DBG) log("iccTransmitApduLogicalChannel: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3726 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3727 | // Append the returned status code to the end of the response payload. |
| 3728 | String s = Integer.toHexString( |
| 3729 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3730 | if (response.payload != null) { |
| 3731 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3732 | } |
| 3733 | return s; |
| 3734 | } finally { |
| 3735 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3736 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3737 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3738 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3739 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3740 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3741 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3742 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3743 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3744 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3745 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3746 | final long identity = Binder.clearCallingIdentity(); |
| 3747 | try { |
| 3748 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3749 | && TextUtils.equals(ISDR_AID, data)) { |
| 3750 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3751 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3752 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3753 | if (bestComponent == null |
| 3754 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3755 | loge("The calling package is not allowed to select ISD-R."); |
| 3756 | throw new SecurityException( |
| 3757 | "The calling package is not allowed to select ISD-R."); |
| 3758 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3759 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3760 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3761 | if (DBG) { |
| 3762 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3763 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3764 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3765 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3766 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
| 3767 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId); |
| 3768 | if (DBG) log("iccTransmitApduBasicChannel: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3769 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3770 | // Append the returned status code to the end of the response payload. |
| 3771 | String s = Integer.toHexString( |
| 3772 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3773 | if (response.payload != null) { |
| 3774 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3775 | } |
| 3776 | return s; |
| 3777 | } finally { |
| 3778 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3779 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3780 | } |
| 3781 | |
| 3782 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3783 | 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] | 3784 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3785 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3786 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3787 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3788 | final long identity = Binder.clearCallingIdentity(); |
| 3789 | try { |
| 3790 | if (DBG) { |
| 3791 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3792 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3793 | } |
| 3794 | |
| 3795 | IccIoResult response = |
| 3796 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3797 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3798 | subId); |
| 3799 | |
| 3800 | if (DBG) { |
| 3801 | log("Exchange SIM_IO [R]" + response); |
| 3802 | } |
| 3803 | |
| 3804 | byte[] result = null; |
| 3805 | int length = 2; |
| 3806 | if (response.payload != null) { |
| 3807 | length = 2 + response.payload.length; |
| 3808 | result = new byte[length]; |
| 3809 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3810 | } else { |
| 3811 | result = new byte[length]; |
| 3812 | } |
| 3813 | |
| 3814 | result[length - 1] = (byte) response.sw2; |
| 3815 | result[length - 2] = (byte) response.sw1; |
| 3816 | return result; |
| 3817 | } finally { |
| 3818 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3819 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3820 | } |
| 3821 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3822 | /** |
| 3823 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 3824 | * on a particular subscription |
| 3825 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3826 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 3827 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3828 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 3829 | return null; |
| 3830 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3831 | |
| 3832 | final long identity = Binder.clearCallingIdentity(); |
| 3833 | try { |
| 3834 | if (appType != TelephonyManager.APPTYPE_USIM |
| 3835 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 3836 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 3837 | return null; |
| 3838 | } |
| 3839 | Object response = sendRequest( |
| 3840 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 3841 | if (response instanceof String[]) { |
| 3842 | return (String[]) response; |
| 3843 | } |
| 3844 | // Response is an Exception of some kind, |
| 3845 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3846 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3847 | } finally { |
| 3848 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3849 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3850 | } |
| 3851 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3852 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3853 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3854 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3855 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3856 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3857 | final long identity = Binder.clearCallingIdentity(); |
| 3858 | try { |
| 3859 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 3860 | if (response.payload == null) { |
| 3861 | return ""; |
| 3862 | } |
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 | // Append the returned status code to the end of the response payload. |
| 3865 | String s = Integer.toHexString( |
| 3866 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3867 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3868 | return s; |
| 3869 | } finally { |
| 3870 | Binder.restoreCallingIdentity(identity); |
| 3871 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3872 | } |
| 3873 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3874 | /** |
| 3875 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3876 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3877 | * |
| 3878 | * @param itemID the ID of the item to read |
| 3879 | * @return the NV item as a String, or null on error. |
| 3880 | */ |
| 3881 | @Override |
| 3882 | public String nvReadItem(int itemID) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3883 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3884 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3885 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3886 | |
| 3887 | final long identity = Binder.clearCallingIdentity(); |
| 3888 | try { |
| 3889 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3890 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3891 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 3892 | return value; |
| 3893 | } finally { |
| 3894 | Binder.restoreCallingIdentity(identity); |
| 3895 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3896 | } |
| 3897 | |
| 3898 | /** |
| 3899 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3900 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3901 | * |
| 3902 | * @param itemID the ID of the item to read |
| 3903 | * @param itemValue the value to write, as a String |
| 3904 | * @return true on success; false on any failure |
| 3905 | */ |
| 3906 | @Override |
| 3907 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3908 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3909 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3910 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3911 | |
| 3912 | final long identity = Binder.clearCallingIdentity(); |
| 3913 | try { |
| 3914 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 3915 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3916 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3917 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 3918 | return success; |
| 3919 | } finally { |
| 3920 | Binder.restoreCallingIdentity(identity); |
| 3921 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3922 | } |
| 3923 | |
| 3924 | /** |
| 3925 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 3926 | * Used for device configuration by some CDMA operators. |
| 3927 | * |
| 3928 | * @param preferredRoamingList byte array containing the new PRL |
| 3929 | * @return true on success; false on any failure |
| 3930 | */ |
| 3931 | @Override |
| 3932 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3933 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3934 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3935 | |
| 3936 | final long identity = Binder.clearCallingIdentity(); |
| 3937 | try { |
| 3938 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 3939 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 3940 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 3941 | return success; |
| 3942 | } finally { |
| 3943 | Binder.restoreCallingIdentity(identity); |
| 3944 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3945 | } |
| 3946 | |
| 3947 | /** |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3948 | * 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] | 3949 | * Used for device configuration by some CDMA operators. |
| 3950 | * |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3951 | * @param slotIndex - device slot. |
| 3952 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3953 | * @return true on success; false on any failure |
| 3954 | */ |
| 3955 | @Override |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3956 | public boolean resetModemConfig(int slotIndex) { |
| 3957 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3958 | if (phone != null) { |
| 3959 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3960 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3961 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3962 | final long identity = Binder.clearCallingIdentity(); |
| 3963 | try { |
| 3964 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 3965 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 3966 | return success; |
| 3967 | } finally { |
| 3968 | Binder.restoreCallingIdentity(identity); |
| 3969 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3970 | } |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3971 | return false; |
| 3972 | } |
| 3973 | |
| 3974 | /** |
| 3975 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 3976 | * |
| 3977 | * @param slotIndex - device slot. |
| 3978 | * |
| 3979 | * @return true on success; false on any failure |
| 3980 | */ |
| 3981 | @Override |
| 3982 | public boolean rebootModem(int slotIndex) { |
| 3983 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3984 | if (phone != null) { |
| 3985 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3986 | mApp, phone.getSubId(), "rebootModem"); |
| 3987 | |
| 3988 | final long identity = Binder.clearCallingIdentity(); |
| 3989 | try { |
| 3990 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 3991 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 3992 | return success; |
| 3993 | } finally { |
| 3994 | Binder.restoreCallingIdentity(identity); |
| 3995 | } |
| 3996 | } |
| 3997 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3998 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3999 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4000 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4001 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4002 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4003 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4004 | return new String[0]; |
| 4005 | } |
| 4006 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4007 | final long identity = Binder.clearCallingIdentity(); |
| 4008 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4009 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4010 | } finally { |
| 4011 | Binder.restoreCallingIdentity(identity); |
| 4012 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4013 | } |
| 4014 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4015 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4016 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4017 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4018 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4019 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4020 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4021 | |
| 4022 | final long identity = Binder.clearCallingIdentity(); |
| 4023 | try { |
| 4024 | PhoneFactory.getImsResolver().enableIms(slotId); |
| 4025 | } finally { |
| 4026 | Binder.restoreCallingIdentity(identity); |
| 4027 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4028 | } |
| 4029 | |
| 4030 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4031 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4032 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4033 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4034 | public void disableIms(int slotId) { |
| 4035 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4036 | |
| 4037 | final long identity = Binder.clearCallingIdentity(); |
| 4038 | try { |
| 4039 | PhoneFactory.getImsResolver().disableIms(slotId); |
| 4040 | } finally { |
| 4041 | Binder.restoreCallingIdentity(identity); |
| 4042 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4043 | } |
| 4044 | |
| 4045 | /** |
| 4046 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4047 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4048 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4049 | */ |
| 4050 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4051 | IImsServiceFeatureCallback callback) { |
| 4052 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4053 | |
| 4054 | final long identity = Binder.clearCallingIdentity(); |
| 4055 | try { |
| 4056 | return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback); |
| 4057 | } finally { |
| 4058 | Binder.restoreCallingIdentity(identity); |
| 4059 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4060 | } |
| 4061 | |
| 4062 | /** |
| 4063 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4064 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4065 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4066 | * listener for feature updates. |
| 4067 | */ |
| 4068 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, 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 { |
| 4073 | return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback); |
| 4074 | } finally { |
| 4075 | Binder.restoreCallingIdentity(identity); |
| 4076 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4077 | } |
| 4078 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4079 | /** |
| 4080 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
| 4081 | * specified. |
| 4082 | */ |
| 4083 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4084 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4085 | |
| 4086 | final long identity = Binder.clearCallingIdentity(); |
| 4087 | try { |
| 4088 | return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature); |
| 4089 | } finally { |
| 4090 | Binder.restoreCallingIdentity(identity); |
| 4091 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4092 | } |
| 4093 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4094 | /** |
| 4095 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
| 4096 | * specified. |
| 4097 | */ |
| 4098 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4099 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4100 | |
| 4101 | final long identity = Binder.clearCallingIdentity(); |
| 4102 | try { |
| 4103 | return PhoneFactory.getImsResolver().getImsConfig(slotId, feature); |
| 4104 | } finally { |
| 4105 | Binder.restoreCallingIdentity(identity); |
| 4106 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4107 | } |
| 4108 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4109 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4110 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4111 | * |
| 4112 | * @param slotId the slot ID that the ImsService should bind for. |
| 4113 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4114 | * ImsService is the device default ImsService. |
| 4115 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4116 | * to. |
| 4117 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4118 | * @hide |
| 4119 | */ |
| 4120 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4121 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4122 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4123 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4124 | "setImsService"); |
| 4125 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4126 | final long identity = Binder.clearCallingIdentity(); |
| 4127 | try { |
| 4128 | return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId, |
| 4129 | isCarrierImsService, packageName); |
| 4130 | } finally { |
| 4131 | Binder.restoreCallingIdentity(identity); |
| 4132 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4133 | } |
| 4134 | |
| 4135 | /** |
| 4136 | * Return the ImsService configuration. |
| 4137 | * |
| 4138 | * @param slotId The slot that the ImsService is associated with. |
| 4139 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4140 | * the device default. |
| 4141 | * @return the package name of the ImsService configuration. |
| 4142 | */ |
| 4143 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4144 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4145 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4146 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4147 | "getImsService"); |
| 4148 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4149 | final long identity = Binder.clearCallingIdentity(); |
| 4150 | try { |
| 4151 | return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId, |
| 4152 | isCarrierImsService); |
| 4153 | } finally { |
| 4154 | Binder.restoreCallingIdentity(identity); |
| 4155 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4156 | } |
| 4157 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4158 | public void setImsRegistrationState(boolean registered) { |
| 4159 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4160 | |
| 4161 | final long identity = Binder.clearCallingIdentity(); |
| 4162 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4163 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4164 | } finally { |
| 4165 | Binder.restoreCallingIdentity(identity); |
| 4166 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4167 | } |
| 4168 | |
| 4169 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4170 | * Set the network selection mode to automatic. |
| 4171 | * |
| 4172 | */ |
| 4173 | @Override |
| 4174 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4175 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4176 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4177 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4178 | if (!isActiveSubscription(subId)) { |
| 4179 | return; |
| 4180 | } |
| 4181 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4182 | final long identity = Binder.clearCallingIdentity(); |
| 4183 | try { |
| 4184 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4185 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4186 | } finally { |
| 4187 | Binder.restoreCallingIdentity(identity); |
| 4188 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4189 | } |
| 4190 | |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4191 | /** |
| 4192 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4193 | * |
| 4194 | * @param subId the id of the subscription. |
| 4195 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4196 | * the operator to attach to. |
| 4197 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4198 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4199 | * normal network selection next time. |
| 4200 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4201 | */ |
| 4202 | @Override |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4203 | public boolean setNetworkSelectionModeManual( |
| 4204 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4205 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4206 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4207 | |
| 4208 | if (!isActiveSubscription(subId)) { |
| 4209 | return false; |
| 4210 | } |
| 4211 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4212 | final long identity = Binder.clearCallingIdentity(); |
| 4213 | try { |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4214 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4215 | persistSelection); |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4216 | if (DBG) { |
| 4217 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4218 | + " operator: " + operatorInfo); |
| 4219 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4220 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4221 | } finally { |
| 4222 | Binder.restoreCallingIdentity(identity); |
| 4223 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4224 | } |
| 4225 | |
| 4226 | /** |
| 4227 | * Scans for available networks. |
| 4228 | */ |
| 4229 | @Override |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4230 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4231 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4232 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4233 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4234 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4235 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4236 | .setCallingPackage(callingPackage) |
| 4237 | .setCallingPid(Binder.getCallingPid()) |
| 4238 | .setCallingUid(Binder.getCallingUid()) |
| 4239 | .setMethod("getCellNetworkScanResults") |
| 4240 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4241 | .build()); |
| 4242 | switch (locationResult) { |
| 4243 | case DENIED_HARD: |
| 4244 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4245 | case DENIED_SOFT: |
| 4246 | return null; |
| 4247 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4248 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4249 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4250 | try { |
| 4251 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4252 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4253 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4254 | } finally { |
| 4255 | Binder.restoreCallingIdentity(identity); |
| 4256 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4257 | } |
| 4258 | |
| 4259 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4260 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4261 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4262 | * @param subId id of the subscription |
| 4263 | * @param request contains the radio access networks with bands/channels to scan |
| 4264 | * @param messenger callback messenger for scan results or errors |
| 4265 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4266 | * @return the id of the requested scan which can be used to stop the scan. |
| 4267 | */ |
| 4268 | @Override |
| 4269 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4270 | IBinder binder, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4271 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4272 | mApp, subId, "requestNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4273 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4274 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4275 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4276 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4277 | .setCallingPackage(callingPackage) |
| 4278 | .setCallingPid(Binder.getCallingPid()) |
| 4279 | .setCallingUid(Binder.getCallingUid()) |
| 4280 | .setMethod("requestNetworkScan") |
| 4281 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4282 | .build()); |
| 4283 | switch (locationResult) { |
| 4284 | case DENIED_HARD: |
| 4285 | throw new SecurityException("Not allowed to request network scan -- location"); |
| 4286 | case DENIED_SOFT: |
| 4287 | return -1; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4288 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4289 | |
| 4290 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4291 | request, messenger, binder, getPhone(subId), |
| 4292 | callingPackage); |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4293 | } |
| 4294 | |
| 4295 | /** |
| 4296 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4297 | * |
| 4298 | * @param subId id of the subscription |
| 4299 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4300 | */ |
| 4301 | @Override |
| 4302 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4303 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4304 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4305 | |
| 4306 | final long identity = Binder.clearCallingIdentity(); |
| 4307 | try { |
| 4308 | mNetworkScanRequestTracker.stopNetworkScan(scanId); |
| 4309 | } finally { |
| 4310 | Binder.restoreCallingIdentity(identity); |
| 4311 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4312 | } |
| 4313 | |
| 4314 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4315 | * Get the calculated preferred network type. |
| 4316 | * Used for debugging incorrect network type. |
| 4317 | * |
| 4318 | * @return the preferred network type, defined in RILConstants.java. |
| 4319 | */ |
| 4320 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4321 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4322 | final Phone defaultPhone = getDefaultPhone(); |
| 4323 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4324 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4325 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4326 | } |
| 4327 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4328 | final long identity = Binder.clearCallingIdentity(); |
| 4329 | try { |
| 4330 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4331 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4332 | } finally { |
| 4333 | Binder.restoreCallingIdentity(identity); |
| 4334 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4335 | } |
| 4336 | |
| 4337 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4338 | * Get the preferred network type. |
| 4339 | * Used for device configuration by some CDMA operators. |
| 4340 | * |
| 4341 | * @return the preferred network type, defined in RILConstants.java. |
| 4342 | */ |
| 4343 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4344 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | 4848cd0 | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4345 | TelephonyPermissions |
| 4346 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4347 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4348 | |
| 4349 | final long identity = Binder.clearCallingIdentity(); |
| 4350 | try { |
| 4351 | if (DBG) log("getPreferredNetworkType"); |
| 4352 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4353 | int networkType = (result != null ? result[0] : -1); |
| 4354 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4355 | return networkType; |
| 4356 | } finally { |
| 4357 | Binder.restoreCallingIdentity(identity); |
| 4358 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4359 | } |
| 4360 | |
| 4361 | /** |
| 4362 | * Set the preferred network type. |
| 4363 | * Used for device configuration by some CDMA operators. |
| 4364 | * |
| 4365 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4366 | * @return true on success; false on any failure. |
| 4367 | */ |
| 4368 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4369 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4370 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4371 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4372 | |
| 4373 | final long identity = Binder.clearCallingIdentity(); |
| 4374 | try { |
| 4375 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4376 | Boolean success = (Boolean) sendRequest( |
| 4377 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4378 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4379 | if (success) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4380 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4381 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4382 | } |
| 4383 | return success; |
| 4384 | } finally { |
| 4385 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4386 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4387 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4388 | |
| 4389 | /** |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame^] | 4390 | * Check whether DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4391 | * |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame^] | 4392 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4393 | * @hide |
| 4394 | */ |
| 4395 | @Override |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame^] | 4396 | public boolean getTetherApnRequired() { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4397 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4398 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4399 | final Phone defaultPhone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4400 | try { |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame^] | 4401 | return defaultPhone.hasMatchedTetherApnSetting(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4402 | } finally { |
| 4403 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4404 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4405 | } |
| 4406 | |
| 4407 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4408 | * Set mobile data enabled |
| 4409 | * Used by the user through settings etc to turn on/off mobile data |
| 4410 | * |
| 4411 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4412 | */ |
| 4413 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4414 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4415 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4416 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4417 | |
| 4418 | final long identity = Binder.clearCallingIdentity(); |
| 4419 | try { |
| 4420 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4421 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4422 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4423 | if (phone != null) { |
| 4424 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4425 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4426 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4427 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4428 | } |
| 4429 | } finally { |
| 4430 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4431 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4432 | } |
| 4433 | |
| 4434 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4435 | * Get the user enabled state of Mobile Data. |
| 4436 | * |
| 4437 | * TODO: remove and use isUserDataEnabled. |
| 4438 | * This can't be removed now because some vendor codes |
| 4439 | * calls through ITelephony directly while they should |
| 4440 | * use TelephonyManager. |
| 4441 | * |
| 4442 | * @return true on enabled |
| 4443 | */ |
| 4444 | @Override |
| 4445 | public boolean getDataEnabled(int subId) { |
| 4446 | return isUserDataEnabled(subId); |
| 4447 | } |
| 4448 | |
| 4449 | /** |
| 4450 | * Get whether mobile data is enabled per user setting. |
| 4451 | * |
| 4452 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4453 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4454 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4455 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4456 | * |
| 4457 | * @return {@code true} if data is enabled else {@code false} |
| 4458 | */ |
| 4459 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4460 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4461 | try { |
| 4462 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4463 | null); |
| 4464 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4465 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4466 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4467 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4468 | |
| 4469 | final long identity = Binder.clearCallingIdentity(); |
| 4470 | try { |
| 4471 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4472 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4473 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4474 | if (phone != null) { |
| 4475 | boolean retVal = phone.isUserDataEnabled(); |
| 4476 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4477 | return retVal; |
| 4478 | } else { |
| 4479 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4480 | return false; |
| 4481 | } |
| 4482 | } finally { |
| 4483 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4484 | } |
| 4485 | } |
| 4486 | |
| 4487 | /** |
| 4488 | * Get whether mobile data is enabled. |
| 4489 | * |
| 4490 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4491 | * whether mobile data is actually enabled. |
| 4492 | * |
| 4493 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4494 | * |
| 4495 | * @return {@code true} if data is enabled else {@code false} |
| 4496 | */ |
| 4497 | @Override |
| 4498 | public boolean isDataEnabled(int subId) { |
| 4499 | try { |
| 4500 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4501 | null); |
| 4502 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4503 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4504 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4505 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4506 | |
| 4507 | final long identity = Binder.clearCallingIdentity(); |
| 4508 | try { |
| 4509 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4510 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4511 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4512 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4513 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4514 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4515 | return retVal; |
| 4516 | } else { |
| 4517 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4518 | return false; |
| 4519 | } |
| 4520 | } finally { |
| 4521 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4522 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4523 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4524 | |
| 4525 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4526 | public int getCarrierPrivilegeStatus(int subId) { |
| 4527 | final Phone phone = getPhone(subId); |
| 4528 | if (phone == null) { |
| 4529 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4530 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4531 | } |
| 4532 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4533 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4534 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4535 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4536 | } |
| 4537 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4538 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4539 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4540 | |
| 4541 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4542 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4543 | final Phone phone = getPhone(subId); |
| 4544 | if (phone == null) { |
| 4545 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4546 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4547 | } |
| 4548 | UiccProfile profile = |
| 4549 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4550 | if (profile == null) { |
| 4551 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4552 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4553 | } |
| 4554 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 4555 | } |
| 4556 | |
| 4557 | @Override |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4558 | public int checkCarrierPrivilegesForPackage(String pkgName) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4559 | final Phone defaultPhone = getDefaultPhone(); |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4560 | if (TextUtils.isEmpty(pkgName)) |
| 4561 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4562 | UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4563 | if (card == null) { |
| 4564 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 4565 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4566 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4567 | return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(), |
| 4568 | pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4569 | } |
| 4570 | |
| 4571 | @Override |
| 4572 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4573 | if (TextUtils.isEmpty(pkgName)) |
| 4574 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4575 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4576 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4577 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4578 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4579 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4580 | continue; |
| 4581 | } |
| 4582 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4583 | result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4584 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4585 | break; |
| 4586 | } |
| 4587 | } |
| 4588 | |
| 4589 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4590 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4591 | |
| 4592 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4593 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4594 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4595 | loge("phoneId " + phoneId + " is not valid."); |
| 4596 | return null; |
| 4597 | } |
| 4598 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4599 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4600 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4601 | return null ; |
| 4602 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4603 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4604 | } |
| 4605 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4606 | @Override |
| 4607 | public List<String> getPackagesWithCarrierPrivileges() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4608 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4609 | List<String> privilegedPackages = new ArrayList<>(); |
| 4610 | List<PackageInfo> packages = null; |
| 4611 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4612 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4613 | if (card == null) { |
| 4614 | // No UICC in that slot. |
| 4615 | continue; |
| 4616 | } |
| 4617 | if (card.hasCarrierPrivilegeRules()) { |
| 4618 | if (packages == null) { |
| 4619 | // Only check packages in user 0 for now |
| 4620 | packages = pm.getInstalledPackagesAsUser( |
| 4621 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4622 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4623 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
| 4624 | } |
| 4625 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4626 | PackageInfo pkgInfo = packages.get(p); |
| 4627 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4628 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| 4629 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4630 | privilegedPackages.add(pkgInfo.packageName); |
| 4631 | } |
| 4632 | } |
| 4633 | } |
| 4634 | } |
| 4635 | return privilegedPackages; |
| 4636 | } |
| 4637 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4638 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4639 | final Phone phone = getPhone(subId); |
| 4640 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4641 | if (card == null) { |
| 4642 | loge("getIccId: No UICC"); |
| 4643 | return null; |
| 4644 | } |
| 4645 | String iccId = card.getIccId(); |
| 4646 | if (TextUtils.isEmpty(iccId)) { |
| 4647 | loge("getIccId: ICC ID is null or empty."); |
| 4648 | return null; |
| 4649 | } |
| 4650 | return iccId; |
| 4651 | } |
| 4652 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4653 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4654 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4655 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4656 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4657 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4658 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4659 | final long identity = Binder.clearCallingIdentity(); |
| 4660 | try { |
| 4661 | final String iccId = getIccId(subId); |
| 4662 | final Phone phone = getPhone(subId); |
| 4663 | if (phone == null) { |
| 4664 | return false; |
| 4665 | } |
| 4666 | final String subscriberId = phone.getSubscriberId(); |
| 4667 | |
| 4668 | if (DBG_MERGE) { |
| 4669 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4670 | + subscriberId + " to " + number); |
| 4671 | } |
| 4672 | |
| 4673 | if (TextUtils.isEmpty(iccId)) { |
| 4674 | return false; |
| 4675 | } |
| 4676 | |
| 4677 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4678 | |
| 4679 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4680 | if (alphaTag == null) { |
| 4681 | editor.remove(alphaTagPrefKey); |
| 4682 | } else { |
| 4683 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4684 | } |
| 4685 | |
| 4686 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4687 | // track all merged IMSIs based on line number |
| 4688 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4689 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4690 | if (number == null) { |
| 4691 | editor.remove(numberPrefKey); |
| 4692 | editor.remove(subscriberPrefKey); |
| 4693 | } else { |
| 4694 | editor.putString(numberPrefKey, number); |
| 4695 | editor.putString(subscriberPrefKey, subscriberId); |
| 4696 | } |
| 4697 | |
| 4698 | editor.commit(); |
| 4699 | return true; |
| 4700 | } finally { |
| 4701 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4702 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4703 | } |
| 4704 | |
| 4705 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4706 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4707 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4708 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4709 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4710 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4711 | return null; |
| 4712 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4713 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4714 | final long identity = Binder.clearCallingIdentity(); |
| 4715 | try { |
| 4716 | String iccId = getIccId(subId); |
| 4717 | if (iccId != null) { |
| 4718 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4719 | if (DBG_MERGE) { |
| 4720 | log("getLine1NumberForDisplay returning " |
| 4721 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 4722 | } |
| 4723 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4724 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4725 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 4726 | return null; |
| 4727 | } finally { |
| 4728 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4729 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4730 | } |
| 4731 | |
| 4732 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4733 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4734 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4735 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4736 | return null; |
| 4737 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4738 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4739 | final long identity = Binder.clearCallingIdentity(); |
| 4740 | try { |
| 4741 | String iccId = getIccId(subId); |
| 4742 | if (iccId != null) { |
| 4743 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4744 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 4745 | } |
| 4746 | return null; |
| 4747 | } finally { |
| 4748 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4749 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4750 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4751 | |
| 4752 | @Override |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4753 | public String[] getMergedSubscriberIds(String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4754 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 4755 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4756 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4757 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 4758 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4759 | return null; |
| 4760 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4761 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4762 | final long identity = Binder.clearCallingIdentity(); |
| 4763 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4764 | final Context context = mApp; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4765 | final TelephonyManager tele = TelephonyManager.from(context); |
| 4766 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 4767 | |
| 4768 | // Figure out what subscribers are currently active |
| 4769 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
| 4770 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 4771 | // the process, where TelephonyManager was instantiated. |
| 4772 | // Otherwise AppOps check will fail. |
| 4773 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4774 | final int[] subIds = sub.getActiveSubscriptionIdList(); |
| 4775 | for (int subId : subIds) { |
| 4776 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 4777 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4778 | |
| 4779 | // First pass, find a number override for an active subscriber |
| 4780 | String mergeNumber = null; |
| 4781 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 4782 | for (String key : prefs.keySet()) { |
| 4783 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 4784 | final String subscriberId = (String) prefs.get(key); |
| 4785 | if (activeSubscriberIds.contains(subscriberId)) { |
| 4786 | final String iccId = key.substring( |
| 4787 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 4788 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4789 | mergeNumber = (String) prefs.get(numberKey); |
| 4790 | if (DBG_MERGE) { |
| 4791 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 4792 | + " for active subscriber " + subscriberId); |
| 4793 | } |
| 4794 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 4795 | break; |
| 4796 | } |
| 4797 | } |
| 4798 | } |
| 4799 | } |
| 4800 | |
| 4801 | // Shortcut when no active merged subscribers |
| 4802 | if (TextUtils.isEmpty(mergeNumber)) { |
| 4803 | return null; |
| 4804 | } |
| 4805 | |
| 4806 | // Second pass, find all subscribers under that line override |
| 4807 | final ArraySet<String> result = new ArraySet<>(); |
| 4808 | for (String key : prefs.keySet()) { |
| 4809 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 4810 | final String number = (String) prefs.get(key); |
| 4811 | if (mergeNumber.equals(number)) { |
| 4812 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 4813 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4814 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 4815 | if (!TextUtils.isEmpty(subscriberId)) { |
| 4816 | result.add(subscriberId); |
| 4817 | } |
| 4818 | } |
| 4819 | } |
| 4820 | } |
| 4821 | |
| 4822 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 4823 | Arrays.sort(resultArray); |
| 4824 | if (DBG_MERGE) { |
| 4825 | Slog.d(LOG_TAG, |
| 4826 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 4827 | } |
| 4828 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4829 | } finally { |
| 4830 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4831 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4832 | } |
| 4833 | |
| 4834 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4835 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4836 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4837 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4838 | |
| 4839 | final long identity = Binder.clearCallingIdentity(); |
| 4840 | try { |
| 4841 | final Phone phone = getPhone(subId); |
| 4842 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 4843 | } finally { |
| 4844 | Binder.restoreCallingIdentity(identity); |
| 4845 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4846 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 4847 | |
| 4848 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4849 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4850 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 4851 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4852 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4853 | |
| 4854 | final long identity = Binder.clearCallingIdentity(); |
| 4855 | try { |
| 4856 | final Phone phone = getPhone(subId); |
| 4857 | if (phone == null) { |
| 4858 | return false; |
| 4859 | } |
| 4860 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 4861 | cdmaNonRoamingList); |
| 4862 | } finally { |
| 4863 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4864 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4865 | } |
| 4866 | |
| 4867 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4868 | @Deprecated |
| 4869 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 4870 | enforceModifyPermission(); |
| 4871 | |
| 4872 | int returnValue = 0; |
| 4873 | try { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4874 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4875 | if(result.exception == null) { |
| 4876 | if (result.result != null) { |
| 4877 | byte[] responseData = (byte[])(result.result); |
| 4878 | if(responseData.length > oemResp.length) { |
| 4879 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 4880 | responseData.length + "bytes. Buffer Size is " + |
| 4881 | oemResp.length + "bytes."); |
| 4882 | } |
| 4883 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 4884 | returnValue = responseData.length; |
| 4885 | } |
| 4886 | } else { |
| 4887 | CommandException ex = (CommandException) result.exception; |
| 4888 | returnValue = ex.getCommandError().ordinal(); |
| 4889 | if(returnValue > 0) returnValue *= -1; |
| 4890 | } |
| 4891 | } catch (RuntimeException e) { |
| 4892 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 4893 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 4894 | if(returnValue > 0) returnValue *= -1; |
| 4895 | } |
| 4896 | |
| 4897 | return returnValue; |
| 4898 | } |
| 4899 | |
| 4900 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4901 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 4902 | try { |
| 4903 | ProxyController.getInstance().setRadioCapability(rafs); |
| 4904 | } catch (RuntimeException e) { |
| 4905 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 4906 | } |
| 4907 | } |
| 4908 | |
| 4909 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4910 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4911 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4912 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4913 | if (phone == null) { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4914 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4915 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4916 | final long identity = Binder.clearCallingIdentity(); |
| 4917 | try { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4918 | TelephonyPermissions |
| 4919 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4920 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 4921 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4922 | } finally { |
| 4923 | Binder.restoreCallingIdentity(identity); |
| 4924 | } |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4925 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4926 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4927 | |
| 4928 | @Override |
| 4929 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4930 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4931 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4932 | |
| 4933 | final long identity = Binder.clearCallingIdentity(); |
| 4934 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4935 | ImsManager.getInstance(defaultPhone.getContext(), |
| 4936 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4937 | } finally { |
| 4938 | Binder.restoreCallingIdentity(identity); |
| 4939 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4940 | } |
| 4941 | |
| 4942 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4943 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4944 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4945 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4946 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4947 | return false; |
| 4948 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4949 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4950 | final long identity = Binder.clearCallingIdentity(); |
| 4951 | try { |
| 4952 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 4953 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 4954 | // In the long run, we may instead need to check if there exists a connection service |
| 4955 | // which can support video calling. |
| 4956 | ImsManager imsManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4957 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4958 | return imsManager.isVtEnabledByPlatform() |
| 4959 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 4960 | && imsManager.isVtEnabledByUser(); |
| 4961 | } finally { |
| 4962 | Binder.restoreCallingIdentity(identity); |
| 4963 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4964 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 4965 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4966 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4967 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 4968 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4969 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4970 | return false; |
| 4971 | } |
| 4972 | |
| 4973 | final long identity = Binder.clearCallingIdentity(); |
| 4974 | try { |
| 4975 | CarrierConfigManager configManager = |
| 4976 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4977 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4978 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 4979 | } finally { |
| 4980 | Binder.restoreCallingIdentity(identity); |
| 4981 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4982 | } |
| 4983 | |
| 4984 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4985 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 4986 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4987 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4988 | return false; |
| 4989 | } |
| 4990 | |
| 4991 | final long identity = Binder.clearCallingIdentity(); |
| 4992 | try { |
| 4993 | CarrierConfigManager configManager = |
| 4994 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4995 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4996 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 4997 | } finally { |
| 4998 | Binder.restoreCallingIdentity(identity); |
| 4999 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5000 | } |
| 5001 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5002 | @Override |
| 5003 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5004 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5005 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5006 | } |
| 5007 | |
| 5008 | @Override |
| 5009 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5010 | final long identity = Binder.clearCallingIdentity(); |
| 5011 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5012 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5013 | } finally { |
| 5014 | Binder.restoreCallingIdentity(identity); |
| 5015 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5016 | } |
| 5017 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5018 | /** |
| 5019 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5020 | * support for the feature and device firmware support. |
| 5021 | * |
| 5022 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5023 | */ |
| 5024 | @Override |
| 5025 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5026 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5027 | final Phone phone = getPhone(subscriptionId); |
| 5028 | if (phone == null) { |
| 5029 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5030 | return false; |
| 5031 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5032 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5033 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5034 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5035 | boolean isDeviceSupported = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5036 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5037 | return isCarrierSupported && isDeviceSupported; |
| 5038 | } finally { |
| 5039 | Binder.restoreCallingIdentity(identity); |
| 5040 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5041 | } |
| 5042 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5043 | /** |
| 5044 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier |
| 5045 | * both also support RTT. |
| 5046 | */ |
| 5047 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5048 | final long identity = Binder.clearCallingIdentity(); |
| 5049 | try { |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5050 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5051 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5052 | } finally { |
| 5053 | Binder.restoreCallingIdentity(identity); |
| 5054 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5055 | } |
| 5056 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5057 | /** |
| 5058 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5059 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5060 | * |
| 5061 | * <p>Requires Permission: |
| 5062 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5063 | */ |
| 5064 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5065 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5066 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5067 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5068 | return null; |
| 5069 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5070 | int subId = phone.getSubId(); |
| 5071 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5072 | mApp, subId, callingPackage, "getDeviceId")) { |
| 5073 | return null; |
| 5074 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5075 | |
| 5076 | final long identity = Binder.clearCallingIdentity(); |
| 5077 | try { |
| 5078 | return phone.getDeviceId(); |
| 5079 | } finally { |
| 5080 | Binder.restoreCallingIdentity(identity); |
| 5081 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5082 | } |
| 5083 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5084 | /** |
| 5085 | * {@hide} |
| 5086 | * Returns the IMS Registration Status on a particular subid |
| 5087 | * |
| 5088 | * @param subId |
| 5089 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5090 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5091 | Phone phone = getPhone(subId); |
| 5092 | if (phone != null) { |
| 5093 | return phone.isImsRegistered(); |
| 5094 | } else { |
| 5095 | return false; |
| 5096 | } |
| 5097 | } |
| 5098 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5099 | @Override |
| 5100 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5101 | final long identity = Binder.clearCallingIdentity(); |
| 5102 | try { |
| 5103 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5104 | } finally { |
| 5105 | Binder.restoreCallingIdentity(identity); |
| 5106 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5107 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5108 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5109 | /** |
| 5110 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5111 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5112 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5113 | final long identity = Binder.clearCallingIdentity(); |
| 5114 | try { |
| 5115 | Phone phone = getPhone(subId); |
| 5116 | if (phone != null) { |
| 5117 | return phone.isWifiCallingEnabled(); |
| 5118 | } else { |
| 5119 | return false; |
| 5120 | } |
| 5121 | } finally { |
| 5122 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5123 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5124 | } |
| 5125 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5126 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5127 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5128 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5129 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5130 | final long identity = Binder.clearCallingIdentity(); |
| 5131 | try { |
| 5132 | Phone phone = getPhone(subId); |
| 5133 | if (phone != null) { |
| 5134 | return phone.isVideoEnabled(); |
| 5135 | } else { |
| 5136 | return false; |
| 5137 | } |
| 5138 | } finally { |
| 5139 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5140 | } |
| 5141 | } |
| 5142 | |
| 5143 | /** |
| 5144 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5145 | * defined in {@link ImsRegistrationImplBase}. |
| 5146 | */ |
| 5147 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5148 | final long identity = Binder.clearCallingIdentity(); |
| 5149 | try { |
| 5150 | Phone phone = getPhone(subId); |
| 5151 | if (phone != null) { |
| 5152 | return phone.getImsRegistrationTech(); |
| 5153 | } else { |
| 5154 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5155 | } |
| 5156 | } finally { |
| 5157 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5158 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5159 | } |
| 5160 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5161 | @Override |
| 5162 | public void factoryReset(int subId) { |
| 5163 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5164 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5165 | return; |
| 5166 | } |
| 5167 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5168 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5169 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5170 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5171 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5172 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5173 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5174 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5175 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5176 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5177 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5178 | } |
| 5179 | } finally { |
| 5180 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5181 | } |
| 5182 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5183 | |
| 5184 | @Override |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5185 | public String getSimLocaleForSubscriber(int subId) { |
| 5186 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5187 | final Phone phone = getPhone(subId); |
| 5188 | if (phone == null) { |
| 5189 | log("getSimLocaleForSubscriber, invalid subId"); |
Pengquan Meng | 9c29148 | 2019-01-28 16:26:29 -0800 | [diff] [blame] | 5190 | return null; |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5191 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5192 | final long identity = Binder.clearCallingIdentity(); |
| 5193 | try { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5194 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5195 | phone.getContext().getOpPackageName()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5196 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5197 | // preferences (EF-PL and EF-LI)... |
| 5198 | final int mcc = info.getMcc(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5199 | String simLanguage = null; |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5200 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5201 | if (localeFromDefaultSim != null) { |
| 5202 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5203 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5204 | + localeFromDefaultSim); |
| 5205 | return localeFromDefaultSim.toLanguageTag(); |
| 5206 | } else { |
| 5207 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5208 | } |
| 5209 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5210 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5211 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5212 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5213 | // the SIM and carrier preferences does not include a country we add the country |
| 5214 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5215 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5216 | if (mccLocale != null) { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5217 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5218 | return mccLocale.toLanguageTag(); |
| 5219 | } |
| 5220 | |
| 5221 | if (DBG) log("No locale found - returning null"); |
| 5222 | return null; |
| 5223 | } finally { |
| 5224 | Binder.restoreCallingIdentity(identity); |
| 5225 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5226 | } |
| 5227 | |
| 5228 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5229 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5230 | } |
| 5231 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5232 | /** |
| 5233 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5234 | */ |
| 5235 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5236 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5237 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5238 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5239 | private final ModemActivityInfo mLastModemActivityInfo = |
| 5240 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 5241 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5242 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5243 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5244 | * representing the state of the modem. |
| 5245 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5246 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5247 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5248 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5249 | */ |
| 5250 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5251 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5252 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5253 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5254 | |
| 5255 | final long identity = Binder.clearCallingIdentity(); |
| 5256 | try { |
| 5257 | ModemActivityInfo ret = null; |
| 5258 | synchronized (mLastModemActivityInfo) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5259 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5260 | CMD_GET_MODEM_ACTIVITY_INFO, |
| 5261 | null, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5262 | if (isModemActivityInfoValid(info)) { |
| 5263 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 5264 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 5265 | mergedTxTimeMs[i] = |
| 5266 | info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i]; |
| 5267 | } |
| 5268 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 5269 | mLastModemActivityInfo.setSleepTimeMillis( |
| 5270 | info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis()); |
| 5271 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5272 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 5273 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 5274 | mLastModemActivityInfo.setRxTimeMillis( |
| 5275 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 5276 | mLastModemActivityInfo.setEnergyUsed( |
| 5277 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5278 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5279 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5280 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5281 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 5282 | mLastModemActivityInfo.getTxTimeMillis(), |
| 5283 | mLastModemActivityInfo.getRxTimeMillis(), |
| 5284 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5285 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5286 | Bundle bundle = new Bundle(); |
| 5287 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 5288 | result.send(0, bundle); |
| 5289 | } finally { |
| 5290 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5291 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5292 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5293 | |
Siddharth Ray | f5d2955 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5294 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 5295 | // less than total activity duration. |
| 5296 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 5297 | if (info == null) { |
| 5298 | return false; |
| 5299 | } |
| 5300 | int activityDurationMs = |
| 5301 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 5302 | int totalTxTimeMs = 0; |
| 5303 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 5304 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 5305 | } |
| 5306 | return (info.isValid() |
| 5307 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 5308 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 5309 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 5310 | && (totalTxTimeMs <= activityDurationMs)); |
| 5311 | } |
| 5312 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5313 | /** |
| 5314 | * {@hide} |
| 5315 | * Returns the service state information on specified subscription. |
| 5316 | */ |
| 5317 | @Override |
| 5318 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5319 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5320 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5321 | return null; |
| 5322 | } |
| 5323 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5324 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 5325 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5326 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5327 | .setCallingPackage(callingPackage) |
| 5328 | .setCallingPid(Binder.getCallingPid()) |
| 5329 | .setCallingUid(Binder.getCallingUid()) |
| 5330 | .setMethod("getServiceStateForSubscriber") |
| 5331 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5332 | .build()); |
| 5333 | |
| 5334 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 5335 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5336 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5337 | .setCallingPackage(callingPackage) |
| 5338 | .setCallingPid(Binder.getCallingPid()) |
| 5339 | .setCallingUid(Binder.getCallingUid()) |
| 5340 | .setMethod("getServiceStateForSubscriber") |
| 5341 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5342 | .build()); |
| 5343 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 5344 | boolean hasFinePermission = |
| 5345 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5346 | boolean hasCoarsePermission = |
| 5347 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5348 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5349 | final long identity = Binder.clearCallingIdentity(); |
| 5350 | try { |
| 5351 | final Phone phone = getPhone(subId); |
| 5352 | if (phone == null) { |
| 5353 | return null; |
| 5354 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5355 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5356 | ServiceState ss = phone.getServiceState(); |
| 5357 | |
| 5358 | // Scrub out the location info in ServiceState depending on what level of access |
| 5359 | // the caller has. |
| 5360 | if (hasFinePermission) return ss; |
| 5361 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 5362 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5363 | } finally { |
| 5364 | Binder.restoreCallingIdentity(identity); |
| 5365 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5366 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5367 | |
| 5368 | /** |
| 5369 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5370 | * |
| 5371 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5372 | * voicemail ringtone. |
| 5373 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5374 | * PhoneAccount. |
| 5375 | */ |
| 5376 | @Override |
| 5377 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5378 | final long identity = Binder.clearCallingIdentity(); |
| 5379 | try { |
| 5380 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5381 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5382 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5383 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5384 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5385 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5386 | } finally { |
| 5387 | Binder.restoreCallingIdentity(identity); |
| 5388 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5389 | } |
| 5390 | |
| 5391 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5392 | * Sets the per-account voicemail ringtone. |
| 5393 | * |
| 5394 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5395 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5396 | * |
| 5397 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5398 | * voicemail ringtone. |
| 5399 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5400 | * PhoneAccount. |
| 5401 | */ |
| 5402 | @Override |
| 5403 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5404 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5405 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5406 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5407 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5408 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5409 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5410 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5411 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5412 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5413 | |
| 5414 | final long identity = Binder.clearCallingIdentity(); |
| 5415 | try { |
| 5416 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5417 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5418 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5419 | } |
| 5420 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5421 | } finally { |
| 5422 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5423 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5424 | } |
| 5425 | |
| 5426 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5427 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5428 | * |
| 5429 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5430 | * voicemail vibration setting. |
| 5431 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5432 | */ |
| 5433 | @Override |
| 5434 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5435 | final long identity = Binder.clearCallingIdentity(); |
| 5436 | try { |
| 5437 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5438 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5439 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5440 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5441 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5442 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5443 | } finally { |
| 5444 | Binder.restoreCallingIdentity(identity); |
| 5445 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5446 | } |
| 5447 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5448 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5449 | * Sets the per-account voicemail vibration. |
| 5450 | * |
| 5451 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5452 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5453 | * |
| 5454 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5455 | * voicemail vibration setting. |
| 5456 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5457 | * specific PhoneAccount. |
| 5458 | */ |
| 5459 | @Override |
| 5460 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5461 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5462 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5463 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5464 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5465 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5466 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5467 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5468 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5469 | } |
| 5470 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5471 | final long identity = Binder.clearCallingIdentity(); |
| 5472 | try { |
| 5473 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5474 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5475 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5476 | } |
| 5477 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5478 | } finally { |
| 5479 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5480 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5481 | } |
| 5482 | |
| 5483 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5484 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5485 | * |
| 5486 | * @throws SecurityException if the caller does not have the required permission |
| 5487 | */ |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5488 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5489 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5490 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5491 | } |
| 5492 | |
| 5493 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5494 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5495 | * permission. |
| 5496 | * |
| 5497 | * @throws SecurityException if the caller does not have the required permission |
| 5498 | */ |
| 5499 | private void enforceSendSmsPermission() { |
| 5500 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5501 | } |
| 5502 | |
| 5503 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5504 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5505 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5506 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5507 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5508 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5509 | final long identity = Binder.clearCallingIdentity(); |
| 5510 | try { |
| 5511 | ComponentName componentName = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5512 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5513 | if (componentName == null) { |
| 5514 | throw new SecurityException( |
| 5515 | "Caller not current active visual voicemail package[null]"); |
| 5516 | } |
| 5517 | String vvmPackage = componentName.getPackageName(); |
| 5518 | if (!callingPackage.equals(vvmPackage)) { |
| 5519 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5520 | + vvmPackage + "]"); |
| 5521 | } |
| 5522 | } finally { |
| 5523 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5524 | } |
| 5525 | } |
| 5526 | |
| 5527 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5528 | * Return the application ID for the app type. |
| 5529 | * |
| 5530 | * @param subId the subscription ID that this request applies to. |
| 5531 | * @param appType the uicc app type. |
| 5532 | * @return Application ID for specificied app type, or null if no uicc. |
| 5533 | */ |
| 5534 | @Override |
| 5535 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5536 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5537 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5538 | |
| 5539 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5540 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5541 | if (phone == null) { |
| 5542 | return null; |
| 5543 | } |
| 5544 | String aid = null; |
| 5545 | try { |
| 5546 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5547 | .getApplicationByType(appType).getAid(); |
| 5548 | } catch (Exception e) { |
| 5549 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5550 | } |
| 5551 | return aid; |
| 5552 | } finally { |
| 5553 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5554 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5555 | } |
| 5556 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5557 | /** |
| 5558 | * Return the Electronic Serial Number. |
| 5559 | * |
| 5560 | * @param subId the subscription ID that this request applies to. |
| 5561 | * @return ESN or null if error. |
| 5562 | */ |
| 5563 | @Override |
| 5564 | public String getEsn(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5565 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5566 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5567 | |
| 5568 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5569 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5570 | if (phone == null) { |
| 5571 | return null; |
| 5572 | } |
| 5573 | String esn = null; |
| 5574 | try { |
| 5575 | esn = phone.getEsn(); |
| 5576 | } catch (Exception e) { |
| 5577 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5578 | } |
| 5579 | return esn; |
| 5580 | } finally { |
| 5581 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5582 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5583 | } |
| 5584 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5585 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5586 | * Return the Preferred Roaming List Version. |
| 5587 | * |
| 5588 | * @param subId the subscription ID that this request applies to. |
| 5589 | * @return PRLVersion or null if error. |
| 5590 | */ |
| 5591 | @Override |
| 5592 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5593 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5594 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5595 | |
| 5596 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5597 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5598 | if (phone == null) { |
| 5599 | return null; |
| 5600 | } |
| 5601 | String cdmaPrlVersion = null; |
| 5602 | try { |
| 5603 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 5604 | } catch (Exception e) { |
| 5605 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 5606 | } |
| 5607 | return cdmaPrlVersion; |
| 5608 | } finally { |
| 5609 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5610 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5611 | } |
| 5612 | |
| 5613 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5614 | * Get snapshot of Telephony histograms |
| 5615 | * @return List of Telephony histograms |
| 5616 | * @hide |
| 5617 | */ |
| 5618 | @Override |
| 5619 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5620 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5621 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5622 | |
| 5623 | final long identity = Binder.clearCallingIdentity(); |
| 5624 | try { |
| 5625 | return RIL.getTelephonyRILTimingHistograms(); |
| 5626 | } finally { |
| 5627 | Binder.restoreCallingIdentity(identity); |
| 5628 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5629 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5630 | |
| 5631 | /** |
| 5632 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5633 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 5634 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5635 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5636 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5637 | * @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] | 5638 | */ |
| 5639 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5640 | @TelephonyManager.SetCarrierRestrictionResult |
| 5641 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5642 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5643 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5644 | |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5645 | if (carrierRestrictionRules == null) { |
| 5646 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5647 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5648 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5649 | final long identity = Binder.clearCallingIdentity(); |
| 5650 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5651 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5652 | workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5653 | } finally { |
| 5654 | Binder.restoreCallingIdentity(identity); |
| 5655 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5656 | } |
| 5657 | |
| 5658 | /** |
| 5659 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5660 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 5661 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5662 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5663 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5664 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5665 | */ |
| 5666 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5667 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5668 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5669 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5670 | |
| 5671 | final long identity = Binder.clearCallingIdentity(); |
| 5672 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5673 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 5674 | if (response instanceof CarrierRestrictionRules) { |
| 5675 | return (CarrierRestrictionRules) response; |
| 5676 | } |
| 5677 | // Response is an Exception of some kind, |
| 5678 | // which is signalled to the user as a NULL retval |
| 5679 | return null; |
| 5680 | } catch (Exception e) { |
| 5681 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 5682 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5683 | } finally { |
| 5684 | Binder.restoreCallingIdentity(identity); |
| 5685 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5686 | } |
| 5687 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5688 | /** |
| 5689 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 5690 | * @param subId the subscription ID that this action applies to. |
| 5691 | * @param enabled control enable or disable metered apns. |
| 5692 | * {@hide} |
| 5693 | */ |
| 5694 | @Override |
| 5695 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 5696 | enforceModifyPermission(); |
| 5697 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5698 | |
| 5699 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5700 | if (phone == null) { |
| 5701 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 5702 | return; |
| 5703 | } |
| 5704 | try { |
| 5705 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 5706 | } catch (Exception e) { |
| 5707 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5708 | } finally { |
| 5709 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5710 | } |
| 5711 | } |
| 5712 | |
| 5713 | /** |
| 5714 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 5715 | * @param subId the subscription ID that this action applies to. |
| 5716 | * @param enabled control enable or disable radio. |
| 5717 | * {@hide} |
| 5718 | */ |
| 5719 | @Override |
| 5720 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 5721 | enforceModifyPermission(); |
| 5722 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5723 | |
| 5724 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5725 | if (phone == null) { |
| 5726 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 5727 | return; |
| 5728 | } |
| 5729 | try { |
| 5730 | phone.carrierActionSetRadioEnabled(enabled); |
| 5731 | } catch (Exception e) { |
| 5732 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5733 | } finally { |
| 5734 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5735 | } |
| 5736 | } |
| 5737 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5738 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5739 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 5740 | * network status based on which carrier apps could apply actions accordingly, |
| 5741 | * enable/disable default url handler for example. |
| 5742 | * |
| 5743 | * @param subId the subscription ID that this action applies to. |
| 5744 | * @param report control start/stop reporting the default network status. |
| 5745 | * {@hide} |
| 5746 | */ |
| 5747 | @Override |
| 5748 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 5749 | enforceModifyPermission(); |
| 5750 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5751 | |
| 5752 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5753 | if (phone == null) { |
| 5754 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 5755 | return; |
| 5756 | } |
| 5757 | try { |
| 5758 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 5759 | } catch (Exception e) { |
| 5760 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5761 | } finally { |
| 5762 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5763 | } |
| 5764 | } |
| 5765 | |
| 5766 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5767 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 5768 | * bug report is being generated. |
| 5769 | */ |
| 5770 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 5771 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5772 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 5773 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 5774 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 5775 | + Binder.getCallingPid() |
| 5776 | + ", uid=" + Binder.getCallingUid() |
| 5777 | + "without permission " |
| 5778 | + android.Manifest.permission.DUMP); |
| 5779 | return; |
| 5780 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5781 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5782 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5783 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5784 | @Override |
| 5785 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 5786 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 5787 | throws RemoteException { |
| 5788 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 5789 | } |
| 5790 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5791 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5792 | * Get aggregated video call data usage since boot. |
| 5793 | * |
| 5794 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 5795 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5796 | * {@hide} |
| 5797 | */ |
| 5798 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5799 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5800 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 5801 | null); |
| 5802 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5803 | final long identity = Binder.clearCallingIdentity(); |
| 5804 | try { |
| 5805 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 5806 | // records the delta with the corresponding network identity. |
| 5807 | // We just return the total video call data usage snapshot since boot. |
| 5808 | Phone phone = getPhone(subId); |
| 5809 | if (phone != null) { |
| 5810 | return phone.getVtDataUsage(perUidStats); |
| 5811 | } |
| 5812 | return null; |
| 5813 | } finally { |
| 5814 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5815 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5816 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5817 | |
| 5818 | /** |
| 5819 | * Policy control of data connection. Usually used when data limit is passed. |
| 5820 | * @param enabled True if enabling the data, otherwise disabling. |
| 5821 | * @param subId Subscription index |
| 5822 | * {@hide} |
| 5823 | */ |
| 5824 | @Override |
| 5825 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 5826 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5827 | |
| 5828 | final long identity = Binder.clearCallingIdentity(); |
| 5829 | try { |
| 5830 | Phone phone = getPhone(subId); |
| 5831 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5832 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5833 | } |
| 5834 | } finally { |
| 5835 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5836 | } |
| 5837 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5838 | |
| 5839 | /** |
| 5840 | * Get Client request stats |
| 5841 | * @return List of Client Request Stats |
| 5842 | * @hide |
| 5843 | */ |
| 5844 | @Override |
| 5845 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5846 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5847 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5848 | return null; |
| 5849 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5850 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5851 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5852 | final long identity = Binder.clearCallingIdentity(); |
| 5853 | try { |
| 5854 | if (phone != null) { |
| 5855 | return phone.getClientRequestStats(); |
| 5856 | } |
| 5857 | |
| 5858 | return null; |
| 5859 | } finally { |
| 5860 | Binder.restoreCallingIdentity(identity); |
| 5861 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5862 | } |
| 5863 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5864 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5865 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5866 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5867 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5868 | |
| 5869 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5870 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5871 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5872 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5873 | * @param state State of SIM (power down, power up, pass through) |
| 5874 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 5875 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 5876 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5877 | * |
| 5878 | **/ |
| 5879 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5880 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5881 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5882 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5883 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5884 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5885 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5886 | final long identity = Binder.clearCallingIdentity(); |
| 5887 | try { |
| 5888 | if (phone != null) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5889 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5890 | } |
| 5891 | } finally { |
| 5892 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5893 | } |
| 5894 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5895 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5896 | private boolean isUssdApiAllowed(int subId) { |
| 5897 | CarrierConfigManager configManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5898 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5899 | if (configManager == null) { |
| 5900 | return false; |
| 5901 | } |
| 5902 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 5903 | if (pb == null) { |
| 5904 | return false; |
| 5905 | } |
| 5906 | return pb.getBoolean( |
| 5907 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 5908 | } |
| 5909 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5910 | /** |
| 5911 | * Check if phone is in emergency callback mode |
| 5912 | * @return true if phone is in emergency callback mode |
| 5913 | * @param subId sub id |
| 5914 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 5915 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5916 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5917 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5918 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5919 | |
| 5920 | final long identity = Binder.clearCallingIdentity(); |
| 5921 | try { |
| 5922 | if (phone != null) { |
| 5923 | return phone.isInEcm(); |
| 5924 | } else { |
| 5925 | return false; |
| 5926 | } |
| 5927 | } finally { |
| 5928 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5929 | } |
| 5930 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5931 | |
| 5932 | /** |
| 5933 | * Get the current signal strength information for the given subscription. |
| 5934 | * Because this information is not updated when the device is in a low power state |
| 5935 | * it should not be relied-upon to be current. |
| 5936 | * @param subId Subscription index |
| 5937 | * @return the most recent cached signal strength info from the modem |
| 5938 | */ |
| 5939 | @Override |
| 5940 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5941 | final long identity = Binder.clearCallingIdentity(); |
| 5942 | try { |
| 5943 | Phone p = getPhone(subId); |
| 5944 | if (p == null) { |
| 5945 | return null; |
| 5946 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5947 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5948 | return p.getSignalStrength(); |
| 5949 | } finally { |
| 5950 | Binder.restoreCallingIdentity(identity); |
| 5951 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5952 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5953 | |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5954 | /** |
chen xu | 907e5a2 | 2018-10-11 13:21:04 -0700 | [diff] [blame] | 5955 | * Get the current modem radio state for the given slot. |
| 5956 | * @param slotIndex slot index. |
| 5957 | * @param callingPackage the name of the package making the call. |
| 5958 | * @return the current radio power state from the modem |
| 5959 | */ |
| 5960 | @Override |
| 5961 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 5962 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5963 | if (phone != null) { |
| 5964 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5965 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 5966 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5967 | } |
| 5968 | |
| 5969 | final long identity = Binder.clearCallingIdentity(); |
| 5970 | try { |
| 5971 | return phone.getRadioPowerState(); |
| 5972 | } finally { |
| 5973 | Binder.restoreCallingIdentity(identity); |
| 5974 | } |
| 5975 | } |
| 5976 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5977 | } |
| 5978 | |
| 5979 | /** |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5980 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 5981 | * |
| 5982 | * <p>Requires one of the following permissions: |
| 5983 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 5984 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 5985 | * privileges. |
| 5986 | * |
| 5987 | * @param subId subscription id |
| 5988 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 5989 | * {@code false}. |
| 5990 | */ |
| 5991 | @Override |
| 5992 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5993 | boolean isEnabled = false; |
| 5994 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5995 | try { |
| 5996 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5997 | null /* message */); |
| 5998 | Phone phone = getPhone(subId); |
| 5999 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6000 | } catch (Exception e) { |
| 6001 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6002 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6003 | } finally { |
| 6004 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6005 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6006 | return isEnabled; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6007 | } |
| 6008 | |
| 6009 | |
| 6010 | /** |
| 6011 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6012 | * |
| 6013 | * <p> Requires permission: |
| 6014 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6015 | * privileges. |
| 6016 | * |
| 6017 | * @param subId subscription id |
| 6018 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6019 | */ |
| 6020 | @Override |
| 6021 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6022 | final long identity = Binder.clearCallingIdentity(); |
| 6023 | try { |
| 6024 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6025 | mApp, subId, "setDataRoamingEnabled"); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6026 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6027 | Phone phone = getPhone(subId); |
| 6028 | if (phone != null) { |
| 6029 | phone.setDataRoamingEnabled(isEnabled); |
| 6030 | } |
| 6031 | } finally { |
| 6032 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6033 | } |
| 6034 | } |
| 6035 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6036 | @Override |
Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6037 | public boolean isManualNetworkSelectionAllowed(int subId) { |
| 6038 | boolean isAllowed = true; |
| 6039 | final long identity = Binder.clearCallingIdentity(); |
| 6040 | try { |
| 6041 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6042 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6043 | Phone phone = getPhone(subId); |
| 6044 | if (phone != null) { |
| 6045 | isAllowed = phone.isCspPlmnEnabled(); |
| 6046 | } |
| 6047 | } finally { |
| 6048 | Binder.restoreCallingIdentity(identity); |
| 6049 | } |
| 6050 | return isAllowed; |
| 6051 | } |
| 6052 | |
| 6053 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6054 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 53fdb78 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6055 | try { |
| 6056 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
| 6057 | } catch (SecurityException e) { |
| 6058 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6059 | // has carrier privileges on an active UICC |
| 6060 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6061 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6062 | throw new SecurityException("Caller does not have carrier privileges on any UICC"); |
| 6063 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6064 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6065 | |
| 6066 | final long identity = Binder.clearCallingIdentity(); |
| 6067 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6068 | UiccController uiccController = UiccController.getInstance(); |
| 6069 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
| 6070 | |
| 6071 | ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0); |
| 6072 | if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 6073 | // Remove private info if the caller doesn't have access |
| 6074 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6075 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6076 | UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex()); |
| 6077 | UiccProfile profile = card.getUiccProfile(); |
| 6078 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6079 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6080 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6081 | } else { |
| 6082 | filteredInfos.add(cardInfo); |
| 6083 | } |
| 6084 | } |
| 6085 | return filteredInfos; |
| 6086 | } |
| 6087 | return cardInfos; |
| 6088 | } catch (PackageManager.NameNotFoundException e) { |
| 6089 | // This should not happen since we pass the package info in from TelephonyManager |
| 6090 | throw new SecurityException("Invalid calling package."); |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6091 | } finally { |
| 6092 | Binder.restoreCallingIdentity(identity); |
| 6093 | } |
| 6094 | } |
| 6095 | |
| 6096 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6097 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6098 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6099 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6100 | final long identity = Binder.clearCallingIdentity(); |
| 6101 | try { |
| 6102 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6103 | if (slots == null) { |
| 6104 | Rlog.i(LOG_TAG, "slots is null."); |
| 6105 | return null; |
| 6106 | } |
| 6107 | |
| 6108 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6109 | for (int i = 0; i < slots.length; i++) { |
| 6110 | UiccSlot slot = slots[i]; |
| 6111 | if (slot == null) { |
| 6112 | continue; |
| 6113 | } |
| 6114 | |
| 6115 | String cardId; |
| 6116 | UiccCard card = slot.getUiccCard(); |
| 6117 | if (card != null) { |
| 6118 | cardId = card.getCardId(); |
| 6119 | } else { |
| 6120 | cardId = slot.getIccId(); |
| 6121 | } |
| 6122 | |
| 6123 | int cardState = 0; |
| 6124 | switch (slot.getCardState()) { |
| 6125 | case CARDSTATE_ABSENT: |
| 6126 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6127 | break; |
| 6128 | case CARDSTATE_PRESENT: |
| 6129 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6130 | break; |
| 6131 | case CARDSTATE_ERROR: |
| 6132 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6133 | break; |
| 6134 | case CARDSTATE_RESTRICTED: |
| 6135 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6136 | break; |
| 6137 | default: |
| 6138 | break; |
| 6139 | |
| 6140 | } |
| 6141 | |
| 6142 | infos[i] = new UiccSlotInfo( |
| 6143 | slot.isActive(), |
| 6144 | slot.isEuicc(), |
| 6145 | cardId, |
| 6146 | cardState, |
| 6147 | slot.getPhoneId(), |
| 6148 | slot.isExtendedApduSupported()); |
| 6149 | } |
| 6150 | return infos; |
| 6151 | } finally { |
| 6152 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6153 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6154 | } |
| 6155 | |
| 6156 | @Override |
| 6157 | public boolean switchSlots(int[] physicalSlots) { |
| 6158 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6159 | |
| 6160 | final long identity = Binder.clearCallingIdentity(); |
| 6161 | try { |
| 6162 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6163 | } finally { |
| 6164 | Binder.restoreCallingIdentity(identity); |
| 6165 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6166 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6167 | |
| 6168 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6169 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6170 | final long identity = Binder.clearCallingIdentity(); |
| 6171 | try { |
| 6172 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6173 | } finally { |
| 6174 | Binder.restoreCallingIdentity(identity); |
| 6175 | } |
| 6176 | } |
| 6177 | |
| 6178 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6179 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6180 | enforceModifyPermission(); |
| 6181 | final Phone phone = getPhone(subId); |
| 6182 | if (phone == null) { |
| 6183 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6184 | return; |
| 6185 | } |
| 6186 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6187 | final long identity = Binder.clearCallingIdentity(); |
| 6188 | try { |
| 6189 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6190 | } finally { |
| 6191 | Binder.restoreCallingIdentity(identity); |
| 6192 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6193 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6194 | |
| 6195 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6196 | * A test API to reload the UICC profile. |
| 6197 | * |
| 6198 | * <p>Requires that the calling app has permission |
| 6199 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6200 | * @hide |
| 6201 | */ |
| 6202 | @Override |
| 6203 | public void refreshUiccProfile(int subId) { |
| 6204 | enforceModifyPermission(); |
| 6205 | |
| 6206 | final long identity = Binder.clearCallingIdentity(); |
| 6207 | try { |
| 6208 | Phone phone = getPhone(subId); |
| 6209 | if (phone == null) { |
| 6210 | return; |
| 6211 | } |
| 6212 | UiccCard uiccCard = phone.getUiccCard(); |
| 6213 | if (uiccCard == null) { |
| 6214 | return; |
| 6215 | } |
| 6216 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6217 | if (uiccProfile == null) { |
| 6218 | return; |
| 6219 | } |
| 6220 | uiccProfile.refresh(); |
| 6221 | } finally { |
| 6222 | Binder.restoreCallingIdentity(identity); |
| 6223 | } |
| 6224 | } |
| 6225 | |
| 6226 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6227 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6228 | */ |
| 6229 | private boolean getDefaultDataEnabled() { |
| 6230 | return "true".equalsIgnoreCase( |
| 6231 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6232 | } |
| 6233 | |
| 6234 | /** |
| 6235 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6236 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6237 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6238 | */ |
| 6239 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6240 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6241 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6242 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6243 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6244 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6245 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 6246 | return isDataRoamingEnabled; |
| 6247 | } |
| 6248 | |
| 6249 | /** |
| 6250 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 6251 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 6252 | */ |
| 6253 | private int getDefaultNetworkType(int subId) { |
| 6254 | return Integer.parseInt( |
| 6255 | TelephonyManager.getTelephonyProperty( |
| 6256 | mSubscriptionController.getPhoneId(subId), |
| 6257 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 6258 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 6259 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6260 | |
| 6261 | @Override |
| 6262 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
| 6263 | gid1, String gid2, String plmn, String spn) { |
| 6264 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6265 | |
| 6266 | final long identity = Binder.clearCallingIdentity(); |
| 6267 | try { |
| 6268 | final Phone phone = getPhone(subId); |
| 6269 | if (phone == null) { |
| 6270 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 6271 | return; |
| 6272 | } |
| 6273 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn); |
| 6274 | } finally { |
| 6275 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6276 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6277 | } |
| 6278 | |
| 6279 | @Override |
| 6280 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6281 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6282 | |
| 6283 | final long identity = Binder.clearCallingIdentity(); |
| 6284 | try { |
| 6285 | final Phone phone = getPhone(subId); |
| 6286 | if (phone == null) { |
| 6287 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 6288 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 6289 | } |
| 6290 | return phone.getCarrierIdListVersion(); |
| 6291 | } finally { |
| 6292 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6293 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6294 | } |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6295 | |
| 6296 | @Override |
| 6297 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 6298 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6299 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 6300 | return -1; |
| 6301 | } |
| 6302 | |
| 6303 | final long identity = Binder.clearCallingIdentity(); |
| 6304 | try { |
| 6305 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 6306 | } finally { |
| 6307 | Binder.restoreCallingIdentity(identity); |
| 6308 | } |
| 6309 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6310 | |
| 6311 | @Override |
| 6312 | public int getCdmaRoamingMode(int subId) { |
| 6313 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6314 | mApp, subId, "getCdmaRoamingMode"); |
| 6315 | |
| 6316 | final long identity = Binder.clearCallingIdentity(); |
| 6317 | try { |
| 6318 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 6319 | } finally { |
| 6320 | Binder.restoreCallingIdentity(identity); |
| 6321 | } |
| 6322 | } |
| 6323 | |
| 6324 | @Override |
| 6325 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 6326 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6327 | mApp, subId, "setCdmaRoamingMode"); |
| 6328 | |
| 6329 | final long identity = Binder.clearCallingIdentity(); |
| 6330 | try { |
| 6331 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 6332 | } finally { |
| 6333 | Binder.restoreCallingIdentity(identity); |
| 6334 | } |
| 6335 | } |
| 6336 | |
| 6337 | @Override |
| 6338 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 6339 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6340 | mApp, subId, "setCdmaSubscriptionMode"); |
| 6341 | |
| 6342 | final long identity = Binder.clearCallingIdentity(); |
| 6343 | try { |
| 6344 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 6345 | } finally { |
| 6346 | Binder.restoreCallingIdentity(identity); |
| 6347 | } |
| 6348 | } |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6349 | |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 6350 | private void ensureUserRunning(int userId) { |
| 6351 | if (!mUserManager.isUserRunning(userId)) { |
| 6352 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 6353 | } |
| 6354 | } |
| 6355 | |
| 6356 | /** |
| 6357 | * Returns a list of SMS apps on a given user. |
| 6358 | * |
| 6359 | * Only the shell user (UID 2000 or 0) can call it. |
| 6360 | * Target user must be running. |
| 6361 | */ |
| 6362 | @Override |
| 6363 | public String[] getSmsApps(int userId) { |
| 6364 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 6365 | ensureUserRunning(userId); |
| 6366 | |
| 6367 | final Collection<SmsApplicationData> apps = |
| 6368 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 6369 | |
| 6370 | String[] ret = new String[apps.size()]; |
| 6371 | int i = 0; |
| 6372 | for (SmsApplicationData app : apps) { |
| 6373 | ret[i++] = app.mPackageName; |
| 6374 | } |
| 6375 | return ret; |
| 6376 | } |
| 6377 | |
| 6378 | /** |
| 6379 | * Returns the default SMS app package name on a given user. |
| 6380 | * |
| 6381 | * Only the shell user (UID 2000 or 0) can call it. |
| 6382 | * Target user must be running. |
| 6383 | */ |
| 6384 | @Override |
| 6385 | public String getDefaultSmsApp(int userId) { |
| 6386 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 6387 | ensureUserRunning(userId); |
| 6388 | |
| 6389 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 6390 | /* updateIfNeeded= */ true, userId); |
| 6391 | return cn == null ? null : cn.getPackageName(); |
| 6392 | } |
| 6393 | |
| 6394 | /** |
| 6395 | * Set a package as the default SMS app on a given user. |
| 6396 | * |
| 6397 | * Only the shell user (UID 2000 or 0) can call it. |
| 6398 | * Target user must be running. |
| 6399 | */ |
| 6400 | @Override |
| 6401 | public void setDefaultSmsApp(int userId, String packageName) { |
| 6402 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6403 | ensureUserRunning(userId); |
| 6404 | |
| 6405 | boolean found = false; |
| 6406 | for (String pkg : getSmsApps(userId)) { |
| 6407 | if (TextUtils.equals(packageName, pkg)) { |
| 6408 | found = true; |
| 6409 | break; |
| 6410 | } |
| 6411 | } |
| 6412 | if (!found) { |
| 6413 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6414 | } |
| 6415 | |
| 6416 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6417 | } |
| 6418 | |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6419 | @Override |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6420 | public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList( |
| 6421 | String callingPackage) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6422 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6423 | mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) { |
| 6424 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6425 | } |
| 6426 | final long identity = Binder.clearCallingIdentity(); |
| 6427 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6428 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6429 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6430 | if (phone.getEmergencyNumberTracker() != null |
| 6431 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6432 | emergencyNumberListInternal.put( |
| 6433 | phone.getSubId(), |
| 6434 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6435 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6436 | } |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6437 | return emergencyNumberListInternal; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6438 | } finally { |
| 6439 | Binder.restoreCallingIdentity(identity); |
| 6440 | } |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6441 | } |
| 6442 | |
| 6443 | @Override |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6444 | public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) { |
| 6445 | final Phone defaultPhone = getDefaultPhone(); |
| 6446 | if (!exactMatch) { |
| 6447 | TelephonyPermissions |
| 6448 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6449 | mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)"); |
| 6450 | } |
| 6451 | final long identity = Binder.clearCallingIdentity(); |
| 6452 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6453 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6454 | if (phone.getEmergencyNumberTracker() != null |
| 6455 | && phone.getEmergencyNumberTracker() != null) { |
| 6456 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 6457 | number, exactMatch)) { |
| 6458 | return true; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6459 | } |
| 6460 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6461 | } |
| 6462 | return false; |
| 6463 | } finally { |
| 6464 | Binder.restoreCallingIdentity(identity); |
| 6465 | } |
| 6466 | } |
| 6467 | |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6468 | /** |
| 6469 | * Update emergency number list for test mode. |
| 6470 | */ |
| 6471 | @Override |
| 6472 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 6473 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6474 | "updateEmergencyNumberListTestMode"); |
| 6475 | |
| 6476 | final long identity = Binder.clearCallingIdentity(); |
| 6477 | try { |
| 6478 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6479 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6480 | if (tracker != null) { |
| 6481 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 6482 | } |
| 6483 | } |
| 6484 | } finally { |
| 6485 | Binder.restoreCallingIdentity(identity); |
| 6486 | } |
| 6487 | } |
| 6488 | |
| 6489 | /** |
| 6490 | * Get the full emergency number list for test mode. |
| 6491 | */ |
| 6492 | @Override |
| 6493 | public List<String> getEmergencyNumberListTestMode() { |
| 6494 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6495 | "getEmergencyNumberListTestMode"); |
| 6496 | |
| 6497 | final long identity = Binder.clearCallingIdentity(); |
| 6498 | try { |
| 6499 | Set<String> emergencyNumbers = new HashSet<>(); |
| 6500 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6501 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6502 | if (tracker != null) { |
| 6503 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 6504 | emergencyNumbers.add(num.getNumber()); |
| 6505 | } |
| 6506 | } |
| 6507 | } |
| 6508 | return new ArrayList<>(emergencyNumbers); |
| 6509 | } finally { |
| 6510 | Binder.restoreCallingIdentity(identity); |
| 6511 | } |
| 6512 | } |
| 6513 | |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6514 | @Override |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6515 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6516 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6517 | Phone phone = getPhone(subId); |
| 6518 | if (phone == null) { |
| 6519 | return null; |
| 6520 | } |
| 6521 | final long identity = Binder.clearCallingIdentity(); |
| 6522 | try { |
| 6523 | UiccProfile profile = UiccController.getInstance() |
| 6524 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6525 | if (profile != null) { |
| 6526 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6527 | } |
| 6528 | } finally { |
| 6529 | Binder.restoreCallingIdentity(identity); |
| 6530 | } |
| 6531 | return null; |
| 6532 | } |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6533 | |
| 6534 | /** |
| 6535 | * Enable or disable a modem stack. |
| 6536 | */ |
| 6537 | @Override |
| 6538 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 6539 | enforceModifyPermission(); |
| 6540 | |
| 6541 | final long identity = Binder.clearCallingIdentity(); |
| 6542 | try { |
| 6543 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6544 | if (phone == null) { |
| 6545 | return false; |
| 6546 | } else { |
| 6547 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 6548 | } |
| 6549 | } finally { |
| 6550 | Binder.restoreCallingIdentity(identity); |
| 6551 | } |
| 6552 | } |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6553 | |
| 6554 | @Override |
| 6555 | public void setMultisimCarrierRestriction(boolean isMultisimCarrierRestricted) { |
| 6556 | enforceModifyPermission(); |
| 6557 | |
| 6558 | final long identity = Binder.clearCallingIdentity(); |
| 6559 | try { |
| 6560 | mTelephonySharedPreferences.edit() |
| 6561 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultisimCarrierRestricted) |
| 6562 | .commit(); |
| 6563 | } finally { |
| 6564 | Binder.restoreCallingIdentity(identity); |
| 6565 | } |
| 6566 | } |
| 6567 | |
| 6568 | @Override |
| 6569 | public boolean isMultisimCarrierRestricted() { |
| 6570 | enforceReadPrivilegedPermission("isMultisimCarrierRestricted"); |
| 6571 | |
| 6572 | final long identity = Binder.clearCallingIdentity(); |
| 6573 | try { |
| 6574 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 6575 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 6576 | if (numPhysicalSlots < 2) { |
| 6577 | loge("isMultisimCarrierRestricted: requires at least 2 cards"); |
| 6578 | return true; |
| 6579 | } |
| 6580 | |
| 6581 | // Default value is false. Multi SIM is allowed unless explicitly restricted. |
| 6582 | return mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false); |
| 6583 | } finally { |
| 6584 | Binder.restoreCallingIdentity(identity); |
| 6585 | } |
| 6586 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6587 | |
| 6588 | /** |
| 6589 | * Switch configs to enable multi-sim or switch back to single-sim |
| 6590 | * @param numOfSims number of active sims we want to switch to |
| 6591 | */ |
| 6592 | @Override |
| 6593 | public void switchMultiSimConfig(int numOfSims) { |
| 6594 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6595 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 6596 | final long identity = Binder.clearCallingIdentity(); |
| 6597 | try { |
| 6598 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 6599 | } finally { |
| 6600 | Binder.restoreCallingIdentity(identity); |
| 6601 | } |
| 6602 | } |
| 6603 | |
| 6604 | /** |
Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6605 | * 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] | 6606 | * Return value defaults to true |
Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6607 | */ |
| 6608 | @Override |
| 6609 | public boolean isRebootRequiredForModemConfigChange() { |
| 6610 | enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange"); |
| 6611 | final long identity = Binder.clearCallingIdentity(); |
| 6612 | try { |
| 6613 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 6614 | } finally { |
| 6615 | Binder.restoreCallingIdentity(identity); |
| 6616 | } |
| 6617 | } |
| 6618 | |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 6619 | private void updateModemStateMetrics() { |
| 6620 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 6621 | // TODO: check the state for each modem if the api is ready. |
| 6622 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 6623 | } |
| 6624 | |
Pengquan Meng | 3aceaec | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 6625 | @Override |
| 6626 | public int[] getSlotsMapping() { |
| 6627 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 6628 | |
| 6629 | final long identity = Binder.clearCallingIdentity(); |
| 6630 | try { |
| 6631 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 6632 | // All logical slots should have a mapping to a physical slot. |
| 6633 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 6634 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 6635 | for (int i = 0; i < slotInfos.length; i++) { |
| 6636 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 6637 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 6638 | } |
| 6639 | } |
| 6640 | return logicalSlotsMapping; |
| 6641 | } finally { |
| 6642 | Binder.restoreCallingIdentity(identity); |
| 6643 | } |
| 6644 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 6645 | |
| 6646 | /** |
| 6647 | * Get the IRadio HAL Version |
| 6648 | */ |
| 6649 | @Override |
| 6650 | public int getRadioHalVersion() { |
| 6651 | Phone phone = getDefaultPhone(); |
| 6652 | if (phone == null) return -1; |
| 6653 | HalVersion hv = phone.getHalVersion(); |
| 6654 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 6655 | return hv.major * 100 + hv.minor; |
| 6656 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6657 | } |