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; |
| 38 | import android.os.Bundle; |
| 39 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 40 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.os.Looper; |
| 42 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 43 | import android.os.Messenger; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 44 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 45 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 46 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 47 | import android.os.ServiceManager; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 48 | import android.os.ShellCallback; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 49 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 51 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 52 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 53 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 54 | import android.provider.Settings; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 55 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 56 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 57 | import android.telecom.TelecomManager; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 58 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 59 | import android.telephony.CarrierRestrictionRules; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 60 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 61 | import android.telephony.CellInfoGsm; |
| 62 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 63 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 64 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 65 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 66 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 67 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 68 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 69 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 70 | import android.telephony.NetworkScanRequest; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 71 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 72 | import android.telephony.RadioAccessFamily; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 73 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 74 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 75 | import android.telephony.SignalStrength; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 76 | import android.telephony.SmsManager; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 77 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 78 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 79 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 80 | import android.telephony.TelephonyManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 81 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 82 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 83 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 84 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 85 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 86 | import android.telephony.data.ApnSetting; |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 87 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 88 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 89 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 90 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 91 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 92 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 93 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 94 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 95 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 96 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 97 | import android.telephony.ims.feature.MmTelFeature; |
| 98 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 99 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 100 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 101 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 102 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 103 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 104 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 105 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 106 | import com.android.ims.ImsException; |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 107 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 108 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 109 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 110 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 111 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 112 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 113 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 114 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 115 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 116 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 117 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 118 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 119 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 120 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 121 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 122 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.Phone; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 125 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.ServiceStateTracker; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.SmsApplication; |
| 133 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 135 | import com.android.internal.telephony.TelephonyPermissions; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.euicc.EuiccConnector; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.uicc.IccIoResult; |
| 139 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 140 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 144 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 145 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 147 | import com.android.internal.util.HexDump; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 148 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 149 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 150 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 151 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 152 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 153 | import java.io.FileDescriptor; |
| 154 | import java.io.PrintWriter; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 155 | import java.nio.charset.StandardCharsets; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 156 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 157 | import java.util.Arrays; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 158 | import java.util.Collection; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 159 | import java.util.HashMap; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 160 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 161 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 162 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 163 | import java.util.Map; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 164 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 165 | |
| 166 | /** |
| 167 | * Implementation of the ITelephony interface. |
| 168 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 169 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 170 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 171 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 172 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 173 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 174 | |
| 175 | // Message codes used with mMainThreadHandler |
| 176 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 177 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 178 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 179 | private static final int CMD_OPEN_CHANNEL = 9; |
| 180 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 181 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 182 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 183 | private static final int CMD_NV_READ_ITEM = 13; |
| 184 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 185 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 186 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 187 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 188 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 189 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 190 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 191 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 192 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 193 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 194 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 195 | private static final int CMD_SEND_ENVELOPE = 25; |
| 196 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 197 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 198 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 199 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 200 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 201 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 202 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 203 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 204 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 205 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 206 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 207 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 208 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 209 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 210 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 211 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 212 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 213 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 214 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 215 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 216 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 217 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 218 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 219 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 220 | private static final int CMD_SWITCH_SLOTS = 50; |
| 221 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 222 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 223 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 224 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 225 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 226 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 227 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 228 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 229 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 230 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 231 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 232 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 233 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 234 | private static final int CMD_MODEM_REBOOT = 64; |
| 235 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 236 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 237 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 238 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 239 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 240 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 241 | // Parameters of select command. |
| 242 | private static final int SELECT_COMMAND = 0xA4; |
| 243 | private static final int SELECT_P1 = 0x04; |
| 244 | private static final int SELECT_P2 = 0; |
| 245 | private static final int SELECT_P3 = 0x10; |
| 246 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 247 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 248 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 249 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 250 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 251 | /** The singleton instance. */ |
| 252 | private static PhoneInterfaceManager sInstance; |
| 253 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 254 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 255 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 256 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 257 | private AppOpsManager mAppOps; |
| 258 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 259 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 260 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 261 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 262 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 263 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 264 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 265 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 266 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 267 | |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 268 | // String to store multi SIM allowed |
| 269 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 270 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 271 | // The AID of ISD-R. |
| 272 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 273 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 274 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 275 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 276 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 277 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 278 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 279 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 280 | * A request object to use for transmitting data to an ICC. |
| 281 | */ |
| 282 | private static final class IccAPDUArgument { |
| 283 | public int channel, cla, command, p1, p2, p3; |
| 284 | public String data; |
| 285 | |
| 286 | public IccAPDUArgument(int channel, int cla, int command, |
| 287 | int p1, int p2, int p3, String data) { |
| 288 | this.channel = channel; |
| 289 | this.cla = cla; |
| 290 | this.command = command; |
| 291 | this.p1 = p1; |
| 292 | this.p2 = p2; |
| 293 | this.p3 = p3; |
| 294 | this.data = data; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 299 | * A request object to use for transmitting data to an ICC. |
| 300 | */ |
| 301 | private static final class ManualNetworkSelectionArgument { |
| 302 | public OperatorInfo operatorInfo; |
| 303 | public boolean persistSelection; |
| 304 | |
| 305 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 306 | this.operatorInfo = operatorInfo; |
| 307 | this.persistSelection = persistSelection; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 312 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 313 | * request after sending. The main thread will notify the request when it is complete. |
| 314 | */ |
| 315 | private static final class MainThreadRequest { |
| 316 | /** The argument to use for the request */ |
| 317 | public Object argument; |
| 318 | /** The result of the request that is run on the main thread */ |
| 319 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 320 | // The subscriber id that this request applies to. Defaults to |
| 321 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 322 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 323 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 324 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 325 | public Phone phone; |
| 326 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 327 | public WorkSource workSource; |
| 328 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 329 | public MainThreadRequest(Object argument) { |
| 330 | this.argument = argument; |
| 331 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 332 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 333 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 334 | this.argument = argument; |
| 335 | if (phone != null) { |
| 336 | this.phone = phone; |
| 337 | } |
| 338 | this.workSource = workSource; |
| 339 | } |
| 340 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 341 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 342 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 343 | if (subId != null) { |
| 344 | this.subId = subId; |
| 345 | } |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 346 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 347 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 350 | private static final class IncomingThirdPartyCallArgs { |
| 351 | public final ComponentName component; |
| 352 | public final String callId; |
| 353 | public final String callerDisplayName; |
| 354 | |
| 355 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 356 | String callerDisplayName) { |
| 357 | this.component = component; |
| 358 | this.callId = callId; |
| 359 | this.callerDisplayName = callerDisplayName; |
| 360 | } |
| 361 | } |
| 362 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 363 | /** |
| 364 | * A handler that processes messages on the main thread in the phone process. Since many |
| 365 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 366 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 367 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 368 | * on, which will be notified when the operation completes and will contain the result of the |
| 369 | * request. |
| 370 | * |
| 371 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 372 | * note that request.result must be set to something non-null for the calling thread to |
| 373 | * unblock. |
| 374 | */ |
| 375 | private final class MainThreadHandler extends Handler { |
| 376 | @Override |
| 377 | public void handleMessage(Message msg) { |
| 378 | MainThreadRequest request; |
| 379 | Message onCompleted; |
| 380 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 381 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 382 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 383 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 384 | |
| 385 | switch (msg.what) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 386 | case CMD_HANDLE_USSD_REQUEST: { |
| 387 | request = (MainThreadRequest) msg.obj; |
| 388 | final Phone phone = getPhoneFromRequest(request); |
| 389 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 390 | String ussdRequest = ussdObject.first; |
| 391 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 392 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 393 | if (!isUssdApiAllowed(request.subId)) { |
| 394 | // Carrier does not support use of this API, return failure. |
| 395 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 396 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 397 | Bundle returnData = new Bundle(); |
| 398 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 399 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 400 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 401 | request.result = true; |
| 402 | notifyRequester(request); |
| 403 | return; |
| 404 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 405 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 406 | try { |
| 407 | request.result = phone != null |
| 408 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 409 | } catch (CallStateException cse) { |
| 410 | request.result = false; |
| 411 | } |
| 412 | // Wake up the requesting thread |
| 413 | notifyRequester(request); |
| 414 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 417 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 418 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 419 | final Phone phone = getPhoneFromRequest(request); |
| 420 | request.result = phone != null ? |
| 421 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 422 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 423 | // Wake up the requesting thread |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 424 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 425 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 426 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 427 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 428 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 429 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 430 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 431 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 432 | if (uiccCard == null) { |
| 433 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 434 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 435 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 436 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 437 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 438 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 439 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 440 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 441 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 442 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 443 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 444 | break; |
| 445 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 446 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 447 | ar = (AsyncResult) msg.obj; |
| 448 | request = (MainThreadRequest) ar.userObj; |
| 449 | if (ar.exception == null && ar.result != null) { |
| 450 | request.result = ar.result; |
| 451 | } else { |
| 452 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 453 | if (ar.result == null) { |
| 454 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 455 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 456 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 457 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 458 | } else { |
| 459 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 460 | } |
| 461 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 462 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 463 | break; |
| 464 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 465 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 466 | request = (MainThreadRequest) msg.obj; |
| 467 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 468 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 469 | if (uiccCard == null) { |
| 470 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 471 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 472 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 473 | } else { |
| 474 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 475 | request); |
| 476 | uiccCard.iccTransmitApduBasicChannel( |
| 477 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 478 | iccArgument.p3, iccArgument.data, onCompleted); |
| 479 | } |
| 480 | break; |
| 481 | |
| 482 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 483 | ar = (AsyncResult) msg.obj; |
| 484 | request = (MainThreadRequest) ar.userObj; |
| 485 | if (ar.exception == null && ar.result != null) { |
| 486 | request.result = ar.result; |
| 487 | } else { |
| 488 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 489 | if (ar.result == null) { |
| 490 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 491 | } else if (ar.exception instanceof CommandException) { |
| 492 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 493 | ar.exception); |
| 494 | } else { |
| 495 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 496 | } |
| 497 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 498 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 499 | break; |
| 500 | |
| 501 | case CMD_EXCHANGE_SIM_IO: |
| 502 | request = (MainThreadRequest) msg.obj; |
| 503 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 504 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 505 | if (uiccCard == null) { |
| 506 | loge("iccExchangeSimIO: No UICC"); |
| 507 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 508 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 509 | } else { |
| 510 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 511 | request); |
| 512 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 513 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 514 | iccArgument.data, onCompleted); |
| 515 | } |
| 516 | break; |
| 517 | |
| 518 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 519 | ar = (AsyncResult) msg.obj; |
| 520 | request = (MainThreadRequest) ar.userObj; |
| 521 | if (ar.exception == null && ar.result != null) { |
| 522 | request.result = ar.result; |
| 523 | } else { |
| 524 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 525 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 526 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 527 | break; |
| 528 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 529 | case CMD_SEND_ENVELOPE: |
| 530 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 531 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 532 | if (uiccCard == null) { |
| 533 | loge("sendEnvelopeWithStatus: No UICC"); |
| 534 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 535 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 536 | } else { |
| 537 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 538 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 539 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 540 | break; |
| 541 | |
| 542 | case EVENT_SEND_ENVELOPE_DONE: |
| 543 | ar = (AsyncResult) msg.obj; |
| 544 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 545 | if (ar.exception == null && ar.result != null) { |
| 546 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 547 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 548 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 549 | if (ar.result == null) { |
| 550 | loge("sendEnvelopeWithStatus: Empty response"); |
| 551 | } else if (ar.exception instanceof CommandException) { |
| 552 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 553 | ar.exception); |
| 554 | } else { |
| 555 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 556 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 557 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 558 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 559 | break; |
| 560 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 561 | case CMD_OPEN_CHANNEL: |
| 562 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 563 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 564 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 565 | if (uiccCard == null) { |
| 566 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 567 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 568 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 569 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 570 | } else { |
| 571 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 572 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 573 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 574 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 575 | break; |
| 576 | |
| 577 | case EVENT_OPEN_CHANNEL_DONE: |
| 578 | ar = (AsyncResult) msg.obj; |
| 579 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 580 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 581 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 582 | int[] result = (int[]) ar.result; |
| 583 | int channelId = result[0]; |
| 584 | byte[] selectResponse = null; |
| 585 | if (result.length > 1) { |
| 586 | selectResponse = new byte[result.length - 1]; |
| 587 | for (int i = 1; i < result.length; ++i) { |
| 588 | selectResponse[i - 1] = (byte) result[i]; |
| 589 | } |
| 590 | } |
| 591 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 592 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 593 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 594 | if (ar.result == null) { |
| 595 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 596 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 597 | if (ar.exception != null) { |
| 598 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 599 | } |
| 600 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 601 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 602 | if (ar.exception instanceof CommandException) { |
| 603 | CommandException.Error error = |
| 604 | ((CommandException) (ar.exception)).getCommandError(); |
| 605 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 606 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 607 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 608 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 609 | } |
| 610 | } |
| 611 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 612 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 613 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 614 | request.result = openChannelResp; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 615 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 616 | break; |
| 617 | |
| 618 | case CMD_CLOSE_CHANNEL: |
| 619 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 620 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 621 | if (uiccCard == null) { |
| 622 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 623 | request.result = false; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 624 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 625 | } else { |
| 626 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 627 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 628 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 629 | break; |
| 630 | |
| 631 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 632 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 633 | break; |
| 634 | |
| 635 | case CMD_NV_READ_ITEM: |
| 636 | request = (MainThreadRequest) msg.obj; |
| 637 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 638 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 639 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 640 | break; |
| 641 | |
| 642 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 643 | ar = (AsyncResult) msg.obj; |
| 644 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 645 | if (ar.exception == null && ar.result != null) { |
| 646 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 647 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 648 | request.result = ""; |
| 649 | if (ar.result == null) { |
| 650 | loge("nvReadItem: Empty response"); |
| 651 | } else if (ar.exception instanceof CommandException) { |
| 652 | loge("nvReadItem: CommandException: " + |
| 653 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 654 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 655 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 656 | } |
| 657 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 658 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 659 | break; |
| 660 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 661 | case CMD_NV_WRITE_ITEM: |
| 662 | request = (MainThreadRequest) msg.obj; |
| 663 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 664 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 665 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 666 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 667 | break; |
| 668 | |
| 669 | case EVENT_NV_WRITE_ITEM_DONE: |
| 670 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 671 | break; |
| 672 | |
| 673 | case CMD_NV_WRITE_CDMA_PRL: |
| 674 | request = (MainThreadRequest) msg.obj; |
| 675 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 676 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 677 | break; |
| 678 | |
| 679 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 680 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 681 | break; |
| 682 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 683 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 684 | request = (MainThreadRequest) msg.obj; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 685 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 686 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 687 | break; |
| 688 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 689 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 690 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 691 | break; |
| 692 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 693 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 694 | request = (MainThreadRequest) msg.obj; |
| 695 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 696 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 697 | break; |
| 698 | |
| 699 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 700 | ar = (AsyncResult) msg.obj; |
| 701 | request = (MainThreadRequest) ar.userObj; |
| 702 | if (ar.exception == null && ar.result != null) { |
| 703 | request.result = ar.result; // Integer |
| 704 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 705 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 706 | if (ar.result == null) { |
| 707 | loge("getPreferredNetworkType: Empty response"); |
| 708 | } else if (ar.exception instanceof CommandException) { |
| 709 | loge("getPreferredNetworkType: CommandException: " + |
| 710 | ar.exception); |
| 711 | } else { |
| 712 | loge("getPreferredNetworkType: Unknown exception"); |
| 713 | } |
| 714 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 715 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 716 | break; |
| 717 | |
| 718 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 719 | request = (MainThreadRequest) msg.obj; |
| 720 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 721 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 722 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 723 | break; |
| 724 | |
| 725 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 726 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 727 | break; |
| 728 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 729 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 730 | request = (MainThreadRequest)msg.obj; |
| 731 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 732 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 733 | break; |
| 734 | |
| 735 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 736 | ar = (AsyncResult)msg.obj; |
| 737 | request = (MainThreadRequest)ar.userObj; |
| 738 | request.result = ar; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 739 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 740 | break; |
| 741 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 742 | case CMD_SET_VOICEMAIL_NUMBER: |
| 743 | request = (MainThreadRequest) msg.obj; |
| 744 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 745 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 746 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 747 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 748 | break; |
| 749 | |
| 750 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 751 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 752 | break; |
| 753 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 754 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 755 | request = (MainThreadRequest) msg.obj; |
| 756 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 757 | request); |
| 758 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 759 | break; |
| 760 | |
| 761 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 762 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 763 | break; |
| 764 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 765 | case CMD_PERFORM_NETWORK_SCAN: |
| 766 | request = (MainThreadRequest) msg.obj; |
| 767 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 768 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 769 | break; |
| 770 | |
| 771 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 772 | ar = (AsyncResult) msg.obj; |
| 773 | request = (MainThreadRequest) ar.userObj; |
| 774 | CellNetworkScanResult cellScanResult; |
| 775 | if (ar.exception == null && ar.result != null) { |
| 776 | cellScanResult = new CellNetworkScanResult( |
| 777 | CellNetworkScanResult.STATUS_SUCCESS, |
| 778 | (List<OperatorInfo>) ar.result); |
| 779 | } else { |
| 780 | if (ar.result == null) { |
| 781 | loge("getCellNetworkScanResults: Empty response"); |
| 782 | } |
| 783 | if (ar.exception != null) { |
| 784 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 785 | } |
| 786 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 787 | if (ar.exception instanceof CommandException) { |
| 788 | CommandException.Error error = |
| 789 | ((CommandException) (ar.exception)).getCommandError(); |
| 790 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 791 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 792 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 793 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 794 | } |
| 795 | } |
| 796 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 797 | } |
| 798 | request.result = cellScanResult; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 799 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 800 | break; |
| 801 | |
| 802 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 803 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 804 | ManualNetworkSelectionArgument selArg = |
| 805 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 806 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 807 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 808 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 809 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 810 | break; |
| 811 | |
| 812 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | dd9ac82 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 813 | ar = (AsyncResult) msg.obj; |
| 814 | request = (MainThreadRequest) ar.userObj; |
| 815 | if (ar.exception == null) { |
| 816 | request.result = true; |
| 817 | } else { |
| 818 | request.result = false; |
| 819 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 820 | } |
| 821 | notifyRequester(request); |
| 822 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 823 | break; |
| 824 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 825 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 826 | request = (MainThreadRequest) msg.obj; |
| 827 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 828 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 829 | break; |
| 830 | |
| 831 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 832 | ar = (AsyncResult) msg.obj; |
| 833 | request = (MainThreadRequest) ar.userObj; |
| 834 | if (ar.exception == null && ar.result != null) { |
| 835 | request.result = ar.result; |
| 836 | } else { |
| 837 | if (ar.result == null) { |
| 838 | loge("queryModemActivityInfo: Empty response"); |
| 839 | } else if (ar.exception instanceof CommandException) { |
| 840 | loge("queryModemActivityInfo: CommandException: " + |
| 841 | ar.exception); |
| 842 | } else { |
| 843 | loge("queryModemActivityInfo: Unknown exception"); |
| 844 | } |
| 845 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 846 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 847 | if (request.result == null) { |
| 848 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 849 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 850 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 851 | break; |
| 852 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 853 | case CMD_SET_ALLOWED_CARRIERS: |
| 854 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 855 | CarrierRestrictionRules argument = |
| 856 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 857 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 858 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 859 | break; |
| 860 | |
| 861 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 862 | ar = (AsyncResult) msg.obj; |
| 863 | request = (MainThreadRequest) ar.userObj; |
| 864 | if (ar.exception == null && ar.result != null) { |
| 865 | request.result = ar.result; |
| 866 | } else { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 867 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 868 | if (ar.exception instanceof CommandException) { |
| 869 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 870 | CommandException.Error error = |
| 871 | ((CommandException) (ar.exception)).getCommandError(); |
| 872 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 873 | request.result = |
| 874 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 875 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 876 | } else { |
| 877 | loge("setAllowedCarriers: Unknown exception"); |
| 878 | } |
| 879 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 880 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 881 | break; |
| 882 | |
| 883 | case CMD_GET_ALLOWED_CARRIERS: |
| 884 | request = (MainThreadRequest) msg.obj; |
| 885 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 886 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 887 | break; |
| 888 | |
| 889 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 890 | ar = (AsyncResult) msg.obj; |
| 891 | request = (MainThreadRequest) ar.userObj; |
| 892 | if (ar.exception == null && ar.result != null) { |
| 893 | request.result = ar.result; |
| 894 | } else { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 895 | request.result = new IllegalStateException( |
| 896 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 897 | if (ar.result == null) { |
| 898 | loge("getAllowedCarriers: Empty response"); |
| 899 | } else if (ar.exception instanceof CommandException) { |
| 900 | loge("getAllowedCarriers: CommandException: " + |
| 901 | ar.exception); |
| 902 | } else { |
| 903 | loge("getAllowedCarriers: Unknown exception"); |
| 904 | } |
| 905 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 906 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 907 | break; |
| 908 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 909 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 910 | ar = (AsyncResult) msg.obj; |
| 911 | request = (MainThreadRequest) ar.userObj; |
| 912 | if (ar.exception == null && ar.result != null) { |
| 913 | request.result = ar.result; |
| 914 | } else { |
| 915 | request.result = new IllegalArgumentException( |
| 916 | "Failed to retrieve Forbidden Plmns"); |
| 917 | if (ar.result == null) { |
| 918 | loge("getForbiddenPlmns: Empty response"); |
| 919 | } else { |
| 920 | loge("getForbiddenPlmns: Unknown exception"); |
| 921 | } |
| 922 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 923 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 924 | break; |
| 925 | |
| 926 | case CMD_GET_FORBIDDEN_PLMNS: |
| 927 | request = (MainThreadRequest) msg.obj; |
| 928 | uiccCard = getUiccCardFromRequest(request); |
| 929 | if (uiccCard == null) { |
| 930 | loge("getForbiddenPlmns() UiccCard is null"); |
| 931 | request.result = new IllegalArgumentException( |
| 932 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 933 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 934 | break; |
| 935 | } |
| 936 | Integer appType = (Integer) request.argument; |
| 937 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 938 | if (uiccApp == null) { |
| 939 | loge("getForbiddenPlmns() no app with specified type -- " |
| 940 | + appType); |
| 941 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 942 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 943 | break; |
| 944 | } else { |
| 945 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 946 | + " specified type -- " + appType); |
| 947 | } |
| 948 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 949 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 950 | onCompleted); |
| 951 | break; |
| 952 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 953 | case CMD_SWITCH_SLOTS: |
| 954 | request = (MainThreadRequest) msg.obj; |
| 955 | int[] physicalSlots = (int[]) request.argument; |
| 956 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 957 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 958 | break; |
| 959 | |
| 960 | case EVENT_SWITCH_SLOTS_DONE: |
| 961 | ar = (AsyncResult) msg.obj; |
| 962 | request = (MainThreadRequest) ar.userObj; |
| 963 | request.result = (ar.exception == null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 964 | notifyRequester(request); |
| 965 | break; |
| 966 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 967 | request = (MainThreadRequest) msg.obj; |
| 968 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 969 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 970 | break; |
| 971 | |
| 972 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 973 | ar = (AsyncResult) msg.obj; |
| 974 | request = (MainThreadRequest) ar.userObj; |
| 975 | if (ar.exception != null) { |
| 976 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 977 | } else { |
| 978 | int mode = ((int[]) ar.result)[0]; |
| 979 | if (mode == 0) { |
| 980 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 981 | } else { |
| 982 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 983 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 984 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 985 | notifyRequester(request); |
| 986 | break; |
| 987 | case CMD_GET_CDMA_ROAMING_MODE: |
| 988 | request = (MainThreadRequest) msg.obj; |
| 989 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 990 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 991 | break; |
| 992 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 993 | ar = (AsyncResult) msg.obj; |
| 994 | request = (MainThreadRequest) ar.userObj; |
| 995 | if (ar.exception != null) { |
| 996 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 997 | } else { |
| 998 | request.result = ((int[]) ar.result)[0]; |
| 999 | } |
| 1000 | notifyRequester(request); |
| 1001 | break; |
| 1002 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1003 | request = (MainThreadRequest) msg.obj; |
| 1004 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1005 | int mode = (int) request.argument; |
| 1006 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1007 | break; |
| 1008 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1009 | ar = (AsyncResult) msg.obj; |
| 1010 | request = (MainThreadRequest) ar.userObj; |
| 1011 | request.result = ar.exception == null; |
| 1012 | notifyRequester(request); |
| 1013 | break; |
| 1014 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1015 | request = (MainThreadRequest) msg.obj; |
| 1016 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1017 | int subscriptionMode = (int) request.argument; |
| 1018 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1019 | break; |
| 1020 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1021 | ar = (AsyncResult) msg.obj; |
| 1022 | request = (MainThreadRequest) ar.userObj; |
| 1023 | request.result = ar.exception == null; |
| 1024 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1025 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1026 | case CMD_GET_ALL_CELL_INFO: |
| 1027 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1028 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1029 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1030 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1031 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1032 | ar = (AsyncResult) msg.obj; |
| 1033 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1034 | // If a timeout occurs, the response will be null |
| 1035 | request.result = (ar.exception == null && ar.result != null) |
| 1036 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1037 | synchronized (request) { |
| 1038 | request.notifyAll(); |
| 1039 | } |
| 1040 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1041 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1042 | request = (MainThreadRequest) msg.obj; |
| 1043 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1044 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1045 | break; |
| 1046 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1047 | ar = (AsyncResult) msg.obj; |
| 1048 | request = (MainThreadRequest) ar.userObj; |
| 1049 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1050 | try { |
| 1051 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1052 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1053 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1054 | new android.os.ParcelableException(ar.exception)); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1055 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1056 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1057 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1058 | } else { |
| 1059 | // use the result as returned |
| 1060 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1061 | } |
| 1062 | } catch (RemoteException re) { |
| 1063 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1064 | } |
| 1065 | break; |
| 1066 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1067 | request = (MainThreadRequest) msg.obj; |
| 1068 | WorkSource ws = (WorkSource) request.argument; |
| 1069 | Phone phone = getPhoneFromRequest(request); |
| 1070 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1071 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1072 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1073 | ar = (AsyncResult) msg.obj; |
| 1074 | request = (MainThreadRequest) ar.userObj; |
| 1075 | if (ar.exception == null) { |
| 1076 | request.result = ar.result; |
| 1077 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1078 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1079 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1080 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1081 | } |
| 1082 | |
| 1083 | synchronized (request) { |
| 1084 | request.notifyAll(); |
| 1085 | } |
| 1086 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1087 | case CMD_MODEM_REBOOT: |
| 1088 | request = (MainThreadRequest) msg.obj; |
| 1089 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1090 | defaultPhone.rebootModem(onCompleted); |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1091 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1092 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1093 | handleNullReturnEvent(msg, "rebootModem"); |
| 1094 | break; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1095 | case CMD_REQUEST_ENABLE_MODEM: |
| 1096 | request = (MainThreadRequest) msg.obj; |
| 1097 | boolean enable = (boolean) request.argument; |
| 1098 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
| 1099 | PhoneConfigurationManager.getInstance() |
| 1100 | .enablePhone(request.phone, enable, onCompleted); |
| 1101 | break; |
| 1102 | case EVENT_ENABLE_MODEM_DONE: |
| 1103 | ar = (AsyncResult) msg.obj; |
| 1104 | request = (MainThreadRequest) ar.userObj; |
| 1105 | request.result = (ar.exception == null); |
| 1106 | notifyRequester(request); |
| 1107 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1108 | default: |
| 1109 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1110 | break; |
| 1111 | } |
| 1112 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1113 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1114 | private void notifyRequester(MainThreadRequest request) { |
| 1115 | synchronized (request) { |
| 1116 | request.notifyAll(); |
| 1117 | } |
| 1118 | } |
| 1119 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1120 | private void handleNullReturnEvent(Message msg, String command) { |
| 1121 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1122 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1123 | if (ar.exception == null) { |
| 1124 | request.result = true; |
| 1125 | } else { |
| 1126 | request.result = false; |
| 1127 | if (ar.exception instanceof CommandException) { |
| 1128 | loge(command + ": CommandException: " + ar.exception); |
| 1129 | } else { |
| 1130 | loge(command + ": Unknown exception"); |
| 1131 | } |
| 1132 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1133 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1134 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | /** |
| 1138 | * Posts the specified command to be executed on the main thread, |
| 1139 | * waits for the request to complete, and returns the result. |
| 1140 | * @see #sendRequestAsync |
| 1141 | */ |
| 1142 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1143 | return sendRequest( |
| 1144 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | /** |
| 1148 | * Posts the specified command to be executed on the main thread, |
| 1149 | * waits for the request to complete, and returns the result. |
| 1150 | * @see #sendRequestAsync |
| 1151 | */ |
| 1152 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1153 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1154 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | /** |
| 1158 | * Posts the specified command to be executed on the main thread, |
| 1159 | * waits for the request to complete, and returns the result. |
| 1160 | * @see #sendRequestAsync |
| 1161 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1162 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1163 | return sendRequest(command, argument, subId, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | /** |
| 1167 | * Posts the specified command to be executed on the main thread, |
| 1168 | * waits for the request to complete, and returns the result. |
| 1169 | * @see #sendRequestAsync |
| 1170 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1171 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1172 | return sendRequest(command, argument, subId, null, workSource); |
| 1173 | } |
| 1174 | |
| 1175 | /** |
| 1176 | * Posts the specified command to be executed on the main thread, |
| 1177 | * waits for the request to complete, and returns the result. |
| 1178 | * @see #sendRequestAsync |
| 1179 | */ |
| 1180 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1181 | return sendRequest( |
| 1182 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1183 | } |
| 1184 | |
| 1185 | /** |
| 1186 | * Posts the specified command to be executed on the main thread, |
| 1187 | * waits for the request to complete, and returns the result. |
| 1188 | * @see #sendRequestAsync |
| 1189 | */ |
| 1190 | private Object sendRequest( |
| 1191 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1192 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1193 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1194 | } |
| 1195 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1196 | MainThreadRequest request = null; |
| 1197 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1198 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1199 | } else if (phone != null) { |
| 1200 | request = new MainThreadRequest(argument, phone, workSource); |
| 1201 | } else { |
| 1202 | request = new MainThreadRequest(argument, subId, workSource); |
| 1203 | } |
| 1204 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1205 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1206 | msg.sendToTarget(); |
| 1207 | |
| 1208 | // Wait for the request to complete |
| 1209 | synchronized (request) { |
| 1210 | while (request.result == null) { |
| 1211 | try { |
| 1212 | request.wait(); |
| 1213 | } catch (InterruptedException e) { |
| 1214 | // Do nothing, go back and wait until the request is complete |
| 1215 | } |
| 1216 | } |
| 1217 | } |
| 1218 | return request.result; |
| 1219 | } |
| 1220 | |
| 1221 | /** |
| 1222 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1223 | * Posts the specified command to be executed on the main thread, and |
| 1224 | * returns immediately. |
| 1225 | * @see #sendRequest |
| 1226 | */ |
| 1227 | private void sendRequestAsync(int command) { |
| 1228 | mMainThreadHandler.sendEmptyMessage(command); |
| 1229 | } |
| 1230 | |
| 1231 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1232 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1233 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1234 | */ |
| 1235 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1236 | sendRequestAsync(command, argument, null, null); |
| 1237 | } |
| 1238 | |
| 1239 | /** |
| 1240 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1241 | * @see {@link #sendRequest(int,Object)} |
| 1242 | */ |
| 1243 | private void sendRequestAsync( |
| 1244 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1245 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1246 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1247 | msg.sendToTarget(); |
| 1248 | } |
| 1249 | |
| 1250 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1251 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1252 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1253 | */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1254 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1255 | synchronized (PhoneInterfaceManager.class) { |
| 1256 | if (sInstance == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1257 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1258 | } else { |
| 1259 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1260 | } |
| 1261 | return sInstance; |
| 1262 | } |
| 1263 | } |
| 1264 | |
| 1265 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1266 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1267 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1268 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1269 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1270 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1271 | mMainThreadHandler = new MainThreadHandler(); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1272 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1273 | mTelephonySharedPreferences = |
| 1274 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1275 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1276 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1277 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1278 | publish(); |
| 1279 | } |
| 1280 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1281 | private Phone getDefaultPhone() { |
| 1282 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1283 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1284 | } |
| 1285 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1286 | private void publish() { |
| 1287 | if (DBG) log("publish: " + this); |
| 1288 | |
| 1289 | ServiceManager.addService("phone", this); |
| 1290 | } |
| 1291 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1292 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 1293 | return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1294 | ? getDefaultPhone() : getPhone(request.subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1295 | } |
| 1296 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1297 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1298 | Phone phone = getPhoneFromRequest(request); |
| 1299 | return phone == null ? null : |
| 1300 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1301 | } |
| 1302 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1303 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1304 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1305 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1306 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1307 | |
| 1308 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1309 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1310 | } |
| 1311 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1312 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1313 | if (DBG) log("dial: " + number); |
| 1314 | // No permission check needed here: This is just a wrapper around the |
| 1315 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1316 | // the UI before it does anything. |
| 1317 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1318 | final long identity = Binder.clearCallingIdentity(); |
| 1319 | try { |
| 1320 | String url = createTelUrl(number); |
| 1321 | if (url == null) { |
| 1322 | return; |
| 1323 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1324 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1325 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1326 | PhoneConstants.State state = mCM.getState(subId); |
| 1327 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1328 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1329 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1330 | mApp.startActivity(intent); |
| 1331 | } |
| 1332 | } finally { |
| 1333 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1334 | } |
| 1335 | } |
| 1336 | |
| 1337 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1338 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1339 | } |
| 1340 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1341 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1342 | if (DBG) log("call: " + number); |
| 1343 | |
| 1344 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1345 | // need to do a permission check since we're calling startActivity() |
| 1346 | // from the context of the phone app. |
| 1347 | enforceCallPermission(); |
| 1348 | |
| 1349 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1350 | != AppOpsManager.MODE_ALLOWED) { |
| 1351 | return; |
| 1352 | } |
| 1353 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1354 | final long identity = Binder.clearCallingIdentity(); |
| 1355 | try { |
| 1356 | String url = createTelUrl(number); |
| 1357 | if (url == null) { |
| 1358 | return; |
| 1359 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1360 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1361 | boolean isValid = false; |
| 1362 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1363 | if (slist != null) { |
| 1364 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1365 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1366 | isValid = true; |
| 1367 | break; |
| 1368 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1369 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1370 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1371 | if (!isValid) { |
| 1372 | return; |
| 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 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1376 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1377 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1378 | mApp.startActivity(intent); |
| 1379 | } finally { |
| 1380 | Binder.restoreCallingIdentity(identity); |
| 1381 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1382 | } |
| 1383 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1384 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1385 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1386 | } |
| 1387 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1388 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1389 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1390 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1391 | } |
| 1392 | |
| 1393 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1394 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1395 | } |
| 1396 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1397 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1398 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1399 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1400 | } |
| 1401 | |
| 1402 | /** {@hide} */ |
| 1403 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1404 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1405 | } |
| 1406 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1407 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1408 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1409 | |
| 1410 | final long identity = Binder.clearCallingIdentity(); |
| 1411 | try { |
| 1412 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1413 | checkSimPin.start(); |
| 1414 | return checkSimPin.unlockSim(null, pin); |
| 1415 | } finally { |
| 1416 | Binder.restoreCallingIdentity(identity); |
| 1417 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1418 | } |
| 1419 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1420 | /** {@hide} */ |
| 1421 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1422 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1423 | } |
| 1424 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1425 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1426 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1427 | |
| 1428 | final long identity = Binder.clearCallingIdentity(); |
| 1429 | try { |
| 1430 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1431 | checkSimPuk.start(); |
| 1432 | return checkSimPuk.unlockSim(puk, pin); |
| 1433 | } finally { |
| 1434 | Binder.restoreCallingIdentity(identity); |
| 1435 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1439 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1440 | * a synchronous one. |
| 1441 | */ |
| 1442 | private static class UnlockSim extends Thread { |
| 1443 | |
| 1444 | private final IccCard mSimCard; |
| 1445 | |
| 1446 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1447 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1448 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1449 | |
| 1450 | // For replies from SimCard interface |
| 1451 | private Handler mHandler; |
| 1452 | |
| 1453 | // For async handler to identify request type |
| 1454 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1455 | |
| 1456 | public UnlockSim(IccCard simCard) { |
| 1457 | mSimCard = simCard; |
| 1458 | } |
| 1459 | |
| 1460 | @Override |
| 1461 | public void run() { |
| 1462 | Looper.prepare(); |
| 1463 | synchronized (UnlockSim.this) { |
| 1464 | mHandler = new Handler() { |
| 1465 | @Override |
| 1466 | public void handleMessage(Message msg) { |
| 1467 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1468 | switch (msg.what) { |
| 1469 | case SUPPLY_PIN_COMPLETE: |
| 1470 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1471 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1472 | mRetryCount = msg.arg1; |
| 1473 | if (ar.exception != null) { |
| 1474 | if (ar.exception instanceof CommandException && |
| 1475 | ((CommandException)(ar.exception)).getCommandError() |
| 1476 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1477 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1478 | } else { |
| 1479 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1480 | } |
| 1481 | } else { |
| 1482 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1483 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1484 | mDone = true; |
| 1485 | UnlockSim.this.notifyAll(); |
| 1486 | } |
| 1487 | break; |
| 1488 | } |
| 1489 | } |
| 1490 | }; |
| 1491 | UnlockSim.this.notifyAll(); |
| 1492 | } |
| 1493 | Looper.loop(); |
| 1494 | } |
| 1495 | |
| 1496 | /* |
| 1497 | * Use PIN or PUK to unlock SIM card |
| 1498 | * |
| 1499 | * If PUK is null, unlock SIM card with PIN |
| 1500 | * |
| 1501 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1502 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1503 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1504 | |
| 1505 | while (mHandler == null) { |
| 1506 | try { |
| 1507 | wait(); |
| 1508 | } catch (InterruptedException e) { |
| 1509 | Thread.currentThread().interrupt(); |
| 1510 | } |
| 1511 | } |
| 1512 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1513 | |
| 1514 | if (puk == null) { |
| 1515 | mSimCard.supplyPin(pin, callback); |
| 1516 | } else { |
| 1517 | mSimCard.supplyPuk(puk, pin, callback); |
| 1518 | } |
| 1519 | |
| 1520 | while (!mDone) { |
| 1521 | try { |
| 1522 | Log.d(LOG_TAG, "wait for done"); |
| 1523 | wait(); |
| 1524 | } catch (InterruptedException e) { |
| 1525 | // Restore the interrupted status |
| 1526 | Thread.currentThread().interrupt(); |
| 1527 | } |
| 1528 | } |
| 1529 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1530 | int[] resultArray = new int[2]; |
| 1531 | resultArray[0] = mResult; |
| 1532 | resultArray[1] = mRetryCount; |
| 1533 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1534 | } |
| 1535 | } |
| 1536 | |
| 1537 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1538 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1539 | |
| 1540 | } |
| 1541 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1542 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1543 | // No permission check needed here: this call is harmless, and it's |
| 1544 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1545 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1546 | final long identity = Binder.clearCallingIdentity(); |
| 1547 | try { |
| 1548 | final Phone phone = getPhone(subId); |
| 1549 | if (phone != null) { |
| 1550 | phone.updateServiceLocation(); |
| 1551 | } |
| 1552 | } finally { |
| 1553 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1554 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1555 | } |
| 1556 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1557 | @Override |
| 1558 | public boolean isRadioOn(String callingPackage) { |
| 1559 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1560 | } |
| 1561 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1562 | @Override |
| 1563 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1564 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1565 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1566 | return false; |
| 1567 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1568 | |
| 1569 | final long identity = Binder.clearCallingIdentity(); |
| 1570 | try { |
| 1571 | return isRadioOnForSubscriber(subId); |
| 1572 | } finally { |
| 1573 | Binder.restoreCallingIdentity(identity); |
| 1574 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1578 | final long identity = Binder.clearCallingIdentity(); |
| 1579 | try { |
| 1580 | final Phone phone = getPhone(subId); |
| 1581 | if (phone != null) { |
| 1582 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1583 | } else { |
| 1584 | return false; |
| 1585 | } |
| 1586 | } finally { |
| 1587 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1588 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1589 | } |
| 1590 | |
| 1591 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1592 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1593 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1594 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1595 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1596 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1597 | |
| 1598 | final long identity = Binder.clearCallingIdentity(); |
| 1599 | try { |
| 1600 | final Phone phone = getPhone(subId); |
| 1601 | if (phone != null) { |
| 1602 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1603 | } |
| 1604 | } finally { |
| 1605 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1606 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1607 | } |
| 1608 | |
| 1609 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1610 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1611 | } |
| 1612 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1613 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1614 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1615 | |
| 1616 | final long identity = Binder.clearCallingIdentity(); |
| 1617 | try { |
| 1618 | final Phone phone = getPhone(subId); |
| 1619 | if (phone == null) { |
| 1620 | return false; |
| 1621 | } |
| 1622 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1623 | toggleRadioOnOffForSubscriber(subId); |
| 1624 | } |
| 1625 | return true; |
| 1626 | } finally { |
| 1627 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1628 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1629 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1630 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1631 | public boolean needMobileRadioShutdown() { |
| 1632 | /* |
| 1633 | * If any of the Radios are available, it will need to be |
| 1634 | * shutdown. So return true if any Radio is available. |
| 1635 | */ |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1636 | final long identity = Binder.clearCallingIdentity(); |
| 1637 | try { |
| 1638 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1639 | Phone phone = PhoneFactory.getPhone(i); |
| 1640 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1641 | } |
| 1642 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1643 | return false; |
| 1644 | } finally { |
| 1645 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1646 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1647 | } |
| 1648 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1649 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1650 | public void shutdownMobileRadios() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1651 | enforceModifyPermission(); |
| 1652 | |
| 1653 | final long identity = Binder.clearCallingIdentity(); |
| 1654 | try { |
| 1655 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1656 | logv("Shutting down Phone " + i); |
| 1657 | shutdownRadioUsingPhoneId(i); |
| 1658 | } |
| 1659 | } finally { |
| 1660 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1661 | } |
| 1662 | } |
| 1663 | |
| 1664 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1665 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1666 | if (phone != null && phone.isRadioAvailable()) { |
| 1667 | phone.shutdownRadio(); |
| 1668 | } |
| 1669 | } |
| 1670 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1671 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1672 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1673 | |
| 1674 | final long identity = Binder.clearCallingIdentity(); |
| 1675 | try { |
| 1676 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1677 | if (defaultPhone != null) { |
| 1678 | defaultPhone.setRadioPower(turnOn); |
| 1679 | return true; |
| 1680 | } else { |
| 1681 | loge("There's no default phone."); |
| 1682 | return false; |
| 1683 | } |
| 1684 | } finally { |
| 1685 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1686 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1687 | } |
| 1688 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1689 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1690 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1691 | |
| 1692 | final long identity = Binder.clearCallingIdentity(); |
| 1693 | try { |
| 1694 | final Phone phone = getPhone(subId); |
| 1695 | if (phone != null) { |
| 1696 | phone.setRadioPower(turnOn); |
| 1697 | return true; |
| 1698 | } else { |
| 1699 | return false; |
| 1700 | } |
| 1701 | } finally { |
| 1702 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1703 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1704 | } |
| 1705 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1706 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1707 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1708 | public boolean enableDataConnectivity() { |
| 1709 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1710 | |
| 1711 | final long identity = Binder.clearCallingIdentity(); |
| 1712 | try { |
| 1713 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1714 | final Phone phone = getPhone(subId); |
| 1715 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1716 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1717 | return true; |
| 1718 | } else { |
| 1719 | return false; |
| 1720 | } |
| 1721 | } finally { |
| 1722 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1723 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1724 | } |
| 1725 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1726 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1727 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1728 | public boolean disableDataConnectivity() { |
| 1729 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1730 | |
| 1731 | final long identity = Binder.clearCallingIdentity(); |
| 1732 | try { |
| 1733 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1734 | final Phone phone = getPhone(subId); |
| 1735 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1736 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1737 | return true; |
| 1738 | } else { |
| 1739 | return false; |
| 1740 | } |
| 1741 | } finally { |
| 1742 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1743 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1744 | } |
| 1745 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1746 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1747 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1748 | final long identity = Binder.clearCallingIdentity(); |
| 1749 | try { |
| 1750 | final Phone phone = getPhone(subId); |
| 1751 | if (phone != null) { |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1752 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1753 | } else { |
| 1754 | return false; |
| 1755 | } |
| 1756 | } finally { |
| 1757 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1758 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1762 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1763 | } |
| 1764 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1765 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1766 | enforceCallPermission(); |
| 1767 | |
| 1768 | final long identity = Binder.clearCallingIdentity(); |
| 1769 | try { |
| 1770 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1771 | return; |
| 1772 | } |
| 1773 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1774 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1775 | } finally { |
| 1776 | Binder.restoreCallingIdentity(identity); |
| 1777 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1778 | }; |
| 1779 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1780 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1781 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1782 | |
| 1783 | final long identity = Binder.clearCallingIdentity(); |
| 1784 | try { |
| 1785 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1786 | return false; |
| 1787 | } |
| 1788 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1789 | } finally { |
| 1790 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1791 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1792 | } |
| 1793 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1794 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1795 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1796 | } |
| 1797 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1798 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1799 | final long identity = Binder.clearCallingIdentity(); |
| 1800 | try { |
| 1801 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1802 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1803 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1804 | } finally { |
| 1805 | Binder.restoreCallingIdentity(identity); |
| 1806 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1809 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1810 | public int getDataState() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1811 | final long identity = Binder.clearCallingIdentity(); |
| 1812 | try { |
| 1813 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1814 | if (phone != null) { |
| 1815 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1816 | } else { |
| 1817 | return PhoneConstantConversions.convertDataState( |
| 1818 | PhoneConstants.DataState.DISCONNECTED); |
| 1819 | } |
| 1820 | } finally { |
| 1821 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1822 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1825 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1826 | public int getDataActivity() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1827 | final long identity = Binder.clearCallingIdentity(); |
| 1828 | try { |
| 1829 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1830 | if (phone != null) { |
| 1831 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1832 | } else { |
| 1833 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1834 | } |
| 1835 | } finally { |
| 1836 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1837 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
| 1840 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1841 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1842 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1843 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1844 | if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage, |
| 1845 | Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1846 | return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1847 | } |
| 1848 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1849 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1850 | final long identity = Binder.clearCallingIdentity(); |
| 1851 | try { |
| 1852 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1853 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1854 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1855 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1856 | cl.fillInNotifierBundle(data); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1857 | return data; |
| 1858 | } finally { |
| 1859 | Binder.restoreCallingIdentity(identity); |
| 1860 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1861 | } |
| 1862 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1863 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1864 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1865 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1866 | // registered cell info, so return a NULL country instead. |
| 1867 | final long identity = Binder.clearCallingIdentity(); |
| 1868 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1869 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1870 | // Get default phone in this case. |
| 1871 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1872 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1873 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1874 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1875 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1876 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1877 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1878 | return ""; |
| 1879 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1880 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1881 | if (phone != null) { |
| 1882 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 1883 | if (sst != null) { |
| 1884 | LocaleTracker lt = sst.getLocaleTracker(); |
| 1885 | if (lt != null) { |
| 1886 | return lt.getCurrentCountry(); |
| 1887 | } |
| 1888 | } |
| 1889 | } |
| 1890 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1891 | } finally { |
| 1892 | Binder.restoreCallingIdentity(identity); |
| 1893 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1897 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1898 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1899 | } |
| 1900 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1901 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1902 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1903 | mApp.enforceCallingOrSelfPermission( |
| 1904 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1905 | |
| 1906 | final long identity = Binder.clearCallingIdentity(); |
| 1907 | try { |
| 1908 | final Phone phone = getPhone(subId); |
| 1909 | if (phone != null) { |
| 1910 | phone.enableLocationUpdates(); |
| 1911 | } |
| 1912 | } finally { |
| 1913 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1914 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | @Override |
| 1918 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1919 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1920 | } |
| 1921 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1922 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1923 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1924 | mApp.enforceCallingOrSelfPermission( |
| 1925 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1926 | |
| 1927 | final long identity = Binder.clearCallingIdentity(); |
| 1928 | try { |
| 1929 | final Phone phone = getPhone(subId); |
| 1930 | if (phone != null) { |
| 1931 | phone.disableLocationUpdates(); |
| 1932 | } |
| 1933 | } finally { |
| 1934 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1935 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1936 | } |
| 1937 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1938 | /** |
| 1939 | * Returns the target SDK version number for a given package name. |
| 1940 | * |
| 1941 | * @return target SDK if the package is found or INT_MAX. |
| 1942 | */ |
| 1943 | private int getTargetSdk(String packageName) { |
| 1944 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1945 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo( |
| 1946 | packageName, 0); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1947 | if (ai != null) return ai.targetSdkVersion; |
| 1948 | } catch (PackageManager.NameNotFoundException unexpected) { |
| 1949 | } |
| 1950 | return Integer.MAX_VALUE; |
| 1951 | } |
| 1952 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1953 | @Override |
| 1954 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1955 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 1956 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 1957 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 1958 | throw new SecurityException( |
| 1959 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 1960 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 1961 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1962 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 1963 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 1964 | return null; |
| 1965 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1966 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1967 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1968 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1969 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 1970 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1971 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1972 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 1973 | for (CellInfo ci : info) { |
| 1974 | if (ci instanceof CellInfoGsm) { |
| 1975 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 1976 | } else if (ci instanceof CellInfoWcdma) { |
| 1977 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 1978 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1979 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1980 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1981 | } |
| 1982 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1983 | private List<CellInfo> getCachedCellInfo() { |
| 1984 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 1985 | for (Phone phone : PhoneFactory.getPhones()) { |
| 1986 | List<CellInfo> info = phone.getAllCellInfo(); |
| 1987 | if (info != null) cellInfos.addAll(info); |
| 1988 | } |
| 1989 | return cellInfos; |
| 1990 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1991 | |
| 1992 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1993 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1994 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1995 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1996 | if (!LocationAccessPolicy.canAccessCellLocation(mApp, |
Svet Ganov | 4af6628 | 2018-03-07 19:57:05 -0800 | [diff] [blame] | 1997 | callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1998 | return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2001 | final int targetSdk = getTargetSdk(callingPackage); |
| 2002 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2003 | return getCachedCellInfo(); |
| 2004 | } |
| 2005 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2006 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2007 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2008 | final long identity = Binder.clearCallingIdentity(); |
| 2009 | try { |
| 2010 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2011 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2012 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2013 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2014 | if (info != null) cellInfos.addAll(info); |
| 2015 | } |
| 2016 | return cellInfos; |
| 2017 | } finally { |
| 2018 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2019 | } |
| 2020 | } |
| 2021 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2022 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2023 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2024 | requestCellInfoUpdateInternal( |
| 2025 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2026 | } |
| 2027 | |
| 2028 | @Override |
| 2029 | public void requestCellInfoUpdateWithWorkSource( |
| 2030 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2031 | enforceModifyPermission(); |
| 2032 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2033 | } |
| 2034 | |
| 2035 | private void requestCellInfoUpdateInternal( |
| 2036 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2037 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2038 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2039 | if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage, |
| 2040 | Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2041 | return; |
| 2042 | } |
| 2043 | |
| 2044 | final Phone phone = getPhone(subId); |
| 2045 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2046 | |
| 2047 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2048 | } |
| 2049 | |
| 2050 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2051 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2052 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2053 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2054 | |
| 2055 | final long identity = Binder.clearCallingIdentity(); |
| 2056 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2057 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2058 | } finally { |
| 2059 | Binder.restoreCallingIdentity(identity); |
| 2060 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2061 | } |
| 2062 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2063 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2064 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2065 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2066 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2067 | return null; |
| 2068 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2069 | int subId = phone.getSubId(); |
| 2070 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2071 | mApp, subId, callingPackage, "getImeiForSlot")) { |
| 2072 | return null; |
| 2073 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2074 | |
| 2075 | final long identity = Binder.clearCallingIdentity(); |
| 2076 | try { |
| 2077 | return phone.getImei(); |
| 2078 | } finally { |
| 2079 | Binder.restoreCallingIdentity(identity); |
| 2080 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2084 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2085 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2086 | String tac = null; |
| 2087 | if (phone != null) { |
| 2088 | String imei = phone.getImei(); |
| 2089 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2090 | } |
| 2091 | return tac; |
| 2092 | } |
| 2093 | |
| 2094 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2095 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2096 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2097 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2098 | return null; |
| 2099 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2100 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2101 | int subId = phone.getSubId(); |
| 2102 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2103 | mApp, subId, callingPackage, "getMeidForSlot")) { |
| 2104 | return null; |
| 2105 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2106 | |
| 2107 | final long identity = Binder.clearCallingIdentity(); |
| 2108 | try { |
| 2109 | return phone.getMeid(); |
| 2110 | } finally { |
| 2111 | Binder.restoreCallingIdentity(identity); |
| 2112 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2116 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2117 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2118 | String manufacturerCode = null; |
| 2119 | if (phone != null) { |
| 2120 | String meid = phone.getMeid(); |
| 2121 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2122 | } |
| 2123 | return manufacturerCode; |
| 2124 | } |
| 2125 | |
| 2126 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2127 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2128 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2129 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2130 | return null; |
| 2131 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2132 | int subId = phone.getSubId(); |
| 2133 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2134 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2135 | return null; |
| 2136 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2137 | |
| 2138 | final long identity = Binder.clearCallingIdentity(); |
| 2139 | try { |
| 2140 | return phone.getDeviceSvn(); |
| 2141 | } finally { |
| 2142 | Binder.restoreCallingIdentity(identity); |
| 2143 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2144 | } |
| 2145 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2146 | @Override |
| 2147 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2148 | final long identity = Binder.clearCallingIdentity(); |
| 2149 | try { |
| 2150 | final Phone phone = getPhone(subId); |
| 2151 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2152 | } finally { |
| 2153 | Binder.restoreCallingIdentity(identity); |
| 2154 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2155 | } |
| 2156 | |
| 2157 | @Override |
| 2158 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2159 | final long identity = Binder.clearCallingIdentity(); |
| 2160 | try { |
| 2161 | final Phone phone = getPhone(subId); |
| 2162 | return phone == null ? null : phone.getCarrierName(); |
| 2163 | } finally { |
| 2164 | Binder.restoreCallingIdentity(identity); |
| 2165 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2166 | } |
| 2167 | |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2168 | @Override |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2169 | public int getSubscriptionPreciseCarrierId(int subId) { |
| 2170 | final long identity = Binder.clearCallingIdentity(); |
| 2171 | try { |
| 2172 | final Phone phone = getPhone(subId); |
| 2173 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
| 2174 | : phone.getPreciseCarrierId(); |
| 2175 | } finally { |
| 2176 | Binder.restoreCallingIdentity(identity); |
| 2177 | } |
| 2178 | } |
| 2179 | |
| 2180 | @Override |
| 2181 | public String getSubscriptionPreciseCarrierName(int subId) { |
| 2182 | final long identity = Binder.clearCallingIdentity(); |
| 2183 | try { |
| 2184 | final Phone phone = getPhone(subId); |
| 2185 | return phone == null ? null : phone.getPreciseCarrierName(); |
| 2186 | } finally { |
| 2187 | Binder.restoreCallingIdentity(identity); |
| 2188 | } |
| 2189 | } |
| 2190 | |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2191 | @Override |
chen xu | 4ca4e69 | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2192 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2193 | if (!isSubscriptionMccMnc) { |
| 2194 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2195 | } |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2196 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2197 | if (phone == null) { |
| 2198 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2199 | } |
| 2200 | final long identity = Binder.clearCallingIdentity(); |
| 2201 | try { |
| 2202 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2203 | } finally { |
| 2204 | Binder.restoreCallingIdentity(identity); |
| 2205 | } |
| 2206 | } |
| 2207 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2208 | // |
| 2209 | // Internal helper methods. |
| 2210 | // |
| 2211 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2212 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2213 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2214 | * |
| 2215 | * @throws SecurityException if the caller does not have the required permission |
| 2216 | */ |
| 2217 | private void enforceModifyPermission() { |
| 2218 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2219 | } |
| 2220 | |
| 2221 | /** |
| 2222 | * Make sure the caller has the CALL_PHONE permission. |
| 2223 | * |
| 2224 | * @throws SecurityException if the caller does not have the required permission |
| 2225 | */ |
| 2226 | private void enforceCallPermission() { |
| 2227 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2228 | } |
| 2229 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2230 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2231 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2232 | "ConnectivityService"); |
| 2233 | } |
| 2234 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2235 | private String createTelUrl(String number) { |
| 2236 | if (TextUtils.isEmpty(number)) { |
| 2237 | return null; |
| 2238 | } |
| 2239 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2240 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2241 | } |
| 2242 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2243 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2244 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2245 | } |
| 2246 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2247 | private static void logv(String msg) { |
| 2248 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2249 | } |
| 2250 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2251 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2252 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2253 | } |
| 2254 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2255 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2256 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2257 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2258 | } |
| 2259 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2260 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2261 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2262 | final long identity = Binder.clearCallingIdentity(); |
| 2263 | try { |
| 2264 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2265 | if (phone == null) { |
| 2266 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2267 | } else { |
| 2268 | return phone.getPhoneType(); |
| 2269 | } |
| 2270 | } finally { |
| 2271 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2272 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | /** |
| 2276 | * Returns the CDMA ERI icon index to display |
| 2277 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2278 | @Override |
| 2279 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2280 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2281 | } |
| 2282 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2283 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2284 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2285 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2286 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2287 | return -1; |
| 2288 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2289 | |
| 2290 | final long identity = Binder.clearCallingIdentity(); |
| 2291 | try { |
| 2292 | final Phone phone = getPhone(subId); |
| 2293 | if (phone != null) { |
| 2294 | return phone.getCdmaEriIconIndex(); |
| 2295 | } else { |
| 2296 | return -1; |
| 2297 | } |
| 2298 | } finally { |
| 2299 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2300 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | /** |
| 2304 | * Returns the CDMA ERI icon mode, |
| 2305 | * 0 - ON |
| 2306 | * 1 - FLASHING |
| 2307 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2308 | @Override |
| 2309 | public int getCdmaEriIconMode(String callingPackage) { |
| 2310 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2311 | } |
| 2312 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2313 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2314 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2315 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2316 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2317 | return -1; |
| 2318 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2319 | |
| 2320 | final long identity = Binder.clearCallingIdentity(); |
| 2321 | try { |
| 2322 | final Phone phone = getPhone(subId); |
| 2323 | if (phone != null) { |
| 2324 | return phone.getCdmaEriIconMode(); |
| 2325 | } else { |
| 2326 | return -1; |
| 2327 | } |
| 2328 | } finally { |
| 2329 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2330 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | /** |
| 2334 | * Returns the CDMA ERI text, |
| 2335 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2336 | @Override |
| 2337 | public String getCdmaEriText(String callingPackage) { |
| 2338 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2339 | } |
| 2340 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2341 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2342 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2343 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2344 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2345 | return null; |
| 2346 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2347 | |
| 2348 | final long identity = Binder.clearCallingIdentity(); |
| 2349 | try { |
| 2350 | final Phone phone = getPhone(subId); |
| 2351 | if (phone != null) { |
| 2352 | return phone.getCdmaEriText(); |
| 2353 | } else { |
| 2354 | return null; |
| 2355 | } |
| 2356 | } finally { |
| 2357 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2358 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2362 | * Returns the CDMA MDN. |
| 2363 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2364 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2365 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2366 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2367 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2368 | |
| 2369 | final long identity = Binder.clearCallingIdentity(); |
| 2370 | try { |
| 2371 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2372 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2373 | return phone.getLine1Number(); |
| 2374 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2375 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2376 | return null; |
| 2377 | } |
| 2378 | } finally { |
| 2379 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2380 | } |
| 2381 | } |
| 2382 | |
| 2383 | /** |
| 2384 | * Returns the CDMA MIN. |
| 2385 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2386 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2387 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2388 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2389 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2390 | |
| 2391 | final long identity = Binder.clearCallingIdentity(); |
| 2392 | try { |
| 2393 | final Phone phone = getPhone(subId); |
| 2394 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2395 | return phone.getCdmaMin(); |
| 2396 | } else { |
| 2397 | return null; |
| 2398 | } |
| 2399 | } finally { |
| 2400 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2401 | } |
| 2402 | } |
| 2403 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2404 | @Override |
| 2405 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2406 | INumberVerificationCallback callback, String callingPackage) { |
| 2407 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2408 | != PERMISSION_GRANTED) { |
| 2409 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2410 | } |
| 2411 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2412 | |
| 2413 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2414 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2415 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2416 | } |
| 2417 | |
| 2418 | if (range == null) { |
| 2419 | throw new NullPointerException("Range must be non-null"); |
| 2420 | } |
| 2421 | |
| 2422 | timeoutMillis = Math.min(timeoutMillis, |
| 2423 | TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS); |
| 2424 | |
| 2425 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2426 | } |
| 2427 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2428 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2429 | * Returns true if CDMA provisioning needs to run. |
| 2430 | */ |
| 2431 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2432 | final long identity = Binder.clearCallingIdentity(); |
| 2433 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2434 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2435 | } finally { |
| 2436 | Binder.restoreCallingIdentity(identity); |
| 2437 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2438 | } |
| 2439 | |
| 2440 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2441 | * Sets the voice mail number of a given subId. |
| 2442 | */ |
| 2443 | @Override |
| 2444 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2445 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2446 | |
| 2447 | final long identity = Binder.clearCallingIdentity(); |
| 2448 | try { |
| 2449 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2450 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2451 | return success; |
| 2452 | } finally { |
| 2453 | Binder.restoreCallingIdentity(identity); |
| 2454 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2455 | } |
| 2456 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2457 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2458 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2459 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2460 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2461 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2462 | throw new SecurityException("caller must be system dialer"); |
| 2463 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2464 | |
| 2465 | final long identity = Binder.clearCallingIdentity(); |
| 2466 | try { |
| 2467 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2468 | if (phoneAccountHandle == null) { |
| 2469 | return null; |
| 2470 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2471 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2472 | } finally { |
| 2473 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2474 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2475 | } |
| 2476 | |
| 2477 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2478 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2479 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2480 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2481 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2482 | return null; |
| 2483 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2484 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2485 | final long identity = Binder.clearCallingIdentity(); |
| 2486 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2487 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2488 | } finally { |
| 2489 | Binder.restoreCallingIdentity(identity); |
| 2490 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2491 | } |
| 2492 | |
| 2493 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2494 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2495 | VisualVoicemailSmsFilterSettings settings) { |
| 2496 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2497 | |
| 2498 | final long identity = Binder.clearCallingIdentity(); |
| 2499 | try { |
| 2500 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2501 | mApp, callingPackage, subId, settings); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2502 | } finally { |
| 2503 | Binder.restoreCallingIdentity(identity); |
| 2504 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2505 | } |
| 2506 | |
| 2507 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2508 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2509 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2510 | |
| 2511 | final long identity = Binder.clearCallingIdentity(); |
| 2512 | try { |
| 2513 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2514 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2515 | } finally { |
| 2516 | Binder.restoreCallingIdentity(identity); |
| 2517 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2518 | } |
| 2519 | |
| 2520 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2521 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2522 | String callingPackage, int subId) { |
| 2523 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2524 | |
| 2525 | final long identity = Binder.clearCallingIdentity(); |
| 2526 | try { |
| 2527 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2528 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2529 | } finally { |
| 2530 | Binder.restoreCallingIdentity(identity); |
| 2531 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2532 | } |
| 2533 | |
| 2534 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2535 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2536 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2537 | |
| 2538 | final long identity = Binder.clearCallingIdentity(); |
| 2539 | try { |
| 2540 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2541 | mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2542 | } finally { |
| 2543 | Binder.restoreCallingIdentity(identity); |
| 2544 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2545 | } |
| 2546 | |
| 2547 | @Override |
| 2548 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2549 | String number, int port, String text, PendingIntent sentIntent) { |
| 2550 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2551 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2552 | enforceSendSmsPermission(); |
| 2553 | // Make the calls as the phone process. |
| 2554 | final long identity = Binder.clearCallingIdentity(); |
| 2555 | try { |
| 2556 | SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); |
| 2557 | if (port == 0) { |
| 2558 | smsManager.sendTextMessageWithSelfPermissions(number, null, text, |
| 2559 | sentIntent, null, false); |
| 2560 | } else { |
| 2561 | byte[] data = text.getBytes(StandardCharsets.UTF_8); |
| 2562 | smsManager.sendDataMessageWithSelfPermissions(number, null, |
| 2563 | (short) port, data, sentIntent, null); |
| 2564 | } |
| 2565 | } finally { |
| 2566 | Binder.restoreCallingIdentity(identity); |
| 2567 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2568 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2569 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2570 | * Sets the voice activation state of a given subId. |
| 2571 | */ |
| 2572 | @Override |
| 2573 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2574 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2575 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2576 | |
| 2577 | final long identity = Binder.clearCallingIdentity(); |
| 2578 | try { |
| 2579 | final Phone phone = getPhone(subId); |
| 2580 | if (phone != null) { |
| 2581 | phone.setVoiceActivationState(activationState); |
| 2582 | } else { |
| 2583 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2584 | } |
| 2585 | } finally { |
| 2586 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2587 | } |
| 2588 | } |
| 2589 | |
| 2590 | /** |
| 2591 | * Sets the data activation state of a given subId. |
| 2592 | */ |
| 2593 | @Override |
| 2594 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2595 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2596 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2597 | |
| 2598 | final long identity = Binder.clearCallingIdentity(); |
| 2599 | try { |
| 2600 | final Phone phone = getPhone(subId); |
| 2601 | if (phone != null) { |
| 2602 | phone.setDataActivationState(activationState); |
| 2603 | } else { |
| 2604 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2605 | } |
| 2606 | } finally { |
| 2607 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2608 | } |
| 2609 | } |
| 2610 | |
| 2611 | /** |
| 2612 | * Returns the voice activation state of a given subId. |
| 2613 | */ |
| 2614 | @Override |
| 2615 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2616 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2617 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2618 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2619 | final long identity = Binder.clearCallingIdentity(); |
| 2620 | try { |
| 2621 | if (phone != null) { |
| 2622 | return phone.getVoiceActivationState(); |
| 2623 | } else { |
| 2624 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2625 | } |
| 2626 | } finally { |
| 2627 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2628 | } |
| 2629 | } |
| 2630 | |
| 2631 | /** |
| 2632 | * Returns the data activation state of a given subId. |
| 2633 | */ |
| 2634 | @Override |
| 2635 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2636 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2637 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2638 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2639 | final long identity = Binder.clearCallingIdentity(); |
| 2640 | try { |
| 2641 | if (phone != null) { |
| 2642 | return phone.getDataActivationState(); |
| 2643 | } else { |
| 2644 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2645 | } |
| 2646 | } finally { |
| 2647 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2648 | } |
| 2649 | } |
| 2650 | |
| 2651 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2652 | * Returns the unread count of voicemails for a subId |
| 2653 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2654 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2655 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2656 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2657 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2658 | return 0; |
| 2659 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2660 | final long identity = Binder.clearCallingIdentity(); |
| 2661 | try { |
| 2662 | final Phone phone = getPhone(subId); |
| 2663 | if (phone != null) { |
| 2664 | return phone.getVoiceMessageCount(); |
| 2665 | } else { |
| 2666 | return 0; |
| 2667 | } |
| 2668 | } finally { |
| 2669 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2670 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2674 | * returns true, if the device is in a state where both voice and data |
| 2675 | * are supported simultaneously. This can change based on location or network condition. |
| 2676 | */ |
| 2677 | @Override |
| 2678 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2679 | final long identity = Binder.clearCallingIdentity(); |
| 2680 | try { |
| 2681 | final Phone phone = getPhone(subId); |
| 2682 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2683 | } finally { |
| 2684 | Binder.restoreCallingIdentity(identity); |
| 2685 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2686 | } |
| 2687 | |
| 2688 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2689 | * Send the dialer code if called from the current default dialer or the caller has |
| 2690 | * carrier privilege. |
| 2691 | * @param inputCode The dialer code to send |
| 2692 | */ |
| 2693 | @Override |
| 2694 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2695 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2696 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2697 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2698 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2699 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2700 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2701 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2702 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2703 | |
| 2704 | final long identity = Binder.clearCallingIdentity(); |
| 2705 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2706 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2707 | } finally { |
| 2708 | Binder.restoreCallingIdentity(identity); |
| 2709 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2710 | } |
| 2711 | |
| 2712 | /** |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2713 | * Returns the data network type. |
| 2714 | * Legacy call, permission-free. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2715 | * |
| 2716 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 2717 | */ |
| 2718 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2719 | public int getNetworkType() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2720 | final long identity = Binder.clearCallingIdentity(); |
| 2721 | try { |
| 2722 | final Phone phone = getPhone(getDefaultSubscription()); |
| 2723 | if (phone != null) { |
| 2724 | return phone.getServiceState().getDataNetworkType(); |
| 2725 | } else { |
| 2726 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2727 | } |
| 2728 | } finally { |
| 2729 | Binder.restoreCallingIdentity(identity); |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2730 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2731 | } |
| 2732 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2733 | @Override |
| 2734 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2735 | if (!isActiveSubscription(subId)) { |
| 2736 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2737 | } |
| 2738 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2739 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2740 | } |
| 2741 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2742 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2743 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2744 | throws RemoteException { |
| 2745 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2746 | final long token = Binder.clearCallingIdentity(); |
| 2747 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2748 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2749 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2750 | .addRegistrationCallbackForSubscription(c, subId); |
| 2751 | } finally { |
| 2752 | Binder.restoreCallingIdentity(token); |
| 2753 | } |
| 2754 | } |
| 2755 | |
| 2756 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2757 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2758 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2759 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2760 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2761 | } |
| 2762 | Binder.withCleanCallingIdentity(() -> { |
| 2763 | try { |
| 2764 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2765 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2766 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2767 | } catch (IllegalArgumentException e) { |
| 2768 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2769 | + "is inactive, ignoring unregister."); |
| 2770 | // If the subscription is no longer active, just return, since the callback |
| 2771 | // will already have been removed internally. |
| 2772 | } |
| 2773 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2774 | } |
| 2775 | |
| 2776 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2777 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2778 | throws RemoteException { |
| 2779 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2780 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2781 | final long token = Binder.clearCallingIdentity(); |
| 2782 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2783 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2784 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2785 | } finally { |
| 2786 | Binder.restoreCallingIdentity(token); |
| 2787 | } |
| 2788 | } |
| 2789 | |
| 2790 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2791 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2792 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2793 | |
| 2794 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2795 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2796 | } |
| 2797 | Binder.withCleanCallingIdentity(() -> { |
| 2798 | try { |
| 2799 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2800 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2801 | .removeCapabilitiesCallbackForSubscription(c, subId); |
| 2802 | } catch (IllegalArgumentException e) { |
| 2803 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2804 | + "is inactive, ignoring unregister."); |
| 2805 | // If the subscription is no longer active, just return, since the callback |
| 2806 | // will already have been removed internally. |
| 2807 | } |
| 2808 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2809 | } |
| 2810 | |
| 2811 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2812 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2813 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2814 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2815 | final long token = Binder.clearCallingIdentity(); |
| 2816 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2817 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2818 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2819 | } catch (ImsException e) { |
| 2820 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2821 | return false; |
| 2822 | } finally { |
| 2823 | Binder.restoreCallingIdentity(token); |
| 2824 | } |
| 2825 | } |
| 2826 | |
| 2827 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2828 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2829 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2830 | final long token = Binder.clearCallingIdentity(); |
| 2831 | try { |
| 2832 | Phone phone = getPhone(subId); |
| 2833 | if (phone == null) return false; |
| 2834 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2835 | } finally { |
| 2836 | Binder.restoreCallingIdentity(token); |
| 2837 | } |
| 2838 | } |
| 2839 | |
| 2840 | @Override |
| 2841 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2842 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2843 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2844 | final long token = Binder.clearCallingIdentity(); |
| 2845 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2846 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2847 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2848 | } finally { |
| 2849 | Binder.restoreCallingIdentity(token); |
| 2850 | } |
| 2851 | } |
| 2852 | |
| 2853 | @Override |
| 2854 | public void setAdvancedCallingSetting(int subId, boolean isEnabled) { |
| 2855 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2856 | "setAdvancedCallingSetting"); |
| 2857 | final long identity = Binder.clearCallingIdentity(); |
| 2858 | try { |
| 2859 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2860 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2861 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 2862 | } finally { |
| 2863 | Binder.restoreCallingIdentity(identity); |
| 2864 | } |
| 2865 | } |
| 2866 | |
| 2867 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2868 | public boolean isVtSettingEnabled(int subId) { |
| 2869 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2870 | final long identity = Binder.clearCallingIdentity(); |
| 2871 | try { |
| 2872 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2873 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2874 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2875 | } finally { |
| 2876 | Binder.restoreCallingIdentity(identity); |
| 2877 | } |
| 2878 | } |
| 2879 | |
| 2880 | @Override |
| 2881 | public void setVtSetting(int subId, boolean isEnabled) { |
| 2882 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2883 | "setVtSetting"); |
| 2884 | final long identity = Binder.clearCallingIdentity(); |
| 2885 | try { |
| 2886 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2887 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2888 | } finally { |
| 2889 | Binder.restoreCallingIdentity(identity); |
| 2890 | } |
| 2891 | } |
| 2892 | |
| 2893 | @Override |
| 2894 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 2895 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 2896 | final long identity = Binder.clearCallingIdentity(); |
| 2897 | try { |
| 2898 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2899 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2900 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 2901 | } finally { |
| 2902 | Binder.restoreCallingIdentity(identity); |
| 2903 | } |
| 2904 | } |
| 2905 | |
| 2906 | @Override |
| 2907 | public void setVoWiFiSetting(int subId, boolean isEnabled) { |
| 2908 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2909 | "setVoWiFiSetting"); |
| 2910 | final long identity = Binder.clearCallingIdentity(); |
| 2911 | try { |
| 2912 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2913 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2914 | } finally { |
| 2915 | Binder.restoreCallingIdentity(identity); |
| 2916 | } |
| 2917 | } |
| 2918 | |
| 2919 | @Override |
| 2920 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 2921 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 2922 | final long identity = Binder.clearCallingIdentity(); |
| 2923 | try { |
| 2924 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2925 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2926 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 2927 | } finally { |
| 2928 | Binder.restoreCallingIdentity(identity); |
| 2929 | } |
| 2930 | } |
| 2931 | |
| 2932 | @Override |
| 2933 | public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) { |
| 2934 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2935 | "setVoWiFiRoamingSetting"); |
| 2936 | final long identity = Binder.clearCallingIdentity(); |
| 2937 | try { |
| 2938 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2939 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2940 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 2941 | } finally { |
| 2942 | Binder.restoreCallingIdentity(identity); |
| 2943 | } |
| 2944 | } |
| 2945 | |
| 2946 | @Override |
| 2947 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 2948 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2949 | "setVoWiFiNonPersistent"); |
| 2950 | final long identity = Binder.clearCallingIdentity(); |
| 2951 | try { |
| 2952 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 2953 | boolean isRoaming = TelephonyManager.from( |
| 2954 | getPhone(subId).getContext()).isNetworkRoaming(subId); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2955 | ImsManager.getInstance(mApp, |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 2956 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming); |
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 int getVoWiFiModeSetting(int subId) { |
| 2964 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 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)).getWfcMode(false /*isRoaming*/); |
| 2970 | } finally { |
| 2971 | Binder.restoreCallingIdentity(identity); |
| 2972 | } |
| 2973 | } |
| 2974 | |
| 2975 | @Override |
| 2976 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 2977 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2978 | "setVoWiFiModeSetting"); |
| 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)).setWfcMode(mode, false /*isRoaming*/); |
| 2984 | } finally { |
| 2985 | Binder.restoreCallingIdentity(identity); |
| 2986 | } |
| 2987 | } |
| 2988 | |
| 2989 | @Override |
| 2990 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 2991 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 2992 | final long identity = Binder.clearCallingIdentity(); |
| 2993 | try { |
| 2994 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2995 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2996 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 2997 | } finally { |
| 2998 | Binder.restoreCallingIdentity(identity); |
| 2999 | } |
| 3000 | } |
| 3001 | |
| 3002 | @Override |
| 3003 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3004 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3005 | "setVoWiFiRoamingModeSetting"); |
| 3006 | final long identity = Binder.clearCallingIdentity(); |
| 3007 | try { |
| 3008 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3009 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3010 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 3011 | } finally { |
| 3012 | Binder.restoreCallingIdentity(identity); |
| 3013 | } |
| 3014 | } |
| 3015 | |
| 3016 | @Override |
| 3017 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3018 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3019 | "setRttCapabilityEnabled"); |
| 3020 | final long identity = Binder.clearCallingIdentity(); |
| 3021 | try { |
| 3022 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3023 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3024 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3025 | } finally { |
| 3026 | Binder.restoreCallingIdentity(identity); |
| 3027 | } |
| 3028 | } |
| 3029 | |
| 3030 | @Override |
| 3031 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3032 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3033 | final long identity = Binder.clearCallingIdentity(); |
| 3034 | try { |
| 3035 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3036 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3037 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 3038 | } finally { |
| 3039 | Binder.restoreCallingIdentity(identity); |
| 3040 | } |
| 3041 | } |
| 3042 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3043 | @Override |
| 3044 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3045 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3046 | final long identity = Binder.clearCallingIdentity(); |
| 3047 | try { |
| 3048 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3049 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3050 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3051 | } finally { |
| 3052 | Binder.restoreCallingIdentity(identity); |
| 3053 | } |
| 3054 | } |
| 3055 | |
| 3056 | @Override |
| 3057 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3058 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3059 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3060 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3061 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3062 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3063 | try { |
| 3064 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3065 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3066 | .removeProvisioningCallbackForSubscription(callback, subId); |
| 3067 | } catch (IllegalArgumentException e) { |
| 3068 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3069 | + "is inactive, ignoring unregister."); |
| 3070 | // If the subscription is no longer active, just return, since the callback will already |
| 3071 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3072 | } finally { |
| 3073 | Binder.restoreCallingIdentity(identity); |
| 3074 | } |
| 3075 | } |
| 3076 | |
| 3077 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3078 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3079 | boolean isProvisioned) { |
| 3080 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3081 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3082 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3083 | } |
| 3084 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3085 | "setProvisioningStatusForCapability"); |
| 3086 | final long identity = Binder.clearCallingIdentity(); |
| 3087 | try { |
| 3088 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3089 | Phone phone = getPhone(subId); |
| 3090 | if (phone == null) { |
| 3091 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3092 | + subId); |
| 3093 | return; |
| 3094 | } |
| 3095 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3096 | return; |
| 3097 | } |
| 3098 | |
| 3099 | // this capability requires provisioning, route to the correct API. |
| 3100 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3101 | switch (capability) { |
| 3102 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3103 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3104 | ims.setVolteProvisioned(isProvisioned); |
| 3105 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3106 | ims.setWfcProvisioned(isProvisioned); |
| 3107 | } |
| 3108 | break; |
| 3109 | } |
| 3110 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3111 | // There is currently no difference in VT provisioning type. |
| 3112 | ims.setVtProvisioned(isProvisioned); |
| 3113 | break; |
| 3114 | } |
| 3115 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3116 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3117 | // change the capability of the feature instead if needed. |
| 3118 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3119 | == isProvisioned) { |
| 3120 | // No change in provisioning. |
| 3121 | return; |
| 3122 | } |
| 3123 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3124 | try { |
| 3125 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
| 3126 | } catch (ImsException e) { |
| 3127 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3128 | + ", Exception" + e.getMessage()); |
| 3129 | } |
| 3130 | break; |
| 3131 | } |
| 3132 | default: { |
| 3133 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3134 | + capability + "', which does not require provisioning."); |
| 3135 | } |
| 3136 | } |
| 3137 | |
| 3138 | } finally { |
| 3139 | Binder.restoreCallingIdentity(identity); |
| 3140 | } |
| 3141 | } |
| 3142 | |
| 3143 | @Override |
| 3144 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3145 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3146 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3147 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3148 | } |
| 3149 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3150 | final long identity = Binder.clearCallingIdentity(); |
| 3151 | try { |
| 3152 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3153 | Phone phone = getPhone(subId); |
| 3154 | if (phone == null) { |
| 3155 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3156 | + subId); |
| 3157 | // We will fail with "true" as the provisioning status because this is the default |
| 3158 | // if we do not require provisioning. |
| 3159 | return true; |
| 3160 | } |
| 3161 | |
| 3162 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3163 | return true; |
| 3164 | } |
| 3165 | |
| 3166 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3167 | switch (capability) { |
| 3168 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3169 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3170 | return ims.isVolteProvisionedOnDevice(); |
| 3171 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3172 | return ims.isWfcProvisionedOnDevice(); |
| 3173 | } |
| 3174 | // This should never happen, since we are checking tech above to make sure it |
| 3175 | // is either LTE or IWLAN. |
| 3176 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3177 | + "capability."); |
| 3178 | } |
| 3179 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3180 | // There is currently no difference in VT provisioning type. |
| 3181 | return ims.isVtProvisionedOnDevice(); |
| 3182 | } |
| 3183 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3184 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3185 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3186 | } |
| 3187 | default: { |
| 3188 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3189 | + capability + "', which does not require provisioning."); |
| 3190 | } |
| 3191 | } |
| 3192 | |
| 3193 | } finally { |
| 3194 | Binder.restoreCallingIdentity(identity); |
| 3195 | } |
| 3196 | } |
| 3197 | |
| 3198 | @Override |
| 3199 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3200 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3201 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3202 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3203 | } |
| 3204 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3205 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3206 | return (provisionedBits & capability) > 0; |
| 3207 | } |
| 3208 | |
| 3209 | @Override |
| 3210 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3211 | boolean isProvisioned) { |
| 3212 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3213 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3214 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3215 | } |
| 3216 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3217 | "setProvisioningStatusForCapability"); |
| 3218 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3219 | // If the current provisioning status for capability already matches isProvisioned, |
| 3220 | // do nothing. |
| 3221 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3222 | return; |
| 3223 | } |
| 3224 | if (isProvisioned) { |
| 3225 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3226 | } else { |
| 3227 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3228 | } |
| 3229 | } |
| 3230 | |
| 3231 | /** |
| 3232 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3233 | * technology. The bitfield should mirror the bitfield defined by |
| 3234 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3235 | */ |
| 3236 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3237 | String key = getMmTelProvisioningKey(subId, tech); |
| 3238 | // Default is no capabilities are provisioned. |
| 3239 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3240 | } |
| 3241 | |
| 3242 | /** |
| 3243 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3244 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3245 | * technology specified. |
| 3246 | * |
| 3247 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3248 | */ |
| 3249 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3250 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3251 | String key = getMmTelProvisioningKey(subId, tech); |
| 3252 | editor.putInt(key, newField); |
| 3253 | editor.commit(); |
| 3254 | } |
| 3255 | |
| 3256 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3257 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3258 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3259 | } |
| 3260 | |
| 3261 | /** |
| 3262 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3263 | * carrier associated with the subscription id. |
| 3264 | */ |
| 3265 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3266 | int capability) { |
| 3267 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3268 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3269 | boolean requireUtProvisioning = c.getBoolean( |
| 3270 | // By default, this config is true (even if there is no SIM). We also check to make |
| 3271 | // sure the subscription needs provisioning here, so we do not need to check for |
| 3272 | // the no-SIM case, where we would normally shortcut this to false. |
| 3273 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true) |
| 3274 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3275 | false); |
| 3276 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3277 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3278 | |
| 3279 | // First check to make sure that the capability requires provisioning. |
| 3280 | switch (capability) { |
| 3281 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3282 | // intentional fallthrough |
| 3283 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3284 | if (requireVoiceVtProvisioning) { |
| 3285 | // Voice and Video requires provisioning |
| 3286 | return true; |
| 3287 | } |
| 3288 | break; |
| 3289 | } |
| 3290 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3291 | if (requireUtProvisioning) { |
| 3292 | // UT requires provisioning |
| 3293 | return true; |
| 3294 | } |
| 3295 | break; |
| 3296 | } |
| 3297 | } |
| 3298 | return false; |
| 3299 | } |
| 3300 | |
| 3301 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3302 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3303 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3304 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3305 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3306 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3307 | final long identity = Binder.clearCallingIdentity(); |
| 3308 | try { |
| 3309 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3310 | int slotId = getSlotIndex(subId); |
| 3311 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3312 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3313 | + subId + "' for key:" + key); |
| 3314 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3315 | } |
| 3316 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3317 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3318 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3319 | + subId + "' for key:" + key); |
| 3320 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3321 | } finally { |
| 3322 | Binder.restoreCallingIdentity(identity); |
| 3323 | } |
| 3324 | } |
| 3325 | |
| 3326 | @Override |
| 3327 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3328 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3329 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3330 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3331 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3332 | final long identity = Binder.clearCallingIdentity(); |
| 3333 | try { |
| 3334 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3335 | int slotId = getSlotIndex(subId); |
| 3336 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3337 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3338 | + subId + "' for key:" + key); |
| 3339 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3340 | } |
| 3341 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3342 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3343 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3344 | + subId + "' for key:" + key); |
| 3345 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3346 | } finally { |
| 3347 | Binder.restoreCallingIdentity(identity); |
| 3348 | } |
| 3349 | } |
| 3350 | |
| 3351 | @Override |
| 3352 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3353 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3354 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3355 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3356 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3357 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3358 | final long identity = Binder.clearCallingIdentity(); |
| 3359 | try { |
| 3360 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3361 | int slotId = getSlotIndex(subId); |
| 3362 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3363 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3364 | + subId + "' for key:" + key); |
| 3365 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3366 | } |
| 3367 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3368 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3369 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3370 | + "' for key:" + key); |
| 3371 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3372 | } finally { |
| 3373 | Binder.restoreCallingIdentity(identity); |
| 3374 | } |
| 3375 | } |
| 3376 | |
| 3377 | @Override |
| 3378 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3379 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3380 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3381 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3382 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3383 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3384 | final long identity = Binder.clearCallingIdentity(); |
| 3385 | try { |
| 3386 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3387 | int slotId = getSlotIndex(subId); |
| 3388 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3389 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3390 | + subId + "' for key:" + key); |
| 3391 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3392 | } |
| 3393 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3394 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3395 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3396 | + "' for key:" + key); |
| 3397 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3398 | } finally { |
| 3399 | Binder.restoreCallingIdentity(identity); |
| 3400 | } |
| 3401 | } |
| 3402 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3403 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 3404 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3405 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3406 | throw new IllegalArgumentException("Invalid Subscription Id."); |
| 3407 | } |
| 3408 | return slotId; |
| 3409 | } |
| 3410 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3411 | private int getSlotIndex(int subId) { |
| 3412 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3413 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3414 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3415 | } |
| 3416 | return slotId; |
| 3417 | } |
| 3418 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3419 | /** |
| 3420 | * Returns the network type for a subId |
| 3421 | */ |
| 3422 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3423 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3424 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3425 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3426 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3427 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3428 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3429 | final long identity = Binder.clearCallingIdentity(); |
| 3430 | try { |
| 3431 | final Phone phone = getPhone(subId); |
| 3432 | if (phone != null) { |
| 3433 | return phone.getServiceState().getDataNetworkType(); |
| 3434 | } else { |
| 3435 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3436 | } |
| 3437 | } finally { |
| 3438 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3439 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3440 | } |
| 3441 | |
| 3442 | /** |
| 3443 | * Returns the data network type |
| 3444 | */ |
| 3445 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3446 | public int getDataNetworkType(String callingPackage) { |
| 3447 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3448 | } |
| 3449 | |
| 3450 | /** |
| 3451 | * Returns the data network type for a subId |
| 3452 | */ |
| 3453 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3454 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3455 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3456 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3457 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3458 | } |
| 3459 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3460 | final long identity = Binder.clearCallingIdentity(); |
| 3461 | try { |
| 3462 | final Phone phone = getPhone(subId); |
| 3463 | if (phone != null) { |
| 3464 | return phone.getServiceState().getDataNetworkType(); |
| 3465 | } else { |
| 3466 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3467 | } |
| 3468 | } finally { |
| 3469 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3470 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3471 | } |
| 3472 | |
| 3473 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3474 | * Returns the Voice network type for a subId |
| 3475 | */ |
| 3476 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3477 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3478 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3479 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3480 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3481 | } |
| 3482 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3483 | final long identity = Binder.clearCallingIdentity(); |
| 3484 | try { |
| 3485 | final Phone phone = getPhone(subId); |
| 3486 | if (phone != null) { |
| 3487 | return phone.getServiceState().getVoiceNetworkType(); |
| 3488 | } else { |
| 3489 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3490 | } |
| 3491 | } finally { |
| 3492 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3493 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3494 | } |
| 3495 | |
| 3496 | /** |
| 3497 | * @return true if a ICC card is present |
| 3498 | */ |
| 3499 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3500 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3501 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3502 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3503 | } |
| 3504 | |
| 3505 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3506 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3507 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3508 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3509 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3510 | final long identity = Binder.clearCallingIdentity(); |
| 3511 | try { |
| 3512 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3513 | if (phone != null) { |
| 3514 | return phone.getIccCard().hasIccCard(); |
| 3515 | } else { |
| 3516 | return false; |
| 3517 | } |
| 3518 | } finally { |
| 3519 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3520 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3521 | } |
| 3522 | |
| 3523 | /** |
| 3524 | * Return if the current radio is LTE on CDMA. This |
| 3525 | * is a tri-state return value as for a period of time |
| 3526 | * the mode may be unknown. |
| 3527 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3528 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3529 | * @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] | 3530 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3531 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3532 | @Override |
| 3533 | public int getLteOnCdmaMode(String callingPackage) { |
| 3534 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3535 | } |
| 3536 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3537 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3538 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3539 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3540 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3541 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3542 | } |
| 3543 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3544 | final long identity = Binder.clearCallingIdentity(); |
| 3545 | try { |
| 3546 | final Phone phone = getPhone(subId); |
| 3547 | if (phone == null) { |
| 3548 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3549 | } else { |
| 3550 | return phone.getLteOnCdmaMode(); |
| 3551 | } |
| 3552 | } finally { |
| 3553 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3554 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3555 | } |
| 3556 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3557 | /** |
| 3558 | * {@hide} |
| 3559 | * Returns Default subId, 0 in the case of single standby. |
| 3560 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3561 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3562 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3563 | } |
| 3564 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3565 | private int getSlotForDefaultSubscription() { |
| 3566 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3567 | } |
| 3568 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3569 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3570 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3571 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3572 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3573 | private boolean isActiveSubscription(int subId) { |
| 3574 | return mSubscriptionController.isActiveSubId(subId); |
| 3575 | } |
| 3576 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3577 | /** |
| 3578 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3579 | */ |
| 3580 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3581 | final long identity = Binder.clearCallingIdentity(); |
| 3582 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3583 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3584 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3585 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3586 | } finally { |
| 3587 | Binder.restoreCallingIdentity(identity); |
| 3588 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3589 | } |
| 3590 | |
| 3591 | /** |
| 3592 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3593 | */ |
| 3594 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3595 | final long identity = Binder.clearCallingIdentity(); |
| 3596 | try { |
| 3597 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3598 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3599 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3600 | } finally { |
| 3601 | Binder.restoreCallingIdentity(identity); |
| 3602 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3603 | } |
| 3604 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3605 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3606 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3607 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3608 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3609 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3610 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3611 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3612 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3613 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3614 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3615 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3616 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3617 | final long identity = Binder.clearCallingIdentity(); |
| 3618 | try { |
| 3619 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3620 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3621 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3622 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3623 | if (bestComponent == null |
| 3624 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3625 | loge("The calling package is not allowed to access ISD-R."); |
| 3626 | throw new SecurityException( |
| 3627 | "The calling package is not allowed to access ISD-R."); |
| 3628 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3629 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3630 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3631 | if (DBG) { |
| 3632 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3633 | } |
| 3634 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
| 3635 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId); |
| 3636 | if (DBG) log("iccOpenLogicalChannel: " + response); |
| 3637 | return response; |
| 3638 | } finally { |
| 3639 | Binder.restoreCallingIdentity(identity); |
| 3640 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3641 | } |
| 3642 | |
| 3643 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3644 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3645 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3646 | mApp, subId, "iccCloseLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3647 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3648 | final long identity = Binder.clearCallingIdentity(); |
| 3649 | try { |
| 3650 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3651 | if (channel < 0) { |
| 3652 | return false; |
| 3653 | } |
| 3654 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId); |
| 3655 | if (DBG) log("iccCloseLogicalChannel: " + success); |
| 3656 | return success; |
| 3657 | } finally { |
| 3658 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3659 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3660 | } |
| 3661 | |
| 3662 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3663 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3664 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3665 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3666 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3667 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3668 | final long identity = Binder.clearCallingIdentity(); |
| 3669 | try { |
| 3670 | if (DBG) { |
| 3671 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3672 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3673 | + p3 + " data=" + data); |
| 3674 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3675 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3676 | if (channel < 0) { |
| 3677 | return ""; |
| 3678 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3679 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3680 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
| 3681 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId); |
| 3682 | if (DBG) log("iccTransmitApduLogicalChannel: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3683 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3684 | // Append the returned status code to the end of the response payload. |
| 3685 | String s = Integer.toHexString( |
| 3686 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3687 | if (response.payload != null) { |
| 3688 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3689 | } |
| 3690 | return s; |
| 3691 | } finally { |
| 3692 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3693 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3694 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3695 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3696 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3697 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3698 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3699 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3700 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3701 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3702 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3703 | final long identity = Binder.clearCallingIdentity(); |
| 3704 | try { |
| 3705 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3706 | && TextUtils.equals(ISDR_AID, data)) { |
| 3707 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3708 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3709 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3710 | if (bestComponent == null |
| 3711 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3712 | loge("The calling package is not allowed to select ISD-R."); |
| 3713 | throw new SecurityException( |
| 3714 | "The calling package is not allowed to select ISD-R."); |
| 3715 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3716 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3717 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3718 | if (DBG) { |
| 3719 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3720 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3721 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3722 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3723 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
| 3724 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId); |
| 3725 | if (DBG) log("iccTransmitApduBasicChannel: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -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 | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3737 | } |
| 3738 | |
| 3739 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3740 | 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] | 3741 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3742 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3743 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3744 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3745 | final long identity = Binder.clearCallingIdentity(); |
| 3746 | try { |
| 3747 | if (DBG) { |
| 3748 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3749 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3750 | } |
| 3751 | |
| 3752 | IccIoResult response = |
| 3753 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3754 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3755 | subId); |
| 3756 | |
| 3757 | if (DBG) { |
| 3758 | log("Exchange SIM_IO [R]" + response); |
| 3759 | } |
| 3760 | |
| 3761 | byte[] result = null; |
| 3762 | int length = 2; |
| 3763 | if (response.payload != null) { |
| 3764 | length = 2 + response.payload.length; |
| 3765 | result = new byte[length]; |
| 3766 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3767 | } else { |
| 3768 | result = new byte[length]; |
| 3769 | } |
| 3770 | |
| 3771 | result[length - 1] = (byte) response.sw2; |
| 3772 | result[length - 2] = (byte) response.sw1; |
| 3773 | return result; |
| 3774 | } finally { |
| 3775 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3776 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3777 | } |
| 3778 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3779 | /** |
| 3780 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 3781 | * on a particular subscription |
| 3782 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3783 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 3784 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3785 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 3786 | return null; |
| 3787 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3788 | |
| 3789 | final long identity = Binder.clearCallingIdentity(); |
| 3790 | try { |
| 3791 | if (appType != TelephonyManager.APPTYPE_USIM |
| 3792 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 3793 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 3794 | return null; |
| 3795 | } |
| 3796 | Object response = sendRequest( |
| 3797 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 3798 | if (response instanceof String[]) { |
| 3799 | return (String[]) response; |
| 3800 | } |
| 3801 | // Response is an Exception of some kind, |
| 3802 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3803 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3804 | } finally { |
| 3805 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3806 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3807 | } |
| 3808 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3809 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3810 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3811 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3812 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3813 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3814 | final long identity = Binder.clearCallingIdentity(); |
| 3815 | try { |
| 3816 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 3817 | if (response.payload == null) { |
| 3818 | return ""; |
| 3819 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3820 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3821 | // Append the returned status code to the end of the response payload. |
| 3822 | String s = Integer.toHexString( |
| 3823 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3824 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3825 | return s; |
| 3826 | } finally { |
| 3827 | Binder.restoreCallingIdentity(identity); |
| 3828 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3829 | } |
| 3830 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3831 | /** |
| 3832 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3833 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3834 | * |
| 3835 | * @param itemID the ID of the item to read |
| 3836 | * @return the NV item as a String, or null on error. |
| 3837 | */ |
| 3838 | @Override |
| 3839 | public String nvReadItem(int itemID) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3840 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3841 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3842 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3843 | |
| 3844 | final long identity = Binder.clearCallingIdentity(); |
| 3845 | try { |
| 3846 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3847 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3848 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 3849 | return value; |
| 3850 | } finally { |
| 3851 | Binder.restoreCallingIdentity(identity); |
| 3852 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3853 | } |
| 3854 | |
| 3855 | /** |
| 3856 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3857 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3858 | * |
| 3859 | * @param itemID the ID of the item to read |
| 3860 | * @param itemValue the value to write, as a String |
| 3861 | * @return true on success; false on any failure |
| 3862 | */ |
| 3863 | @Override |
| 3864 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3865 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3866 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3867 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3868 | |
| 3869 | final long identity = Binder.clearCallingIdentity(); |
| 3870 | try { |
| 3871 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 3872 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3873 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3874 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 3875 | return success; |
| 3876 | } finally { |
| 3877 | Binder.restoreCallingIdentity(identity); |
| 3878 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3879 | } |
| 3880 | |
| 3881 | /** |
| 3882 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 3883 | * Used for device configuration by some CDMA operators. |
| 3884 | * |
| 3885 | * @param preferredRoamingList byte array containing the new PRL |
| 3886 | * @return true on success; false on any failure |
| 3887 | */ |
| 3888 | @Override |
| 3889 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3890 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3891 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3892 | |
| 3893 | final long identity = Binder.clearCallingIdentity(); |
| 3894 | try { |
| 3895 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 3896 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 3897 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 3898 | return success; |
| 3899 | } finally { |
| 3900 | Binder.restoreCallingIdentity(identity); |
| 3901 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3902 | } |
| 3903 | |
| 3904 | /** |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3905 | * 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] | 3906 | * Used for device configuration by some CDMA operators. |
| 3907 | * |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3908 | * @param slotIndex - device slot. |
| 3909 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3910 | * @return true on success; false on any failure |
| 3911 | */ |
| 3912 | @Override |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3913 | public boolean resetModemConfig(int slotIndex) { |
| 3914 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3915 | if (phone != null) { |
| 3916 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3917 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3918 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3919 | final long identity = Binder.clearCallingIdentity(); |
| 3920 | try { |
| 3921 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 3922 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 3923 | return success; |
| 3924 | } finally { |
| 3925 | Binder.restoreCallingIdentity(identity); |
| 3926 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3927 | } |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3928 | return false; |
| 3929 | } |
| 3930 | |
| 3931 | /** |
| 3932 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 3933 | * |
| 3934 | * @param slotIndex - device slot. |
| 3935 | * |
| 3936 | * @return true on success; false on any failure |
| 3937 | */ |
| 3938 | @Override |
| 3939 | public boolean rebootModem(int slotIndex) { |
| 3940 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3941 | if (phone != null) { |
| 3942 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3943 | mApp, phone.getSubId(), "rebootModem"); |
| 3944 | |
| 3945 | final long identity = Binder.clearCallingIdentity(); |
| 3946 | try { |
| 3947 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 3948 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 3949 | return success; |
| 3950 | } finally { |
| 3951 | Binder.restoreCallingIdentity(identity); |
| 3952 | } |
| 3953 | } |
| 3954 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3955 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3956 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3957 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3958 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3959 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3960 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3961 | return new String[0]; |
| 3962 | } |
| 3963 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3964 | final long identity = Binder.clearCallingIdentity(); |
| 3965 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3966 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3967 | } finally { |
| 3968 | Binder.restoreCallingIdentity(identity); |
| 3969 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3970 | } |
| 3971 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3972 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3973 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 3974 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3975 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3976 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3977 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3978 | |
| 3979 | final long identity = Binder.clearCallingIdentity(); |
| 3980 | try { |
| 3981 | PhoneFactory.getImsResolver().enableIms(slotId); |
| 3982 | } finally { |
| 3983 | Binder.restoreCallingIdentity(identity); |
| 3984 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3985 | } |
| 3986 | |
| 3987 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3988 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 3989 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3990 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3991 | public void disableIms(int slotId) { |
| 3992 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3993 | |
| 3994 | final long identity = Binder.clearCallingIdentity(); |
| 3995 | try { |
| 3996 | PhoneFactory.getImsResolver().disableIms(slotId); |
| 3997 | } finally { |
| 3998 | Binder.restoreCallingIdentity(identity); |
| 3999 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4000 | } |
| 4001 | |
| 4002 | /** |
| 4003 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4004 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4005 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4006 | */ |
| 4007 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4008 | IImsServiceFeatureCallback callback) { |
| 4009 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4010 | |
| 4011 | final long identity = Binder.clearCallingIdentity(); |
| 4012 | try { |
| 4013 | return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback); |
| 4014 | } finally { |
| 4015 | Binder.restoreCallingIdentity(identity); |
| 4016 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4017 | } |
| 4018 | |
| 4019 | /** |
| 4020 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4021 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4022 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4023 | * listener for feature updates. |
| 4024 | */ |
| 4025 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4026 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4027 | |
| 4028 | final long identity = Binder.clearCallingIdentity(); |
| 4029 | try { |
| 4030 | return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback); |
| 4031 | } finally { |
| 4032 | Binder.restoreCallingIdentity(identity); |
| 4033 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4034 | } |
| 4035 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4036 | /** |
| 4037 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
| 4038 | * specified. |
| 4039 | */ |
| 4040 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4041 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4042 | |
| 4043 | final long identity = Binder.clearCallingIdentity(); |
| 4044 | try { |
| 4045 | return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature); |
| 4046 | } finally { |
| 4047 | Binder.restoreCallingIdentity(identity); |
| 4048 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4049 | } |
| 4050 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4051 | /** |
| 4052 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
| 4053 | * specified. |
| 4054 | */ |
| 4055 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4056 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4057 | |
| 4058 | final long identity = Binder.clearCallingIdentity(); |
| 4059 | try { |
| 4060 | return PhoneFactory.getImsResolver().getImsConfig(slotId, feature); |
| 4061 | } finally { |
| 4062 | Binder.restoreCallingIdentity(identity); |
| 4063 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4064 | } |
| 4065 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4066 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4067 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4068 | * |
| 4069 | * @param slotId the slot ID that the ImsService should bind for. |
| 4070 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4071 | * ImsService is the device default ImsService. |
| 4072 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4073 | * to. |
| 4074 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4075 | * @hide |
| 4076 | */ |
| 4077 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4078 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4079 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4080 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4081 | "setImsService"); |
| 4082 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4083 | final long identity = Binder.clearCallingIdentity(); |
| 4084 | try { |
| 4085 | return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId, |
| 4086 | isCarrierImsService, packageName); |
| 4087 | } finally { |
| 4088 | Binder.restoreCallingIdentity(identity); |
| 4089 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4090 | } |
| 4091 | |
| 4092 | /** |
| 4093 | * Return the ImsService configuration. |
| 4094 | * |
| 4095 | * @param slotId The slot that the ImsService is associated with. |
| 4096 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4097 | * the device default. |
| 4098 | * @return the package name of the ImsService configuration. |
| 4099 | */ |
| 4100 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4101 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4102 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4103 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4104 | "getImsService"); |
| 4105 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4106 | final long identity = Binder.clearCallingIdentity(); |
| 4107 | try { |
| 4108 | return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId, |
| 4109 | isCarrierImsService); |
| 4110 | } finally { |
| 4111 | Binder.restoreCallingIdentity(identity); |
| 4112 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4113 | } |
| 4114 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4115 | public void setImsRegistrationState(boolean registered) { |
| 4116 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4117 | |
| 4118 | final long identity = Binder.clearCallingIdentity(); |
| 4119 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4120 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4121 | } finally { |
| 4122 | Binder.restoreCallingIdentity(identity); |
| 4123 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4124 | } |
| 4125 | |
| 4126 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4127 | * Set the network selection mode to automatic. |
| 4128 | * |
| 4129 | */ |
| 4130 | @Override |
| 4131 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4132 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4133 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4134 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4135 | if (!isActiveSubscription(subId)) { |
| 4136 | return; |
| 4137 | } |
| 4138 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4139 | final long identity = Binder.clearCallingIdentity(); |
| 4140 | try { |
| 4141 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4142 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4143 | } finally { |
| 4144 | Binder.restoreCallingIdentity(identity); |
| 4145 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4146 | } |
| 4147 | |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4148 | /** |
| 4149 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4150 | * |
| 4151 | * @param subId the id of the subscription. |
| 4152 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4153 | * the operator to attach to. |
| 4154 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4155 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4156 | * normal network selection next time. |
| 4157 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4158 | */ |
| 4159 | @Override |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4160 | public boolean setNetworkSelectionModeManual( |
| 4161 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4162 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4163 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4164 | |
| 4165 | if (!isActiveSubscription(subId)) { |
| 4166 | return false; |
| 4167 | } |
| 4168 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4169 | final long identity = Binder.clearCallingIdentity(); |
| 4170 | try { |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4171 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4172 | persistSelection); |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4173 | if (DBG) { |
| 4174 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4175 | + " operator: " + operatorInfo); |
| 4176 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4177 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4178 | } finally { |
| 4179 | Binder.restoreCallingIdentity(identity); |
| 4180 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4181 | } |
| 4182 | |
| 4183 | /** |
| 4184 | * Scans for available networks. |
| 4185 | */ |
| 4186 | @Override |
| 4187 | public CellNetworkScanResult getCellNetworkScanResults(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4188 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4189 | mApp, subId, "getCellNetworkScanResults"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4190 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4191 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4192 | try { |
| 4193 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4194 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4195 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4196 | } finally { |
| 4197 | Binder.restoreCallingIdentity(identity); |
| 4198 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4199 | } |
| 4200 | |
| 4201 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4202 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4203 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4204 | * @param subId id of the subscription |
| 4205 | * @param request contains the radio access networks with bands/channels to scan |
| 4206 | * @param messenger callback messenger for scan results or errors |
| 4207 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4208 | * @return the id of the requested scan which can be used to stop the scan. |
| 4209 | */ |
| 4210 | @Override |
| 4211 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
| 4212 | IBinder binder) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4213 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4214 | mApp, subId, "requestNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4215 | |
| 4216 | final long identity = Binder.clearCallingIdentity(); |
| 4217 | try { |
| 4218 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4219 | request, messenger, binder, getPhone(subId)); |
| 4220 | } finally { |
| 4221 | Binder.restoreCallingIdentity(identity); |
| 4222 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4223 | } |
| 4224 | |
| 4225 | /** |
| 4226 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4227 | * |
| 4228 | * @param subId id of the subscription |
| 4229 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4230 | */ |
| 4231 | @Override |
| 4232 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4233 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4234 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4235 | |
| 4236 | final long identity = Binder.clearCallingIdentity(); |
| 4237 | try { |
| 4238 | mNetworkScanRequestTracker.stopNetworkScan(scanId); |
| 4239 | } finally { |
| 4240 | Binder.restoreCallingIdentity(identity); |
| 4241 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4242 | } |
| 4243 | |
| 4244 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4245 | * Get the calculated preferred network type. |
| 4246 | * Used for debugging incorrect network type. |
| 4247 | * |
| 4248 | * @return the preferred network type, defined in RILConstants.java. |
| 4249 | */ |
| 4250 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4251 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4252 | final Phone defaultPhone = getDefaultPhone(); |
| 4253 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4254 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4255 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4256 | } |
| 4257 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4258 | final long identity = Binder.clearCallingIdentity(); |
| 4259 | try { |
| 4260 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4261 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4262 | } finally { |
| 4263 | Binder.restoreCallingIdentity(identity); |
| 4264 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4265 | } |
| 4266 | |
| 4267 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4268 | * Get the preferred network type. |
| 4269 | * Used for device configuration by some CDMA operators. |
| 4270 | * |
| 4271 | * @return the preferred network type, defined in RILConstants.java. |
| 4272 | */ |
| 4273 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4274 | public int getPreferredNetworkType(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4275 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4276 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4277 | |
| 4278 | final long identity = Binder.clearCallingIdentity(); |
| 4279 | try { |
| 4280 | if (DBG) log("getPreferredNetworkType"); |
| 4281 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4282 | int networkType = (result != null ? result[0] : -1); |
| 4283 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4284 | return networkType; |
| 4285 | } finally { |
| 4286 | Binder.restoreCallingIdentity(identity); |
| 4287 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4288 | } |
| 4289 | |
| 4290 | /** |
| 4291 | * Set the preferred network type. |
| 4292 | * Used for device configuration by some CDMA operators. |
| 4293 | * |
| 4294 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4295 | * @return true on success; false on any failure. |
| 4296 | */ |
| 4297 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4298 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4299 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4300 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4301 | |
| 4302 | final long identity = Binder.clearCallingIdentity(); |
| 4303 | try { |
| 4304 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4305 | Boolean success = (Boolean) sendRequest( |
| 4306 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4307 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4308 | if (success) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4309 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4310 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4311 | } |
| 4312 | return success; |
| 4313 | } finally { |
| 4314 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4315 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4316 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4317 | |
| 4318 | /** |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4319 | * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning |
Jack Yu | 13db0fe | 2018-10-30 17:41:31 -0700 | [diff] [blame] | 4320 | * SystemProperty to decide whether DUN APN is required for |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4321 | * tethering. |
| 4322 | * |
| 4323 | * @return 0: Not required. 1: required. 2: Not set. |
| 4324 | * @hide |
| 4325 | */ |
| 4326 | @Override |
| 4327 | public int getTetherApnRequired() { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4328 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4329 | |
| 4330 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4331 | final Phone defaultPhone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4332 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4333 | int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4334 | Settings.Global.TETHER_DUN_REQUIRED, 2); |
Jack Yu | 13db0fe | 2018-10-30 17:41:31 -0700 | [diff] [blame] | 4335 | // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4336 | if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4337 | dunRequired = 1; |
| 4338 | } |
| 4339 | return dunRequired; |
| 4340 | } finally { |
| 4341 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4342 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4343 | } |
| 4344 | |
| 4345 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4346 | * Set mobile data enabled |
| 4347 | * Used by the user through settings etc to turn on/off mobile data |
| 4348 | * |
| 4349 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4350 | */ |
| 4351 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4352 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4353 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4354 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4355 | |
| 4356 | final long identity = Binder.clearCallingIdentity(); |
| 4357 | try { |
| 4358 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4359 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4360 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4361 | if (phone != null) { |
| 4362 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4363 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4364 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4365 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4366 | } |
| 4367 | } finally { |
| 4368 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4369 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4370 | } |
| 4371 | |
| 4372 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4373 | * Get the user enabled state of Mobile Data. |
| 4374 | * |
| 4375 | * TODO: remove and use isUserDataEnabled. |
| 4376 | * This can't be removed now because some vendor codes |
| 4377 | * calls through ITelephony directly while they should |
| 4378 | * use TelephonyManager. |
| 4379 | * |
| 4380 | * @return true on enabled |
| 4381 | */ |
| 4382 | @Override |
| 4383 | public boolean getDataEnabled(int subId) { |
| 4384 | return isUserDataEnabled(subId); |
| 4385 | } |
| 4386 | |
| 4387 | /** |
| 4388 | * Get whether mobile data is enabled per user setting. |
| 4389 | * |
| 4390 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4391 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4392 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4393 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4394 | * |
| 4395 | * @return {@code true} if data is enabled else {@code false} |
| 4396 | */ |
| 4397 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4398 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4399 | try { |
| 4400 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4401 | null); |
| 4402 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4403 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4404 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4405 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4406 | |
| 4407 | final long identity = Binder.clearCallingIdentity(); |
| 4408 | try { |
| 4409 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4410 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4411 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4412 | if (phone != null) { |
| 4413 | boolean retVal = phone.isUserDataEnabled(); |
| 4414 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4415 | return retVal; |
| 4416 | } else { |
| 4417 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4418 | return false; |
| 4419 | } |
| 4420 | } finally { |
| 4421 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4422 | } |
| 4423 | } |
| 4424 | |
| 4425 | /** |
| 4426 | * Get whether mobile data is enabled. |
| 4427 | * |
| 4428 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4429 | * whether mobile data is actually enabled. |
| 4430 | * |
| 4431 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4432 | * |
| 4433 | * @return {@code true} if data is enabled else {@code false} |
| 4434 | */ |
| 4435 | @Override |
| 4436 | public boolean isDataEnabled(int subId) { |
| 4437 | try { |
| 4438 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4439 | null); |
| 4440 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4441 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4442 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4443 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4444 | |
| 4445 | final long identity = Binder.clearCallingIdentity(); |
| 4446 | try { |
| 4447 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4448 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4449 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4450 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4451 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4452 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4453 | return retVal; |
| 4454 | } else { |
| 4455 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4456 | return false; |
| 4457 | } |
| 4458 | } finally { |
| 4459 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4460 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4461 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4462 | |
| 4463 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4464 | public int getCarrierPrivilegeStatus(int subId) { |
| 4465 | final Phone phone = getPhone(subId); |
| 4466 | if (phone == null) { |
| 4467 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4468 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4469 | } |
| 4470 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4471 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4472 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4473 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4474 | } |
| 4475 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4476 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4477 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4478 | |
| 4479 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4480 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4481 | final Phone phone = getPhone(subId); |
| 4482 | if (phone == null) { |
| 4483 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4484 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4485 | } |
| 4486 | UiccProfile profile = |
| 4487 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4488 | if (profile == null) { |
| 4489 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4490 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4491 | } |
| 4492 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 4493 | } |
| 4494 | |
| 4495 | @Override |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4496 | public int checkCarrierPrivilegesForPackage(String pkgName) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4497 | final Phone defaultPhone = getDefaultPhone(); |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4498 | if (TextUtils.isEmpty(pkgName)) |
| 4499 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4500 | UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4501 | if (card == null) { |
| 4502 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 4503 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4504 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4505 | return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(), |
| 4506 | pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4507 | } |
| 4508 | |
| 4509 | @Override |
| 4510 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4511 | if (TextUtils.isEmpty(pkgName)) |
| 4512 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4513 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4514 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4515 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4516 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4517 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4518 | continue; |
| 4519 | } |
| 4520 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4521 | result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4522 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4523 | break; |
| 4524 | } |
| 4525 | } |
| 4526 | |
| 4527 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4528 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4529 | |
| 4530 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4531 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4532 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4533 | loge("phoneId " + phoneId + " is not valid."); |
| 4534 | return null; |
| 4535 | } |
| 4536 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4537 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4538 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4539 | return null ; |
| 4540 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4541 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4542 | } |
| 4543 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4544 | @Override |
| 4545 | public List<String> getPackagesWithCarrierPrivileges() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4546 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4547 | List<String> privilegedPackages = new ArrayList<>(); |
| 4548 | List<PackageInfo> packages = null; |
| 4549 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4550 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4551 | if (card == null) { |
| 4552 | // No UICC in that slot. |
| 4553 | continue; |
| 4554 | } |
| 4555 | if (card.hasCarrierPrivilegeRules()) { |
| 4556 | if (packages == null) { |
| 4557 | // Only check packages in user 0 for now |
| 4558 | packages = pm.getInstalledPackagesAsUser( |
| 4559 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4560 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4561 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
| 4562 | } |
| 4563 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4564 | PackageInfo pkgInfo = packages.get(p); |
| 4565 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4566 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| 4567 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4568 | privilegedPackages.add(pkgInfo.packageName); |
| 4569 | } |
| 4570 | } |
| 4571 | } |
| 4572 | } |
| 4573 | return privilegedPackages; |
| 4574 | } |
| 4575 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4576 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4577 | final Phone phone = getPhone(subId); |
| 4578 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4579 | if (card == null) { |
| 4580 | loge("getIccId: No UICC"); |
| 4581 | return null; |
| 4582 | } |
| 4583 | String iccId = card.getIccId(); |
| 4584 | if (TextUtils.isEmpty(iccId)) { |
| 4585 | loge("getIccId: ICC ID is null or empty."); |
| 4586 | return null; |
| 4587 | } |
| 4588 | return iccId; |
| 4589 | } |
| 4590 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4591 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4592 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4593 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4594 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4595 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4596 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4597 | final long identity = Binder.clearCallingIdentity(); |
| 4598 | try { |
| 4599 | final String iccId = getIccId(subId); |
| 4600 | final Phone phone = getPhone(subId); |
| 4601 | if (phone == null) { |
| 4602 | return false; |
| 4603 | } |
| 4604 | final String subscriberId = phone.getSubscriberId(); |
| 4605 | |
| 4606 | if (DBG_MERGE) { |
| 4607 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4608 | + subscriberId + " to " + number); |
| 4609 | } |
| 4610 | |
| 4611 | if (TextUtils.isEmpty(iccId)) { |
| 4612 | return false; |
| 4613 | } |
| 4614 | |
| 4615 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4616 | |
| 4617 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4618 | if (alphaTag == null) { |
| 4619 | editor.remove(alphaTagPrefKey); |
| 4620 | } else { |
| 4621 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4622 | } |
| 4623 | |
| 4624 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4625 | // track all merged IMSIs based on line number |
| 4626 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4627 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4628 | if (number == null) { |
| 4629 | editor.remove(numberPrefKey); |
| 4630 | editor.remove(subscriberPrefKey); |
| 4631 | } else { |
| 4632 | editor.putString(numberPrefKey, number); |
| 4633 | editor.putString(subscriberPrefKey, subscriberId); |
| 4634 | } |
| 4635 | |
| 4636 | editor.commit(); |
| 4637 | return true; |
| 4638 | } finally { |
| 4639 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4640 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4641 | } |
| 4642 | |
| 4643 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4644 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4645 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4646 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4647 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4648 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4649 | return null; |
| 4650 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4651 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4652 | final long identity = Binder.clearCallingIdentity(); |
| 4653 | try { |
| 4654 | String iccId = getIccId(subId); |
| 4655 | if (iccId != null) { |
| 4656 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4657 | if (DBG_MERGE) { |
| 4658 | log("getLine1NumberForDisplay returning " |
| 4659 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 4660 | } |
| 4661 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4662 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4663 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 4664 | return null; |
| 4665 | } finally { |
| 4666 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4667 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4668 | } |
| 4669 | |
| 4670 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4671 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4672 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4673 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4674 | return null; |
| 4675 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4676 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4677 | final long identity = Binder.clearCallingIdentity(); |
| 4678 | try { |
| 4679 | String iccId = getIccId(subId); |
| 4680 | if (iccId != null) { |
| 4681 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4682 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 4683 | } |
| 4684 | return null; |
| 4685 | } finally { |
| 4686 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4687 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4688 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4689 | |
| 4690 | @Override |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4691 | public String[] getMergedSubscriberIds(String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4692 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 4693 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4694 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4695 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 4696 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4697 | return null; |
| 4698 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4699 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4700 | final long identity = Binder.clearCallingIdentity(); |
| 4701 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4702 | final Context context = mApp; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4703 | final TelephonyManager tele = TelephonyManager.from(context); |
| 4704 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 4705 | |
| 4706 | // Figure out what subscribers are currently active |
| 4707 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
| 4708 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 4709 | // the process, where TelephonyManager was instantiated. |
| 4710 | // Otherwise AppOps check will fail. |
| 4711 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4712 | final int[] subIds = sub.getActiveSubscriptionIdList(); |
| 4713 | for (int subId : subIds) { |
| 4714 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 4715 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4716 | |
| 4717 | // First pass, find a number override for an active subscriber |
| 4718 | String mergeNumber = null; |
| 4719 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 4720 | for (String key : prefs.keySet()) { |
| 4721 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 4722 | final String subscriberId = (String) prefs.get(key); |
| 4723 | if (activeSubscriberIds.contains(subscriberId)) { |
| 4724 | final String iccId = key.substring( |
| 4725 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 4726 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4727 | mergeNumber = (String) prefs.get(numberKey); |
| 4728 | if (DBG_MERGE) { |
| 4729 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 4730 | + " for active subscriber " + subscriberId); |
| 4731 | } |
| 4732 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 4733 | break; |
| 4734 | } |
| 4735 | } |
| 4736 | } |
| 4737 | } |
| 4738 | |
| 4739 | // Shortcut when no active merged subscribers |
| 4740 | if (TextUtils.isEmpty(mergeNumber)) { |
| 4741 | return null; |
| 4742 | } |
| 4743 | |
| 4744 | // Second pass, find all subscribers under that line override |
| 4745 | final ArraySet<String> result = new ArraySet<>(); |
| 4746 | for (String key : prefs.keySet()) { |
| 4747 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 4748 | final String number = (String) prefs.get(key); |
| 4749 | if (mergeNumber.equals(number)) { |
| 4750 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 4751 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4752 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 4753 | if (!TextUtils.isEmpty(subscriberId)) { |
| 4754 | result.add(subscriberId); |
| 4755 | } |
| 4756 | } |
| 4757 | } |
| 4758 | } |
| 4759 | |
| 4760 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 4761 | Arrays.sort(resultArray); |
| 4762 | if (DBG_MERGE) { |
| 4763 | Slog.d(LOG_TAG, |
| 4764 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 4765 | } |
| 4766 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4767 | } finally { |
| 4768 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4769 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4770 | } |
| 4771 | |
| 4772 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4773 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4774 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4775 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4776 | |
| 4777 | final long identity = Binder.clearCallingIdentity(); |
| 4778 | try { |
| 4779 | final Phone phone = getPhone(subId); |
| 4780 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 4781 | } finally { |
| 4782 | Binder.restoreCallingIdentity(identity); |
| 4783 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4784 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 4785 | |
| 4786 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4787 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4788 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 4789 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4790 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4791 | |
| 4792 | final long identity = Binder.clearCallingIdentity(); |
| 4793 | try { |
| 4794 | final Phone phone = getPhone(subId); |
| 4795 | if (phone == null) { |
| 4796 | return false; |
| 4797 | } |
| 4798 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 4799 | cdmaNonRoamingList); |
| 4800 | } finally { |
| 4801 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4802 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4803 | } |
| 4804 | |
| 4805 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4806 | @Deprecated |
| 4807 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 4808 | enforceModifyPermission(); |
| 4809 | |
| 4810 | int returnValue = 0; |
| 4811 | try { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4812 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4813 | if(result.exception == null) { |
| 4814 | if (result.result != null) { |
| 4815 | byte[] responseData = (byte[])(result.result); |
| 4816 | if(responseData.length > oemResp.length) { |
| 4817 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 4818 | responseData.length + "bytes. Buffer Size is " + |
| 4819 | oemResp.length + "bytes."); |
| 4820 | } |
| 4821 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 4822 | returnValue = responseData.length; |
| 4823 | } |
| 4824 | } else { |
| 4825 | CommandException ex = (CommandException) result.exception; |
| 4826 | returnValue = ex.getCommandError().ordinal(); |
| 4827 | if(returnValue > 0) returnValue *= -1; |
| 4828 | } |
| 4829 | } catch (RuntimeException e) { |
| 4830 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 4831 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 4832 | if(returnValue > 0) returnValue *= -1; |
| 4833 | } |
| 4834 | |
| 4835 | return returnValue; |
| 4836 | } |
| 4837 | |
| 4838 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4839 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 4840 | try { |
| 4841 | ProxyController.getInstance().setRadioCapability(rafs); |
| 4842 | } catch (RuntimeException e) { |
| 4843 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 4844 | } |
| 4845 | } |
| 4846 | |
| 4847 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4848 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4849 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4850 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4851 | if (phone == null) { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4852 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4853 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4854 | final long identity = Binder.clearCallingIdentity(); |
| 4855 | try { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4856 | TelephonyPermissions |
| 4857 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4858 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 4859 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4860 | } finally { |
| 4861 | Binder.restoreCallingIdentity(identity); |
| 4862 | } |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4863 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4864 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4865 | |
| 4866 | @Override |
| 4867 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4868 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4869 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4870 | |
| 4871 | final long identity = Binder.clearCallingIdentity(); |
| 4872 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4873 | ImsManager.getInstance(defaultPhone.getContext(), |
| 4874 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4875 | } finally { |
| 4876 | Binder.restoreCallingIdentity(identity); |
| 4877 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4878 | } |
| 4879 | |
| 4880 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4881 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4882 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4883 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4884 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4885 | return false; |
| 4886 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4887 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4888 | final long identity = Binder.clearCallingIdentity(); |
| 4889 | try { |
| 4890 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 4891 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 4892 | // In the long run, we may instead need to check if there exists a connection service |
| 4893 | // which can support video calling. |
| 4894 | ImsManager imsManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4895 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4896 | return imsManager.isVtEnabledByPlatform() |
| 4897 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 4898 | && imsManager.isVtEnabledByUser(); |
| 4899 | } finally { |
| 4900 | Binder.restoreCallingIdentity(identity); |
| 4901 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4902 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 4903 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4904 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4905 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 4906 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4907 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4908 | return false; |
| 4909 | } |
| 4910 | |
| 4911 | final long identity = Binder.clearCallingIdentity(); |
| 4912 | try { |
| 4913 | CarrierConfigManager configManager = |
| 4914 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4915 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4916 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 4917 | } finally { |
| 4918 | Binder.restoreCallingIdentity(identity); |
| 4919 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4920 | } |
| 4921 | |
| 4922 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4923 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 4924 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4925 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4926 | return false; |
| 4927 | } |
| 4928 | |
| 4929 | final long identity = Binder.clearCallingIdentity(); |
| 4930 | try { |
| 4931 | CarrierConfigManager configManager = |
| 4932 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4933 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4934 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 4935 | } finally { |
| 4936 | Binder.restoreCallingIdentity(identity); |
| 4937 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4938 | } |
| 4939 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4940 | @Override |
| 4941 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4942 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 4943 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4944 | } |
| 4945 | |
| 4946 | @Override |
| 4947 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4948 | final long identity = Binder.clearCallingIdentity(); |
| 4949 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4950 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4951 | } finally { |
| 4952 | Binder.restoreCallingIdentity(identity); |
| 4953 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4954 | } |
| 4955 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4956 | /** |
| 4957 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 4958 | * support for the feature and device firmware support. |
| 4959 | * |
| 4960 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 4961 | */ |
| 4962 | @Override |
| 4963 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4964 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4965 | final Phone phone = getPhone(subscriptionId); |
| 4966 | if (phone == null) { |
| 4967 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 4968 | return false; |
| 4969 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4970 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4971 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4972 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 4973 | boolean isDeviceSupported = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4974 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4975 | return isCarrierSupported && isDeviceSupported; |
| 4976 | } finally { |
| 4977 | Binder.restoreCallingIdentity(identity); |
| 4978 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 4979 | } |
| 4980 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4981 | /** |
| 4982 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier |
| 4983 | * both also support RTT. |
| 4984 | */ |
| 4985 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4986 | final long identity = Binder.clearCallingIdentity(); |
| 4987 | try { |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4988 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4989 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4990 | } finally { |
| 4991 | Binder.restoreCallingIdentity(identity); |
| 4992 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 4993 | } |
| 4994 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4995 | /** |
| 4996 | * Returns the unique device ID of phone, for example, the IMEI for |
| 4997 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 4998 | * |
| 4999 | * <p>Requires Permission: |
| 5000 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5001 | */ |
| 5002 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5003 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5004 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5005 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5006 | return null; |
| 5007 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5008 | int subId = phone.getSubId(); |
| 5009 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5010 | mApp, subId, callingPackage, "getDeviceId")) { |
| 5011 | return null; |
| 5012 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5013 | |
| 5014 | final long identity = Binder.clearCallingIdentity(); |
| 5015 | try { |
| 5016 | return phone.getDeviceId(); |
| 5017 | } finally { |
| 5018 | Binder.restoreCallingIdentity(identity); |
| 5019 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5020 | } |
| 5021 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5022 | /** |
| 5023 | * {@hide} |
| 5024 | * Returns the IMS Registration Status on a particular subid |
| 5025 | * |
| 5026 | * @param subId |
| 5027 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5028 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5029 | Phone phone = getPhone(subId); |
| 5030 | if (phone != null) { |
| 5031 | return phone.isImsRegistered(); |
| 5032 | } else { |
| 5033 | return false; |
| 5034 | } |
| 5035 | } |
| 5036 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5037 | @Override |
| 5038 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5039 | final long identity = Binder.clearCallingIdentity(); |
| 5040 | try { |
| 5041 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5042 | } finally { |
| 5043 | Binder.restoreCallingIdentity(identity); |
| 5044 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5045 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5046 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5047 | /** |
| 5048 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5049 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5050 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5051 | final long identity = Binder.clearCallingIdentity(); |
| 5052 | try { |
| 5053 | Phone phone = getPhone(subId); |
| 5054 | if (phone != null) { |
| 5055 | return phone.isWifiCallingEnabled(); |
| 5056 | } else { |
| 5057 | return false; |
| 5058 | } |
| 5059 | } finally { |
| 5060 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5061 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5062 | } |
| 5063 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5064 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5065 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5066 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5067 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5068 | final long identity = Binder.clearCallingIdentity(); |
| 5069 | try { |
| 5070 | Phone phone = getPhone(subId); |
| 5071 | if (phone != null) { |
| 5072 | return phone.isVideoEnabled(); |
| 5073 | } else { |
| 5074 | return false; |
| 5075 | } |
| 5076 | } finally { |
| 5077 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5078 | } |
| 5079 | } |
| 5080 | |
| 5081 | /** |
| 5082 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5083 | * defined in {@link ImsRegistrationImplBase}. |
| 5084 | */ |
| 5085 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5086 | final long identity = Binder.clearCallingIdentity(); |
| 5087 | try { |
| 5088 | Phone phone = getPhone(subId); |
| 5089 | if (phone != null) { |
| 5090 | return phone.getImsRegistrationTech(); |
| 5091 | } else { |
| 5092 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5093 | } |
| 5094 | } finally { |
| 5095 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5096 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5097 | } |
| 5098 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5099 | @Override |
| 5100 | public void factoryReset(int subId) { |
| 5101 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5102 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5103 | return; |
| 5104 | } |
| 5105 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5106 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5107 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5108 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5109 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5110 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5111 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5112 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5113 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5114 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5115 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5116 | } |
| 5117 | } finally { |
| 5118 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5119 | } |
| 5120 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5121 | |
| 5122 | @Override |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5123 | public String getSimLocaleForSubscriber(int subId) { |
| 5124 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5125 | final Phone phone = getPhone(subId); |
| 5126 | if (phone == null) { |
| 5127 | log("getSimLocaleForSubscriber, invalid subId"); |
Pengquan Meng | 9c29148 | 2019-01-28 16:26:29 -0800 | [diff] [blame] | 5128 | return null; |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5129 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5130 | final long identity = Binder.clearCallingIdentity(); |
| 5131 | try { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5132 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5133 | phone.getContext().getOpPackageName()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5134 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5135 | // preferences (EF-PL and EF-LI)... |
| 5136 | final int mcc = info.getMcc(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5137 | String simLanguage = null; |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5138 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5139 | if (localeFromDefaultSim != null) { |
| 5140 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5141 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5142 | + localeFromDefaultSim); |
| 5143 | return localeFromDefaultSim.toLanguageTag(); |
| 5144 | } else { |
| 5145 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5146 | } |
| 5147 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5148 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5149 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5150 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5151 | // the SIM and carrier preferences does not include a country we add the country |
| 5152 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5153 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5154 | if (mccLocale != null) { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5155 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5156 | return mccLocale.toLanguageTag(); |
| 5157 | } |
| 5158 | |
| 5159 | if (DBG) log("No locale found - returning null"); |
| 5160 | return null; |
| 5161 | } finally { |
| 5162 | Binder.restoreCallingIdentity(identity); |
| 5163 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5164 | } |
| 5165 | |
| 5166 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5167 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5168 | } |
| 5169 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5170 | /** |
| 5171 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5172 | */ |
| 5173 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5174 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5175 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5176 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5177 | private final ModemActivityInfo mLastModemActivityInfo = |
| 5178 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 5179 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5180 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5181 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5182 | * representing the state of the modem. |
| 5183 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5184 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5185 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5186 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5187 | */ |
| 5188 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5189 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5190 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5191 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5192 | |
| 5193 | final long identity = Binder.clearCallingIdentity(); |
| 5194 | try { |
| 5195 | ModemActivityInfo ret = null; |
| 5196 | synchronized (mLastModemActivityInfo) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5197 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5198 | CMD_GET_MODEM_ACTIVITY_INFO, |
| 5199 | null, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5200 | if (isModemActivityInfoValid(info)) { |
| 5201 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 5202 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 5203 | mergedTxTimeMs[i] = |
| 5204 | info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i]; |
| 5205 | } |
| 5206 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 5207 | mLastModemActivityInfo.setSleepTimeMillis( |
| 5208 | info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis()); |
| 5209 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5210 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 5211 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 5212 | mLastModemActivityInfo.setRxTimeMillis( |
| 5213 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 5214 | mLastModemActivityInfo.setEnergyUsed( |
| 5215 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5216 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5217 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5218 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5219 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 5220 | mLastModemActivityInfo.getTxTimeMillis(), |
| 5221 | mLastModemActivityInfo.getRxTimeMillis(), |
| 5222 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5223 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5224 | Bundle bundle = new Bundle(); |
| 5225 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 5226 | result.send(0, bundle); |
| 5227 | } finally { |
| 5228 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5229 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5230 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5231 | |
Siddharth Ray | f5d2955 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5232 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 5233 | // less than total activity duration. |
| 5234 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 5235 | if (info == null) { |
| 5236 | return false; |
| 5237 | } |
| 5238 | int activityDurationMs = |
| 5239 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 5240 | int totalTxTimeMs = 0; |
| 5241 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 5242 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 5243 | } |
| 5244 | return (info.isValid() |
| 5245 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 5246 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 5247 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 5248 | && (totalTxTimeMs <= activityDurationMs)); |
| 5249 | } |
| 5250 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5251 | /** |
| 5252 | * {@hide} |
| 5253 | * Returns the service state information on specified subscription. |
| 5254 | */ |
| 5255 | @Override |
| 5256 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5257 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5258 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5259 | return null; |
| 5260 | } |
| 5261 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5262 | final long identity = Binder.clearCallingIdentity(); |
| 5263 | try { |
| 5264 | final Phone phone = getPhone(subId); |
| 5265 | if (phone == null) { |
| 5266 | return null; |
| 5267 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5268 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5269 | return phone.getServiceState(); |
| 5270 | } finally { |
| 5271 | Binder.restoreCallingIdentity(identity); |
| 5272 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5273 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5274 | |
| 5275 | /** |
| 5276 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5277 | * |
| 5278 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5279 | * voicemail ringtone. |
| 5280 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5281 | * PhoneAccount. |
| 5282 | */ |
| 5283 | @Override |
| 5284 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5285 | final long identity = Binder.clearCallingIdentity(); |
| 5286 | try { |
| 5287 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5288 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5289 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5290 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5291 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5292 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5293 | } finally { |
| 5294 | Binder.restoreCallingIdentity(identity); |
| 5295 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5296 | } |
| 5297 | |
| 5298 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5299 | * Sets the per-account voicemail ringtone. |
| 5300 | * |
| 5301 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5302 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5303 | * |
| 5304 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5305 | * voicemail ringtone. |
| 5306 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5307 | * PhoneAccount. |
| 5308 | */ |
| 5309 | @Override |
| 5310 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5311 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5312 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5313 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5314 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5315 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5316 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5317 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5318 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5319 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5320 | |
| 5321 | final long identity = Binder.clearCallingIdentity(); |
| 5322 | try { |
| 5323 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5324 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5325 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5326 | } |
| 5327 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5328 | } finally { |
| 5329 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5330 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5331 | } |
| 5332 | |
| 5333 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5334 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5335 | * |
| 5336 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5337 | * voicemail vibration setting. |
| 5338 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5339 | */ |
| 5340 | @Override |
| 5341 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5342 | final long identity = Binder.clearCallingIdentity(); |
| 5343 | try { |
| 5344 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5345 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5346 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5347 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5348 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5349 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5350 | } finally { |
| 5351 | Binder.restoreCallingIdentity(identity); |
| 5352 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5353 | } |
| 5354 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5355 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5356 | * Sets the per-account voicemail vibration. |
| 5357 | * |
| 5358 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5359 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5360 | * |
| 5361 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5362 | * voicemail vibration setting. |
| 5363 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5364 | * specific PhoneAccount. |
| 5365 | */ |
| 5366 | @Override |
| 5367 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5368 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5369 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5370 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5371 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5372 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5373 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5374 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5375 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5376 | } |
| 5377 | |
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(phoneAccountHandle); |
| 5381 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5382 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5383 | } |
| 5384 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5385 | } finally { |
| 5386 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5387 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5388 | } |
| 5389 | |
| 5390 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5391 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5392 | * |
| 5393 | * @throws SecurityException if the caller does not have the required permission |
| 5394 | */ |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5395 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5396 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5397 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5398 | } |
| 5399 | |
| 5400 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5401 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5402 | * permission. |
| 5403 | * |
| 5404 | * @throws SecurityException if the caller does not have the required permission |
| 5405 | */ |
| 5406 | private void enforceSendSmsPermission() { |
| 5407 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5408 | } |
| 5409 | |
| 5410 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5411 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5412 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5413 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5414 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5415 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5416 | final long identity = Binder.clearCallingIdentity(); |
| 5417 | try { |
| 5418 | ComponentName componentName = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5419 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5420 | if (componentName == null) { |
| 5421 | throw new SecurityException( |
| 5422 | "Caller not current active visual voicemail package[null]"); |
| 5423 | } |
| 5424 | String vvmPackage = componentName.getPackageName(); |
| 5425 | if (!callingPackage.equals(vvmPackage)) { |
| 5426 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5427 | + vvmPackage + "]"); |
| 5428 | } |
| 5429 | } finally { |
| 5430 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5431 | } |
| 5432 | } |
| 5433 | |
| 5434 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5435 | * Return the application ID for the app type. |
| 5436 | * |
| 5437 | * @param subId the subscription ID that this request applies to. |
| 5438 | * @param appType the uicc app type. |
| 5439 | * @return Application ID for specificied app type, or null if no uicc. |
| 5440 | */ |
| 5441 | @Override |
| 5442 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5443 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5444 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5445 | |
| 5446 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5447 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5448 | if (phone == null) { |
| 5449 | return null; |
| 5450 | } |
| 5451 | String aid = null; |
| 5452 | try { |
| 5453 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5454 | .getApplicationByType(appType).getAid(); |
| 5455 | } catch (Exception e) { |
| 5456 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5457 | } |
| 5458 | return aid; |
| 5459 | } finally { |
| 5460 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5461 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5462 | } |
| 5463 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5464 | /** |
| 5465 | * Return the Electronic Serial Number. |
| 5466 | * |
| 5467 | * @param subId the subscription ID that this request applies to. |
| 5468 | * @return ESN or null if error. |
| 5469 | */ |
| 5470 | @Override |
| 5471 | public String getEsn(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5472 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5473 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5474 | |
| 5475 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5476 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5477 | if (phone == null) { |
| 5478 | return null; |
| 5479 | } |
| 5480 | String esn = null; |
| 5481 | try { |
| 5482 | esn = phone.getEsn(); |
| 5483 | } catch (Exception e) { |
| 5484 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5485 | } |
| 5486 | return esn; |
| 5487 | } finally { |
| 5488 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5489 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5490 | } |
| 5491 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5492 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5493 | * Return the Preferred Roaming List Version. |
| 5494 | * |
| 5495 | * @param subId the subscription ID that this request applies to. |
| 5496 | * @return PRLVersion or null if error. |
| 5497 | */ |
| 5498 | @Override |
| 5499 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5500 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5501 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5502 | |
| 5503 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5504 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5505 | if (phone == null) { |
| 5506 | return null; |
| 5507 | } |
| 5508 | String cdmaPrlVersion = null; |
| 5509 | try { |
| 5510 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 5511 | } catch (Exception e) { |
| 5512 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 5513 | } |
| 5514 | return cdmaPrlVersion; |
| 5515 | } finally { |
| 5516 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5517 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5518 | } |
| 5519 | |
| 5520 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5521 | * Get snapshot of Telephony histograms |
| 5522 | * @return List of Telephony histograms |
| 5523 | * @hide |
| 5524 | */ |
| 5525 | @Override |
| 5526 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5527 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5528 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5529 | |
| 5530 | final long identity = Binder.clearCallingIdentity(); |
| 5531 | try { |
| 5532 | return RIL.getTelephonyRILTimingHistograms(); |
| 5533 | } finally { |
| 5534 | Binder.restoreCallingIdentity(identity); |
| 5535 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5536 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5537 | |
| 5538 | /** |
| 5539 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5540 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 5541 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5542 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5543 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5544 | * @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] | 5545 | */ |
| 5546 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5547 | @TelephonyManager.SetCarrierRestrictionResult |
| 5548 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5549 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5550 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5551 | |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5552 | if (carrierRestrictionRules == null) { |
| 5553 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5554 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5555 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5556 | final long identity = Binder.clearCallingIdentity(); |
| 5557 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5558 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5559 | workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5560 | } finally { |
| 5561 | Binder.restoreCallingIdentity(identity); |
| 5562 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5563 | } |
| 5564 | |
| 5565 | /** |
| 5566 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5567 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 5568 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5569 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5570 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5571 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5572 | */ |
| 5573 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5574 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5575 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5576 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5577 | |
| 5578 | final long identity = Binder.clearCallingIdentity(); |
| 5579 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5580 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 5581 | if (response instanceof CarrierRestrictionRules) { |
| 5582 | return (CarrierRestrictionRules) response; |
| 5583 | } |
| 5584 | // Response is an Exception of some kind, |
| 5585 | // which is signalled to the user as a NULL retval |
| 5586 | return null; |
| 5587 | } catch (Exception e) { |
| 5588 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 5589 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5590 | } finally { |
| 5591 | Binder.restoreCallingIdentity(identity); |
| 5592 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5593 | } |
| 5594 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5595 | /** |
| 5596 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 5597 | * @param subId the subscription ID that this action applies to. |
| 5598 | * @param enabled control enable or disable metered apns. |
| 5599 | * {@hide} |
| 5600 | */ |
| 5601 | @Override |
| 5602 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 5603 | enforceModifyPermission(); |
| 5604 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5605 | |
| 5606 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5607 | if (phone == null) { |
| 5608 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 5609 | return; |
| 5610 | } |
| 5611 | try { |
| 5612 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 5613 | } catch (Exception e) { |
| 5614 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5615 | } finally { |
| 5616 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5617 | } |
| 5618 | } |
| 5619 | |
| 5620 | /** |
| 5621 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 5622 | * @param subId the subscription ID that this action applies to. |
| 5623 | * @param enabled control enable or disable radio. |
| 5624 | * {@hide} |
| 5625 | */ |
| 5626 | @Override |
| 5627 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 5628 | enforceModifyPermission(); |
| 5629 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5630 | |
| 5631 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5632 | if (phone == null) { |
| 5633 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 5634 | return; |
| 5635 | } |
| 5636 | try { |
| 5637 | phone.carrierActionSetRadioEnabled(enabled); |
| 5638 | } catch (Exception e) { |
| 5639 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5640 | } finally { |
| 5641 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5642 | } |
| 5643 | } |
| 5644 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5645 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5646 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 5647 | * network status based on which carrier apps could apply actions accordingly, |
| 5648 | * enable/disable default url handler for example. |
| 5649 | * |
| 5650 | * @param subId the subscription ID that this action applies to. |
| 5651 | * @param report control start/stop reporting the default network status. |
| 5652 | * {@hide} |
| 5653 | */ |
| 5654 | @Override |
| 5655 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 5656 | enforceModifyPermission(); |
| 5657 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5658 | |
| 5659 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5660 | if (phone == null) { |
| 5661 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 5662 | return; |
| 5663 | } |
| 5664 | try { |
| 5665 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 5666 | } catch (Exception e) { |
| 5667 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5668 | } finally { |
| 5669 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5670 | } |
| 5671 | } |
| 5672 | |
| 5673 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5674 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 5675 | * bug report is being generated. |
| 5676 | */ |
| 5677 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 5678 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5679 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 5680 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 5681 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 5682 | + Binder.getCallingPid() |
| 5683 | + ", uid=" + Binder.getCallingUid() |
| 5684 | + "without permission " |
| 5685 | + android.Manifest.permission.DUMP); |
| 5686 | return; |
| 5687 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5688 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5689 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5690 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5691 | @Override |
| 5692 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 5693 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 5694 | throws RemoteException { |
| 5695 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 5696 | } |
| 5697 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5698 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5699 | * Get aggregated video call data usage since boot. |
| 5700 | * |
| 5701 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 5702 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5703 | * {@hide} |
| 5704 | */ |
| 5705 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5706 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5707 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 5708 | null); |
| 5709 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5710 | final long identity = Binder.clearCallingIdentity(); |
| 5711 | try { |
| 5712 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 5713 | // records the delta with the corresponding network identity. |
| 5714 | // We just return the total video call data usage snapshot since boot. |
| 5715 | Phone phone = getPhone(subId); |
| 5716 | if (phone != null) { |
| 5717 | return phone.getVtDataUsage(perUidStats); |
| 5718 | } |
| 5719 | return null; |
| 5720 | } finally { |
| 5721 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5722 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5723 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5724 | |
| 5725 | /** |
| 5726 | * Policy control of data connection. Usually used when data limit is passed. |
| 5727 | * @param enabled True if enabling the data, otherwise disabling. |
| 5728 | * @param subId Subscription index |
| 5729 | * {@hide} |
| 5730 | */ |
| 5731 | @Override |
| 5732 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 5733 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5734 | |
| 5735 | final long identity = Binder.clearCallingIdentity(); |
| 5736 | try { |
| 5737 | Phone phone = getPhone(subId); |
| 5738 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5739 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5740 | } |
| 5741 | } finally { |
| 5742 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5743 | } |
| 5744 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5745 | |
| 5746 | /** |
| 5747 | * Get Client request stats |
| 5748 | * @return List of Client Request Stats |
| 5749 | * @hide |
| 5750 | */ |
| 5751 | @Override |
| 5752 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5753 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5754 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5755 | return null; |
| 5756 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5757 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5758 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5759 | final long identity = Binder.clearCallingIdentity(); |
| 5760 | try { |
| 5761 | if (phone != null) { |
| 5762 | return phone.getClientRequestStats(); |
| 5763 | } |
| 5764 | |
| 5765 | return null; |
| 5766 | } finally { |
| 5767 | Binder.restoreCallingIdentity(identity); |
| 5768 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5769 | } |
| 5770 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5771 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5772 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5773 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5774 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5775 | |
| 5776 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5777 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5778 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5779 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5780 | * @param state State of SIM (power down, power up, pass through) |
| 5781 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 5782 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 5783 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5784 | * |
| 5785 | **/ |
| 5786 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5787 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5788 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5789 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5790 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5791 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5792 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5793 | final long identity = Binder.clearCallingIdentity(); |
| 5794 | try { |
| 5795 | if (phone != null) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5796 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5797 | } |
| 5798 | } finally { |
| 5799 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5800 | } |
| 5801 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5802 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5803 | private boolean isUssdApiAllowed(int subId) { |
| 5804 | CarrierConfigManager configManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5805 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5806 | if (configManager == null) { |
| 5807 | return false; |
| 5808 | } |
| 5809 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 5810 | if (pb == null) { |
| 5811 | return false; |
| 5812 | } |
| 5813 | return pb.getBoolean( |
| 5814 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 5815 | } |
| 5816 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5817 | /** |
| 5818 | * Check if phone is in emergency callback mode |
| 5819 | * @return true if phone is in emergency callback mode |
| 5820 | * @param subId sub id |
| 5821 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 5822 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5823 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5824 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5825 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5826 | |
| 5827 | final long identity = Binder.clearCallingIdentity(); |
| 5828 | try { |
| 5829 | if (phone != null) { |
| 5830 | return phone.isInEcm(); |
| 5831 | } else { |
| 5832 | return false; |
| 5833 | } |
| 5834 | } finally { |
| 5835 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5836 | } |
| 5837 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5838 | |
| 5839 | /** |
| 5840 | * Get the current signal strength information for the given subscription. |
| 5841 | * Because this information is not updated when the device is in a low power state |
| 5842 | * it should not be relied-upon to be current. |
| 5843 | * @param subId Subscription index |
| 5844 | * @return the most recent cached signal strength info from the modem |
| 5845 | */ |
| 5846 | @Override |
| 5847 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5848 | final long identity = Binder.clearCallingIdentity(); |
| 5849 | try { |
| 5850 | Phone p = getPhone(subId); |
| 5851 | if (p == null) { |
| 5852 | return null; |
| 5853 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5854 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5855 | return p.getSignalStrength(); |
| 5856 | } finally { |
| 5857 | Binder.restoreCallingIdentity(identity); |
| 5858 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5859 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5860 | |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5861 | /** |
chen xu | 907e5a2 | 2018-10-11 13:21:04 -0700 | [diff] [blame] | 5862 | * Get the current modem radio state for the given slot. |
| 5863 | * @param slotIndex slot index. |
| 5864 | * @param callingPackage the name of the package making the call. |
| 5865 | * @return the current radio power state from the modem |
| 5866 | */ |
| 5867 | @Override |
| 5868 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 5869 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5870 | if (phone != null) { |
| 5871 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5872 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 5873 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5874 | } |
| 5875 | |
| 5876 | final long identity = Binder.clearCallingIdentity(); |
| 5877 | try { |
| 5878 | return phone.getRadioPowerState(); |
| 5879 | } finally { |
| 5880 | Binder.restoreCallingIdentity(identity); |
| 5881 | } |
| 5882 | } |
| 5883 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5884 | } |
| 5885 | |
| 5886 | /** |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5887 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 5888 | * |
| 5889 | * <p>Requires one of the following permissions: |
| 5890 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 5891 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 5892 | * privileges. |
| 5893 | * |
| 5894 | * @param subId subscription id |
| 5895 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 5896 | * {@code false}. |
| 5897 | */ |
| 5898 | @Override |
| 5899 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5900 | boolean isEnabled = false; |
| 5901 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5902 | try { |
| 5903 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5904 | null /* message */); |
| 5905 | Phone phone = getPhone(subId); |
| 5906 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5907 | } catch (Exception e) { |
| 5908 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 5909 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5910 | } finally { |
| 5911 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5912 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5913 | return isEnabled; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5914 | } |
| 5915 | |
| 5916 | |
| 5917 | /** |
| 5918 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 5919 | * |
| 5920 | * <p> Requires permission: |
| 5921 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 5922 | * privileges. |
| 5923 | * |
| 5924 | * @param subId subscription id |
| 5925 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 5926 | */ |
| 5927 | @Override |
| 5928 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5929 | final long identity = Binder.clearCallingIdentity(); |
| 5930 | try { |
| 5931 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5932 | mApp, subId, "setDataRoamingEnabled"); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5933 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5934 | Phone phone = getPhone(subId); |
| 5935 | if (phone != null) { |
| 5936 | phone.setDataRoamingEnabled(isEnabled); |
| 5937 | } |
| 5938 | } finally { |
| 5939 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5940 | } |
| 5941 | } |
| 5942 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5943 | @Override |
Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 5944 | public boolean isManualNetworkSelectionAllowed(int subId) { |
| 5945 | boolean isAllowed = true; |
| 5946 | final long identity = Binder.clearCallingIdentity(); |
| 5947 | try { |
| 5948 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 5949 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 5950 | Phone phone = getPhone(subId); |
| 5951 | if (phone != null) { |
| 5952 | isAllowed = phone.isCspPlmnEnabled(); |
| 5953 | } |
| 5954 | } finally { |
| 5955 | Binder.restoreCallingIdentity(identity); |
| 5956 | } |
| 5957 | return isAllowed; |
| 5958 | } |
| 5959 | |
| 5960 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 5961 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
| 5962 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 5963 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5964 | throw new SecurityException("Caller does not have carrier privileges on any UICC."); |
| 5965 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 5966 | |
| 5967 | final long identity = Binder.clearCallingIdentity(); |
| 5968 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 5969 | UiccController uiccController = UiccController.getInstance(); |
| 5970 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
| 5971 | |
| 5972 | ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0); |
| 5973 | if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 5974 | // Remove private info if the caller doesn't have access |
| 5975 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 5976 | for (UiccCardInfo cardInfo : cardInfos) { |
| 5977 | UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex()); |
| 5978 | UiccProfile profile = card.getUiccProfile(); |
| 5979 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 5980 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5981 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 5982 | } else { |
| 5983 | filteredInfos.add(cardInfo); |
| 5984 | } |
| 5985 | } |
| 5986 | return filteredInfos; |
| 5987 | } |
| 5988 | return cardInfos; |
| 5989 | } catch (PackageManager.NameNotFoundException e) { |
| 5990 | // This should not happen since we pass the package info in from TelephonyManager |
| 5991 | throw new SecurityException("Invalid calling package."); |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 5992 | } finally { |
| 5993 | Binder.restoreCallingIdentity(identity); |
| 5994 | } |
| 5995 | } |
| 5996 | |
| 5997 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5998 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5999 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6000 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6001 | final long identity = Binder.clearCallingIdentity(); |
| 6002 | try { |
| 6003 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6004 | if (slots == null) { |
| 6005 | Rlog.i(LOG_TAG, "slots is null."); |
| 6006 | return null; |
| 6007 | } |
| 6008 | |
| 6009 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6010 | for (int i = 0; i < slots.length; i++) { |
| 6011 | UiccSlot slot = slots[i]; |
| 6012 | if (slot == null) { |
| 6013 | continue; |
| 6014 | } |
| 6015 | |
| 6016 | String cardId; |
| 6017 | UiccCard card = slot.getUiccCard(); |
| 6018 | if (card != null) { |
| 6019 | cardId = card.getCardId(); |
| 6020 | } else { |
| 6021 | cardId = slot.getIccId(); |
| 6022 | } |
| 6023 | |
| 6024 | int cardState = 0; |
| 6025 | switch (slot.getCardState()) { |
| 6026 | case CARDSTATE_ABSENT: |
| 6027 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6028 | break; |
| 6029 | case CARDSTATE_PRESENT: |
| 6030 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6031 | break; |
| 6032 | case CARDSTATE_ERROR: |
| 6033 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6034 | break; |
| 6035 | case CARDSTATE_RESTRICTED: |
| 6036 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6037 | break; |
| 6038 | default: |
| 6039 | break; |
| 6040 | |
| 6041 | } |
| 6042 | |
| 6043 | infos[i] = new UiccSlotInfo( |
| 6044 | slot.isActive(), |
| 6045 | slot.isEuicc(), |
| 6046 | cardId, |
| 6047 | cardState, |
| 6048 | slot.getPhoneId(), |
| 6049 | slot.isExtendedApduSupported()); |
| 6050 | } |
| 6051 | return infos; |
| 6052 | } finally { |
| 6053 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6054 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6055 | } |
| 6056 | |
| 6057 | @Override |
| 6058 | public boolean switchSlots(int[] physicalSlots) { |
| 6059 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6060 | |
| 6061 | final long identity = Binder.clearCallingIdentity(); |
| 6062 | try { |
| 6063 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6064 | } finally { |
| 6065 | Binder.restoreCallingIdentity(identity); |
| 6066 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6067 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6068 | |
| 6069 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6070 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6071 | final long identity = Binder.clearCallingIdentity(); |
| 6072 | try { |
| 6073 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6074 | } finally { |
| 6075 | Binder.restoreCallingIdentity(identity); |
| 6076 | } |
| 6077 | } |
| 6078 | |
| 6079 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6080 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6081 | enforceModifyPermission(); |
| 6082 | final Phone phone = getPhone(subId); |
| 6083 | if (phone == null) { |
| 6084 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6085 | return; |
| 6086 | } |
| 6087 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6088 | final long identity = Binder.clearCallingIdentity(); |
| 6089 | try { |
| 6090 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6091 | } finally { |
| 6092 | Binder.restoreCallingIdentity(identity); |
| 6093 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6094 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6095 | |
| 6096 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6097 | * A test API to reload the UICC profile. |
| 6098 | * |
| 6099 | * <p>Requires that the calling app has permission |
| 6100 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6101 | * @hide |
| 6102 | */ |
| 6103 | @Override |
| 6104 | public void refreshUiccProfile(int subId) { |
| 6105 | enforceModifyPermission(); |
| 6106 | |
| 6107 | final long identity = Binder.clearCallingIdentity(); |
| 6108 | try { |
| 6109 | Phone phone = getPhone(subId); |
| 6110 | if (phone == null) { |
| 6111 | return; |
| 6112 | } |
| 6113 | UiccCard uiccCard = phone.getUiccCard(); |
| 6114 | if (uiccCard == null) { |
| 6115 | return; |
| 6116 | } |
| 6117 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6118 | if (uiccProfile == null) { |
| 6119 | return; |
| 6120 | } |
| 6121 | uiccProfile.refresh(); |
| 6122 | } finally { |
| 6123 | Binder.restoreCallingIdentity(identity); |
| 6124 | } |
| 6125 | } |
| 6126 | |
| 6127 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6128 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6129 | */ |
| 6130 | private boolean getDefaultDataEnabled() { |
| 6131 | return "true".equalsIgnoreCase( |
| 6132 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6133 | } |
| 6134 | |
| 6135 | /** |
| 6136 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6137 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6138 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6139 | */ |
| 6140 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6141 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6142 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6143 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6144 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6145 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6146 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 6147 | return isDataRoamingEnabled; |
| 6148 | } |
| 6149 | |
| 6150 | /** |
| 6151 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 6152 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 6153 | */ |
| 6154 | private int getDefaultNetworkType(int subId) { |
| 6155 | return Integer.parseInt( |
| 6156 | TelephonyManager.getTelephonyProperty( |
| 6157 | mSubscriptionController.getPhoneId(subId), |
| 6158 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 6159 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 6160 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6161 | |
| 6162 | @Override |
| 6163 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
| 6164 | gid1, String gid2, String plmn, String spn) { |
| 6165 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6166 | |
| 6167 | final long identity = Binder.clearCallingIdentity(); |
| 6168 | try { |
| 6169 | final Phone phone = getPhone(subId); |
| 6170 | if (phone == null) { |
| 6171 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 6172 | return; |
| 6173 | } |
| 6174 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn); |
| 6175 | } finally { |
| 6176 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6177 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6178 | } |
| 6179 | |
| 6180 | @Override |
| 6181 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6182 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6183 | |
| 6184 | final long identity = Binder.clearCallingIdentity(); |
| 6185 | try { |
| 6186 | final Phone phone = getPhone(subId); |
| 6187 | if (phone == null) { |
| 6188 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 6189 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 6190 | } |
| 6191 | return phone.getCarrierIdListVersion(); |
| 6192 | } finally { |
| 6193 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6194 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6195 | } |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6196 | |
| 6197 | @Override |
| 6198 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 6199 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6200 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 6201 | return -1; |
| 6202 | } |
| 6203 | |
| 6204 | final long identity = Binder.clearCallingIdentity(); |
| 6205 | try { |
| 6206 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 6207 | } finally { |
| 6208 | Binder.restoreCallingIdentity(identity); |
| 6209 | } |
| 6210 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6211 | |
| 6212 | @Override |
| 6213 | public int getCdmaRoamingMode(int subId) { |
| 6214 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6215 | mApp, subId, "getCdmaRoamingMode"); |
| 6216 | |
| 6217 | final long identity = Binder.clearCallingIdentity(); |
| 6218 | try { |
| 6219 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 6220 | } finally { |
| 6221 | Binder.restoreCallingIdentity(identity); |
| 6222 | } |
| 6223 | } |
| 6224 | |
| 6225 | @Override |
| 6226 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 6227 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6228 | mApp, subId, "setCdmaRoamingMode"); |
| 6229 | |
| 6230 | final long identity = Binder.clearCallingIdentity(); |
| 6231 | try { |
| 6232 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 6233 | } finally { |
| 6234 | Binder.restoreCallingIdentity(identity); |
| 6235 | } |
| 6236 | } |
| 6237 | |
| 6238 | @Override |
| 6239 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 6240 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6241 | mApp, subId, "setCdmaSubscriptionMode"); |
| 6242 | |
| 6243 | final long identity = Binder.clearCallingIdentity(); |
| 6244 | try { |
| 6245 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 6246 | } finally { |
| 6247 | Binder.restoreCallingIdentity(identity); |
| 6248 | } |
| 6249 | } |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6250 | |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 6251 | private void ensureUserRunning(int userId) { |
| 6252 | if (!mUserManager.isUserRunning(userId)) { |
| 6253 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 6254 | } |
| 6255 | } |
| 6256 | |
| 6257 | /** |
| 6258 | * Returns a list of SMS apps on a given user. |
| 6259 | * |
| 6260 | * Only the shell user (UID 2000 or 0) can call it. |
| 6261 | * Target user must be running. |
| 6262 | */ |
| 6263 | @Override |
| 6264 | public String[] getSmsApps(int userId) { |
| 6265 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 6266 | ensureUserRunning(userId); |
| 6267 | |
| 6268 | final Collection<SmsApplicationData> apps = |
| 6269 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 6270 | |
| 6271 | String[] ret = new String[apps.size()]; |
| 6272 | int i = 0; |
| 6273 | for (SmsApplicationData app : apps) { |
| 6274 | ret[i++] = app.mPackageName; |
| 6275 | } |
| 6276 | return ret; |
| 6277 | } |
| 6278 | |
| 6279 | /** |
| 6280 | * Returns the default SMS app package name on a given user. |
| 6281 | * |
| 6282 | * Only the shell user (UID 2000 or 0) can call it. |
| 6283 | * Target user must be running. |
| 6284 | */ |
| 6285 | @Override |
| 6286 | public String getDefaultSmsApp(int userId) { |
| 6287 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 6288 | ensureUserRunning(userId); |
| 6289 | |
| 6290 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 6291 | /* updateIfNeeded= */ true, userId); |
| 6292 | return cn == null ? null : cn.getPackageName(); |
| 6293 | } |
| 6294 | |
| 6295 | /** |
| 6296 | * Set a package as the default SMS app on a given user. |
| 6297 | * |
| 6298 | * Only the shell user (UID 2000 or 0) can call it. |
| 6299 | * Target user must be running. |
| 6300 | */ |
| 6301 | @Override |
| 6302 | public void setDefaultSmsApp(int userId, String packageName) { |
| 6303 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6304 | ensureUserRunning(userId); |
| 6305 | |
| 6306 | boolean found = false; |
| 6307 | for (String pkg : getSmsApps(userId)) { |
| 6308 | if (TextUtils.equals(packageName, pkg)) { |
| 6309 | found = true; |
| 6310 | break; |
| 6311 | } |
| 6312 | } |
| 6313 | if (!found) { |
| 6314 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6315 | } |
| 6316 | |
| 6317 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6318 | } |
| 6319 | |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6320 | @Override |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6321 | public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList( |
| 6322 | String callingPackage) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6323 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6324 | mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) { |
| 6325 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6326 | } |
| 6327 | final long identity = Binder.clearCallingIdentity(); |
| 6328 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6329 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6330 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6331 | if (phone.getEmergencyNumberTracker() != null |
| 6332 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6333 | emergencyNumberListInternal.put( |
| 6334 | phone.getSubId(), |
| 6335 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6336 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6337 | } |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6338 | return emergencyNumberListInternal; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6339 | } finally { |
| 6340 | Binder.restoreCallingIdentity(identity); |
| 6341 | } |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6342 | } |
| 6343 | |
| 6344 | @Override |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6345 | public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) { |
| 6346 | final Phone defaultPhone = getDefaultPhone(); |
| 6347 | if (!exactMatch) { |
| 6348 | TelephonyPermissions |
| 6349 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6350 | mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)"); |
| 6351 | } |
| 6352 | final long identity = Binder.clearCallingIdentity(); |
| 6353 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6354 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6355 | if (phone.getEmergencyNumberTracker() != null |
| 6356 | && phone.getEmergencyNumberTracker() != null) { |
| 6357 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 6358 | number, exactMatch)) { |
| 6359 | return true; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6360 | } |
| 6361 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6362 | } |
| 6363 | return false; |
| 6364 | } finally { |
| 6365 | Binder.restoreCallingIdentity(identity); |
| 6366 | } |
| 6367 | } |
| 6368 | |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6369 | /** |
| 6370 | * Update emergency number list for test mode. |
| 6371 | */ |
| 6372 | @Override |
| 6373 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 6374 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6375 | "updateEmergencyNumberListTestMode"); |
| 6376 | |
| 6377 | final long identity = Binder.clearCallingIdentity(); |
| 6378 | try { |
| 6379 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6380 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6381 | if (tracker != null) { |
| 6382 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 6383 | } |
| 6384 | } |
| 6385 | } finally { |
| 6386 | Binder.restoreCallingIdentity(identity); |
| 6387 | } |
| 6388 | } |
| 6389 | |
| 6390 | /** |
| 6391 | * Get the full emergency number list for test mode. |
| 6392 | */ |
| 6393 | @Override |
| 6394 | public List<String> getEmergencyNumberListTestMode() { |
| 6395 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6396 | "getEmergencyNumberListTestMode"); |
| 6397 | |
| 6398 | final long identity = Binder.clearCallingIdentity(); |
| 6399 | try { |
| 6400 | Set<String> emergencyNumbers = new HashSet<>(); |
| 6401 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6402 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6403 | if (tracker != null) { |
| 6404 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 6405 | emergencyNumbers.add(num.getNumber()); |
| 6406 | } |
| 6407 | } |
| 6408 | } |
| 6409 | return new ArrayList<>(emergencyNumbers); |
| 6410 | } finally { |
| 6411 | Binder.restoreCallingIdentity(identity); |
| 6412 | } |
| 6413 | } |
| 6414 | |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6415 | @Override |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6416 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6417 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6418 | Phone phone = getPhone(subId); |
| 6419 | if (phone == null) { |
| 6420 | return null; |
| 6421 | } |
| 6422 | final long identity = Binder.clearCallingIdentity(); |
| 6423 | try { |
| 6424 | UiccProfile profile = UiccController.getInstance() |
| 6425 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6426 | if (profile != null) { |
| 6427 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6428 | } |
| 6429 | } finally { |
| 6430 | Binder.restoreCallingIdentity(identity); |
| 6431 | } |
| 6432 | return null; |
| 6433 | } |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6434 | |
| 6435 | /** |
| 6436 | * Enable or disable a modem stack. |
| 6437 | */ |
| 6438 | @Override |
| 6439 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 6440 | enforceModifyPermission(); |
| 6441 | |
| 6442 | final long identity = Binder.clearCallingIdentity(); |
| 6443 | try { |
| 6444 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6445 | if (phone == null) { |
| 6446 | return false; |
| 6447 | } else { |
| 6448 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 6449 | } |
| 6450 | } finally { |
| 6451 | Binder.restoreCallingIdentity(identity); |
| 6452 | } |
| 6453 | } |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6454 | |
| 6455 | @Override |
| 6456 | public void setMultisimCarrierRestriction(boolean isMultisimCarrierRestricted) { |
| 6457 | enforceModifyPermission(); |
| 6458 | |
| 6459 | final long identity = Binder.clearCallingIdentity(); |
| 6460 | try { |
| 6461 | mTelephonySharedPreferences.edit() |
| 6462 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultisimCarrierRestricted) |
| 6463 | .commit(); |
| 6464 | } finally { |
| 6465 | Binder.restoreCallingIdentity(identity); |
| 6466 | } |
| 6467 | } |
| 6468 | |
| 6469 | @Override |
| 6470 | public boolean isMultisimCarrierRestricted() { |
| 6471 | enforceReadPrivilegedPermission("isMultisimCarrierRestricted"); |
| 6472 | |
| 6473 | final long identity = Binder.clearCallingIdentity(); |
| 6474 | try { |
| 6475 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 6476 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 6477 | if (numPhysicalSlots < 2) { |
| 6478 | loge("isMultisimCarrierRestricted: requires at least 2 cards"); |
| 6479 | return true; |
| 6480 | } |
| 6481 | |
| 6482 | // Default value is false. Multi SIM is allowed unless explicitly restricted. |
| 6483 | return mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false); |
| 6484 | } finally { |
| 6485 | Binder.restoreCallingIdentity(identity); |
| 6486 | } |
| 6487 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame^] | 6488 | |
| 6489 | /** |
| 6490 | * Switch configs to enable multi-sim or switch back to single-sim |
| 6491 | * @param numOfSims number of active sims we want to switch to |
| 6492 | */ |
| 6493 | @Override |
| 6494 | public void switchMultiSimConfig(int numOfSims) { |
| 6495 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6496 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 6497 | final long identity = Binder.clearCallingIdentity(); |
| 6498 | try { |
| 6499 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 6500 | } finally { |
| 6501 | Binder.restoreCallingIdentity(identity); |
| 6502 | } |
| 6503 | } |
| 6504 | |
| 6505 | /** |
| 6506 | * Get how many sims have been activated on the phone |
| 6507 | */ |
| 6508 | @Override |
| 6509 | public int getNumOfActiveSims() { |
| 6510 | final long identity = Binder.clearCallingIdentity(); |
| 6511 | try { |
| 6512 | return mPhoneConfigurationManager.getNumOfActiveSims(); |
| 6513 | } finally { |
| 6514 | Binder.restoreCallingIdentity(identity); |
| 6515 | } |
| 6516 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6517 | } |