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; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 55 | import android.service.carrier.CarrierIdentifier; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 56 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 57 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 58 | import android.telecom.TelecomManager; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 59 | import android.telephony.CarrierConfigManager; |
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; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame^] | 72 | import android.telephony.PhoneNumberUtils; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 73 | import android.telephony.RadioAccessFamily; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 74 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 75 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 76 | import android.telephony.SignalStrength; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 77 | import android.telephony.SmsManager; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 78 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 79 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 80 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 81 | import android.telephony.TelephonyManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 82 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 83 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 84 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 85 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 86 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 87 | import android.telephony.data.ApnSetting; |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 88 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 89 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 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 | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 97 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 98 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 99 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 100 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 101 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 102 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 103 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 104 | import com.android.ims.ImsException; |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 105 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 106 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 107 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 108 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 109 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 110 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 111 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 112 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 113 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 114 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 115 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 116 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 117 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 118 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 119 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 120 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 121 | import com.android.internal.telephony.Phone; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 122 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 123 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.ServiceStateTracker; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 130 | import com.android.internal.telephony.SmsApplication; |
| 131 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 133 | import com.android.internal.telephony.TelephonyPermissions; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.euicc.EuiccConnector; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.uicc.IccIoResult; |
| 136 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 137 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 139 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 141 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 142 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 144 | import com.android.internal.util.HexDump; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 145 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 146 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 147 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 148 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 149 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 150 | import java.io.FileDescriptor; |
| 151 | import java.io.PrintWriter; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 152 | import java.nio.charset.StandardCharsets; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 153 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 154 | import java.util.Arrays; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 155 | import java.util.Collection; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame^] | 156 | import java.util.HashMap; |
| 157 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 158 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 159 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 160 | import java.util.Map; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame^] | 161 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 162 | |
| 163 | /** |
| 164 | * Implementation of the ITelephony interface. |
| 165 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 166 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 167 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 168 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 169 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 170 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 171 | |
| 172 | // Message codes used with mMainThreadHandler |
| 173 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 174 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 175 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 176 | private static final int CMD_OPEN_CHANNEL = 9; |
| 177 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 178 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 179 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 180 | private static final int CMD_NV_READ_ITEM = 13; |
| 181 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 182 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 183 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 184 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 185 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 186 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 187 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 188 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 189 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 190 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 191 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 192 | private static final int CMD_SEND_ENVELOPE = 25; |
| 193 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 194 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 195 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 196 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 197 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 198 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 199 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 200 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 201 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 202 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 203 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 204 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 205 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 206 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 207 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 208 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 209 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 210 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 211 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 212 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 213 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 214 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 215 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 216 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 217 | private static final int CMD_SWITCH_SLOTS = 50; |
| 218 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 219 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 220 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 221 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 222 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 223 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 224 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 225 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 226 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 227 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 228 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 229 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 230 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 231 | private static final int CMD_MODEM_REBOOT = 64; |
| 232 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 233 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 234 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 235 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 236 | // Parameters of select command. |
| 237 | private static final int SELECT_COMMAND = 0xA4; |
| 238 | private static final int SELECT_P1 = 0x04; |
| 239 | private static final int SELECT_P2 = 0; |
| 240 | private static final int SELECT_P3 = 0x10; |
| 241 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 242 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 243 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 244 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 245 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 246 | /** The singleton instance. */ |
| 247 | private static PhoneInterfaceManager sInstance; |
| 248 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 249 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 250 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 251 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 252 | private AppOpsManager mAppOps; |
| 253 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 254 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 255 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 256 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 257 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 258 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 259 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 260 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 261 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 262 | // The AID of ISD-R. |
| 263 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 264 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 265 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 266 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 267 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 268 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 269 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 270 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 271 | * A request object to use for transmitting data to an ICC. |
| 272 | */ |
| 273 | private static final class IccAPDUArgument { |
| 274 | public int channel, cla, command, p1, p2, p3; |
| 275 | public String data; |
| 276 | |
| 277 | public IccAPDUArgument(int channel, int cla, int command, |
| 278 | int p1, int p2, int p3, String data) { |
| 279 | this.channel = channel; |
| 280 | this.cla = cla; |
| 281 | this.command = command; |
| 282 | this.p1 = p1; |
| 283 | this.p2 = p2; |
| 284 | this.p3 = p3; |
| 285 | this.data = data; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 290 | * A request object to use for transmitting data to an ICC. |
| 291 | */ |
| 292 | private static final class ManualNetworkSelectionArgument { |
| 293 | public OperatorInfo operatorInfo; |
| 294 | public boolean persistSelection; |
| 295 | |
| 296 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 297 | this.operatorInfo = operatorInfo; |
| 298 | this.persistSelection = persistSelection; |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 303 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 304 | * request after sending. The main thread will notify the request when it is complete. |
| 305 | */ |
| 306 | private static final class MainThreadRequest { |
| 307 | /** The argument to use for the request */ |
| 308 | public Object argument; |
| 309 | /** The result of the request that is run on the main thread */ |
| 310 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 311 | // The subscriber id that this request applies to. Defaults to |
| 312 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 313 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 314 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 315 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 316 | public Phone phone; |
| 317 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 318 | public WorkSource workSource; |
| 319 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 320 | public MainThreadRequest(Object argument) { |
| 321 | this.argument = argument; |
| 322 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 323 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 324 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 325 | this.argument = argument; |
| 326 | if (phone != null) { |
| 327 | this.phone = phone; |
| 328 | } |
| 329 | this.workSource = workSource; |
| 330 | } |
| 331 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 332 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 333 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 334 | if (subId != null) { |
| 335 | this.subId = subId; |
| 336 | } |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 337 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 338 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 341 | private static final class IncomingThirdPartyCallArgs { |
| 342 | public final ComponentName component; |
| 343 | public final String callId; |
| 344 | public final String callerDisplayName; |
| 345 | |
| 346 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 347 | String callerDisplayName) { |
| 348 | this.component = component; |
| 349 | this.callId = callId; |
| 350 | this.callerDisplayName = callerDisplayName; |
| 351 | } |
| 352 | } |
| 353 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 354 | /** |
| 355 | * A handler that processes messages on the main thread in the phone process. Since many |
| 356 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 357 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 358 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 359 | * on, which will be notified when the operation completes and will contain the result of the |
| 360 | * request. |
| 361 | * |
| 362 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 363 | * note that request.result must be set to something non-null for the calling thread to |
| 364 | * unblock. |
| 365 | */ |
| 366 | private final class MainThreadHandler extends Handler { |
| 367 | @Override |
| 368 | public void handleMessage(Message msg) { |
| 369 | MainThreadRequest request; |
| 370 | Message onCompleted; |
| 371 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 372 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 373 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 374 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 375 | |
| 376 | switch (msg.what) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 377 | case CMD_HANDLE_USSD_REQUEST: { |
| 378 | request = (MainThreadRequest) msg.obj; |
| 379 | final Phone phone = getPhoneFromRequest(request); |
| 380 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 381 | String ussdRequest = ussdObject.first; |
| 382 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 383 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 384 | if (!isUssdApiAllowed(request.subId)) { |
| 385 | // Carrier does not support use of this API, return failure. |
| 386 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 387 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 388 | Bundle returnData = new Bundle(); |
| 389 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 390 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 391 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 392 | request.result = true; |
| 393 | notifyRequester(request); |
| 394 | return; |
| 395 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 396 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 397 | try { |
| 398 | request.result = phone != null |
| 399 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 400 | } catch (CallStateException cse) { |
| 401 | request.result = false; |
| 402 | } |
| 403 | // Wake up the requesting thread |
| 404 | notifyRequester(request); |
| 405 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 406 | } |
| 407 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 408 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 409 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 410 | final Phone phone = getPhoneFromRequest(request); |
| 411 | request.result = phone != null ? |
| 412 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 413 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 414 | // Wake up the requesting thread |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 415 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 416 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 417 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 418 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 419 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 420 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 421 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 422 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 423 | if (uiccCard == null) { |
| 424 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 425 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 426 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 427 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 428 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 429 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 430 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 431 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 432 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 433 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 434 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 435 | break; |
| 436 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 437 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 438 | ar = (AsyncResult) msg.obj; |
| 439 | request = (MainThreadRequest) ar.userObj; |
| 440 | if (ar.exception == null && ar.result != null) { |
| 441 | request.result = ar.result; |
| 442 | } else { |
| 443 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 444 | if (ar.result == null) { |
| 445 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 446 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 447 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 448 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 449 | } else { |
| 450 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 451 | } |
| 452 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 453 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 454 | break; |
| 455 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 456 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 457 | request = (MainThreadRequest) msg.obj; |
| 458 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 459 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 460 | if (uiccCard == null) { |
| 461 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 462 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 463 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 464 | } else { |
| 465 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 466 | request); |
| 467 | uiccCard.iccTransmitApduBasicChannel( |
| 468 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 469 | iccArgument.p3, iccArgument.data, onCompleted); |
| 470 | } |
| 471 | break; |
| 472 | |
| 473 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 474 | ar = (AsyncResult) msg.obj; |
| 475 | request = (MainThreadRequest) ar.userObj; |
| 476 | if (ar.exception == null && ar.result != null) { |
| 477 | request.result = ar.result; |
| 478 | } else { |
| 479 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 480 | if (ar.result == null) { |
| 481 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 482 | } else if (ar.exception instanceof CommandException) { |
| 483 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 484 | ar.exception); |
| 485 | } else { |
| 486 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 487 | } |
| 488 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 489 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 490 | break; |
| 491 | |
| 492 | case CMD_EXCHANGE_SIM_IO: |
| 493 | request = (MainThreadRequest) msg.obj; |
| 494 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 495 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 496 | if (uiccCard == null) { |
| 497 | loge("iccExchangeSimIO: No UICC"); |
| 498 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 499 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 500 | } else { |
| 501 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 502 | request); |
| 503 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 504 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 505 | iccArgument.data, onCompleted); |
| 506 | } |
| 507 | break; |
| 508 | |
| 509 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 510 | ar = (AsyncResult) msg.obj; |
| 511 | request = (MainThreadRequest) ar.userObj; |
| 512 | if (ar.exception == null && ar.result != null) { |
| 513 | request.result = ar.result; |
| 514 | } else { |
| 515 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 516 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 517 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 518 | break; |
| 519 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 520 | case CMD_SEND_ENVELOPE: |
| 521 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 522 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 523 | if (uiccCard == null) { |
| 524 | loge("sendEnvelopeWithStatus: No UICC"); |
| 525 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 526 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 527 | } else { |
| 528 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 529 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 530 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 531 | break; |
| 532 | |
| 533 | case EVENT_SEND_ENVELOPE_DONE: |
| 534 | ar = (AsyncResult) msg.obj; |
| 535 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 536 | if (ar.exception == null && ar.result != null) { |
| 537 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 538 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 539 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 540 | if (ar.result == null) { |
| 541 | loge("sendEnvelopeWithStatus: Empty response"); |
| 542 | } else if (ar.exception instanceof CommandException) { |
| 543 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 544 | ar.exception); |
| 545 | } else { |
| 546 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 547 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 548 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 549 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 550 | break; |
| 551 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 552 | case CMD_OPEN_CHANNEL: |
| 553 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 554 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 555 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 556 | if (uiccCard == null) { |
| 557 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 558 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 559 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 560 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 561 | } else { |
| 562 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 563 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 564 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 565 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 566 | break; |
| 567 | |
| 568 | case EVENT_OPEN_CHANNEL_DONE: |
| 569 | ar = (AsyncResult) msg.obj; |
| 570 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 571 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 572 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 573 | int[] result = (int[]) ar.result; |
| 574 | int channelId = result[0]; |
| 575 | byte[] selectResponse = null; |
| 576 | if (result.length > 1) { |
| 577 | selectResponse = new byte[result.length - 1]; |
| 578 | for (int i = 1; i < result.length; ++i) { |
| 579 | selectResponse[i - 1] = (byte) result[i]; |
| 580 | } |
| 581 | } |
| 582 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 583 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 584 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 585 | if (ar.result == null) { |
| 586 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 587 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 588 | if (ar.exception != null) { |
| 589 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 590 | } |
| 591 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 592 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 593 | if (ar.exception instanceof CommandException) { |
| 594 | CommandException.Error error = |
| 595 | ((CommandException) (ar.exception)).getCommandError(); |
| 596 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 597 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 598 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 599 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 600 | } |
| 601 | } |
| 602 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 603 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 604 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 605 | request.result = openChannelResp; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 606 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 607 | break; |
| 608 | |
| 609 | case CMD_CLOSE_CHANNEL: |
| 610 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 611 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 612 | if (uiccCard == null) { |
| 613 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 614 | request.result = false; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 615 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 616 | } else { |
| 617 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 618 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 619 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 620 | break; |
| 621 | |
| 622 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 623 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 624 | break; |
| 625 | |
| 626 | case CMD_NV_READ_ITEM: |
| 627 | request = (MainThreadRequest) msg.obj; |
| 628 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 629 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 630 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 631 | break; |
| 632 | |
| 633 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 634 | ar = (AsyncResult) msg.obj; |
| 635 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 636 | if (ar.exception == null && ar.result != null) { |
| 637 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 638 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 639 | request.result = ""; |
| 640 | if (ar.result == null) { |
| 641 | loge("nvReadItem: Empty response"); |
| 642 | } else if (ar.exception instanceof CommandException) { |
| 643 | loge("nvReadItem: CommandException: " + |
| 644 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 645 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 646 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 647 | } |
| 648 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 649 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 650 | break; |
| 651 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 652 | case CMD_NV_WRITE_ITEM: |
| 653 | request = (MainThreadRequest) msg.obj; |
| 654 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 655 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 656 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 657 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 658 | break; |
| 659 | |
| 660 | case EVENT_NV_WRITE_ITEM_DONE: |
| 661 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 662 | break; |
| 663 | |
| 664 | case CMD_NV_WRITE_CDMA_PRL: |
| 665 | request = (MainThreadRequest) msg.obj; |
| 666 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 667 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 668 | break; |
| 669 | |
| 670 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 671 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 672 | break; |
| 673 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 674 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 675 | request = (MainThreadRequest) msg.obj; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 676 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 677 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 678 | break; |
| 679 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 680 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 681 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 682 | break; |
| 683 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 684 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 685 | request = (MainThreadRequest) msg.obj; |
| 686 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 687 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 688 | break; |
| 689 | |
| 690 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 691 | ar = (AsyncResult) msg.obj; |
| 692 | request = (MainThreadRequest) ar.userObj; |
| 693 | if (ar.exception == null && ar.result != null) { |
| 694 | request.result = ar.result; // Integer |
| 695 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 696 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 697 | if (ar.result == null) { |
| 698 | loge("getPreferredNetworkType: Empty response"); |
| 699 | } else if (ar.exception instanceof CommandException) { |
| 700 | loge("getPreferredNetworkType: CommandException: " + |
| 701 | ar.exception); |
| 702 | } else { |
| 703 | loge("getPreferredNetworkType: Unknown exception"); |
| 704 | } |
| 705 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 706 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 707 | break; |
| 708 | |
| 709 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 710 | request = (MainThreadRequest) msg.obj; |
| 711 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 712 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 713 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 714 | break; |
| 715 | |
| 716 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 717 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 718 | break; |
| 719 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 720 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 721 | request = (MainThreadRequest)msg.obj; |
| 722 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 723 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 724 | break; |
| 725 | |
| 726 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 727 | ar = (AsyncResult)msg.obj; |
| 728 | request = (MainThreadRequest)ar.userObj; |
| 729 | request.result = ar; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 730 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 731 | break; |
| 732 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 733 | case CMD_SET_VOICEMAIL_NUMBER: |
| 734 | request = (MainThreadRequest) msg.obj; |
| 735 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 736 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 737 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 738 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 739 | break; |
| 740 | |
| 741 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 742 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 743 | break; |
| 744 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 745 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 746 | request = (MainThreadRequest) msg.obj; |
| 747 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 748 | request); |
| 749 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 750 | break; |
| 751 | |
| 752 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 753 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 754 | break; |
| 755 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 756 | case CMD_PERFORM_NETWORK_SCAN: |
| 757 | request = (MainThreadRequest) msg.obj; |
| 758 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 759 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 760 | break; |
| 761 | |
| 762 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 763 | ar = (AsyncResult) msg.obj; |
| 764 | request = (MainThreadRequest) ar.userObj; |
| 765 | CellNetworkScanResult cellScanResult; |
| 766 | if (ar.exception == null && ar.result != null) { |
| 767 | cellScanResult = new CellNetworkScanResult( |
| 768 | CellNetworkScanResult.STATUS_SUCCESS, |
| 769 | (List<OperatorInfo>) ar.result); |
| 770 | } else { |
| 771 | if (ar.result == null) { |
| 772 | loge("getCellNetworkScanResults: Empty response"); |
| 773 | } |
| 774 | if (ar.exception != null) { |
| 775 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 776 | } |
| 777 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 778 | if (ar.exception instanceof CommandException) { |
| 779 | CommandException.Error error = |
| 780 | ((CommandException) (ar.exception)).getCommandError(); |
| 781 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 782 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 783 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 784 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 785 | } |
| 786 | } |
| 787 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 788 | } |
| 789 | request.result = cellScanResult; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 790 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 791 | break; |
| 792 | |
| 793 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 794 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 795 | ManualNetworkSelectionArgument selArg = |
| 796 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 797 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 798 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 799 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 800 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 801 | break; |
| 802 | |
| 803 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | dd9ac82 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 804 | ar = (AsyncResult) msg.obj; |
| 805 | request = (MainThreadRequest) ar.userObj; |
| 806 | if (ar.exception == null) { |
| 807 | request.result = true; |
| 808 | } else { |
| 809 | request.result = false; |
| 810 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 811 | } |
| 812 | notifyRequester(request); |
| 813 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 814 | break; |
| 815 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 816 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 817 | request = (MainThreadRequest) msg.obj; |
| 818 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 819 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 820 | break; |
| 821 | |
| 822 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 823 | ar = (AsyncResult) msg.obj; |
| 824 | request = (MainThreadRequest) ar.userObj; |
| 825 | if (ar.exception == null && ar.result != null) { |
| 826 | request.result = ar.result; |
| 827 | } else { |
| 828 | if (ar.result == null) { |
| 829 | loge("queryModemActivityInfo: Empty response"); |
| 830 | } else if (ar.exception instanceof CommandException) { |
| 831 | loge("queryModemActivityInfo: CommandException: " + |
| 832 | ar.exception); |
| 833 | } else { |
| 834 | loge("queryModemActivityInfo: Unknown exception"); |
| 835 | } |
| 836 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 837 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 838 | if (request.result == null) { |
| 839 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 840 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 841 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 842 | break; |
| 843 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 844 | case CMD_SET_ALLOWED_CARRIERS: |
| 845 | request = (MainThreadRequest) msg.obj; |
| 846 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 847 | defaultPhone.setAllowedCarriers( |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 848 | (List<CarrierIdentifier>) request.argument, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 849 | onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 850 | break; |
| 851 | |
| 852 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 853 | ar = (AsyncResult) msg.obj; |
| 854 | request = (MainThreadRequest) ar.userObj; |
| 855 | if (ar.exception == null && ar.result != null) { |
| 856 | request.result = ar.result; |
| 857 | } else { |
| 858 | if (ar.result == null) { |
| 859 | loge("setAllowedCarriers: Empty response"); |
| 860 | } else if (ar.exception instanceof CommandException) { |
| 861 | loge("setAllowedCarriers: CommandException: " + |
| 862 | ar.exception); |
| 863 | } else { |
| 864 | loge("setAllowedCarriers: Unknown exception"); |
| 865 | } |
| 866 | } |
| 867 | // Result cannot be null. Return -1 on error. |
| 868 | if (request.result == null) { |
| 869 | request.result = new int[]{-1}; |
| 870 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 871 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 872 | break; |
| 873 | |
| 874 | case CMD_GET_ALLOWED_CARRIERS: |
| 875 | request = (MainThreadRequest) msg.obj; |
| 876 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 877 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 878 | break; |
| 879 | |
| 880 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 881 | ar = (AsyncResult) msg.obj; |
| 882 | request = (MainThreadRequest) ar.userObj; |
| 883 | if (ar.exception == null && ar.result != null) { |
| 884 | request.result = ar.result; |
| 885 | } else { |
| 886 | if (ar.result == null) { |
| 887 | loge("getAllowedCarriers: Empty response"); |
| 888 | } else if (ar.exception instanceof CommandException) { |
| 889 | loge("getAllowedCarriers: CommandException: " + |
| 890 | ar.exception); |
| 891 | } else { |
| 892 | loge("getAllowedCarriers: Unknown exception"); |
| 893 | } |
| 894 | } |
| 895 | // Result cannot be null. Return empty list of CarrierIdentifier. |
| 896 | if (request.result == null) { |
| 897 | request.result = new ArrayList<CarrierIdentifier>(0); |
| 898 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 899 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 900 | break; |
| 901 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 902 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 903 | ar = (AsyncResult) msg.obj; |
| 904 | request = (MainThreadRequest) ar.userObj; |
| 905 | if (ar.exception == null && ar.result != null) { |
| 906 | request.result = ar.result; |
| 907 | } else { |
| 908 | request.result = new IllegalArgumentException( |
| 909 | "Failed to retrieve Forbidden Plmns"); |
| 910 | if (ar.result == null) { |
| 911 | loge("getForbiddenPlmns: Empty response"); |
| 912 | } else { |
| 913 | loge("getForbiddenPlmns: Unknown exception"); |
| 914 | } |
| 915 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 916 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 917 | break; |
| 918 | |
| 919 | case CMD_GET_FORBIDDEN_PLMNS: |
| 920 | request = (MainThreadRequest) msg.obj; |
| 921 | uiccCard = getUiccCardFromRequest(request); |
| 922 | if (uiccCard == null) { |
| 923 | loge("getForbiddenPlmns() UiccCard is null"); |
| 924 | request.result = new IllegalArgumentException( |
| 925 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 926 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 927 | break; |
| 928 | } |
| 929 | Integer appType = (Integer) request.argument; |
| 930 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 931 | if (uiccApp == null) { |
| 932 | loge("getForbiddenPlmns() no app with specified type -- " |
| 933 | + appType); |
| 934 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 935 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 936 | break; |
| 937 | } else { |
| 938 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 939 | + " specified type -- " + appType); |
| 940 | } |
| 941 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 942 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 943 | onCompleted); |
| 944 | break; |
| 945 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 946 | case CMD_SWITCH_SLOTS: |
| 947 | request = (MainThreadRequest) msg.obj; |
| 948 | int[] physicalSlots = (int[]) request.argument; |
| 949 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 950 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 951 | break; |
| 952 | |
| 953 | case EVENT_SWITCH_SLOTS_DONE: |
| 954 | ar = (AsyncResult) msg.obj; |
| 955 | request = (MainThreadRequest) ar.userObj; |
| 956 | request.result = (ar.exception == null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 957 | notifyRequester(request); |
| 958 | break; |
| 959 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 960 | request = (MainThreadRequest) msg.obj; |
| 961 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 962 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 963 | break; |
| 964 | |
| 965 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 966 | ar = (AsyncResult) msg.obj; |
| 967 | request = (MainThreadRequest) ar.userObj; |
| 968 | if (ar.exception != null) { |
| 969 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 970 | } else { |
| 971 | int mode = ((int[]) ar.result)[0]; |
| 972 | if (mode == 0) { |
| 973 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 974 | } else { |
| 975 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 976 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 977 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 978 | notifyRequester(request); |
| 979 | break; |
| 980 | case CMD_GET_CDMA_ROAMING_MODE: |
| 981 | request = (MainThreadRequest) msg.obj; |
| 982 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 983 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 984 | break; |
| 985 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 986 | ar = (AsyncResult) msg.obj; |
| 987 | request = (MainThreadRequest) ar.userObj; |
| 988 | if (ar.exception != null) { |
| 989 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 990 | } else { |
| 991 | request.result = ((int[]) ar.result)[0]; |
| 992 | } |
| 993 | notifyRequester(request); |
| 994 | break; |
| 995 | case CMD_SET_CDMA_ROAMING_MODE: |
| 996 | request = (MainThreadRequest) msg.obj; |
| 997 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 998 | int mode = (int) request.argument; |
| 999 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1000 | break; |
| 1001 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1002 | ar = (AsyncResult) msg.obj; |
| 1003 | request = (MainThreadRequest) ar.userObj; |
| 1004 | request.result = ar.exception == null; |
| 1005 | notifyRequester(request); |
| 1006 | break; |
| 1007 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1008 | request = (MainThreadRequest) msg.obj; |
| 1009 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1010 | int subscriptionMode = (int) request.argument; |
| 1011 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1012 | break; |
| 1013 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1014 | ar = (AsyncResult) msg.obj; |
| 1015 | request = (MainThreadRequest) ar.userObj; |
| 1016 | request.result = ar.exception == null; |
| 1017 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1018 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1019 | case CMD_GET_ALL_CELL_INFO: |
| 1020 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1021 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1022 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1023 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1024 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1025 | ar = (AsyncResult) msg.obj; |
| 1026 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1027 | // If a timeout occurs, the response will be null |
| 1028 | request.result = (ar.exception == null && ar.result != null) |
| 1029 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1030 | synchronized (request) { |
| 1031 | request.notifyAll(); |
| 1032 | } |
| 1033 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1034 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1035 | request = (MainThreadRequest) msg.obj; |
| 1036 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1037 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1038 | break; |
| 1039 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1040 | ar = (AsyncResult) msg.obj; |
| 1041 | request = (MainThreadRequest) ar.userObj; |
| 1042 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1043 | try { |
| 1044 | if (ar.exception != null) { |
| 1045 | // something went wrong... the response is null |
| 1046 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
| 1047 | cb.onCellInfo(null); |
| 1048 | } else if (ar.result == null) { |
| 1049 | // timeout occurred, so force the result to non-null "empty" |
| 1050 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
| 1051 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 1052 | } else { |
| 1053 | // use the result as returned |
| 1054 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1055 | } |
| 1056 | } catch (RemoteException re) { |
| 1057 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1058 | } |
| 1059 | break; |
| 1060 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1061 | request = (MainThreadRequest) msg.obj; |
| 1062 | WorkSource ws = (WorkSource) request.argument; |
| 1063 | Phone phone = getPhoneFromRequest(request); |
| 1064 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1065 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1066 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1067 | ar = (AsyncResult) msg.obj; |
| 1068 | request = (MainThreadRequest) ar.userObj; |
| 1069 | if (ar.exception == null) { |
| 1070 | request.result = ar.result; |
| 1071 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1072 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1073 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1074 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1075 | } |
| 1076 | |
| 1077 | synchronized (request) { |
| 1078 | request.notifyAll(); |
| 1079 | } |
| 1080 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1081 | case CMD_MODEM_REBOOT: |
| 1082 | request = (MainThreadRequest) msg.obj; |
| 1083 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1084 | defaultPhone.rebootModem(onCompleted); |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1085 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1086 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1087 | handleNullReturnEvent(msg, "rebootModem"); |
| 1088 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1089 | default: |
| 1090 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1091 | break; |
| 1092 | } |
| 1093 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1094 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1095 | private void notifyRequester(MainThreadRequest request) { |
| 1096 | synchronized (request) { |
| 1097 | request.notifyAll(); |
| 1098 | } |
| 1099 | } |
| 1100 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1101 | private void handleNullReturnEvent(Message msg, String command) { |
| 1102 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1103 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1104 | if (ar.exception == null) { |
| 1105 | request.result = true; |
| 1106 | } else { |
| 1107 | request.result = false; |
| 1108 | if (ar.exception instanceof CommandException) { |
| 1109 | loge(command + ": CommandException: " + ar.exception); |
| 1110 | } else { |
| 1111 | loge(command + ": Unknown exception"); |
| 1112 | } |
| 1113 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1114 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1115 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | /** |
| 1119 | * Posts the specified command to be executed on the main thread, |
| 1120 | * waits for the request to complete, and returns the result. |
| 1121 | * @see #sendRequestAsync |
| 1122 | */ |
| 1123 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1124 | return sendRequest( |
| 1125 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | /** |
| 1129 | * Posts the specified command to be executed on the main thread, |
| 1130 | * waits for the request to complete, and returns the result. |
| 1131 | * @see #sendRequestAsync |
| 1132 | */ |
| 1133 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1134 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1135 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | /** |
| 1139 | * Posts the specified command to be executed on the main thread, |
| 1140 | * waits for the request to complete, and returns the result. |
| 1141 | * @see #sendRequestAsync |
| 1142 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1143 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1144 | return sendRequest(command, argument, subId, 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 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1152 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1153 | return sendRequest(command, argument, subId, null, workSource); |
| 1154 | } |
| 1155 | |
| 1156 | /** |
| 1157 | * Posts the specified command to be executed on the main thread, |
| 1158 | * waits for the request to complete, and returns the result. |
| 1159 | * @see #sendRequestAsync |
| 1160 | */ |
| 1161 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1162 | return sendRequest( |
| 1163 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 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 | */ |
| 1171 | private Object sendRequest( |
| 1172 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1173 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1174 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1175 | } |
| 1176 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1177 | MainThreadRequest request = null; |
| 1178 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1179 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1180 | } else if (phone != null) { |
| 1181 | request = new MainThreadRequest(argument, phone, workSource); |
| 1182 | } else { |
| 1183 | request = new MainThreadRequest(argument, subId, workSource); |
| 1184 | } |
| 1185 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1186 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1187 | msg.sendToTarget(); |
| 1188 | |
| 1189 | // Wait for the request to complete |
| 1190 | synchronized (request) { |
| 1191 | while (request.result == null) { |
| 1192 | try { |
| 1193 | request.wait(); |
| 1194 | } catch (InterruptedException e) { |
| 1195 | // Do nothing, go back and wait until the request is complete |
| 1196 | } |
| 1197 | } |
| 1198 | } |
| 1199 | return request.result; |
| 1200 | } |
| 1201 | |
| 1202 | /** |
| 1203 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1204 | * Posts the specified command to be executed on the main thread, and |
| 1205 | * returns immediately. |
| 1206 | * @see #sendRequest |
| 1207 | */ |
| 1208 | private void sendRequestAsync(int command) { |
| 1209 | mMainThreadHandler.sendEmptyMessage(command); |
| 1210 | } |
| 1211 | |
| 1212 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1213 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1214 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1215 | */ |
| 1216 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1217 | sendRequestAsync(command, argument, null, null); |
| 1218 | } |
| 1219 | |
| 1220 | /** |
| 1221 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1222 | * @see {@link #sendRequest(int,Object)} |
| 1223 | */ |
| 1224 | private void sendRequestAsync( |
| 1225 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1226 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1227 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1228 | msg.sendToTarget(); |
| 1229 | } |
| 1230 | |
| 1231 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1232 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1233 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1234 | */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1235 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1236 | synchronized (PhoneInterfaceManager.class) { |
| 1237 | if (sInstance == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1238 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1239 | } else { |
| 1240 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1241 | } |
| 1242 | return sInstance; |
| 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1247 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1248 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1249 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1250 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1251 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1252 | mMainThreadHandler = new MainThreadHandler(); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1253 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1254 | mTelephonySharedPreferences = |
| 1255 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1256 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1257 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1258 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1259 | publish(); |
| 1260 | } |
| 1261 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1262 | private Phone getDefaultPhone() { |
| 1263 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1264 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1265 | } |
| 1266 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1267 | private void publish() { |
| 1268 | if (DBG) log("publish: " + this); |
| 1269 | |
| 1270 | ServiceManager.addService("phone", this); |
| 1271 | } |
| 1272 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1273 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 1274 | return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1275 | ? getDefaultPhone() : getPhone(request.subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1276 | } |
| 1277 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1278 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1279 | Phone phone = getPhoneFromRequest(request); |
| 1280 | return phone == null ? null : |
| 1281 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1282 | } |
| 1283 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1284 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1285 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1286 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1287 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1288 | |
| 1289 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1290 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1291 | } |
| 1292 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1293 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1294 | if (DBG) log("dial: " + number); |
| 1295 | // No permission check needed here: This is just a wrapper around the |
| 1296 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1297 | // the UI before it does anything. |
| 1298 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1299 | final long identity = Binder.clearCallingIdentity(); |
| 1300 | try { |
| 1301 | String url = createTelUrl(number); |
| 1302 | if (url == null) { |
| 1303 | return; |
| 1304 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1305 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1306 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1307 | PhoneConstants.State state = mCM.getState(subId); |
| 1308 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1309 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1310 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1311 | mApp.startActivity(intent); |
| 1312 | } |
| 1313 | } finally { |
| 1314 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1319 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1320 | } |
| 1321 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1322 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1323 | if (DBG) log("call: " + number); |
| 1324 | |
| 1325 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1326 | // need to do a permission check since we're calling startActivity() |
| 1327 | // from the context of the phone app. |
| 1328 | enforceCallPermission(); |
| 1329 | |
| 1330 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1331 | != AppOpsManager.MODE_ALLOWED) { |
| 1332 | return; |
| 1333 | } |
| 1334 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1335 | final long identity = Binder.clearCallingIdentity(); |
| 1336 | try { |
| 1337 | String url = createTelUrl(number); |
| 1338 | if (url == null) { |
| 1339 | return; |
| 1340 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1341 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1342 | boolean isValid = false; |
| 1343 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1344 | if (slist != null) { |
| 1345 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1346 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1347 | isValid = true; |
| 1348 | break; |
| 1349 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1350 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1351 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1352 | if (!isValid) { |
| 1353 | return; |
| 1354 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1355 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1356 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1357 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1358 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1359 | mApp.startActivity(intent); |
| 1360 | } finally { |
| 1361 | Binder.restoreCallingIdentity(identity); |
| 1362 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1363 | } |
| 1364 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1365 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1366 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1367 | } |
| 1368 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1369 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1370 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1371 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1372 | } |
| 1373 | |
| 1374 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1375 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1376 | } |
| 1377 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1378 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1379 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1380 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1381 | } |
| 1382 | |
| 1383 | /** {@hide} */ |
| 1384 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1385 | return supplyPinReportResultForSubscriber(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 int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1389 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1390 | |
| 1391 | final long identity = Binder.clearCallingIdentity(); |
| 1392 | try { |
| 1393 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1394 | checkSimPin.start(); |
| 1395 | return checkSimPin.unlockSim(null, pin); |
| 1396 | } finally { |
| 1397 | Binder.restoreCallingIdentity(identity); |
| 1398 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1399 | } |
| 1400 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1401 | /** {@hide} */ |
| 1402 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1403 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1406 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1407 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1408 | |
| 1409 | final long identity = Binder.clearCallingIdentity(); |
| 1410 | try { |
| 1411 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1412 | checkSimPuk.start(); |
| 1413 | return checkSimPuk.unlockSim(puk, pin); |
| 1414 | } finally { |
| 1415 | Binder.restoreCallingIdentity(identity); |
| 1416 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1420 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1421 | * a synchronous one. |
| 1422 | */ |
| 1423 | private static class UnlockSim extends Thread { |
| 1424 | |
| 1425 | private final IccCard mSimCard; |
| 1426 | |
| 1427 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1428 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1429 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1430 | |
| 1431 | // For replies from SimCard interface |
| 1432 | private Handler mHandler; |
| 1433 | |
| 1434 | // For async handler to identify request type |
| 1435 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1436 | |
| 1437 | public UnlockSim(IccCard simCard) { |
| 1438 | mSimCard = simCard; |
| 1439 | } |
| 1440 | |
| 1441 | @Override |
| 1442 | public void run() { |
| 1443 | Looper.prepare(); |
| 1444 | synchronized (UnlockSim.this) { |
| 1445 | mHandler = new Handler() { |
| 1446 | @Override |
| 1447 | public void handleMessage(Message msg) { |
| 1448 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1449 | switch (msg.what) { |
| 1450 | case SUPPLY_PIN_COMPLETE: |
| 1451 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1452 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1453 | mRetryCount = msg.arg1; |
| 1454 | if (ar.exception != null) { |
| 1455 | if (ar.exception instanceof CommandException && |
| 1456 | ((CommandException)(ar.exception)).getCommandError() |
| 1457 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1458 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1459 | } else { |
| 1460 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1461 | } |
| 1462 | } else { |
| 1463 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1464 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1465 | mDone = true; |
| 1466 | UnlockSim.this.notifyAll(); |
| 1467 | } |
| 1468 | break; |
| 1469 | } |
| 1470 | } |
| 1471 | }; |
| 1472 | UnlockSim.this.notifyAll(); |
| 1473 | } |
| 1474 | Looper.loop(); |
| 1475 | } |
| 1476 | |
| 1477 | /* |
| 1478 | * Use PIN or PUK to unlock SIM card |
| 1479 | * |
| 1480 | * If PUK is null, unlock SIM card with PIN |
| 1481 | * |
| 1482 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1483 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1484 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1485 | |
| 1486 | while (mHandler == null) { |
| 1487 | try { |
| 1488 | wait(); |
| 1489 | } catch (InterruptedException e) { |
| 1490 | Thread.currentThread().interrupt(); |
| 1491 | } |
| 1492 | } |
| 1493 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1494 | |
| 1495 | if (puk == null) { |
| 1496 | mSimCard.supplyPin(pin, callback); |
| 1497 | } else { |
| 1498 | mSimCard.supplyPuk(puk, pin, callback); |
| 1499 | } |
| 1500 | |
| 1501 | while (!mDone) { |
| 1502 | try { |
| 1503 | Log.d(LOG_TAG, "wait for done"); |
| 1504 | wait(); |
| 1505 | } catch (InterruptedException e) { |
| 1506 | // Restore the interrupted status |
| 1507 | Thread.currentThread().interrupt(); |
| 1508 | } |
| 1509 | } |
| 1510 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1511 | int[] resultArray = new int[2]; |
| 1512 | resultArray[0] = mResult; |
| 1513 | resultArray[1] = mRetryCount; |
| 1514 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1515 | } |
| 1516 | } |
| 1517 | |
| 1518 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1519 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1520 | |
| 1521 | } |
| 1522 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1523 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1524 | // No permission check needed here: this call is harmless, and it's |
| 1525 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1526 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1527 | final long identity = Binder.clearCallingIdentity(); |
| 1528 | try { |
| 1529 | final Phone phone = getPhone(subId); |
| 1530 | if (phone != null) { |
| 1531 | phone.updateServiceLocation(); |
| 1532 | } |
| 1533 | } finally { |
| 1534 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1535 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1536 | } |
| 1537 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1538 | @Override |
| 1539 | public boolean isRadioOn(String callingPackage) { |
| 1540 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1541 | } |
| 1542 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1543 | @Override |
| 1544 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1545 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1546 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1547 | return false; |
| 1548 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1549 | |
| 1550 | final long identity = Binder.clearCallingIdentity(); |
| 1551 | try { |
| 1552 | return isRadioOnForSubscriber(subId); |
| 1553 | } finally { |
| 1554 | Binder.restoreCallingIdentity(identity); |
| 1555 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1559 | final long identity = Binder.clearCallingIdentity(); |
| 1560 | try { |
| 1561 | final Phone phone = getPhone(subId); |
| 1562 | if (phone != null) { |
| 1563 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1564 | } else { |
| 1565 | return false; |
| 1566 | } |
| 1567 | } finally { |
| 1568 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1569 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1573 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1574 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1575 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1576 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1577 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1578 | |
| 1579 | final long identity = Binder.clearCallingIdentity(); |
| 1580 | try { |
| 1581 | final Phone phone = getPhone(subId); |
| 1582 | if (phone != null) { |
| 1583 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1584 | } |
| 1585 | } finally { |
| 1586 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1587 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1591 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1592 | } |
| 1593 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1594 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1595 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1596 | |
| 1597 | final long identity = Binder.clearCallingIdentity(); |
| 1598 | try { |
| 1599 | final Phone phone = getPhone(subId); |
| 1600 | if (phone == null) { |
| 1601 | return false; |
| 1602 | } |
| 1603 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1604 | toggleRadioOnOffForSubscriber(subId); |
| 1605 | } |
| 1606 | return true; |
| 1607 | } finally { |
| 1608 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1609 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1610 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1611 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1612 | public boolean needMobileRadioShutdown() { |
| 1613 | /* |
| 1614 | * If any of the Radios are available, it will need to be |
| 1615 | * shutdown. So return true if any Radio is available. |
| 1616 | */ |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1617 | final long identity = Binder.clearCallingIdentity(); |
| 1618 | try { |
| 1619 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1620 | Phone phone = PhoneFactory.getPhone(i); |
| 1621 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1622 | } |
| 1623 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1624 | return false; |
| 1625 | } finally { |
| 1626 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1627 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1628 | } |
| 1629 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1630 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1631 | public void shutdownMobileRadios() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1632 | enforceModifyPermission(); |
| 1633 | |
| 1634 | final long identity = Binder.clearCallingIdentity(); |
| 1635 | try { |
| 1636 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1637 | logv("Shutting down Phone " + i); |
| 1638 | shutdownRadioUsingPhoneId(i); |
| 1639 | } |
| 1640 | } finally { |
| 1641 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1642 | } |
| 1643 | } |
| 1644 | |
| 1645 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1646 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1647 | if (phone != null && phone.isRadioAvailable()) { |
| 1648 | phone.shutdownRadio(); |
| 1649 | } |
| 1650 | } |
| 1651 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1652 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1653 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1654 | |
| 1655 | final long identity = Binder.clearCallingIdentity(); |
| 1656 | try { |
| 1657 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1658 | if (defaultPhone != null) { |
| 1659 | defaultPhone.setRadioPower(turnOn); |
| 1660 | return true; |
| 1661 | } else { |
| 1662 | loge("There's no default phone."); |
| 1663 | return false; |
| 1664 | } |
| 1665 | } finally { |
| 1666 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1667 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1668 | } |
| 1669 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1670 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1671 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1672 | |
| 1673 | final long identity = Binder.clearCallingIdentity(); |
| 1674 | try { |
| 1675 | final Phone phone = getPhone(subId); |
| 1676 | if (phone != null) { |
| 1677 | phone.setRadioPower(turnOn); |
| 1678 | return true; |
| 1679 | } else { |
| 1680 | return false; |
| 1681 | } |
| 1682 | } finally { |
| 1683 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1684 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1685 | } |
| 1686 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1687 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1688 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1689 | public boolean enableDataConnectivity() { |
| 1690 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1691 | |
| 1692 | final long identity = Binder.clearCallingIdentity(); |
| 1693 | try { |
| 1694 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1695 | final Phone phone = getPhone(subId); |
| 1696 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1697 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1698 | return true; |
| 1699 | } else { |
| 1700 | return false; |
| 1701 | } |
| 1702 | } finally { |
| 1703 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1704 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1705 | } |
| 1706 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1707 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1708 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1709 | public boolean disableDataConnectivity() { |
| 1710 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1711 | |
| 1712 | final long identity = Binder.clearCallingIdentity(); |
| 1713 | try { |
| 1714 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1715 | final Phone phone = getPhone(subId); |
| 1716 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1717 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1718 | return true; |
| 1719 | } else { |
| 1720 | return false; |
| 1721 | } |
| 1722 | } finally { |
| 1723 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1724 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1725 | } |
| 1726 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1727 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1728 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1729 | final long identity = Binder.clearCallingIdentity(); |
| 1730 | try { |
| 1731 | final Phone phone = getPhone(subId); |
| 1732 | if (phone != null) { |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1733 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1734 | } else { |
| 1735 | return false; |
| 1736 | } |
| 1737 | } finally { |
| 1738 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1739 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1740 | } |
| 1741 | |
| 1742 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1743 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1744 | } |
| 1745 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1746 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1747 | enforceCallPermission(); |
| 1748 | |
| 1749 | final long identity = Binder.clearCallingIdentity(); |
| 1750 | try { |
| 1751 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1752 | return; |
| 1753 | } |
| 1754 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1755 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1756 | } finally { |
| 1757 | Binder.restoreCallingIdentity(identity); |
| 1758 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1759 | }; |
| 1760 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1761 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1762 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1763 | |
| 1764 | final long identity = Binder.clearCallingIdentity(); |
| 1765 | try { |
| 1766 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1767 | return false; |
| 1768 | } |
| 1769 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1770 | } finally { |
| 1771 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1772 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1775 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1776 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1779 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1780 | final long identity = Binder.clearCallingIdentity(); |
| 1781 | try { |
| 1782 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1783 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1784 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1785 | } finally { |
| 1786 | Binder.restoreCallingIdentity(identity); |
| 1787 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1788 | } |
| 1789 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1790 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1791 | public int getDataState() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1792 | final long identity = Binder.clearCallingIdentity(); |
| 1793 | try { |
| 1794 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1795 | if (phone != null) { |
| 1796 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1797 | } else { |
| 1798 | return PhoneConstantConversions.convertDataState( |
| 1799 | PhoneConstants.DataState.DISCONNECTED); |
| 1800 | } |
| 1801 | } finally { |
| 1802 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1803 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1804 | } |
| 1805 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1806 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1807 | public int getDataActivity() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1808 | final long identity = Binder.clearCallingIdentity(); |
| 1809 | try { |
| 1810 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1811 | if (phone != null) { |
| 1812 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1813 | } else { |
| 1814 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1815 | } |
| 1816 | } finally { |
| 1817 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1818 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1822 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1823 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1824 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1825 | if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage, |
| 1826 | Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1827 | return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1828 | } |
| 1829 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1830 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1831 | final long identity = Binder.clearCallingIdentity(); |
| 1832 | try { |
| 1833 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1834 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1835 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1836 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1837 | cl.fillInNotifierBundle(data); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1838 | return data; |
| 1839 | } finally { |
| 1840 | Binder.restoreCallingIdentity(identity); |
| 1841 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1842 | } |
| 1843 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1844 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1845 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1846 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1847 | // registered cell info, so return a NULL country instead. |
| 1848 | final long identity = Binder.clearCallingIdentity(); |
| 1849 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1850 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1851 | // Get default phone in this case. |
| 1852 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1853 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1854 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1855 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1856 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1857 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1858 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1859 | return ""; |
| 1860 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1861 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1862 | if (phone != null) { |
| 1863 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 1864 | if (sst != null) { |
| 1865 | LocaleTracker lt = sst.getLocaleTracker(); |
| 1866 | if (lt != null) { |
| 1867 | return lt.getCurrentCountry(); |
| 1868 | } |
| 1869 | } |
| 1870 | } |
| 1871 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1872 | } finally { |
| 1873 | Binder.restoreCallingIdentity(identity); |
| 1874 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1878 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1879 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1880 | } |
| 1881 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1882 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1883 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1884 | mApp.enforceCallingOrSelfPermission( |
| 1885 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1886 | |
| 1887 | final long identity = Binder.clearCallingIdentity(); |
| 1888 | try { |
| 1889 | final Phone phone = getPhone(subId); |
| 1890 | if (phone != null) { |
| 1891 | phone.enableLocationUpdates(); |
| 1892 | } |
| 1893 | } finally { |
| 1894 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1895 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1896 | } |
| 1897 | |
| 1898 | @Override |
| 1899 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1900 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1901 | } |
| 1902 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1903 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1904 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1905 | mApp.enforceCallingOrSelfPermission( |
| 1906 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1907 | |
| 1908 | final long identity = Binder.clearCallingIdentity(); |
| 1909 | try { |
| 1910 | final Phone phone = getPhone(subId); |
| 1911 | if (phone != null) { |
| 1912 | phone.disableLocationUpdates(); |
| 1913 | } |
| 1914 | } finally { |
| 1915 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1916 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1917 | } |
| 1918 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1919 | /** |
| 1920 | * Returns the target SDK version number for a given package name. |
| 1921 | * |
| 1922 | * @return target SDK if the package is found or INT_MAX. |
| 1923 | */ |
| 1924 | private int getTargetSdk(String packageName) { |
| 1925 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1926 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo( |
| 1927 | packageName, 0); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1928 | if (ai != null) return ai.targetSdkVersion; |
| 1929 | } catch (PackageManager.NameNotFoundException unexpected) { |
| 1930 | } |
| 1931 | return Integer.MAX_VALUE; |
| 1932 | } |
| 1933 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1934 | @Override |
| 1935 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1936 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 1937 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 1938 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 1939 | throw new SecurityException( |
| 1940 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 1941 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 1942 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1943 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 1944 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 1945 | return null; |
| 1946 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1947 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1948 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1949 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1950 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 1951 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1952 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1953 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 1954 | for (CellInfo ci : info) { |
| 1955 | if (ci instanceof CellInfoGsm) { |
| 1956 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 1957 | } else if (ci instanceof CellInfoWcdma) { |
| 1958 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 1959 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1960 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1961 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1964 | private List<CellInfo> getCachedCellInfo() { |
| 1965 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 1966 | for (Phone phone : PhoneFactory.getPhones()) { |
| 1967 | List<CellInfo> info = phone.getAllCellInfo(); |
| 1968 | if (info != null) cellInfos.addAll(info); |
| 1969 | } |
| 1970 | return cellInfos; |
| 1971 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1972 | |
| 1973 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1974 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1975 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1976 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1977 | if (!LocationAccessPolicy.canAccessCellLocation(mApp, |
Svet Ganov | 4af6628 | 2018-03-07 19:57:05 -0800 | [diff] [blame] | 1978 | callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1979 | return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1980 | } |
| 1981 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1982 | final int targetSdk = getTargetSdk(callingPackage); |
| 1983 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 1984 | return getCachedCellInfo(); |
| 1985 | } |
| 1986 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1987 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1988 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1989 | final long identity = Binder.clearCallingIdentity(); |
| 1990 | try { |
| 1991 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 1992 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1993 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1994 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1995 | if (info != null) cellInfos.addAll(info); |
| 1996 | } |
| 1997 | return cellInfos; |
| 1998 | } finally { |
| 1999 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2000 | } |
| 2001 | } |
| 2002 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2003 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2004 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2005 | requestCellInfoUpdateInternal( |
| 2006 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2007 | } |
| 2008 | |
| 2009 | @Override |
| 2010 | public void requestCellInfoUpdateWithWorkSource( |
| 2011 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2012 | enforceModifyPermission(); |
| 2013 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2014 | } |
| 2015 | |
| 2016 | private void requestCellInfoUpdateInternal( |
| 2017 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2018 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2019 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2020 | if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage, |
| 2021 | Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2022 | return; |
| 2023 | } |
| 2024 | |
| 2025 | final Phone phone = getPhone(subId); |
| 2026 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2027 | |
| 2028 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2029 | } |
| 2030 | |
| 2031 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2032 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2033 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2034 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2035 | |
| 2036 | final long identity = Binder.clearCallingIdentity(); |
| 2037 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2038 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2039 | } finally { |
| 2040 | Binder.restoreCallingIdentity(identity); |
| 2041 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2042 | } |
| 2043 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2044 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2045 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2046 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2047 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2048 | return null; |
| 2049 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2050 | int subId = phone.getSubId(); |
| 2051 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2052 | mApp, subId, callingPackage, "getImeiForSlot")) { |
| 2053 | return null; |
| 2054 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2055 | |
| 2056 | final long identity = Binder.clearCallingIdentity(); |
| 2057 | try { |
| 2058 | return phone.getImei(); |
| 2059 | } finally { |
| 2060 | Binder.restoreCallingIdentity(identity); |
| 2061 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2065 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2066 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2067 | String tac = null; |
| 2068 | if (phone != null) { |
| 2069 | String imei = phone.getImei(); |
| 2070 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2071 | } |
| 2072 | return tac; |
| 2073 | } |
| 2074 | |
| 2075 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2076 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2077 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2078 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2079 | return null; |
| 2080 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2081 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2082 | int subId = phone.getSubId(); |
| 2083 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2084 | mApp, subId, callingPackage, "getMeidForSlot")) { |
| 2085 | return null; |
| 2086 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2087 | |
| 2088 | final long identity = Binder.clearCallingIdentity(); |
| 2089 | try { |
| 2090 | return phone.getMeid(); |
| 2091 | } finally { |
| 2092 | Binder.restoreCallingIdentity(identity); |
| 2093 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2094 | } |
| 2095 | |
| 2096 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2097 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2098 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2099 | String manufacturerCode = null; |
| 2100 | if (phone != null) { |
| 2101 | String meid = phone.getMeid(); |
| 2102 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2103 | } |
| 2104 | return manufacturerCode; |
| 2105 | } |
| 2106 | |
| 2107 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2108 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2109 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2110 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2111 | return null; |
| 2112 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2113 | int subId = phone.getSubId(); |
| 2114 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2115 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2116 | return null; |
| 2117 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2118 | |
| 2119 | final long identity = Binder.clearCallingIdentity(); |
| 2120 | try { |
| 2121 | return phone.getDeviceSvn(); |
| 2122 | } finally { |
| 2123 | Binder.restoreCallingIdentity(identity); |
| 2124 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2125 | } |
| 2126 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2127 | @Override |
| 2128 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2129 | final long identity = Binder.clearCallingIdentity(); |
| 2130 | try { |
| 2131 | final Phone phone = getPhone(subId); |
| 2132 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2133 | } finally { |
| 2134 | Binder.restoreCallingIdentity(identity); |
| 2135 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | @Override |
| 2139 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2140 | final long identity = Binder.clearCallingIdentity(); |
| 2141 | try { |
| 2142 | final Phone phone = getPhone(subId); |
| 2143 | return phone == null ? null : phone.getCarrierName(); |
| 2144 | } finally { |
| 2145 | Binder.restoreCallingIdentity(identity); |
| 2146 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2147 | } |
| 2148 | |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2149 | @Override |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2150 | public int getSubscriptionPreciseCarrierId(int subId) { |
| 2151 | final long identity = Binder.clearCallingIdentity(); |
| 2152 | try { |
| 2153 | final Phone phone = getPhone(subId); |
| 2154 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
| 2155 | : phone.getPreciseCarrierId(); |
| 2156 | } finally { |
| 2157 | Binder.restoreCallingIdentity(identity); |
| 2158 | } |
| 2159 | } |
| 2160 | |
| 2161 | @Override |
| 2162 | public String getSubscriptionPreciseCarrierName(int subId) { |
| 2163 | final long identity = Binder.clearCallingIdentity(); |
| 2164 | try { |
| 2165 | final Phone phone = getPhone(subId); |
| 2166 | return phone == null ? null : phone.getPreciseCarrierName(); |
| 2167 | } finally { |
| 2168 | Binder.restoreCallingIdentity(identity); |
| 2169 | } |
| 2170 | } |
| 2171 | |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2172 | @Override |
chen xu | 4ca4e69 | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2173 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2174 | if (!isSubscriptionMccMnc) { |
| 2175 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2176 | } |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2177 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2178 | if (phone == null) { |
| 2179 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2180 | } |
| 2181 | final long identity = Binder.clearCallingIdentity(); |
| 2182 | try { |
| 2183 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2184 | } finally { |
| 2185 | Binder.restoreCallingIdentity(identity); |
| 2186 | } |
| 2187 | } |
| 2188 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2189 | // |
| 2190 | // Internal helper methods. |
| 2191 | // |
| 2192 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2193 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2194 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2195 | * |
| 2196 | * @throws SecurityException if the caller does not have the required permission |
| 2197 | */ |
| 2198 | private void enforceModifyPermission() { |
| 2199 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2200 | } |
| 2201 | |
| 2202 | /** |
| 2203 | * Make sure the caller has the CALL_PHONE permission. |
| 2204 | * |
| 2205 | * @throws SecurityException if the caller does not have the required permission |
| 2206 | */ |
| 2207 | private void enforceCallPermission() { |
| 2208 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2209 | } |
| 2210 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2211 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2212 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2213 | "ConnectivityService"); |
| 2214 | } |
| 2215 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2216 | private String createTelUrl(String number) { |
| 2217 | if (TextUtils.isEmpty(number)) { |
| 2218 | return null; |
| 2219 | } |
| 2220 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2221 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2222 | } |
| 2223 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2224 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2225 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2226 | } |
| 2227 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2228 | private static void logv(String msg) { |
| 2229 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2230 | } |
| 2231 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2232 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2233 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2234 | } |
| 2235 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2236 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2237 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2238 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2239 | } |
| 2240 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2241 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2242 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2243 | final long identity = Binder.clearCallingIdentity(); |
| 2244 | try { |
| 2245 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2246 | if (phone == null) { |
| 2247 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2248 | } else { |
| 2249 | return phone.getPhoneType(); |
| 2250 | } |
| 2251 | } finally { |
| 2252 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2253 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2254 | } |
| 2255 | |
| 2256 | /** |
| 2257 | * Returns the CDMA ERI icon index to display |
| 2258 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2259 | @Override |
| 2260 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2261 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2262 | } |
| 2263 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2264 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2265 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2266 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2267 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2268 | return -1; |
| 2269 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2270 | |
| 2271 | final long identity = Binder.clearCallingIdentity(); |
| 2272 | try { |
| 2273 | final Phone phone = getPhone(subId); |
| 2274 | if (phone != null) { |
| 2275 | return phone.getCdmaEriIconIndex(); |
| 2276 | } else { |
| 2277 | return -1; |
| 2278 | } |
| 2279 | } finally { |
| 2280 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2281 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2282 | } |
| 2283 | |
| 2284 | /** |
| 2285 | * Returns the CDMA ERI icon mode, |
| 2286 | * 0 - ON |
| 2287 | * 1 - FLASHING |
| 2288 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2289 | @Override |
| 2290 | public int getCdmaEriIconMode(String callingPackage) { |
| 2291 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2292 | } |
| 2293 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2294 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2295 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2296 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2297 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2298 | return -1; |
| 2299 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2300 | |
| 2301 | final long identity = Binder.clearCallingIdentity(); |
| 2302 | try { |
| 2303 | final Phone phone = getPhone(subId); |
| 2304 | if (phone != null) { |
| 2305 | return phone.getCdmaEriIconMode(); |
| 2306 | } else { |
| 2307 | return -1; |
| 2308 | } |
| 2309 | } finally { |
| 2310 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2311 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | /** |
| 2315 | * Returns the CDMA ERI text, |
| 2316 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2317 | @Override |
| 2318 | public String getCdmaEriText(String callingPackage) { |
| 2319 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2320 | } |
| 2321 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2322 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2323 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2324 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2325 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2326 | return null; |
| 2327 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2328 | |
| 2329 | final long identity = Binder.clearCallingIdentity(); |
| 2330 | try { |
| 2331 | final Phone phone = getPhone(subId); |
| 2332 | if (phone != null) { |
| 2333 | return phone.getCdmaEriText(); |
| 2334 | } else { |
| 2335 | return null; |
| 2336 | } |
| 2337 | } finally { |
| 2338 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2339 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2340 | } |
| 2341 | |
| 2342 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2343 | * Returns the CDMA MDN. |
| 2344 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2345 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2346 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2347 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2348 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2349 | |
| 2350 | final long identity = Binder.clearCallingIdentity(); |
| 2351 | try { |
| 2352 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2353 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2354 | return phone.getLine1Number(); |
| 2355 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2356 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2357 | return null; |
| 2358 | } |
| 2359 | } finally { |
| 2360 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2361 | } |
| 2362 | } |
| 2363 | |
| 2364 | /** |
| 2365 | * Returns the CDMA MIN. |
| 2366 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2367 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2368 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2369 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2370 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2371 | |
| 2372 | final long identity = Binder.clearCallingIdentity(); |
| 2373 | try { |
| 2374 | final Phone phone = getPhone(subId); |
| 2375 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2376 | return phone.getCdmaMin(); |
| 2377 | } else { |
| 2378 | return null; |
| 2379 | } |
| 2380 | } finally { |
| 2381 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2382 | } |
| 2383 | } |
| 2384 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2385 | @Override |
| 2386 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2387 | INumberVerificationCallback callback, String callingPackage) { |
| 2388 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2389 | != PERMISSION_GRANTED) { |
| 2390 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2391 | } |
| 2392 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2393 | |
| 2394 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2395 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2396 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2397 | } |
| 2398 | |
| 2399 | if (range == null) { |
| 2400 | throw new NullPointerException("Range must be non-null"); |
| 2401 | } |
| 2402 | |
| 2403 | timeoutMillis = Math.min(timeoutMillis, |
| 2404 | TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS); |
| 2405 | |
| 2406 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2407 | } |
| 2408 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2409 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2410 | * Returns true if CDMA provisioning needs to run. |
| 2411 | */ |
| 2412 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2413 | final long identity = Binder.clearCallingIdentity(); |
| 2414 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2415 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2416 | } finally { |
| 2417 | Binder.restoreCallingIdentity(identity); |
| 2418 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2419 | } |
| 2420 | |
| 2421 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2422 | * Sets the voice mail number of a given subId. |
| 2423 | */ |
| 2424 | @Override |
| 2425 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2426 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2427 | |
| 2428 | final long identity = Binder.clearCallingIdentity(); |
| 2429 | try { |
| 2430 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2431 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2432 | return success; |
| 2433 | } finally { |
| 2434 | Binder.restoreCallingIdentity(identity); |
| 2435 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2436 | } |
| 2437 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2438 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2439 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2440 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2441 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2442 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2443 | throw new SecurityException("caller must be system dialer"); |
| 2444 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2445 | |
| 2446 | final long identity = Binder.clearCallingIdentity(); |
| 2447 | try { |
| 2448 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2449 | if (phoneAccountHandle == null) { |
| 2450 | return null; |
| 2451 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2452 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2453 | } finally { |
| 2454 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2455 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2456 | } |
| 2457 | |
| 2458 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2459 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2460 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2461 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2462 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2463 | return null; |
| 2464 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2465 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2466 | final long identity = Binder.clearCallingIdentity(); |
| 2467 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2468 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2469 | } finally { |
| 2470 | Binder.restoreCallingIdentity(identity); |
| 2471 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2472 | } |
| 2473 | |
| 2474 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2475 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2476 | VisualVoicemailSmsFilterSettings settings) { |
| 2477 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2478 | |
| 2479 | final long identity = Binder.clearCallingIdentity(); |
| 2480 | try { |
| 2481 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2482 | mApp, callingPackage, subId, settings); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2483 | } finally { |
| 2484 | Binder.restoreCallingIdentity(identity); |
| 2485 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2486 | } |
| 2487 | |
| 2488 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2489 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2490 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2491 | |
| 2492 | final long identity = Binder.clearCallingIdentity(); |
| 2493 | try { |
| 2494 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2495 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2496 | } finally { |
| 2497 | Binder.restoreCallingIdentity(identity); |
| 2498 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2499 | } |
| 2500 | |
| 2501 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2502 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2503 | String callingPackage, int subId) { |
| 2504 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2505 | |
| 2506 | final long identity = Binder.clearCallingIdentity(); |
| 2507 | try { |
| 2508 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2509 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2510 | } finally { |
| 2511 | Binder.restoreCallingIdentity(identity); |
| 2512 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2513 | } |
| 2514 | |
| 2515 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2516 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2517 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2518 | |
| 2519 | final long identity = Binder.clearCallingIdentity(); |
| 2520 | try { |
| 2521 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2522 | mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2523 | } finally { |
| 2524 | Binder.restoreCallingIdentity(identity); |
| 2525 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2526 | } |
| 2527 | |
| 2528 | @Override |
| 2529 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2530 | String number, int port, String text, PendingIntent sentIntent) { |
| 2531 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2532 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2533 | enforceSendSmsPermission(); |
| 2534 | // Make the calls as the phone process. |
| 2535 | final long identity = Binder.clearCallingIdentity(); |
| 2536 | try { |
| 2537 | SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); |
| 2538 | if (port == 0) { |
| 2539 | smsManager.sendTextMessageWithSelfPermissions(number, null, text, |
| 2540 | sentIntent, null, false); |
| 2541 | } else { |
| 2542 | byte[] data = text.getBytes(StandardCharsets.UTF_8); |
| 2543 | smsManager.sendDataMessageWithSelfPermissions(number, null, |
| 2544 | (short) port, data, sentIntent, null); |
| 2545 | } |
| 2546 | } finally { |
| 2547 | Binder.restoreCallingIdentity(identity); |
| 2548 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2549 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2550 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2551 | * Sets the voice activation state of a given subId. |
| 2552 | */ |
| 2553 | @Override |
| 2554 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2555 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2556 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2557 | |
| 2558 | final long identity = Binder.clearCallingIdentity(); |
| 2559 | try { |
| 2560 | final Phone phone = getPhone(subId); |
| 2561 | if (phone != null) { |
| 2562 | phone.setVoiceActivationState(activationState); |
| 2563 | } else { |
| 2564 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2565 | } |
| 2566 | } finally { |
| 2567 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2568 | } |
| 2569 | } |
| 2570 | |
| 2571 | /** |
| 2572 | * Sets the data activation state of a given subId. |
| 2573 | */ |
| 2574 | @Override |
| 2575 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2576 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2577 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2578 | |
| 2579 | final long identity = Binder.clearCallingIdentity(); |
| 2580 | try { |
| 2581 | final Phone phone = getPhone(subId); |
| 2582 | if (phone != null) { |
| 2583 | phone.setDataActivationState(activationState); |
| 2584 | } else { |
| 2585 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2586 | } |
| 2587 | } finally { |
| 2588 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2589 | } |
| 2590 | } |
| 2591 | |
| 2592 | /** |
| 2593 | * Returns the voice activation state of a given subId. |
| 2594 | */ |
| 2595 | @Override |
| 2596 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2597 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2598 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2599 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2600 | final long identity = Binder.clearCallingIdentity(); |
| 2601 | try { |
| 2602 | if (phone != null) { |
| 2603 | return phone.getVoiceActivationState(); |
| 2604 | } else { |
| 2605 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2606 | } |
| 2607 | } finally { |
| 2608 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2609 | } |
| 2610 | } |
| 2611 | |
| 2612 | /** |
| 2613 | * Returns the data activation state of a given subId. |
| 2614 | */ |
| 2615 | @Override |
| 2616 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2617 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2618 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2619 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2620 | final long identity = Binder.clearCallingIdentity(); |
| 2621 | try { |
| 2622 | if (phone != null) { |
| 2623 | return phone.getDataActivationState(); |
| 2624 | } else { |
| 2625 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2626 | } |
| 2627 | } finally { |
| 2628 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2629 | } |
| 2630 | } |
| 2631 | |
| 2632 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2633 | * Returns the unread count of voicemails for a subId |
| 2634 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2635 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2636 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2637 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2638 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2639 | return 0; |
| 2640 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2641 | final long identity = Binder.clearCallingIdentity(); |
| 2642 | try { |
| 2643 | final Phone phone = getPhone(subId); |
| 2644 | if (phone != null) { |
| 2645 | return phone.getVoiceMessageCount(); |
| 2646 | } else { |
| 2647 | return 0; |
| 2648 | } |
| 2649 | } finally { |
| 2650 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2651 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2655 | * returns true, if the device is in a state where both voice and data |
| 2656 | * are supported simultaneously. This can change based on location or network condition. |
| 2657 | */ |
| 2658 | @Override |
| 2659 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
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 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2664 | } finally { |
| 2665 | Binder.restoreCallingIdentity(identity); |
| 2666 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2667 | } |
| 2668 | |
| 2669 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2670 | * Send the dialer code if called from the current default dialer or the caller has |
| 2671 | * carrier privilege. |
| 2672 | * @param inputCode The dialer code to send |
| 2673 | */ |
| 2674 | @Override |
| 2675 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2676 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2677 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2678 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2679 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2680 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2681 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2682 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2683 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2684 | |
| 2685 | final long identity = Binder.clearCallingIdentity(); |
| 2686 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2687 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2688 | } finally { |
| 2689 | Binder.restoreCallingIdentity(identity); |
| 2690 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | /** |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2694 | * Returns the data network type. |
| 2695 | * Legacy call, permission-free. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2696 | * |
| 2697 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 2698 | */ |
| 2699 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2700 | public int getNetworkType() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2701 | final long identity = Binder.clearCallingIdentity(); |
| 2702 | try { |
| 2703 | final Phone phone = getPhone(getDefaultSubscription()); |
| 2704 | if (phone != null) { |
| 2705 | return phone.getServiceState().getDataNetworkType(); |
| 2706 | } else { |
| 2707 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2708 | } |
| 2709 | } finally { |
| 2710 | Binder.restoreCallingIdentity(identity); |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2711 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2712 | } |
| 2713 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2714 | @Override |
| 2715 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2716 | if (!isActiveSubscription(subId)) { |
| 2717 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2718 | } |
| 2719 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2720 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2721 | } |
| 2722 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2723 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2724 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2725 | throws RemoteException { |
| 2726 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2727 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2728 | final long token = Binder.clearCallingIdentity(); |
| 2729 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2730 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2731 | .addRegistrationCallbackForSubscription(c, subId); |
| 2732 | } finally { |
| 2733 | Binder.restoreCallingIdentity(token); |
| 2734 | } |
| 2735 | } |
| 2736 | |
| 2737 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2738 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2739 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2740 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2741 | Binder.withCleanCallingIdentity(() -> |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2742 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2743 | .removeRegistrationCallbackForSubscription(c, subId)); |
| 2744 | } |
| 2745 | |
| 2746 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2747 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2748 | throws RemoteException { |
| 2749 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2750 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2751 | final long token = Binder.clearCallingIdentity(); |
| 2752 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2753 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2754 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2755 | } finally { |
| 2756 | Binder.restoreCallingIdentity(token); |
| 2757 | } |
| 2758 | } |
| 2759 | |
| 2760 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2761 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2762 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2763 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2764 | Binder.withCleanCallingIdentity(() -> |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2765 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2766 | .removeCapabilitiesCallbackForSubscription(c, subId)); |
| 2767 | } |
| 2768 | |
| 2769 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2770 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2771 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2772 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2773 | final long token = Binder.clearCallingIdentity(); |
| 2774 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2775 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2776 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2777 | } catch (ImsException e) { |
| 2778 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2779 | return false; |
| 2780 | } finally { |
| 2781 | Binder.restoreCallingIdentity(token); |
| 2782 | } |
| 2783 | } |
| 2784 | |
| 2785 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2786 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2787 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2788 | final long token = Binder.clearCallingIdentity(); |
| 2789 | try { |
| 2790 | Phone phone = getPhone(subId); |
| 2791 | if (phone == null) return false; |
| 2792 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2793 | } finally { |
| 2794 | Binder.restoreCallingIdentity(token); |
| 2795 | } |
| 2796 | } |
| 2797 | |
| 2798 | @Override |
| 2799 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2800 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2801 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2802 | final long token = Binder.clearCallingIdentity(); |
| 2803 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2804 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2805 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2806 | } finally { |
| 2807 | Binder.restoreCallingIdentity(token); |
| 2808 | } |
| 2809 | } |
| 2810 | |
| 2811 | @Override |
| 2812 | public void setAdvancedCallingSetting(int subId, boolean isEnabled) { |
| 2813 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2814 | "setAdvancedCallingSetting"); |
| 2815 | final long identity = Binder.clearCallingIdentity(); |
| 2816 | try { |
| 2817 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2818 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2819 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 2820 | } finally { |
| 2821 | Binder.restoreCallingIdentity(identity); |
| 2822 | } |
| 2823 | } |
| 2824 | |
| 2825 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2826 | public boolean isVtSettingEnabled(int subId) { |
| 2827 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2828 | final long identity = Binder.clearCallingIdentity(); |
| 2829 | try { |
| 2830 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2831 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2832 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2833 | } finally { |
| 2834 | Binder.restoreCallingIdentity(identity); |
| 2835 | } |
| 2836 | } |
| 2837 | |
| 2838 | @Override |
| 2839 | public void setVtSetting(int subId, boolean isEnabled) { |
| 2840 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2841 | "setVtSetting"); |
| 2842 | final long identity = Binder.clearCallingIdentity(); |
| 2843 | try { |
| 2844 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2845 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2846 | } finally { |
| 2847 | Binder.restoreCallingIdentity(identity); |
| 2848 | } |
| 2849 | } |
| 2850 | |
| 2851 | @Override |
| 2852 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 2853 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 2854 | final long identity = Binder.clearCallingIdentity(); |
| 2855 | try { |
| 2856 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2857 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2858 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 2859 | } finally { |
| 2860 | Binder.restoreCallingIdentity(identity); |
| 2861 | } |
| 2862 | } |
| 2863 | |
| 2864 | @Override |
| 2865 | public void setVoWiFiSetting(int subId, boolean isEnabled) { |
| 2866 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2867 | "setVoWiFiSetting"); |
| 2868 | final long identity = Binder.clearCallingIdentity(); |
| 2869 | try { |
| 2870 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2871 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2872 | } finally { |
| 2873 | Binder.restoreCallingIdentity(identity); |
| 2874 | } |
| 2875 | } |
| 2876 | |
| 2877 | @Override |
| 2878 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 2879 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 2880 | final long identity = Binder.clearCallingIdentity(); |
| 2881 | try { |
| 2882 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2883 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2884 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 2885 | } finally { |
| 2886 | Binder.restoreCallingIdentity(identity); |
| 2887 | } |
| 2888 | } |
| 2889 | |
| 2890 | @Override |
| 2891 | public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) { |
| 2892 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2893 | "setVoWiFiRoamingSetting"); |
| 2894 | final long identity = Binder.clearCallingIdentity(); |
| 2895 | try { |
| 2896 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2897 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2898 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 2899 | } finally { |
| 2900 | Binder.restoreCallingIdentity(identity); |
| 2901 | } |
| 2902 | } |
| 2903 | |
| 2904 | @Override |
| 2905 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 2906 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2907 | "setVoWiFiNonPersistent"); |
| 2908 | final long identity = Binder.clearCallingIdentity(); |
| 2909 | try { |
| 2910 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2911 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2912 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
| 2913 | } finally { |
| 2914 | Binder.restoreCallingIdentity(identity); |
| 2915 | } |
| 2916 | } |
| 2917 | |
| 2918 | @Override |
| 2919 | public int getVoWiFiModeSetting(int subId) { |
| 2920 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 2921 | final long identity = Binder.clearCallingIdentity(); |
| 2922 | try { |
| 2923 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2924 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2925 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 2926 | } finally { |
| 2927 | Binder.restoreCallingIdentity(identity); |
| 2928 | } |
| 2929 | } |
| 2930 | |
| 2931 | @Override |
| 2932 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 2933 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2934 | "setVoWiFiModeSetting"); |
| 2935 | final long identity = Binder.clearCallingIdentity(); |
| 2936 | try { |
| 2937 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2938 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2939 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 2940 | } finally { |
| 2941 | Binder.restoreCallingIdentity(identity); |
| 2942 | } |
| 2943 | } |
| 2944 | |
| 2945 | @Override |
| 2946 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 2947 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 2948 | final long identity = Binder.clearCallingIdentity(); |
| 2949 | try { |
| 2950 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2951 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2952 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 2953 | } finally { |
| 2954 | Binder.restoreCallingIdentity(identity); |
| 2955 | } |
| 2956 | } |
| 2957 | |
| 2958 | @Override |
| 2959 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 2960 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2961 | "setVoWiFiRoamingModeSetting"); |
| 2962 | final long identity = Binder.clearCallingIdentity(); |
| 2963 | try { |
| 2964 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2965 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2966 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 2967 | } finally { |
| 2968 | Binder.restoreCallingIdentity(identity); |
| 2969 | } |
| 2970 | } |
| 2971 | |
| 2972 | @Override |
| 2973 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 2974 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2975 | "setRttCapabilityEnabled"); |
| 2976 | final long identity = Binder.clearCallingIdentity(); |
| 2977 | try { |
| 2978 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2979 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2980 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 2981 | } finally { |
| 2982 | Binder.restoreCallingIdentity(identity); |
| 2983 | } |
| 2984 | } |
| 2985 | |
| 2986 | @Override |
| 2987 | public boolean isTtyOverVolteEnabled(int subId) { |
| 2988 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 2989 | final long identity = Binder.clearCallingIdentity(); |
| 2990 | try { |
| 2991 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2992 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2993 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 2994 | } finally { |
| 2995 | Binder.restoreCallingIdentity(identity); |
| 2996 | } |
| 2997 | } |
| 2998 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 2999 | @Override |
| 3000 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3001 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3002 | final long identity = Binder.clearCallingIdentity(); |
| 3003 | try { |
| 3004 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3005 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3006 | .getConfigInterface().addConfigCallback(callback); |
| 3007 | } catch (ImsException e) { |
| 3008 | throw new IllegalArgumentException(e.getMessage()); |
| 3009 | } finally { |
| 3010 | Binder.restoreCallingIdentity(identity); |
| 3011 | } |
| 3012 | } |
| 3013 | |
| 3014 | @Override |
| 3015 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3016 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3017 | final long identity = Binder.clearCallingIdentity(); |
| 3018 | try { |
| 3019 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3020 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3021 | .getConfigInterface().removeConfigCallback(callback); |
| 3022 | } catch (ImsException e) { |
| 3023 | throw new IllegalArgumentException(e.getMessage()); |
| 3024 | } finally { |
| 3025 | Binder.restoreCallingIdentity(identity); |
| 3026 | } |
| 3027 | } |
| 3028 | |
| 3029 | @Override |
| 3030 | public int getImsProvisioningInt(int subId, int key) { |
| 3031 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3032 | final long identity = Binder.clearCallingIdentity(); |
| 3033 | try { |
| 3034 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3035 | return ImsManager.getInstance(mApp, |
| 3036 | getSlotIndexOrException(subId)).getConfigInterface().getConfigInt(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3037 | } catch (ImsException e) { |
| 3038 | throw new IllegalArgumentException(e.getMessage()); |
| 3039 | } finally { |
| 3040 | Binder.restoreCallingIdentity(identity); |
| 3041 | } |
| 3042 | } |
| 3043 | |
| 3044 | @Override |
| 3045 | public String getImsProvisioningString(int subId, int key) { |
| 3046 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3047 | final long identity = Binder.clearCallingIdentity(); |
| 3048 | try { |
| 3049 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3050 | return ImsManager.getInstance(mApp, |
| 3051 | getSlotIndexOrException(subId)).getConfigInterface().getConfigString(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3052 | } catch (ImsException e) { |
| 3053 | throw new IllegalArgumentException(e.getMessage()); |
| 3054 | } finally { |
| 3055 | Binder.restoreCallingIdentity(identity); |
| 3056 | } |
| 3057 | } |
| 3058 | |
| 3059 | @Override |
| 3060 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3061 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3062 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3063 | final long identity = Binder.clearCallingIdentity(); |
| 3064 | try { |
| 3065 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3066 | return ImsManager.getInstance(mApp, |
| 3067 | getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3068 | } catch (ImsException e) { |
| 3069 | throw new IllegalArgumentException(e.getMessage()); |
| 3070 | } finally { |
| 3071 | Binder.restoreCallingIdentity(identity); |
| 3072 | } |
| 3073 | } |
| 3074 | |
| 3075 | @Override |
| 3076 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3077 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3078 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3079 | final long identity = Binder.clearCallingIdentity(); |
| 3080 | try { |
| 3081 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3082 | return ImsManager.getInstance(mApp, |
| 3083 | getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3084 | } catch (ImsException e) { |
| 3085 | throw new IllegalArgumentException(e.getMessage()); |
| 3086 | } finally { |
| 3087 | Binder.restoreCallingIdentity(identity); |
| 3088 | } |
| 3089 | } |
| 3090 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3091 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 3092 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3093 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3094 | throw new IllegalArgumentException("Invalid Subscription Id."); |
| 3095 | } |
| 3096 | return slotId; |
| 3097 | } |
| 3098 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3099 | /** |
| 3100 | * Returns the network type for a subId |
| 3101 | */ |
| 3102 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3103 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3104 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3105 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3106 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3107 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3108 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3109 | final long identity = Binder.clearCallingIdentity(); |
| 3110 | try { |
| 3111 | final Phone phone = getPhone(subId); |
| 3112 | if (phone != null) { |
| 3113 | return phone.getServiceState().getDataNetworkType(); |
| 3114 | } else { |
| 3115 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3116 | } |
| 3117 | } finally { |
| 3118 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3119 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3120 | } |
| 3121 | |
| 3122 | /** |
| 3123 | * Returns the data network type |
| 3124 | */ |
| 3125 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3126 | public int getDataNetworkType(String callingPackage) { |
| 3127 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3128 | } |
| 3129 | |
| 3130 | /** |
| 3131 | * Returns the data network type for a subId |
| 3132 | */ |
| 3133 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3134 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3135 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3136 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3137 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3138 | } |
| 3139 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3140 | final long identity = Binder.clearCallingIdentity(); |
| 3141 | try { |
| 3142 | final Phone phone = getPhone(subId); |
| 3143 | if (phone != null) { |
| 3144 | return phone.getServiceState().getDataNetworkType(); |
| 3145 | } else { |
| 3146 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3147 | } |
| 3148 | } finally { |
| 3149 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3150 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3151 | } |
| 3152 | |
| 3153 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3154 | * Returns the Voice network type for a subId |
| 3155 | */ |
| 3156 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3157 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3158 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3159 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3160 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3161 | } |
| 3162 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3163 | final long identity = Binder.clearCallingIdentity(); |
| 3164 | try { |
| 3165 | final Phone phone = getPhone(subId); |
| 3166 | if (phone != null) { |
| 3167 | return phone.getServiceState().getVoiceNetworkType(); |
| 3168 | } else { |
| 3169 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3170 | } |
| 3171 | } finally { |
| 3172 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3173 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3174 | } |
| 3175 | |
| 3176 | /** |
| 3177 | * @return true if a ICC card is present |
| 3178 | */ |
| 3179 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3180 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3181 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3182 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3183 | } |
| 3184 | |
| 3185 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3186 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3187 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3188 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3189 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3190 | final long identity = Binder.clearCallingIdentity(); |
| 3191 | try { |
| 3192 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3193 | if (phone != null) { |
| 3194 | return phone.getIccCard().hasIccCard(); |
| 3195 | } else { |
| 3196 | return false; |
| 3197 | } |
| 3198 | } finally { |
| 3199 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3200 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3201 | } |
| 3202 | |
| 3203 | /** |
| 3204 | * Return if the current radio is LTE on CDMA. This |
| 3205 | * is a tri-state return value as for a period of time |
| 3206 | * the mode may be unknown. |
| 3207 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3208 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3209 | * @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] | 3210 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3211 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3212 | @Override |
| 3213 | public int getLteOnCdmaMode(String callingPackage) { |
| 3214 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3215 | } |
| 3216 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3217 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3218 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3219 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3220 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3221 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3222 | } |
| 3223 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3224 | final long identity = Binder.clearCallingIdentity(); |
| 3225 | try { |
| 3226 | final Phone phone = getPhone(subId); |
| 3227 | if (phone == null) { |
| 3228 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3229 | } else { |
| 3230 | return phone.getLteOnCdmaMode(); |
| 3231 | } |
| 3232 | } finally { |
| 3233 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3234 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3235 | } |
| 3236 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3237 | /** |
| 3238 | * {@hide} |
| 3239 | * Returns Default subId, 0 in the case of single standby. |
| 3240 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3241 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3242 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3243 | } |
| 3244 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3245 | private int getSlotForDefaultSubscription() { |
| 3246 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3247 | } |
| 3248 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3249 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3250 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3251 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3252 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3253 | private boolean isActiveSubscription(int subId) { |
| 3254 | return mSubscriptionController.isActiveSubId(subId); |
| 3255 | } |
| 3256 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3257 | /** |
| 3258 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3259 | */ |
| 3260 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3261 | final long identity = Binder.clearCallingIdentity(); |
| 3262 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3263 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3264 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3265 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3266 | } finally { |
| 3267 | Binder.restoreCallingIdentity(identity); |
| 3268 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3269 | } |
| 3270 | |
| 3271 | /** |
| 3272 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3273 | */ |
| 3274 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3275 | final long identity = Binder.clearCallingIdentity(); |
| 3276 | try { |
| 3277 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3278 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3279 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3280 | } finally { |
| 3281 | Binder.restoreCallingIdentity(identity); |
| 3282 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3283 | } |
| 3284 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3285 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3286 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3287 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3288 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3289 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3290 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3291 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3292 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3293 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3294 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3295 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3296 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3297 | final long identity = Binder.clearCallingIdentity(); |
| 3298 | try { |
| 3299 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3300 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3301 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3302 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3303 | if (bestComponent == null |
| 3304 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3305 | loge("The calling package is not allowed to access ISD-R."); |
| 3306 | throw new SecurityException( |
| 3307 | "The calling package is not allowed to access ISD-R."); |
| 3308 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3309 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3310 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3311 | if (DBG) { |
| 3312 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3313 | } |
| 3314 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
| 3315 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId); |
| 3316 | if (DBG) log("iccOpenLogicalChannel: " + response); |
| 3317 | return response; |
| 3318 | } finally { |
| 3319 | Binder.restoreCallingIdentity(identity); |
| 3320 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3324 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3325 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3326 | mApp, subId, "iccCloseLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3327 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3328 | final long identity = Binder.clearCallingIdentity(); |
| 3329 | try { |
| 3330 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3331 | if (channel < 0) { |
| 3332 | return false; |
| 3333 | } |
| 3334 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId); |
| 3335 | if (DBG) log("iccCloseLogicalChannel: " + success); |
| 3336 | return success; |
| 3337 | } finally { |
| 3338 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3339 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3340 | } |
| 3341 | |
| 3342 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3343 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3344 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3345 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3346 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3347 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3348 | final long identity = Binder.clearCallingIdentity(); |
| 3349 | try { |
| 3350 | if (DBG) { |
| 3351 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3352 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3353 | + p3 + " data=" + data); |
| 3354 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3355 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3356 | if (channel < 0) { |
| 3357 | return ""; |
| 3358 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3359 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3360 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
| 3361 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId); |
| 3362 | if (DBG) log("iccTransmitApduLogicalChannel: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3363 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3364 | // Append the returned status code to the end of the response payload. |
| 3365 | String s = Integer.toHexString( |
| 3366 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3367 | if (response.payload != null) { |
| 3368 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3369 | } |
| 3370 | return s; |
| 3371 | } finally { |
| 3372 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3373 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3374 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3375 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3376 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3377 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3378 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3379 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3380 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3381 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3382 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3383 | final long identity = Binder.clearCallingIdentity(); |
| 3384 | try { |
| 3385 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3386 | && TextUtils.equals(ISDR_AID, data)) { |
| 3387 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3388 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3389 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3390 | if (bestComponent == null |
| 3391 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3392 | loge("The calling package is not allowed to select ISD-R."); |
| 3393 | throw new SecurityException( |
| 3394 | "The calling package is not allowed to select ISD-R."); |
| 3395 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3396 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3397 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3398 | if (DBG) { |
| 3399 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3400 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3401 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3402 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3403 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
| 3404 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId); |
| 3405 | if (DBG) log("iccTransmitApduBasicChannel: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3406 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3407 | // Append the returned status code to the end of the response payload. |
| 3408 | String s = Integer.toHexString( |
| 3409 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3410 | if (response.payload != null) { |
| 3411 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3412 | } |
| 3413 | return s; |
| 3414 | } finally { |
| 3415 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3416 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3417 | } |
| 3418 | |
| 3419 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3420 | 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] | 3421 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3422 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3423 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3424 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3425 | final long identity = Binder.clearCallingIdentity(); |
| 3426 | try { |
| 3427 | if (DBG) { |
| 3428 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3429 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3430 | } |
| 3431 | |
| 3432 | IccIoResult response = |
| 3433 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3434 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3435 | subId); |
| 3436 | |
| 3437 | if (DBG) { |
| 3438 | log("Exchange SIM_IO [R]" + response); |
| 3439 | } |
| 3440 | |
| 3441 | byte[] result = null; |
| 3442 | int length = 2; |
| 3443 | if (response.payload != null) { |
| 3444 | length = 2 + response.payload.length; |
| 3445 | result = new byte[length]; |
| 3446 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3447 | } else { |
| 3448 | result = new byte[length]; |
| 3449 | } |
| 3450 | |
| 3451 | result[length - 1] = (byte) response.sw2; |
| 3452 | result[length - 2] = (byte) response.sw1; |
| 3453 | return result; |
| 3454 | } finally { |
| 3455 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3456 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3457 | } |
| 3458 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3459 | /** |
| 3460 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 3461 | * on a particular subscription |
| 3462 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3463 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 3464 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3465 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 3466 | return null; |
| 3467 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3468 | |
| 3469 | final long identity = Binder.clearCallingIdentity(); |
| 3470 | try { |
| 3471 | if (appType != TelephonyManager.APPTYPE_USIM |
| 3472 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 3473 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 3474 | return null; |
| 3475 | } |
| 3476 | Object response = sendRequest( |
| 3477 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 3478 | if (response instanceof String[]) { |
| 3479 | return (String[]) response; |
| 3480 | } |
| 3481 | // Response is an Exception of some kind, |
| 3482 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3483 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3484 | } finally { |
| 3485 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3486 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3487 | } |
| 3488 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3489 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3490 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3491 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3492 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3493 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3494 | final long identity = Binder.clearCallingIdentity(); |
| 3495 | try { |
| 3496 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 3497 | if (response.payload == null) { |
| 3498 | return ""; |
| 3499 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3500 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3501 | // Append the returned status code to the end of the response payload. |
| 3502 | String s = Integer.toHexString( |
| 3503 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3504 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3505 | return s; |
| 3506 | } finally { |
| 3507 | Binder.restoreCallingIdentity(identity); |
| 3508 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3509 | } |
| 3510 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3511 | /** |
| 3512 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3513 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3514 | * |
| 3515 | * @param itemID the ID of the item to read |
| 3516 | * @return the NV item as a String, or null on error. |
| 3517 | */ |
| 3518 | @Override |
| 3519 | public String nvReadItem(int itemID) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3520 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3521 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3522 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3523 | |
| 3524 | final long identity = Binder.clearCallingIdentity(); |
| 3525 | try { |
| 3526 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3527 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3528 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 3529 | return value; |
| 3530 | } finally { |
| 3531 | Binder.restoreCallingIdentity(identity); |
| 3532 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3533 | } |
| 3534 | |
| 3535 | /** |
| 3536 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3537 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3538 | * |
| 3539 | * @param itemID the ID of the item to read |
| 3540 | * @param itemValue the value to write, as a String |
| 3541 | * @return true on success; false on any failure |
| 3542 | */ |
| 3543 | @Override |
| 3544 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3545 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3546 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3547 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3548 | |
| 3549 | final long identity = Binder.clearCallingIdentity(); |
| 3550 | try { |
| 3551 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 3552 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3553 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3554 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 3555 | return success; |
| 3556 | } finally { |
| 3557 | Binder.restoreCallingIdentity(identity); |
| 3558 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3559 | } |
| 3560 | |
| 3561 | /** |
| 3562 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 3563 | * Used for device configuration by some CDMA operators. |
| 3564 | * |
| 3565 | * @param preferredRoamingList byte array containing the new PRL |
| 3566 | * @return true on success; false on any failure |
| 3567 | */ |
| 3568 | @Override |
| 3569 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3570 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3571 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3572 | |
| 3573 | final long identity = Binder.clearCallingIdentity(); |
| 3574 | try { |
| 3575 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 3576 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 3577 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 3578 | return success; |
| 3579 | } finally { |
| 3580 | Binder.restoreCallingIdentity(identity); |
| 3581 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3582 | } |
| 3583 | |
| 3584 | /** |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3585 | * 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] | 3586 | * Used for device configuration by some CDMA operators. |
| 3587 | * |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3588 | * @param slotIndex - device slot. |
| 3589 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3590 | * @return true on success; false on any failure |
| 3591 | */ |
| 3592 | @Override |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3593 | public boolean resetModemConfig(int slotIndex) { |
| 3594 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3595 | if (phone != null) { |
| 3596 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3597 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3598 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3599 | final long identity = Binder.clearCallingIdentity(); |
| 3600 | try { |
| 3601 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 3602 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 3603 | return success; |
| 3604 | } finally { |
| 3605 | Binder.restoreCallingIdentity(identity); |
| 3606 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3607 | } |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3608 | return false; |
| 3609 | } |
| 3610 | |
| 3611 | /** |
| 3612 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 3613 | * |
| 3614 | * @param slotIndex - device slot. |
| 3615 | * |
| 3616 | * @return true on success; false on any failure |
| 3617 | */ |
| 3618 | @Override |
| 3619 | public boolean rebootModem(int slotIndex) { |
| 3620 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3621 | if (phone != null) { |
| 3622 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3623 | mApp, phone.getSubId(), "rebootModem"); |
| 3624 | |
| 3625 | final long identity = Binder.clearCallingIdentity(); |
| 3626 | try { |
| 3627 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 3628 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 3629 | return success; |
| 3630 | } finally { |
| 3631 | Binder.restoreCallingIdentity(identity); |
| 3632 | } |
| 3633 | } |
| 3634 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3635 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3636 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3637 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3638 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3639 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3640 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3641 | return new String[0]; |
| 3642 | } |
| 3643 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3644 | final long identity = Binder.clearCallingIdentity(); |
| 3645 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3646 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3647 | } finally { |
| 3648 | Binder.restoreCallingIdentity(identity); |
| 3649 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3650 | } |
| 3651 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3652 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3653 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 3654 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3655 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3656 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3657 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3658 | |
| 3659 | final long identity = Binder.clearCallingIdentity(); |
| 3660 | try { |
| 3661 | PhoneFactory.getImsResolver().enableIms(slotId); |
| 3662 | } finally { |
| 3663 | Binder.restoreCallingIdentity(identity); |
| 3664 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3665 | } |
| 3666 | |
| 3667 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3668 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 3669 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3670 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3671 | public void disableIms(int slotId) { |
| 3672 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3673 | |
| 3674 | final long identity = Binder.clearCallingIdentity(); |
| 3675 | try { |
| 3676 | PhoneFactory.getImsResolver().disableIms(slotId); |
| 3677 | } finally { |
| 3678 | Binder.restoreCallingIdentity(identity); |
| 3679 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3680 | } |
| 3681 | |
| 3682 | /** |
| 3683 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 3684 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 3685 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 3686 | */ |
| 3687 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3688 | IImsServiceFeatureCallback callback) { |
| 3689 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3690 | |
| 3691 | final long identity = Binder.clearCallingIdentity(); |
| 3692 | try { |
| 3693 | return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback); |
| 3694 | } finally { |
| 3695 | Binder.restoreCallingIdentity(identity); |
| 3696 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3697 | } |
| 3698 | |
| 3699 | /** |
| 3700 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 3701 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 3702 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 3703 | * listener for feature updates. |
| 3704 | */ |
| 3705 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 3706 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3707 | |
| 3708 | final long identity = Binder.clearCallingIdentity(); |
| 3709 | try { |
| 3710 | return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback); |
| 3711 | } finally { |
| 3712 | Binder.restoreCallingIdentity(identity); |
| 3713 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3714 | } |
| 3715 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 3716 | /** |
| 3717 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
| 3718 | * specified. |
| 3719 | */ |
| 3720 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 3721 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3722 | |
| 3723 | final long identity = Binder.clearCallingIdentity(); |
| 3724 | try { |
| 3725 | return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature); |
| 3726 | } finally { |
| 3727 | Binder.restoreCallingIdentity(identity); |
| 3728 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 3729 | } |
| 3730 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3731 | /** |
| 3732 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
| 3733 | * specified. |
| 3734 | */ |
| 3735 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 3736 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3737 | |
| 3738 | final long identity = Binder.clearCallingIdentity(); |
| 3739 | try { |
| 3740 | return PhoneFactory.getImsResolver().getImsConfig(slotId, feature); |
| 3741 | } finally { |
| 3742 | Binder.restoreCallingIdentity(identity); |
| 3743 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3744 | } |
| 3745 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 3746 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 3747 | * Sets the ImsService Package Name that Telephony will bind to. |
| 3748 | * |
| 3749 | * @param slotId the slot ID that the ImsService should bind for. |
| 3750 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 3751 | * ImsService is the device default ImsService. |
| 3752 | * @param packageName The package name of the application that contains the ImsService to bind |
| 3753 | * to. |
| 3754 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 3755 | * @hide |
| 3756 | */ |
| 3757 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 3758 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 3759 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 3760 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 3761 | "setImsService"); |
| 3762 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3763 | final long identity = Binder.clearCallingIdentity(); |
| 3764 | try { |
| 3765 | return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId, |
| 3766 | isCarrierImsService, packageName); |
| 3767 | } finally { |
| 3768 | Binder.restoreCallingIdentity(identity); |
| 3769 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 3770 | } |
| 3771 | |
| 3772 | /** |
| 3773 | * Return the ImsService configuration. |
| 3774 | * |
| 3775 | * @param slotId The slot that the ImsService is associated with. |
| 3776 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 3777 | * the device default. |
| 3778 | * @return the package name of the ImsService configuration. |
| 3779 | */ |
| 3780 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 3781 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 3782 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 3783 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 3784 | "getImsService"); |
| 3785 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3786 | final long identity = Binder.clearCallingIdentity(); |
| 3787 | try { |
| 3788 | return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId, |
| 3789 | isCarrierImsService); |
| 3790 | } finally { |
| 3791 | Binder.restoreCallingIdentity(identity); |
| 3792 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 3793 | } |
| 3794 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3795 | public void setImsRegistrationState(boolean registered) { |
| 3796 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3797 | |
| 3798 | final long identity = Binder.clearCallingIdentity(); |
| 3799 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3800 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3801 | } finally { |
| 3802 | Binder.restoreCallingIdentity(identity); |
| 3803 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3804 | } |
| 3805 | |
| 3806 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3807 | * Set the network selection mode to automatic. |
| 3808 | * |
| 3809 | */ |
| 3810 | @Override |
| 3811 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3812 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3813 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3814 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3815 | if (!isActiveSubscription(subId)) { |
| 3816 | return; |
| 3817 | } |
| 3818 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3819 | final long identity = Binder.clearCallingIdentity(); |
| 3820 | try { |
| 3821 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 3822 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 3823 | } finally { |
| 3824 | Binder.restoreCallingIdentity(identity); |
| 3825 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3826 | } |
| 3827 | |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3828 | /** |
| 3829 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 3830 | * |
| 3831 | * @param subId the id of the subscription. |
| 3832 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 3833 | * the operator to attach to. |
| 3834 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 3835 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 3836 | * normal network selection next time. |
| 3837 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 3838 | */ |
| 3839 | @Override |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3840 | public boolean setNetworkSelectionModeManual( |
| 3841 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3842 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3843 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3844 | |
| 3845 | if (!isActiveSubscription(subId)) { |
| 3846 | return false; |
| 3847 | } |
| 3848 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3849 | final long identity = Binder.clearCallingIdentity(); |
| 3850 | try { |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3851 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3852 | persistSelection); |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3853 | if (DBG) { |
| 3854 | log("setNetworkSelectionModeManual: subId: " + subId |
| 3855 | + " operator: " + operatorInfo); |
| 3856 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3857 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 3858 | } finally { |
| 3859 | Binder.restoreCallingIdentity(identity); |
| 3860 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 3861 | } |
| 3862 | |
| 3863 | /** |
| 3864 | * Scans for available networks. |
| 3865 | */ |
| 3866 | @Override |
| 3867 | public CellNetworkScanResult getCellNetworkScanResults(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3868 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3869 | mApp, subId, "getCellNetworkScanResults"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3870 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3871 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3872 | try { |
| 3873 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3874 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3875 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3876 | } finally { |
| 3877 | Binder.restoreCallingIdentity(identity); |
| 3878 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 3879 | } |
| 3880 | |
| 3881 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3882 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3883 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3884 | * @param subId id of the subscription |
| 3885 | * @param request contains the radio access networks with bands/channels to scan |
| 3886 | * @param messenger callback messenger for scan results or errors |
| 3887 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3888 | * @return the id of the requested scan which can be used to stop the scan. |
| 3889 | */ |
| 3890 | @Override |
| 3891 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
| 3892 | IBinder binder) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3893 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3894 | mApp, subId, "requestNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3895 | |
| 3896 | final long identity = Binder.clearCallingIdentity(); |
| 3897 | try { |
| 3898 | return mNetworkScanRequestTracker.startNetworkScan( |
| 3899 | request, messenger, binder, getPhone(subId)); |
| 3900 | } finally { |
| 3901 | Binder.restoreCallingIdentity(identity); |
| 3902 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3903 | } |
| 3904 | |
| 3905 | /** |
| 3906 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3907 | * |
| 3908 | * @param subId id of the subscription |
| 3909 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3910 | */ |
| 3911 | @Override |
| 3912 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3913 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3914 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3915 | |
| 3916 | final long identity = Binder.clearCallingIdentity(); |
| 3917 | try { |
| 3918 | mNetworkScanRequestTracker.stopNetworkScan(scanId); |
| 3919 | } finally { |
| 3920 | Binder.restoreCallingIdentity(identity); |
| 3921 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3922 | } |
| 3923 | |
| 3924 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 3925 | * Get the calculated preferred network type. |
| 3926 | * Used for debugging incorrect network type. |
| 3927 | * |
| 3928 | * @return the preferred network type, defined in RILConstants.java. |
| 3929 | */ |
| 3930 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3931 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3932 | final Phone defaultPhone = getDefaultPhone(); |
| 3933 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 3934 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3935 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 3936 | } |
| 3937 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3938 | final long identity = Binder.clearCallingIdentity(); |
| 3939 | try { |
| 3940 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3941 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3942 | } finally { |
| 3943 | Binder.restoreCallingIdentity(identity); |
| 3944 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 3945 | } |
| 3946 | |
| 3947 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3948 | * Get the preferred network type. |
| 3949 | * Used for device configuration by some CDMA operators. |
| 3950 | * |
| 3951 | * @return the preferred network type, defined in RILConstants.java. |
| 3952 | */ |
| 3953 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3954 | public int getPreferredNetworkType(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3955 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3956 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3957 | |
| 3958 | final long identity = Binder.clearCallingIdentity(); |
| 3959 | try { |
| 3960 | if (DBG) log("getPreferredNetworkType"); |
| 3961 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 3962 | int networkType = (result != null ? result[0] : -1); |
| 3963 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 3964 | return networkType; |
| 3965 | } finally { |
| 3966 | Binder.restoreCallingIdentity(identity); |
| 3967 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3968 | } |
| 3969 | |
| 3970 | /** |
| 3971 | * Set the preferred network type. |
| 3972 | * Used for device configuration by some CDMA operators. |
| 3973 | * |
| 3974 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 3975 | * @return true on success; false on any failure. |
| 3976 | */ |
| 3977 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3978 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3979 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3980 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3981 | |
| 3982 | final long identity = Binder.clearCallingIdentity(); |
| 3983 | try { |
| 3984 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 3985 | Boolean success = (Boolean) sendRequest( |
| 3986 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 3987 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 3988 | if (success) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3989 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3990 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 3991 | } |
| 3992 | return success; |
| 3993 | } finally { |
| 3994 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 3995 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3996 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 3997 | |
| 3998 | /** |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 3999 | * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning |
Jack Yu | 13db0fe | 2018-10-30 17:41:31 -0700 | [diff] [blame] | 4000 | * SystemProperty to decide whether DUN APN is required for |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4001 | * tethering. |
| 4002 | * |
| 4003 | * @return 0: Not required. 1: required. 2: Not set. |
| 4004 | * @hide |
| 4005 | */ |
| 4006 | @Override |
| 4007 | public int getTetherApnRequired() { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4008 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4009 | |
| 4010 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4011 | final Phone defaultPhone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4012 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4013 | int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4014 | Settings.Global.TETHER_DUN_REQUIRED, 2); |
Jack Yu | 13db0fe | 2018-10-30 17:41:31 -0700 | [diff] [blame] | 4015 | // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4016 | if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4017 | dunRequired = 1; |
| 4018 | } |
| 4019 | return dunRequired; |
| 4020 | } finally { |
| 4021 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4022 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4023 | } |
| 4024 | |
| 4025 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4026 | * Set mobile data enabled |
| 4027 | * Used by the user through settings etc to turn on/off mobile data |
| 4028 | * |
| 4029 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4030 | */ |
| 4031 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4032 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4033 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4034 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4035 | |
| 4036 | final long identity = Binder.clearCallingIdentity(); |
| 4037 | try { |
| 4038 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4039 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4040 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4041 | if (phone != null) { |
| 4042 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4043 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4044 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4045 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4046 | } |
| 4047 | } finally { |
| 4048 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4049 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4050 | } |
| 4051 | |
| 4052 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4053 | * Get the user enabled state of Mobile Data. |
| 4054 | * |
| 4055 | * TODO: remove and use isUserDataEnabled. |
| 4056 | * This can't be removed now because some vendor codes |
| 4057 | * calls through ITelephony directly while they should |
| 4058 | * use TelephonyManager. |
| 4059 | * |
| 4060 | * @return true on enabled |
| 4061 | */ |
| 4062 | @Override |
| 4063 | public boolean getDataEnabled(int subId) { |
| 4064 | return isUserDataEnabled(subId); |
| 4065 | } |
| 4066 | |
| 4067 | /** |
| 4068 | * Get whether mobile data is enabled per user setting. |
| 4069 | * |
| 4070 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4071 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4072 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4073 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4074 | * |
| 4075 | * @return {@code true} if data is enabled else {@code false} |
| 4076 | */ |
| 4077 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4078 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4079 | try { |
| 4080 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4081 | null); |
| 4082 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4083 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4084 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4085 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4086 | |
| 4087 | final long identity = Binder.clearCallingIdentity(); |
| 4088 | try { |
| 4089 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4090 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4091 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4092 | if (phone != null) { |
| 4093 | boolean retVal = phone.isUserDataEnabled(); |
| 4094 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4095 | return retVal; |
| 4096 | } else { |
| 4097 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4098 | return false; |
| 4099 | } |
| 4100 | } finally { |
| 4101 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4102 | } |
| 4103 | } |
| 4104 | |
| 4105 | /** |
| 4106 | * Get whether mobile data is enabled. |
| 4107 | * |
| 4108 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4109 | * whether mobile data is actually enabled. |
| 4110 | * |
| 4111 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4112 | * |
| 4113 | * @return {@code true} if data is enabled else {@code false} |
| 4114 | */ |
| 4115 | @Override |
| 4116 | public boolean isDataEnabled(int subId) { |
| 4117 | try { |
| 4118 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4119 | null); |
| 4120 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4121 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4122 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4123 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4124 | |
| 4125 | final long identity = Binder.clearCallingIdentity(); |
| 4126 | try { |
| 4127 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4128 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4129 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4130 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4131 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4132 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4133 | return retVal; |
| 4134 | } else { |
| 4135 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4136 | return false; |
| 4137 | } |
| 4138 | } finally { |
| 4139 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4140 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4141 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4142 | |
| 4143 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4144 | public int getCarrierPrivilegeStatus(int subId) { |
| 4145 | final Phone phone = getPhone(subId); |
| 4146 | if (phone == null) { |
| 4147 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4148 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4149 | } |
| 4150 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4151 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4152 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4153 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4154 | } |
| 4155 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4156 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4157 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4158 | |
| 4159 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4160 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4161 | final Phone phone = getPhone(subId); |
| 4162 | if (phone == null) { |
| 4163 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4164 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4165 | } |
| 4166 | UiccProfile profile = |
| 4167 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4168 | if (profile == null) { |
| 4169 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4170 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4171 | } |
| 4172 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 4173 | } |
| 4174 | |
| 4175 | @Override |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4176 | public int checkCarrierPrivilegesForPackage(String pkgName) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4177 | final Phone defaultPhone = getDefaultPhone(); |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4178 | if (TextUtils.isEmpty(pkgName)) |
| 4179 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4180 | UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4181 | if (card == null) { |
| 4182 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 4183 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4184 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4185 | return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(), |
| 4186 | pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4187 | } |
| 4188 | |
| 4189 | @Override |
| 4190 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4191 | if (TextUtils.isEmpty(pkgName)) |
| 4192 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4193 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4194 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4195 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4196 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4197 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4198 | continue; |
| 4199 | } |
| 4200 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4201 | result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4202 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4203 | break; |
| 4204 | } |
| 4205 | } |
| 4206 | |
| 4207 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4208 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4209 | |
| 4210 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4211 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4212 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4213 | loge("phoneId " + phoneId + " is not valid."); |
| 4214 | return null; |
| 4215 | } |
| 4216 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4217 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4218 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4219 | return null ; |
| 4220 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4221 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4222 | } |
| 4223 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4224 | @Override |
| 4225 | public List<String> getPackagesWithCarrierPrivileges() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4226 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4227 | List<String> privilegedPackages = new ArrayList<>(); |
| 4228 | List<PackageInfo> packages = null; |
| 4229 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4230 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4231 | if (card == null) { |
| 4232 | // No UICC in that slot. |
| 4233 | continue; |
| 4234 | } |
| 4235 | if (card.hasCarrierPrivilegeRules()) { |
| 4236 | if (packages == null) { |
| 4237 | // Only check packages in user 0 for now |
| 4238 | packages = pm.getInstalledPackagesAsUser( |
| 4239 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4240 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4241 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
| 4242 | } |
| 4243 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4244 | PackageInfo pkgInfo = packages.get(p); |
| 4245 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4246 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| 4247 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4248 | privilegedPackages.add(pkgInfo.packageName); |
| 4249 | } |
| 4250 | } |
| 4251 | } |
| 4252 | } |
| 4253 | return privilegedPackages; |
| 4254 | } |
| 4255 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4256 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4257 | final Phone phone = getPhone(subId); |
| 4258 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4259 | if (card == null) { |
| 4260 | loge("getIccId: No UICC"); |
| 4261 | return null; |
| 4262 | } |
| 4263 | String iccId = card.getIccId(); |
| 4264 | if (TextUtils.isEmpty(iccId)) { |
| 4265 | loge("getIccId: ICC ID is null or empty."); |
| 4266 | return null; |
| 4267 | } |
| 4268 | return iccId; |
| 4269 | } |
| 4270 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4271 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4272 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4273 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4274 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4275 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4276 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4277 | final long identity = Binder.clearCallingIdentity(); |
| 4278 | try { |
| 4279 | final String iccId = getIccId(subId); |
| 4280 | final Phone phone = getPhone(subId); |
| 4281 | if (phone == null) { |
| 4282 | return false; |
| 4283 | } |
| 4284 | final String subscriberId = phone.getSubscriberId(); |
| 4285 | |
| 4286 | if (DBG_MERGE) { |
| 4287 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4288 | + subscriberId + " to " + number); |
| 4289 | } |
| 4290 | |
| 4291 | if (TextUtils.isEmpty(iccId)) { |
| 4292 | return false; |
| 4293 | } |
| 4294 | |
| 4295 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4296 | |
| 4297 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4298 | if (alphaTag == null) { |
| 4299 | editor.remove(alphaTagPrefKey); |
| 4300 | } else { |
| 4301 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4302 | } |
| 4303 | |
| 4304 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4305 | // track all merged IMSIs based on line number |
| 4306 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4307 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4308 | if (number == null) { |
| 4309 | editor.remove(numberPrefKey); |
| 4310 | editor.remove(subscriberPrefKey); |
| 4311 | } else { |
| 4312 | editor.putString(numberPrefKey, number); |
| 4313 | editor.putString(subscriberPrefKey, subscriberId); |
| 4314 | } |
| 4315 | |
| 4316 | editor.commit(); |
| 4317 | return true; |
| 4318 | } finally { |
| 4319 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4320 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4321 | } |
| 4322 | |
| 4323 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4324 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4325 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4326 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4327 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4328 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4329 | return null; |
| 4330 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4331 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4332 | final long identity = Binder.clearCallingIdentity(); |
| 4333 | try { |
| 4334 | String iccId = getIccId(subId); |
| 4335 | if (iccId != null) { |
| 4336 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4337 | if (DBG_MERGE) { |
| 4338 | log("getLine1NumberForDisplay returning " |
| 4339 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 4340 | } |
| 4341 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4342 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4343 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 4344 | return null; |
| 4345 | } finally { |
| 4346 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4347 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4348 | } |
| 4349 | |
| 4350 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4351 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4352 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4353 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4354 | return null; |
| 4355 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4356 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4357 | final long identity = Binder.clearCallingIdentity(); |
| 4358 | try { |
| 4359 | String iccId = getIccId(subId); |
| 4360 | if (iccId != null) { |
| 4361 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4362 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 4363 | } |
| 4364 | return null; |
| 4365 | } finally { |
| 4366 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4367 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4368 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4369 | |
| 4370 | @Override |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4371 | public String[] getMergedSubscriberIds(String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4372 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 4373 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4374 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4375 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 4376 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4377 | return null; |
| 4378 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4379 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4380 | final long identity = Binder.clearCallingIdentity(); |
| 4381 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4382 | final Context context = mApp; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4383 | final TelephonyManager tele = TelephonyManager.from(context); |
| 4384 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 4385 | |
| 4386 | // Figure out what subscribers are currently active |
| 4387 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
| 4388 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 4389 | // the process, where TelephonyManager was instantiated. |
| 4390 | // Otherwise AppOps check will fail. |
| 4391 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4392 | final int[] subIds = sub.getActiveSubscriptionIdList(); |
| 4393 | for (int subId : subIds) { |
| 4394 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 4395 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4396 | |
| 4397 | // First pass, find a number override for an active subscriber |
| 4398 | String mergeNumber = null; |
| 4399 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 4400 | for (String key : prefs.keySet()) { |
| 4401 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 4402 | final String subscriberId = (String) prefs.get(key); |
| 4403 | if (activeSubscriberIds.contains(subscriberId)) { |
| 4404 | final String iccId = key.substring( |
| 4405 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 4406 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4407 | mergeNumber = (String) prefs.get(numberKey); |
| 4408 | if (DBG_MERGE) { |
| 4409 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 4410 | + " for active subscriber " + subscriberId); |
| 4411 | } |
| 4412 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 4413 | break; |
| 4414 | } |
| 4415 | } |
| 4416 | } |
| 4417 | } |
| 4418 | |
| 4419 | // Shortcut when no active merged subscribers |
| 4420 | if (TextUtils.isEmpty(mergeNumber)) { |
| 4421 | return null; |
| 4422 | } |
| 4423 | |
| 4424 | // Second pass, find all subscribers under that line override |
| 4425 | final ArraySet<String> result = new ArraySet<>(); |
| 4426 | for (String key : prefs.keySet()) { |
| 4427 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 4428 | final String number = (String) prefs.get(key); |
| 4429 | if (mergeNumber.equals(number)) { |
| 4430 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 4431 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4432 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 4433 | if (!TextUtils.isEmpty(subscriberId)) { |
| 4434 | result.add(subscriberId); |
| 4435 | } |
| 4436 | } |
| 4437 | } |
| 4438 | } |
| 4439 | |
| 4440 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 4441 | Arrays.sort(resultArray); |
| 4442 | if (DBG_MERGE) { |
| 4443 | Slog.d(LOG_TAG, |
| 4444 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 4445 | } |
| 4446 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4447 | } finally { |
| 4448 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4449 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4450 | } |
| 4451 | |
| 4452 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4453 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4454 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4455 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4456 | |
| 4457 | final long identity = Binder.clearCallingIdentity(); |
| 4458 | try { |
| 4459 | final Phone phone = getPhone(subId); |
| 4460 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 4461 | } finally { |
| 4462 | Binder.restoreCallingIdentity(identity); |
| 4463 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4464 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 4465 | |
| 4466 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4467 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4468 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 4469 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4470 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4471 | |
| 4472 | final long identity = Binder.clearCallingIdentity(); |
| 4473 | try { |
| 4474 | final Phone phone = getPhone(subId); |
| 4475 | if (phone == null) { |
| 4476 | return false; |
| 4477 | } |
| 4478 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 4479 | cdmaNonRoamingList); |
| 4480 | } finally { |
| 4481 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4482 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4483 | } |
| 4484 | |
| 4485 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4486 | @Deprecated |
| 4487 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 4488 | enforceModifyPermission(); |
| 4489 | |
| 4490 | int returnValue = 0; |
| 4491 | try { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4492 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4493 | if(result.exception == null) { |
| 4494 | if (result.result != null) { |
| 4495 | byte[] responseData = (byte[])(result.result); |
| 4496 | if(responseData.length > oemResp.length) { |
| 4497 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 4498 | responseData.length + "bytes. Buffer Size is " + |
| 4499 | oemResp.length + "bytes."); |
| 4500 | } |
| 4501 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 4502 | returnValue = responseData.length; |
| 4503 | } |
| 4504 | } else { |
| 4505 | CommandException ex = (CommandException) result.exception; |
| 4506 | returnValue = ex.getCommandError().ordinal(); |
| 4507 | if(returnValue > 0) returnValue *= -1; |
| 4508 | } |
| 4509 | } catch (RuntimeException e) { |
| 4510 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 4511 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 4512 | if(returnValue > 0) returnValue *= -1; |
| 4513 | } |
| 4514 | |
| 4515 | return returnValue; |
| 4516 | } |
| 4517 | |
| 4518 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4519 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 4520 | try { |
| 4521 | ProxyController.getInstance().setRadioCapability(rafs); |
| 4522 | } catch (RuntimeException e) { |
| 4523 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 4524 | } |
| 4525 | } |
| 4526 | |
| 4527 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4528 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4529 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4530 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4531 | if (phone == null) { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4532 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4533 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4534 | final long identity = Binder.clearCallingIdentity(); |
| 4535 | try { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4536 | TelephonyPermissions |
| 4537 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4538 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 4539 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4540 | } finally { |
| 4541 | Binder.restoreCallingIdentity(identity); |
| 4542 | } |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4543 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4544 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4545 | |
| 4546 | @Override |
| 4547 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4548 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4549 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4550 | |
| 4551 | final long identity = Binder.clearCallingIdentity(); |
| 4552 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4553 | ImsManager.getInstance(defaultPhone.getContext(), |
| 4554 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4555 | } finally { |
| 4556 | Binder.restoreCallingIdentity(identity); |
| 4557 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4558 | } |
| 4559 | |
| 4560 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4561 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4562 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4563 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4564 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4565 | return false; |
| 4566 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4567 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4568 | final long identity = Binder.clearCallingIdentity(); |
| 4569 | try { |
| 4570 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 4571 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 4572 | // In the long run, we may instead need to check if there exists a connection service |
| 4573 | // which can support video calling. |
| 4574 | ImsManager imsManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4575 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4576 | return imsManager.isVtEnabledByPlatform() |
| 4577 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 4578 | && imsManager.isVtEnabledByUser(); |
| 4579 | } finally { |
| 4580 | Binder.restoreCallingIdentity(identity); |
| 4581 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4582 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 4583 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4584 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4585 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 4586 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4587 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4588 | return false; |
| 4589 | } |
| 4590 | |
| 4591 | final long identity = Binder.clearCallingIdentity(); |
| 4592 | try { |
| 4593 | CarrierConfigManager configManager = |
| 4594 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4595 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4596 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 4597 | } finally { |
| 4598 | Binder.restoreCallingIdentity(identity); |
| 4599 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4603 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 4604 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4605 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4606 | return false; |
| 4607 | } |
| 4608 | |
| 4609 | final long identity = Binder.clearCallingIdentity(); |
| 4610 | try { |
| 4611 | CarrierConfigManager configManager = |
| 4612 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4613 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4614 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 4615 | } finally { |
| 4616 | Binder.restoreCallingIdentity(identity); |
| 4617 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4618 | } |
| 4619 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4620 | @Override |
| 4621 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4622 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 4623 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4624 | } |
| 4625 | |
| 4626 | @Override |
| 4627 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4628 | final long identity = Binder.clearCallingIdentity(); |
| 4629 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4630 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4631 | } finally { |
| 4632 | Binder.restoreCallingIdentity(identity); |
| 4633 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4634 | } |
| 4635 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4636 | /** |
| 4637 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 4638 | * support for the feature and device firmware support. |
| 4639 | * |
| 4640 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 4641 | */ |
| 4642 | @Override |
| 4643 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4644 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4645 | final Phone phone = getPhone(subscriptionId); |
| 4646 | if (phone == null) { |
| 4647 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 4648 | return false; |
| 4649 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4650 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4651 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4652 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 4653 | boolean isDeviceSupported = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4654 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4655 | return isCarrierSupported && isDeviceSupported; |
| 4656 | } finally { |
| 4657 | Binder.restoreCallingIdentity(identity); |
| 4658 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 4659 | } |
| 4660 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4661 | /** |
| 4662 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier |
| 4663 | * both also support RTT. |
| 4664 | */ |
| 4665 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4666 | final long identity = Binder.clearCallingIdentity(); |
| 4667 | try { |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4668 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4669 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4670 | } finally { |
| 4671 | Binder.restoreCallingIdentity(identity); |
| 4672 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 4673 | } |
| 4674 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4675 | /** |
| 4676 | * Returns the unique device ID of phone, for example, the IMEI for |
| 4677 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 4678 | * |
| 4679 | * <p>Requires Permission: |
| 4680 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 4681 | */ |
| 4682 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4683 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4684 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4685 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4686 | return null; |
| 4687 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4688 | int subId = phone.getSubId(); |
| 4689 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4690 | mApp, subId, callingPackage, "getDeviceId")) { |
| 4691 | return null; |
| 4692 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4693 | |
| 4694 | final long identity = Binder.clearCallingIdentity(); |
| 4695 | try { |
| 4696 | return phone.getDeviceId(); |
| 4697 | } finally { |
| 4698 | Binder.restoreCallingIdentity(identity); |
| 4699 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4700 | } |
| 4701 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 4702 | /** |
| 4703 | * {@hide} |
| 4704 | * Returns the IMS Registration Status on a particular subid |
| 4705 | * |
| 4706 | * @param subId |
| 4707 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4708 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 4709 | Phone phone = getPhone(subId); |
| 4710 | if (phone != null) { |
| 4711 | return phone.isImsRegistered(); |
| 4712 | } else { |
| 4713 | return false; |
| 4714 | } |
| 4715 | } |
| 4716 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 4717 | @Override |
| 4718 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4719 | final long identity = Binder.clearCallingIdentity(); |
| 4720 | try { |
| 4721 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 4722 | } finally { |
| 4723 | Binder.restoreCallingIdentity(identity); |
| 4724 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 4725 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 4726 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4727 | /** |
| 4728 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 4729 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4730 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4731 | final long identity = Binder.clearCallingIdentity(); |
| 4732 | try { |
| 4733 | Phone phone = getPhone(subId); |
| 4734 | if (phone != null) { |
| 4735 | return phone.isWifiCallingEnabled(); |
| 4736 | } else { |
| 4737 | return false; |
| 4738 | } |
| 4739 | } finally { |
| 4740 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4741 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 4742 | } |
| 4743 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4744 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4745 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 4746 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4747 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4748 | final long identity = Binder.clearCallingIdentity(); |
| 4749 | try { |
| 4750 | Phone phone = getPhone(subId); |
| 4751 | if (phone != null) { |
| 4752 | return phone.isVideoEnabled(); |
| 4753 | } else { |
| 4754 | return false; |
| 4755 | } |
| 4756 | } finally { |
| 4757 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4758 | } |
| 4759 | } |
| 4760 | |
| 4761 | /** |
| 4762 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 4763 | * defined in {@link ImsRegistrationImplBase}. |
| 4764 | */ |
| 4765 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4766 | final long identity = Binder.clearCallingIdentity(); |
| 4767 | try { |
| 4768 | Phone phone = getPhone(subId); |
| 4769 | if (phone != null) { |
| 4770 | return phone.getImsRegistrationTech(); |
| 4771 | } else { |
| 4772 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 4773 | } |
| 4774 | } finally { |
| 4775 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4776 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 4777 | } |
| 4778 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 4779 | @Override |
| 4780 | public void factoryReset(int subId) { |
| 4781 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 4782 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 4783 | return; |
| 4784 | } |
| 4785 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4786 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4787 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4788 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 4789 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 4790 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 4791 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4792 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 4793 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4794 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 4795 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4796 | } |
| 4797 | } finally { |
| 4798 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 4799 | } |
| 4800 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4801 | |
| 4802 | @Override |
| 4803 | public String getLocaleFromDefaultSim() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4804 | final long identity = Binder.clearCallingIdentity(); |
| 4805 | try { |
| 4806 | // We query all subscriptions instead of just the active ones, because |
| 4807 | // this might be called early on in the provisioning flow when the |
| 4808 | // subscriptions potentially aren't active yet. |
| 4809 | final List<SubscriptionInfo> slist = getAllSubscriptionInfoList(); |
| 4810 | if (slist == null || slist.isEmpty()) { |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4811 | return null; |
| 4812 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4813 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4814 | // This function may be called very early, say, from the setup wizard, at |
| 4815 | // which point we won't have a default subscription set. If that's the case |
| 4816 | // we just choose the first, which will be valid in "most cases". |
| 4817 | final int defaultSubId = getDefaultSubscription(); |
| 4818 | SubscriptionInfo info = null; |
| 4819 | if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 4820 | info = slist.get(0); |
| 4821 | } else { |
| 4822 | for (SubscriptionInfo item : slist) { |
| 4823 | if (item.getSubscriptionId() == defaultSubId) { |
| 4824 | info = item; |
| 4825 | break; |
| 4826 | } |
| 4827 | } |
| 4828 | |
| 4829 | if (info == null) { |
| 4830 | return null; |
Tony Hill | 183b2de | 2015-06-24 14:53:58 +0100 | [diff] [blame] | 4831 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4832 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4833 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4834 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 4835 | // preferences (EF-PL and EF-LI)... |
| 4836 | final int mcc = info.getMcc(); |
| 4837 | final Phone defaultPhone = getPhone(info.getSubscriptionId()); |
| 4838 | String simLanguage = null; |
| 4839 | if (defaultPhone != null) { |
| 4840 | final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs(); |
| 4841 | if (localeFromDefaultSim != null) { |
| 4842 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 4843 | if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim); |
| 4844 | return localeFromDefaultSim.toLanguageTag(); |
| 4845 | } else { |
| 4846 | simLanguage = localeFromDefaultSim.getLanguage(); |
| 4847 | } |
| 4848 | } |
| 4849 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4850 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4851 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 4852 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 4853 | // the SIM and carrier preferences does not include a country we add the country |
| 4854 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4855 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4856 | if (mccLocale != null) { |
| 4857 | if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale); |
| 4858 | return mccLocale.toLanguageTag(); |
| 4859 | } |
| 4860 | |
| 4861 | if (DBG) log("No locale found - returning null"); |
| 4862 | return null; |
| 4863 | } finally { |
| 4864 | Binder.restoreCallingIdentity(identity); |
| 4865 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4866 | } |
| 4867 | |
| 4868 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4869 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4870 | } |
| 4871 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4872 | /** |
| 4873 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 4874 | */ |
| 4875 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4876 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4877 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4878 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4879 | private final ModemActivityInfo mLastModemActivityInfo = |
| 4880 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 4881 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4882 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 4883 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 4884 | * representing the state of the modem. |
| 4885 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4886 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 4887 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 4888 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4889 | */ |
| 4890 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 4891 | public void requestModemActivityInfo(ResultReceiver result) { |
| 4892 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4893 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4894 | |
| 4895 | final long identity = Binder.clearCallingIdentity(); |
| 4896 | try { |
| 4897 | ModemActivityInfo ret = null; |
| 4898 | synchronized (mLastModemActivityInfo) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4899 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 4900 | CMD_GET_MODEM_ACTIVITY_INFO, |
| 4901 | null, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4902 | if (isModemActivityInfoValid(info)) { |
| 4903 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 4904 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 4905 | mergedTxTimeMs[i] = |
| 4906 | info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i]; |
| 4907 | } |
| 4908 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 4909 | mLastModemActivityInfo.setSleepTimeMillis( |
| 4910 | info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis()); |
| 4911 | mLastModemActivityInfo.setIdleTimeMillis( |
| 4912 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 4913 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 4914 | mLastModemActivityInfo.setRxTimeMillis( |
| 4915 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 4916 | mLastModemActivityInfo.setEnergyUsed( |
| 4917 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4918 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4919 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 4920 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 4921 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 4922 | mLastModemActivityInfo.getTxTimeMillis(), |
| 4923 | mLastModemActivityInfo.getRxTimeMillis(), |
| 4924 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4925 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4926 | Bundle bundle = new Bundle(); |
| 4927 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 4928 | result.send(0, bundle); |
| 4929 | } finally { |
| 4930 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4931 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4932 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4933 | |
Siddharth Ray | f5d2955 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 4934 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 4935 | // less than total activity duration. |
| 4936 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 4937 | if (info == null) { |
| 4938 | return false; |
| 4939 | } |
| 4940 | int activityDurationMs = |
| 4941 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 4942 | int totalTxTimeMs = 0; |
| 4943 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 4944 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 4945 | } |
| 4946 | return (info.isValid() |
| 4947 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 4948 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 4949 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 4950 | && (totalTxTimeMs <= activityDurationMs)); |
| 4951 | } |
| 4952 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4953 | /** |
| 4954 | * {@hide} |
| 4955 | * Returns the service state information on specified subscription. |
| 4956 | */ |
| 4957 | @Override |
| 4958 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4959 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4960 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4961 | return null; |
| 4962 | } |
| 4963 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4964 | final long identity = Binder.clearCallingIdentity(); |
| 4965 | try { |
| 4966 | final Phone phone = getPhone(subId); |
| 4967 | if (phone == null) { |
| 4968 | return null; |
| 4969 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4970 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4971 | return phone.getServiceState(); |
| 4972 | } finally { |
| 4973 | Binder.restoreCallingIdentity(identity); |
| 4974 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4975 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4976 | |
| 4977 | /** |
| 4978 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 4979 | * |
| 4980 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 4981 | * voicemail ringtone. |
| 4982 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 4983 | * PhoneAccount. |
| 4984 | */ |
| 4985 | @Override |
| 4986 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4987 | final long identity = Binder.clearCallingIdentity(); |
| 4988 | try { |
| 4989 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 4990 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4991 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4992 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4993 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4994 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 4995 | } finally { |
| 4996 | Binder.restoreCallingIdentity(identity); |
| 4997 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4998 | } |
| 4999 | |
| 5000 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5001 | * Sets the per-account voicemail ringtone. |
| 5002 | * |
| 5003 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5004 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5005 | * |
| 5006 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5007 | * voicemail ringtone. |
| 5008 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5009 | * PhoneAccount. |
| 5010 | */ |
| 5011 | @Override |
| 5012 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5013 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5014 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5015 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5016 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5017 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5018 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5019 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5020 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5021 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5022 | |
| 5023 | final long identity = Binder.clearCallingIdentity(); |
| 5024 | try { |
| 5025 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5026 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5027 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5028 | } |
| 5029 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5030 | } finally { |
| 5031 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5032 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5033 | } |
| 5034 | |
| 5035 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5036 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5037 | * |
| 5038 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5039 | * voicemail vibration setting. |
| 5040 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5041 | */ |
| 5042 | @Override |
| 5043 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5044 | final long identity = Binder.clearCallingIdentity(); |
| 5045 | try { |
| 5046 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5047 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5048 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5049 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5050 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5051 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5052 | } finally { |
| 5053 | Binder.restoreCallingIdentity(identity); |
| 5054 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5055 | } |
| 5056 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5057 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5058 | * Sets the per-account voicemail vibration. |
| 5059 | * |
| 5060 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5061 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5062 | * |
| 5063 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5064 | * voicemail vibration setting. |
| 5065 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5066 | * specific PhoneAccount. |
| 5067 | */ |
| 5068 | @Override |
| 5069 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5070 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5071 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5072 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5073 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5074 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5075 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5076 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5077 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5078 | } |
| 5079 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5080 | final long identity = Binder.clearCallingIdentity(); |
| 5081 | try { |
| 5082 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5083 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5084 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5085 | } |
| 5086 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5087 | } finally { |
| 5088 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5089 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5090 | } |
| 5091 | |
| 5092 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5093 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5094 | * |
| 5095 | * @throws SecurityException if the caller does not have the required permission |
| 5096 | */ |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5097 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5098 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5099 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5100 | } |
| 5101 | |
| 5102 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5103 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5104 | * permission. |
| 5105 | * |
| 5106 | * @throws SecurityException if the caller does not have the required permission |
| 5107 | */ |
| 5108 | private void enforceSendSmsPermission() { |
| 5109 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5110 | } |
| 5111 | |
| 5112 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5113 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5114 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5115 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5116 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5117 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5118 | final long identity = Binder.clearCallingIdentity(); |
| 5119 | try { |
| 5120 | ComponentName componentName = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5121 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5122 | if (componentName == null) { |
| 5123 | throw new SecurityException( |
| 5124 | "Caller not current active visual voicemail package[null]"); |
| 5125 | } |
| 5126 | String vvmPackage = componentName.getPackageName(); |
| 5127 | if (!callingPackage.equals(vvmPackage)) { |
| 5128 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5129 | + vvmPackage + "]"); |
| 5130 | } |
| 5131 | } finally { |
| 5132 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5133 | } |
| 5134 | } |
| 5135 | |
| 5136 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5137 | * Return the application ID for the app type. |
| 5138 | * |
| 5139 | * @param subId the subscription ID that this request applies to. |
| 5140 | * @param appType the uicc app type. |
| 5141 | * @return Application ID for specificied app type, or null if no uicc. |
| 5142 | */ |
| 5143 | @Override |
| 5144 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5145 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5146 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5147 | |
| 5148 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5149 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5150 | if (phone == null) { |
| 5151 | return null; |
| 5152 | } |
| 5153 | String aid = null; |
| 5154 | try { |
| 5155 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5156 | .getApplicationByType(appType).getAid(); |
| 5157 | } catch (Exception e) { |
| 5158 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5159 | } |
| 5160 | return aid; |
| 5161 | } finally { |
| 5162 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5163 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5164 | } |
| 5165 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5166 | /** |
| 5167 | * Return the Electronic Serial Number. |
| 5168 | * |
| 5169 | * @param subId the subscription ID that this request applies to. |
| 5170 | * @return ESN or null if error. |
| 5171 | */ |
| 5172 | @Override |
| 5173 | public String getEsn(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5174 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5175 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5176 | |
| 5177 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5178 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5179 | if (phone == null) { |
| 5180 | return null; |
| 5181 | } |
| 5182 | String esn = null; |
| 5183 | try { |
| 5184 | esn = phone.getEsn(); |
| 5185 | } catch (Exception e) { |
| 5186 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5187 | } |
| 5188 | return esn; |
| 5189 | } finally { |
| 5190 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5191 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5192 | } |
| 5193 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5194 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5195 | * Return the Preferred Roaming List Version. |
| 5196 | * |
| 5197 | * @param subId the subscription ID that this request applies to. |
| 5198 | * @return PRLVersion or null if error. |
| 5199 | */ |
| 5200 | @Override |
| 5201 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5202 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5203 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5204 | |
| 5205 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5206 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5207 | if (phone == null) { |
| 5208 | return null; |
| 5209 | } |
| 5210 | String cdmaPrlVersion = null; |
| 5211 | try { |
| 5212 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 5213 | } catch (Exception e) { |
| 5214 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 5215 | } |
| 5216 | return cdmaPrlVersion; |
| 5217 | } finally { |
| 5218 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5219 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5220 | } |
| 5221 | |
| 5222 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5223 | * Get snapshot of Telephony histograms |
| 5224 | * @return List of Telephony histograms |
| 5225 | * @hide |
| 5226 | */ |
| 5227 | @Override |
| 5228 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5229 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5230 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5231 | |
| 5232 | final long identity = Binder.clearCallingIdentity(); |
| 5233 | try { |
| 5234 | return RIL.getTelephonyRILTimingHistograms(); |
| 5235 | } finally { |
| 5236 | Binder.restoreCallingIdentity(identity); |
| 5237 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5238 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5239 | |
| 5240 | /** |
| 5241 | * {@hide} |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5242 | * Set the allowed carrier list for slotIndex |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5243 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5244 | * |
| 5245 | * @return The number of carriers set successfully, should match length of carriers |
| 5246 | */ |
| 5247 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5248 | public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5249 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5250 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5251 | |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5252 | if (carriers == null) { |
| 5253 | throw new NullPointerException("carriers cannot be null"); |
| 5254 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5255 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5256 | final long identity = Binder.clearCallingIdentity(); |
| 5257 | try { |
Michele | 85121de | 2018-12-19 15:25:20 -0800 | [diff] [blame] | 5258 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5259 | int subId = (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5260 | int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId, |
| 5261 | workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5262 | return retVal[0]; |
| 5263 | } finally { |
| 5264 | Binder.restoreCallingIdentity(identity); |
| 5265 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5266 | } |
| 5267 | |
| 5268 | /** |
| 5269 | * {@hide} |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5270 | * Get the allowed carrier list for slotIndex. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5271 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5272 | * |
| 5273 | * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list |
| 5274 | * means all carriers are allowed. |
| 5275 | */ |
| 5276 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5277 | public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5278 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5279 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5280 | |
| 5281 | final long identity = Binder.clearCallingIdentity(); |
| 5282 | try { |
Michele | 85121de | 2018-12-19 15:25:20 -0800 | [diff] [blame] | 5283 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5284 | int subId = (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5285 | return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId, |
| 5286 | workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5287 | } finally { |
| 5288 | Binder.restoreCallingIdentity(identity); |
| 5289 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5290 | } |
| 5291 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5292 | /** |
| 5293 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 5294 | * @param subId the subscription ID that this action applies to. |
| 5295 | * @param enabled control enable or disable metered apns. |
| 5296 | * {@hide} |
| 5297 | */ |
| 5298 | @Override |
| 5299 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 5300 | enforceModifyPermission(); |
| 5301 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5302 | |
| 5303 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5304 | if (phone == null) { |
| 5305 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 5306 | return; |
| 5307 | } |
| 5308 | try { |
| 5309 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 5310 | } catch (Exception e) { |
| 5311 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5312 | } finally { |
| 5313 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5314 | } |
| 5315 | } |
| 5316 | |
| 5317 | /** |
| 5318 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 5319 | * @param subId the subscription ID that this action applies to. |
| 5320 | * @param enabled control enable or disable radio. |
| 5321 | * {@hide} |
| 5322 | */ |
| 5323 | @Override |
| 5324 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 5325 | enforceModifyPermission(); |
| 5326 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5327 | |
| 5328 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5329 | if (phone == null) { |
| 5330 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 5331 | return; |
| 5332 | } |
| 5333 | try { |
| 5334 | phone.carrierActionSetRadioEnabled(enabled); |
| 5335 | } catch (Exception e) { |
| 5336 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5337 | } finally { |
| 5338 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5339 | } |
| 5340 | } |
| 5341 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5342 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5343 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 5344 | * network status based on which carrier apps could apply actions accordingly, |
| 5345 | * enable/disable default url handler for example. |
| 5346 | * |
| 5347 | * @param subId the subscription ID that this action applies to. |
| 5348 | * @param report control start/stop reporting the default network status. |
| 5349 | * {@hide} |
| 5350 | */ |
| 5351 | @Override |
| 5352 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 5353 | enforceModifyPermission(); |
| 5354 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5355 | |
| 5356 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5357 | if (phone == null) { |
| 5358 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 5359 | return; |
| 5360 | } |
| 5361 | try { |
| 5362 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 5363 | } catch (Exception e) { |
| 5364 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5365 | } finally { |
| 5366 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5367 | } |
| 5368 | } |
| 5369 | |
| 5370 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5371 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 5372 | * bug report is being generated. |
| 5373 | */ |
| 5374 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 5375 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5376 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 5377 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 5378 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 5379 | + Binder.getCallingPid() |
| 5380 | + ", uid=" + Binder.getCallingUid() |
| 5381 | + "without permission " |
| 5382 | + android.Manifest.permission.DUMP); |
| 5383 | return; |
| 5384 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5385 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5386 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5387 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5388 | @Override |
| 5389 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 5390 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 5391 | throws RemoteException { |
| 5392 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 5393 | } |
| 5394 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5395 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5396 | * Get aggregated video call data usage since boot. |
| 5397 | * |
| 5398 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 5399 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5400 | * {@hide} |
| 5401 | */ |
| 5402 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5403 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5404 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 5405 | null); |
| 5406 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5407 | final long identity = Binder.clearCallingIdentity(); |
| 5408 | try { |
| 5409 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 5410 | // records the delta with the corresponding network identity. |
| 5411 | // We just return the total video call data usage snapshot since boot. |
| 5412 | Phone phone = getPhone(subId); |
| 5413 | if (phone != null) { |
| 5414 | return phone.getVtDataUsage(perUidStats); |
| 5415 | } |
| 5416 | return null; |
| 5417 | } finally { |
| 5418 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5419 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5420 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5421 | |
| 5422 | /** |
| 5423 | * Policy control of data connection. Usually used when data limit is passed. |
| 5424 | * @param enabled True if enabling the data, otherwise disabling. |
| 5425 | * @param subId Subscription index |
| 5426 | * {@hide} |
| 5427 | */ |
| 5428 | @Override |
| 5429 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 5430 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5431 | |
| 5432 | final long identity = Binder.clearCallingIdentity(); |
| 5433 | try { |
| 5434 | Phone phone = getPhone(subId); |
| 5435 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5436 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5437 | } |
| 5438 | } finally { |
| 5439 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5440 | } |
| 5441 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5442 | |
| 5443 | /** |
| 5444 | * Get Client request stats |
| 5445 | * @return List of Client Request Stats |
| 5446 | * @hide |
| 5447 | */ |
| 5448 | @Override |
| 5449 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5450 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5451 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5452 | return null; |
| 5453 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5454 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5455 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5456 | final long identity = Binder.clearCallingIdentity(); |
| 5457 | try { |
| 5458 | if (phone != null) { |
| 5459 | return phone.getClientRequestStats(); |
| 5460 | } |
| 5461 | |
| 5462 | return null; |
| 5463 | } finally { |
| 5464 | Binder.restoreCallingIdentity(identity); |
| 5465 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5466 | } |
| 5467 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5468 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5469 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5470 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5471 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5472 | |
| 5473 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5474 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5475 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5476 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5477 | * @param state State of SIM (power down, power up, pass through) |
| 5478 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 5479 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 5480 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5481 | * |
| 5482 | **/ |
| 5483 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5484 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5485 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5486 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5487 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5488 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5489 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5490 | final long identity = Binder.clearCallingIdentity(); |
| 5491 | try { |
| 5492 | if (phone != null) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5493 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5494 | } |
| 5495 | } finally { |
| 5496 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5497 | } |
| 5498 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5499 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5500 | private boolean isUssdApiAllowed(int subId) { |
| 5501 | CarrierConfigManager configManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5502 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5503 | if (configManager == null) { |
| 5504 | return false; |
| 5505 | } |
| 5506 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 5507 | if (pb == null) { |
| 5508 | return false; |
| 5509 | } |
| 5510 | return pb.getBoolean( |
| 5511 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 5512 | } |
| 5513 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5514 | /** |
| 5515 | * Check if phone is in emergency callback mode |
| 5516 | * @return true if phone is in emergency callback mode |
| 5517 | * @param subId sub id |
| 5518 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 5519 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5520 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5521 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5522 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5523 | |
| 5524 | final long identity = Binder.clearCallingIdentity(); |
| 5525 | try { |
| 5526 | if (phone != null) { |
| 5527 | return phone.isInEcm(); |
| 5528 | } else { |
| 5529 | return false; |
| 5530 | } |
| 5531 | } finally { |
| 5532 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5533 | } |
| 5534 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5535 | |
| 5536 | /** |
| 5537 | * Get the current signal strength information for the given subscription. |
| 5538 | * Because this information is not updated when the device is in a low power state |
| 5539 | * it should not be relied-upon to be current. |
| 5540 | * @param subId Subscription index |
| 5541 | * @return the most recent cached signal strength info from the modem |
| 5542 | */ |
| 5543 | @Override |
| 5544 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5545 | final long identity = Binder.clearCallingIdentity(); |
| 5546 | try { |
| 5547 | Phone p = getPhone(subId); |
| 5548 | if (p == null) { |
| 5549 | return null; |
| 5550 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5551 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5552 | return p.getSignalStrength(); |
| 5553 | } finally { |
| 5554 | Binder.restoreCallingIdentity(identity); |
| 5555 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5556 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5557 | |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5558 | /** |
chen xu | 907e5a2 | 2018-10-11 13:21:04 -0700 | [diff] [blame] | 5559 | * Get the current modem radio state for the given slot. |
| 5560 | * @param slotIndex slot index. |
| 5561 | * @param callingPackage the name of the package making the call. |
| 5562 | * @return the current radio power state from the modem |
| 5563 | */ |
| 5564 | @Override |
| 5565 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 5566 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5567 | if (phone != null) { |
| 5568 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5569 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 5570 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5571 | } |
| 5572 | |
| 5573 | final long identity = Binder.clearCallingIdentity(); |
| 5574 | try { |
| 5575 | return phone.getRadioPowerState(); |
| 5576 | } finally { |
| 5577 | Binder.restoreCallingIdentity(identity); |
| 5578 | } |
| 5579 | } |
| 5580 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5581 | } |
| 5582 | |
| 5583 | /** |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5584 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 5585 | * |
| 5586 | * <p>Requires one of the following permissions: |
| 5587 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 5588 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 5589 | * privileges. |
| 5590 | * |
| 5591 | * @param subId subscription id |
| 5592 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 5593 | * {@code false}. |
| 5594 | */ |
| 5595 | @Override |
| 5596 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5597 | boolean isEnabled = false; |
| 5598 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5599 | try { |
| 5600 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5601 | null /* message */); |
| 5602 | Phone phone = getPhone(subId); |
| 5603 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5604 | } catch (Exception e) { |
| 5605 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 5606 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5607 | } finally { |
| 5608 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5609 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5610 | return isEnabled; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5611 | } |
| 5612 | |
| 5613 | |
| 5614 | /** |
| 5615 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 5616 | * |
| 5617 | * <p> Requires permission: |
| 5618 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 5619 | * privileges. |
| 5620 | * |
| 5621 | * @param subId subscription id |
| 5622 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 5623 | */ |
| 5624 | @Override |
| 5625 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5626 | final long identity = Binder.clearCallingIdentity(); |
| 5627 | try { |
| 5628 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5629 | mApp, subId, "setDataRoamingEnabled"); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5630 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5631 | Phone phone = getPhone(subId); |
| 5632 | if (phone != null) { |
| 5633 | phone.setDataRoamingEnabled(isEnabled); |
| 5634 | } |
| 5635 | } finally { |
| 5636 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5637 | } |
| 5638 | } |
| 5639 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5640 | @Override |
Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 5641 | public boolean isManualNetworkSelectionAllowed(int subId) { |
| 5642 | boolean isAllowed = true; |
| 5643 | final long identity = Binder.clearCallingIdentity(); |
| 5644 | try { |
| 5645 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 5646 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 5647 | Phone phone = getPhone(subId); |
| 5648 | if (phone != null) { |
| 5649 | isAllowed = phone.isCspPlmnEnabled(); |
| 5650 | } |
| 5651 | } finally { |
| 5652 | Binder.restoreCallingIdentity(identity); |
| 5653 | } |
| 5654 | return isAllowed; |
| 5655 | } |
| 5656 | |
| 5657 | @Override |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 5658 | public UiccCardInfo[] getUiccCardsInfo() { |
| 5659 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
| 5660 | |
| 5661 | final long identity = Binder.clearCallingIdentity(); |
| 5662 | try { |
| 5663 | ArrayList<UiccCardInfo> cards = UiccController.getInstance().getAllUiccCardInfos(); |
| 5664 | return cards.toArray(new UiccCardInfo[cards.size()]); |
| 5665 | } finally { |
| 5666 | Binder.restoreCallingIdentity(identity); |
| 5667 | } |
| 5668 | } |
| 5669 | |
| 5670 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5671 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5672 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5673 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5674 | final long identity = Binder.clearCallingIdentity(); |
| 5675 | try { |
| 5676 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 5677 | if (slots == null) { |
| 5678 | Rlog.i(LOG_TAG, "slots is null."); |
| 5679 | return null; |
| 5680 | } |
| 5681 | |
| 5682 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 5683 | for (int i = 0; i < slots.length; i++) { |
| 5684 | UiccSlot slot = slots[i]; |
| 5685 | if (slot == null) { |
| 5686 | continue; |
| 5687 | } |
| 5688 | |
| 5689 | String cardId; |
| 5690 | UiccCard card = slot.getUiccCard(); |
| 5691 | if (card != null) { |
| 5692 | cardId = card.getCardId(); |
| 5693 | } else { |
| 5694 | cardId = slot.getIccId(); |
| 5695 | } |
| 5696 | |
| 5697 | int cardState = 0; |
| 5698 | switch (slot.getCardState()) { |
| 5699 | case CARDSTATE_ABSENT: |
| 5700 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 5701 | break; |
| 5702 | case CARDSTATE_PRESENT: |
| 5703 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 5704 | break; |
| 5705 | case CARDSTATE_ERROR: |
| 5706 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 5707 | break; |
| 5708 | case CARDSTATE_RESTRICTED: |
| 5709 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 5710 | break; |
| 5711 | default: |
| 5712 | break; |
| 5713 | |
| 5714 | } |
| 5715 | |
| 5716 | infos[i] = new UiccSlotInfo( |
| 5717 | slot.isActive(), |
| 5718 | slot.isEuicc(), |
| 5719 | cardId, |
| 5720 | cardState, |
| 5721 | slot.getPhoneId(), |
| 5722 | slot.isExtendedApduSupported()); |
| 5723 | } |
| 5724 | return infos; |
| 5725 | } finally { |
| 5726 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 5727 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5728 | } |
| 5729 | |
| 5730 | @Override |
| 5731 | public boolean switchSlots(int[] physicalSlots) { |
| 5732 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5733 | |
| 5734 | final long identity = Binder.clearCallingIdentity(); |
| 5735 | try { |
| 5736 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 5737 | } finally { |
| 5738 | Binder.restoreCallingIdentity(identity); |
| 5739 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5740 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 5741 | |
| 5742 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 5743 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
| 5744 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5745 | mApp, subId, callingPackage, "getCardIdForDefaultEuicc")) { |
| 5746 | return TelephonyManager.INVALID_CARD_ID; |
| 5747 | } |
| 5748 | |
| 5749 | final long identity = Binder.clearCallingIdentity(); |
| 5750 | try { |
| 5751 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 5752 | } finally { |
| 5753 | Binder.restoreCallingIdentity(identity); |
| 5754 | } |
| 5755 | } |
| 5756 | |
| 5757 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 5758 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 5759 | enforceModifyPermission(); |
| 5760 | final Phone phone = getPhone(subId); |
| 5761 | if (phone == null) { |
| 5762 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 5763 | return; |
| 5764 | } |
| 5765 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5766 | final long identity = Binder.clearCallingIdentity(); |
| 5767 | try { |
| 5768 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 5769 | } finally { |
| 5770 | Binder.restoreCallingIdentity(identity); |
| 5771 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 5772 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5773 | |
| 5774 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 5775 | * A test API to reload the UICC profile. |
| 5776 | * |
| 5777 | * <p>Requires that the calling app has permission |
| 5778 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5779 | * @hide |
| 5780 | */ |
| 5781 | @Override |
| 5782 | public void refreshUiccProfile(int subId) { |
| 5783 | enforceModifyPermission(); |
| 5784 | |
| 5785 | final long identity = Binder.clearCallingIdentity(); |
| 5786 | try { |
| 5787 | Phone phone = getPhone(subId); |
| 5788 | if (phone == null) { |
| 5789 | return; |
| 5790 | } |
| 5791 | UiccCard uiccCard = phone.getUiccCard(); |
| 5792 | if (uiccCard == null) { |
| 5793 | return; |
| 5794 | } |
| 5795 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 5796 | if (uiccProfile == null) { |
| 5797 | return; |
| 5798 | } |
| 5799 | uiccProfile.refresh(); |
| 5800 | } finally { |
| 5801 | Binder.restoreCallingIdentity(identity); |
| 5802 | } |
| 5803 | } |
| 5804 | |
| 5805 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5806 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 5807 | */ |
| 5808 | private boolean getDefaultDataEnabled() { |
| 5809 | return "true".equalsIgnoreCase( |
| 5810 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 5811 | } |
| 5812 | |
| 5813 | /** |
| 5814 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 5815 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 5816 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 5817 | */ |
| 5818 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 5819 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5820 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5821 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 5822 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 5823 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 5824 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 5825 | return isDataRoamingEnabled; |
| 5826 | } |
| 5827 | |
| 5828 | /** |
| 5829 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 5830 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 5831 | */ |
| 5832 | private int getDefaultNetworkType(int subId) { |
| 5833 | return Integer.parseInt( |
| 5834 | TelephonyManager.getTelephonyProperty( |
| 5835 | mSubscriptionController.getPhoneId(subId), |
| 5836 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 5837 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 5838 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5839 | |
| 5840 | @Override |
| 5841 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
| 5842 | gid1, String gid2, String plmn, String spn) { |
| 5843 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5844 | |
| 5845 | final long identity = Binder.clearCallingIdentity(); |
| 5846 | try { |
| 5847 | final Phone phone = getPhone(subId); |
| 5848 | if (phone == null) { |
| 5849 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 5850 | return; |
| 5851 | } |
| 5852 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn); |
| 5853 | } finally { |
| 5854 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5855 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5856 | } |
| 5857 | |
| 5858 | @Override |
| 5859 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5860 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5861 | |
| 5862 | final long identity = Binder.clearCallingIdentity(); |
| 5863 | try { |
| 5864 | final Phone phone = getPhone(subId); |
| 5865 | if (phone == null) { |
| 5866 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 5867 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 5868 | } |
| 5869 | return phone.getCarrierIdListVersion(); |
| 5870 | } finally { |
| 5871 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5872 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5873 | } |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 5874 | |
| 5875 | @Override |
| 5876 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 5877 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5878 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 5879 | return -1; |
| 5880 | } |
| 5881 | |
| 5882 | final long identity = Binder.clearCallingIdentity(); |
| 5883 | try { |
| 5884 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 5885 | } finally { |
| 5886 | Binder.restoreCallingIdentity(identity); |
| 5887 | } |
| 5888 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5889 | |
| 5890 | @Override |
| 5891 | public int getCdmaRoamingMode(int subId) { |
| 5892 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5893 | mApp, subId, "getCdmaRoamingMode"); |
| 5894 | |
| 5895 | final long identity = Binder.clearCallingIdentity(); |
| 5896 | try { |
| 5897 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 5898 | } finally { |
| 5899 | Binder.restoreCallingIdentity(identity); |
| 5900 | } |
| 5901 | } |
| 5902 | |
| 5903 | @Override |
| 5904 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 5905 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5906 | mApp, subId, "setCdmaRoamingMode"); |
| 5907 | |
| 5908 | final long identity = Binder.clearCallingIdentity(); |
| 5909 | try { |
| 5910 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 5911 | } finally { |
| 5912 | Binder.restoreCallingIdentity(identity); |
| 5913 | } |
| 5914 | } |
| 5915 | |
| 5916 | @Override |
| 5917 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 5918 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5919 | mApp, subId, "setCdmaSubscriptionMode"); |
| 5920 | |
| 5921 | final long identity = Binder.clearCallingIdentity(); |
| 5922 | try { |
| 5923 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 5924 | } finally { |
| 5925 | Binder.restoreCallingIdentity(identity); |
| 5926 | } |
| 5927 | } |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 5928 | |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 5929 | private void ensureUserRunning(int userId) { |
| 5930 | if (!mUserManager.isUserRunning(userId)) { |
| 5931 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 5932 | } |
| 5933 | } |
| 5934 | |
| 5935 | /** |
| 5936 | * Returns a list of SMS apps on a given user. |
| 5937 | * |
| 5938 | * Only the shell user (UID 2000 or 0) can call it. |
| 5939 | * Target user must be running. |
| 5940 | */ |
| 5941 | @Override |
| 5942 | public String[] getSmsApps(int userId) { |
| 5943 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 5944 | ensureUserRunning(userId); |
| 5945 | |
| 5946 | final Collection<SmsApplicationData> apps = |
| 5947 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 5948 | |
| 5949 | String[] ret = new String[apps.size()]; |
| 5950 | int i = 0; |
| 5951 | for (SmsApplicationData app : apps) { |
| 5952 | ret[i++] = app.mPackageName; |
| 5953 | } |
| 5954 | return ret; |
| 5955 | } |
| 5956 | |
| 5957 | /** |
| 5958 | * Returns the default SMS app package name on a given user. |
| 5959 | * |
| 5960 | * Only the shell user (UID 2000 or 0) can call it. |
| 5961 | * Target user must be running. |
| 5962 | */ |
| 5963 | @Override |
| 5964 | public String getDefaultSmsApp(int userId) { |
| 5965 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 5966 | ensureUserRunning(userId); |
| 5967 | |
| 5968 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 5969 | /* updateIfNeeded= */ true, userId); |
| 5970 | return cn == null ? null : cn.getPackageName(); |
| 5971 | } |
| 5972 | |
| 5973 | /** |
| 5974 | * Set a package as the default SMS app on a given user. |
| 5975 | * |
| 5976 | * Only the shell user (UID 2000 or 0) can call it. |
| 5977 | * Target user must be running. |
| 5978 | */ |
| 5979 | @Override |
| 5980 | public void setDefaultSmsApp(int userId, String packageName) { |
| 5981 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 5982 | ensureUserRunning(userId); |
| 5983 | |
| 5984 | boolean found = false; |
| 5985 | for (String pkg : getSmsApps(userId)) { |
| 5986 | if (TextUtils.equals(packageName, pkg)) { |
| 5987 | found = true; |
| 5988 | break; |
| 5989 | } |
| 5990 | } |
| 5991 | if (!found) { |
| 5992 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 5993 | } |
| 5994 | |
| 5995 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 5996 | } |
| 5997 | |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 5998 | @Override |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 5999 | public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList( |
| 6000 | String callingPackage) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame^] | 6001 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6002 | mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) { |
| 6003 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6004 | } |
| 6005 | final long identity = Binder.clearCallingIdentity(); |
| 6006 | try { |
| 6007 | Map<Integer, List<EmergencyNumber>> results = getEmergencyNumberListInternal(); |
| 6008 | // Use ecclist to construct Emergency number list for backward compatibality |
| 6009 | if (results.isEmpty()) { |
| 6010 | results = getEmergencyNumberListFromEccList(); |
| 6011 | } |
| 6012 | return results; |
| 6013 | } finally { |
| 6014 | Binder.restoreCallingIdentity(identity); |
| 6015 | } |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6016 | } |
| 6017 | |
| 6018 | @Override |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame^] | 6019 | public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) { |
| 6020 | final Phone defaultPhone = getDefaultPhone(); |
| 6021 | if (!exactMatch) { |
| 6022 | TelephonyPermissions |
| 6023 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6024 | mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)"); |
| 6025 | } |
| 6026 | final long identity = Binder.clearCallingIdentity(); |
| 6027 | try { |
| 6028 | Map<Integer, List<EmergencyNumber>> emergencyNumberLists = |
| 6029 | getEmergencyNumberListInternal(); |
| 6030 | |
| 6031 | String defaultCountryIso = getNetworkCountryIsoForPhone(defaultPhone.getPhoneId()); |
| 6032 | |
| 6033 | if (!emergencyNumberLists.isEmpty()) { |
| 6034 | for (List<EmergencyNumber> emergencyNumberList : emergencyNumberLists.values()) { |
| 6035 | if (emergencyNumberList != null) { |
| 6036 | for (EmergencyNumber num : emergencyNumberList) { |
| 6037 | // According to com.android.i18n.phonenumbers.ShortNumberInfo, in |
| 6038 | // these countries, if extra digits are added to an emergency number, |
| 6039 | // it no longer connects to the emergency service. |
| 6040 | Set<String> countriesRequiredForExactMatch = new HashSet<>(); |
| 6041 | countriesRequiredForExactMatch.add("br"); |
| 6042 | countriesRequiredForExactMatch.add("cl"); |
| 6043 | countriesRequiredForExactMatch.add("ni"); |
| 6044 | if (exactMatch || countriesRequiredForExactMatch.contains( |
| 6045 | defaultCountryIso)) { |
| 6046 | if (num.getNumber().equals(number)) { |
| 6047 | return true; |
| 6048 | } |
| 6049 | } else { |
| 6050 | if (number.startsWith(num.getNumber())) { |
| 6051 | return true; |
| 6052 | } |
| 6053 | } |
| 6054 | |
| 6055 | } |
| 6056 | } |
| 6057 | } |
| 6058 | } else { |
| 6059 | // For backward compatibility for devices launched before Q |
| 6060 | return PhoneNumberUtils.isEmergencyNumberInternal(number, exactMatch, |
| 6061 | defaultCountryIso); |
| 6062 | } |
| 6063 | return false; |
| 6064 | } finally { |
| 6065 | Binder.restoreCallingIdentity(identity); |
| 6066 | } |
| 6067 | } |
| 6068 | |
| 6069 | private Map<Integer, List<EmergencyNumber>> getEmergencyNumberListInternal() { |
| 6070 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6071 | |
| 6072 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6073 | if (phone.getEmergencyNumberTracker() != null |
| 6074 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6075 | emergencyNumberListInternal.put( |
| 6076 | phone.getSubId(), |
| 6077 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6078 | } |
| 6079 | } |
| 6080 | return emergencyNumberListInternal; |
| 6081 | } |
| 6082 | |
| 6083 | private List<EmergencyNumber> getEmergencyNumberListFromEccList(int subscriptionId) { |
| 6084 | SubscriptionManager sm = (SubscriptionManager) mApp.getSystemService( |
| 6085 | Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6086 | List<EmergencyNumber> emergencyNumberList = new ArrayList<>(); |
| 6087 | int slotId = sm.getSlotIndex(subscriptionId); |
| 6088 | |
| 6089 | String ecclist = (slotId <= 0) ? "ril.ecclist" : ("ril.ecclist" + slotId); |
| 6090 | String emergencyNumbers = SystemProperties.get(ecclist, ""); |
| 6091 | if (TextUtils.isEmpty(emergencyNumbers)) { |
| 6092 | // then read-only ecclist property since old RIL only uses this |
| 6093 | emergencyNumbers = SystemProperties.get("ro.ril.ecclist"); |
| 6094 | } |
| 6095 | if (!TextUtils.isEmpty(emergencyNumbers)) { |
| 6096 | // searches through the comma-separated list for a match, |
| 6097 | // return true if one is found. |
| 6098 | for (String emergencyNum : emergencyNumbers.split(",")) { |
| 6099 | emergencyNumberList.add(new EmergencyNumber(emergencyNum, "", "", |
| 6100 | EmergencyNumber.EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED, 0)); |
| 6101 | } |
| 6102 | } |
| 6103 | emergencyNumbers = ((slotId < 0) ? "112,911,000,08,110,118,119,999" : "112,911"); |
| 6104 | for (String emergencyNum : emergencyNumbers.split(",")) { |
| 6105 | emergencyNumberList.add(new EmergencyNumber(emergencyNum, "", "", |
| 6106 | EmergencyNumber.EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED, 0)); |
| 6107 | } |
| 6108 | EmergencyNumber.mergeSameNumbersInEmergencyNumberList(emergencyNumberList); |
| 6109 | return emergencyNumberList; |
| 6110 | } |
| 6111 | |
| 6112 | /** |
| 6113 | * Get Emergency number list based on EccList. This util is used for solving backward |
| 6114 | * compatibility if device does not support the 1.4 IRadioIndication HAL that reports |
| 6115 | * emergency number list. |
| 6116 | * |
| 6117 | * @return Map including the key as the active subscription ID (Note: if there is no active |
| 6118 | * subscription, the key is {@link SubscriptionManager#getDefaultSubscriptionId}) |
| 6119 | * and the value as the list of {@link EmergencyNumber}. |
| 6120 | */ |
| 6121 | private Map<Integer, List<EmergencyNumber>> getEmergencyNumberListFromEccList() { |
| 6122 | Map<Integer, List<EmergencyNumber>> results = new HashMap<>(); |
| 6123 | SubscriptionManager sm = (SubscriptionManager) mApp.getSystemService( |
| 6124 | Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6125 | int[] activeSubscriptionIds = sm.getActiveSubscriptionIdList(); |
| 6126 | |
| 6127 | if (activeSubscriptionIds.length == 0) { |
| 6128 | int defaultSubscriptionId = getDefaultSubscription(); |
| 6129 | results.put(defaultSubscriptionId, |
| 6130 | getEmergencyNumberListFromEccList(defaultSubscriptionId)); |
| 6131 | } else { |
| 6132 | for (int activeSubscriptionId : activeSubscriptionIds) { |
| 6133 | results.put(activeSubscriptionId, |
| 6134 | getEmergencyNumberListFromEccList(activeSubscriptionId)); |
| 6135 | } |
| 6136 | } |
| 6137 | return results; |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6138 | } |
| 6139 | |
| 6140 | @Override |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6141 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6142 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6143 | Phone phone = getPhone(subId); |
| 6144 | if (phone == null) { |
| 6145 | return null; |
| 6146 | } |
| 6147 | final long identity = Binder.clearCallingIdentity(); |
| 6148 | try { |
| 6149 | UiccProfile profile = UiccController.getInstance() |
| 6150 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6151 | if (profile != null) { |
| 6152 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6153 | } |
| 6154 | } finally { |
| 6155 | Binder.restoreCallingIdentity(identity); |
| 6156 | } |
| 6157 | return null; |
| 6158 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6159 | } |