Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 22 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 23 | import android.Manifest.permission; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 24 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 25 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 26 | import android.content.ComponentName; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.content.Context; |
| 28 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 29 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 30 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 31 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 32 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 33 | import android.content.pm.PackageManager; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 34 | import android.net.NetworkStats; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 35 | import android.net.Uri; |
| 36 | import android.os.AsyncResult; |
| 37 | import android.os.Binder; |
| 38 | import android.os.Bundle; |
| 39 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 40 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.os.Looper; |
| 42 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 43 | import android.os.Messenger; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 44 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 45 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 46 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 47 | import android.os.ServiceManager; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 48 | import android.os.ShellCallback; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 49 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 51 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 52 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 53 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 54 | import android.provider.Settings; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 55 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 56 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 57 | import android.telecom.TelecomManager; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 58 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 59 | import android.telephony.CarrierRestrictionRules; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 60 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 61 | import android.telephony.CellInfoGsm; |
| 62 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 63 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 64 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 65 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 66 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 67 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 68 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 69 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 70 | import android.telephony.NetworkScanRequest; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 71 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 72 | import android.telephony.RadioAccessFamily; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 73 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 74 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 75 | import android.telephony.SignalStrength; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 76 | import android.telephony.SmsManager; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 77 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 78 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 79 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 80 | import android.telephony.TelephonyManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 81 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 82 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 83 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 84 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 85 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 86 | import android.telephony.data.ApnSetting; |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 87 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 88 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 89 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 90 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 91 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 92 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 93 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 94 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 95 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 96 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 97 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 98 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 99 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 100 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 101 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 102 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 103 | import com.android.ims.ImsException; |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 104 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 105 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 106 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 107 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 108 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 109 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 110 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 111 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 112 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 113 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 114 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 115 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 116 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 117 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 118 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 119 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 120 | import com.android.internal.telephony.Phone; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 121 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 122 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.ServiceStateTracker; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 129 | import com.android.internal.telephony.SmsApplication; |
| 130 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 131 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.TelephonyPermissions; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.euicc.EuiccConnector; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.uicc.IccIoResult; |
| 135 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 140 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 141 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 143 | import com.android.internal.util.HexDump; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 144 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 145 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 146 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 147 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 148 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 149 | import java.io.FileDescriptor; |
| 150 | import java.io.PrintWriter; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 151 | import java.nio.charset.StandardCharsets; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 152 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 153 | import java.util.Arrays; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 154 | import java.util.Collection; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 155 | import java.util.HashMap; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 156 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 157 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 158 | import java.util.Map; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 159 | |
| 160 | /** |
| 161 | * Implementation of the ITelephony interface. |
| 162 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 163 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 164 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 165 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 166 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 167 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 168 | |
| 169 | // Message codes used with mMainThreadHandler |
| 170 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 171 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 172 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 173 | private static final int CMD_OPEN_CHANNEL = 9; |
| 174 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 175 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 176 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 177 | private static final int CMD_NV_READ_ITEM = 13; |
| 178 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 179 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 180 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 181 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 182 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 183 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 184 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 185 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 186 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 187 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 188 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 189 | private static final int CMD_SEND_ENVELOPE = 25; |
| 190 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 191 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 192 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 193 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 194 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 195 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 196 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 197 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 198 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 199 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 200 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 201 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 202 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 203 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 204 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 205 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 206 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 207 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 208 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 209 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 210 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 211 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 212 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 213 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 214 | private static final int CMD_SWITCH_SLOTS = 50; |
| 215 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 216 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 217 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 218 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 219 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 220 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 221 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 222 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 223 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 224 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 225 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 226 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 227 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 228 | private static final int CMD_MODEM_REBOOT = 64; |
| 229 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 230 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 231 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 232 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 233 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 234 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 235 | // Parameters of select command. |
| 236 | private static final int SELECT_COMMAND = 0xA4; |
| 237 | private static final int SELECT_P1 = 0x04; |
| 238 | private static final int SELECT_P2 = 0; |
| 239 | private static final int SELECT_P3 = 0x10; |
| 240 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 241 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 242 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 243 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 244 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 245 | /** The singleton instance. */ |
| 246 | private static PhoneInterfaceManager sInstance; |
| 247 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 248 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 249 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 250 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 251 | private AppOpsManager mAppOps; |
| 252 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 253 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 254 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 255 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 256 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 257 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 258 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 259 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 260 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 261 | // The AID of ISD-R. |
| 262 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 263 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 264 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 265 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 266 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 267 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 268 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 269 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 270 | * A request object to use for transmitting data to an ICC. |
| 271 | */ |
| 272 | private static final class IccAPDUArgument { |
| 273 | public int channel, cla, command, p1, p2, p3; |
| 274 | public String data; |
| 275 | |
| 276 | public IccAPDUArgument(int channel, int cla, int command, |
| 277 | int p1, int p2, int p3, String data) { |
| 278 | this.channel = channel; |
| 279 | this.cla = cla; |
| 280 | this.command = command; |
| 281 | this.p1 = p1; |
| 282 | this.p2 = p2; |
| 283 | this.p3 = p3; |
| 284 | this.data = data; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 289 | * A request object to use for transmitting data to an ICC. |
| 290 | */ |
| 291 | private static final class ManualNetworkSelectionArgument { |
| 292 | public OperatorInfo operatorInfo; |
| 293 | public boolean persistSelection; |
| 294 | |
| 295 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 296 | this.operatorInfo = operatorInfo; |
| 297 | this.persistSelection = persistSelection; |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 302 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 303 | * request after sending. The main thread will notify the request when it is complete. |
| 304 | */ |
| 305 | private static final class MainThreadRequest { |
| 306 | /** The argument to use for the request */ |
| 307 | public Object argument; |
| 308 | /** The result of the request that is run on the main thread */ |
| 309 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 310 | // The subscriber id that this request applies to. Defaults to |
| 311 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 312 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 313 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 314 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 315 | public Phone phone; |
| 316 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 317 | public WorkSource workSource; |
| 318 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 319 | public MainThreadRequest(Object argument) { |
| 320 | this.argument = argument; |
| 321 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 322 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 323 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 324 | this.argument = argument; |
| 325 | if (phone != null) { |
| 326 | this.phone = phone; |
| 327 | } |
| 328 | this.workSource = workSource; |
| 329 | } |
| 330 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 331 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 332 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 333 | if (subId != null) { |
| 334 | this.subId = subId; |
| 335 | } |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 336 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 337 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 340 | private static final class IncomingThirdPartyCallArgs { |
| 341 | public final ComponentName component; |
| 342 | public final String callId; |
| 343 | public final String callerDisplayName; |
| 344 | |
| 345 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 346 | String callerDisplayName) { |
| 347 | this.component = component; |
| 348 | this.callId = callId; |
| 349 | this.callerDisplayName = callerDisplayName; |
| 350 | } |
| 351 | } |
| 352 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 353 | /** |
| 354 | * A handler that processes messages on the main thread in the phone process. Since many |
| 355 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 356 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 357 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 358 | * on, which will be notified when the operation completes and will contain the result of the |
| 359 | * request. |
| 360 | * |
| 361 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 362 | * note that request.result must be set to something non-null for the calling thread to |
| 363 | * unblock. |
| 364 | */ |
| 365 | private final class MainThreadHandler extends Handler { |
| 366 | @Override |
| 367 | public void handleMessage(Message msg) { |
| 368 | MainThreadRequest request; |
| 369 | Message onCompleted; |
| 370 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 371 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 372 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 373 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 374 | |
| 375 | switch (msg.what) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 376 | case CMD_HANDLE_USSD_REQUEST: { |
| 377 | request = (MainThreadRequest) msg.obj; |
| 378 | final Phone phone = getPhoneFromRequest(request); |
| 379 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 380 | String ussdRequest = ussdObject.first; |
| 381 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 382 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 383 | if (!isUssdApiAllowed(request.subId)) { |
| 384 | // Carrier does not support use of this API, return failure. |
| 385 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 386 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 387 | Bundle returnData = new Bundle(); |
| 388 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 389 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 390 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 391 | request.result = true; |
| 392 | notifyRequester(request); |
| 393 | return; |
| 394 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 395 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 396 | try { |
| 397 | request.result = phone != null |
| 398 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 399 | } catch (CallStateException cse) { |
| 400 | request.result = false; |
| 401 | } |
| 402 | // Wake up the requesting thread |
| 403 | notifyRequester(request); |
| 404 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 407 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 408 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 409 | final Phone phone = getPhoneFromRequest(request); |
| 410 | request.result = phone != null ? |
| 411 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 412 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 413 | // Wake up the requesting thread |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 414 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 415 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 416 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 417 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 418 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 419 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 420 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 421 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 422 | if (uiccCard == null) { |
| 423 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 424 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 425 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 426 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 427 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 428 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 429 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 430 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 431 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 432 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 433 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 434 | break; |
| 435 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 436 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 437 | ar = (AsyncResult) msg.obj; |
| 438 | request = (MainThreadRequest) ar.userObj; |
| 439 | if (ar.exception == null && ar.result != null) { |
| 440 | request.result = ar.result; |
| 441 | } else { |
| 442 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 443 | if (ar.result == null) { |
| 444 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 445 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 446 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 447 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 448 | } else { |
| 449 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 450 | } |
| 451 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 452 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 453 | break; |
| 454 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 455 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 456 | request = (MainThreadRequest) msg.obj; |
| 457 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 458 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 459 | if (uiccCard == null) { |
| 460 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 461 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 462 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 463 | } else { |
| 464 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 465 | request); |
| 466 | uiccCard.iccTransmitApduBasicChannel( |
| 467 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 468 | iccArgument.p3, iccArgument.data, onCompleted); |
| 469 | } |
| 470 | break; |
| 471 | |
| 472 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 473 | ar = (AsyncResult) msg.obj; |
| 474 | request = (MainThreadRequest) ar.userObj; |
| 475 | if (ar.exception == null && ar.result != null) { |
| 476 | request.result = ar.result; |
| 477 | } else { |
| 478 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 479 | if (ar.result == null) { |
| 480 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 481 | } else if (ar.exception instanceof CommandException) { |
| 482 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 483 | ar.exception); |
| 484 | } else { |
| 485 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 486 | } |
| 487 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 488 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 489 | break; |
| 490 | |
| 491 | case CMD_EXCHANGE_SIM_IO: |
| 492 | request = (MainThreadRequest) msg.obj; |
| 493 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 494 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 495 | if (uiccCard == null) { |
| 496 | loge("iccExchangeSimIO: No UICC"); |
| 497 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 498 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 499 | } else { |
| 500 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 501 | request); |
| 502 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 503 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 504 | iccArgument.data, onCompleted); |
| 505 | } |
| 506 | break; |
| 507 | |
| 508 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 509 | ar = (AsyncResult) msg.obj; |
| 510 | request = (MainThreadRequest) ar.userObj; |
| 511 | if (ar.exception == null && ar.result != null) { |
| 512 | request.result = ar.result; |
| 513 | } else { |
| 514 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 515 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 516 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 517 | break; |
| 518 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 519 | case CMD_SEND_ENVELOPE: |
| 520 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 521 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 522 | if (uiccCard == null) { |
| 523 | loge("sendEnvelopeWithStatus: No UICC"); |
| 524 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 525 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 526 | } else { |
| 527 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 528 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 529 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 530 | break; |
| 531 | |
| 532 | case EVENT_SEND_ENVELOPE_DONE: |
| 533 | ar = (AsyncResult) msg.obj; |
| 534 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 535 | if (ar.exception == null && ar.result != null) { |
| 536 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 537 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 538 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 539 | if (ar.result == null) { |
| 540 | loge("sendEnvelopeWithStatus: Empty response"); |
| 541 | } else if (ar.exception instanceof CommandException) { |
| 542 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 543 | ar.exception); |
| 544 | } else { |
| 545 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 546 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 547 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 548 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 549 | break; |
| 550 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 551 | case CMD_OPEN_CHANNEL: |
| 552 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 553 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 554 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 555 | if (uiccCard == null) { |
| 556 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 557 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 558 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 559 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 560 | } else { |
| 561 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 562 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 563 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 564 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 565 | break; |
| 566 | |
| 567 | case EVENT_OPEN_CHANNEL_DONE: |
| 568 | ar = (AsyncResult) msg.obj; |
| 569 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 570 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 571 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 572 | int[] result = (int[]) ar.result; |
| 573 | int channelId = result[0]; |
| 574 | byte[] selectResponse = null; |
| 575 | if (result.length > 1) { |
| 576 | selectResponse = new byte[result.length - 1]; |
| 577 | for (int i = 1; i < result.length; ++i) { |
| 578 | selectResponse[i - 1] = (byte) result[i]; |
| 579 | } |
| 580 | } |
| 581 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 582 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 583 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 584 | if (ar.result == null) { |
| 585 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 586 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 587 | if (ar.exception != null) { |
| 588 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 589 | } |
| 590 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 591 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 592 | if (ar.exception instanceof CommandException) { |
| 593 | CommandException.Error error = |
| 594 | ((CommandException) (ar.exception)).getCommandError(); |
| 595 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 596 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 597 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 598 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 602 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 603 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 604 | request.result = openChannelResp; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 605 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 606 | break; |
| 607 | |
| 608 | case CMD_CLOSE_CHANNEL: |
| 609 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 610 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 611 | if (uiccCard == null) { |
| 612 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 613 | request.result = false; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 614 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 615 | } else { |
| 616 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 617 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 618 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 619 | break; |
| 620 | |
| 621 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 622 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 623 | break; |
| 624 | |
| 625 | case CMD_NV_READ_ITEM: |
| 626 | request = (MainThreadRequest) msg.obj; |
| 627 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 628 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 629 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 630 | break; |
| 631 | |
| 632 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 633 | ar = (AsyncResult) msg.obj; |
| 634 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 635 | if (ar.exception == null && ar.result != null) { |
| 636 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 637 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 638 | request.result = ""; |
| 639 | if (ar.result == null) { |
| 640 | loge("nvReadItem: Empty response"); |
| 641 | } else if (ar.exception instanceof CommandException) { |
| 642 | loge("nvReadItem: CommandException: " + |
| 643 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 644 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 645 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 646 | } |
| 647 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 648 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 649 | break; |
| 650 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 651 | case CMD_NV_WRITE_ITEM: |
| 652 | request = (MainThreadRequest) msg.obj; |
| 653 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 654 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 655 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 656 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 657 | break; |
| 658 | |
| 659 | case EVENT_NV_WRITE_ITEM_DONE: |
| 660 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 661 | break; |
| 662 | |
| 663 | case CMD_NV_WRITE_CDMA_PRL: |
| 664 | request = (MainThreadRequest) msg.obj; |
| 665 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 666 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 667 | break; |
| 668 | |
| 669 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 670 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 671 | break; |
| 672 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 673 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 674 | request = (MainThreadRequest) msg.obj; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 675 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 676 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 677 | break; |
| 678 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 679 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 680 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 681 | break; |
| 682 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 683 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 684 | request = (MainThreadRequest) msg.obj; |
| 685 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 686 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 687 | break; |
| 688 | |
| 689 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 690 | ar = (AsyncResult) msg.obj; |
| 691 | request = (MainThreadRequest) ar.userObj; |
| 692 | if (ar.exception == null && ar.result != null) { |
| 693 | request.result = ar.result; // Integer |
| 694 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 695 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 696 | if (ar.result == null) { |
| 697 | loge("getPreferredNetworkType: Empty response"); |
| 698 | } else if (ar.exception instanceof CommandException) { |
| 699 | loge("getPreferredNetworkType: CommandException: " + |
| 700 | ar.exception); |
| 701 | } else { |
| 702 | loge("getPreferredNetworkType: Unknown exception"); |
| 703 | } |
| 704 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 705 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 706 | break; |
| 707 | |
| 708 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 709 | request = (MainThreadRequest) msg.obj; |
| 710 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 711 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 712 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 713 | break; |
| 714 | |
| 715 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 716 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 717 | break; |
| 718 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 719 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 720 | request = (MainThreadRequest)msg.obj; |
| 721 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 722 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 723 | break; |
| 724 | |
| 725 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 726 | ar = (AsyncResult)msg.obj; |
| 727 | request = (MainThreadRequest)ar.userObj; |
| 728 | request.result = ar; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 729 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 730 | break; |
| 731 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 732 | case CMD_SET_VOICEMAIL_NUMBER: |
| 733 | request = (MainThreadRequest) msg.obj; |
| 734 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 735 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 736 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 737 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 738 | break; |
| 739 | |
| 740 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 741 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 742 | break; |
| 743 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 744 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 745 | request = (MainThreadRequest) msg.obj; |
| 746 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 747 | request); |
| 748 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 749 | break; |
| 750 | |
| 751 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 752 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 753 | break; |
| 754 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 755 | case CMD_PERFORM_NETWORK_SCAN: |
| 756 | request = (MainThreadRequest) msg.obj; |
| 757 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 758 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 759 | break; |
| 760 | |
| 761 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 762 | ar = (AsyncResult) msg.obj; |
| 763 | request = (MainThreadRequest) ar.userObj; |
| 764 | CellNetworkScanResult cellScanResult; |
| 765 | if (ar.exception == null && ar.result != null) { |
| 766 | cellScanResult = new CellNetworkScanResult( |
| 767 | CellNetworkScanResult.STATUS_SUCCESS, |
| 768 | (List<OperatorInfo>) ar.result); |
| 769 | } else { |
| 770 | if (ar.result == null) { |
| 771 | loge("getCellNetworkScanResults: Empty response"); |
| 772 | } |
| 773 | if (ar.exception != null) { |
| 774 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 775 | } |
| 776 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 777 | if (ar.exception instanceof CommandException) { |
| 778 | CommandException.Error error = |
| 779 | ((CommandException) (ar.exception)).getCommandError(); |
| 780 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 781 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 782 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 783 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 784 | } |
| 785 | } |
| 786 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 787 | } |
| 788 | request.result = cellScanResult; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 789 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 790 | break; |
| 791 | |
| 792 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 793 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 794 | ManualNetworkSelectionArgument selArg = |
| 795 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 796 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 797 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 798 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 799 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 800 | break; |
| 801 | |
| 802 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | dd9ac82 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 803 | ar = (AsyncResult) msg.obj; |
| 804 | request = (MainThreadRequest) ar.userObj; |
| 805 | if (ar.exception == null) { |
| 806 | request.result = true; |
| 807 | } else { |
| 808 | request.result = false; |
| 809 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 810 | } |
| 811 | notifyRequester(request); |
| 812 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 813 | break; |
| 814 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 815 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 816 | request = (MainThreadRequest) msg.obj; |
| 817 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 818 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 819 | break; |
| 820 | |
| 821 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 822 | ar = (AsyncResult) msg.obj; |
| 823 | request = (MainThreadRequest) ar.userObj; |
| 824 | if (ar.exception == null && ar.result != null) { |
| 825 | request.result = ar.result; |
| 826 | } else { |
| 827 | if (ar.result == null) { |
| 828 | loge("queryModemActivityInfo: Empty response"); |
| 829 | } else if (ar.exception instanceof CommandException) { |
| 830 | loge("queryModemActivityInfo: CommandException: " + |
| 831 | ar.exception); |
| 832 | } else { |
| 833 | loge("queryModemActivityInfo: Unknown exception"); |
| 834 | } |
| 835 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 836 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 837 | if (request.result == null) { |
| 838 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 839 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 840 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 841 | break; |
| 842 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 843 | case CMD_SET_ALLOWED_CARRIERS: |
| 844 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 845 | CarrierRestrictionRules argument = |
| 846 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 847 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 848 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 849 | break; |
| 850 | |
| 851 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 852 | ar = (AsyncResult) msg.obj; |
| 853 | request = (MainThreadRequest) ar.userObj; |
| 854 | if (ar.exception == null && ar.result != null) { |
| 855 | request.result = ar.result; |
| 856 | } else { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 857 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 858 | if (ar.exception instanceof CommandException) { |
| 859 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 860 | CommandException.Error error = |
| 861 | ((CommandException) (ar.exception)).getCommandError(); |
| 862 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 863 | request.result = |
| 864 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 865 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 866 | } else { |
| 867 | loge("setAllowedCarriers: Unknown exception"); |
| 868 | } |
| 869 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 870 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 871 | break; |
| 872 | |
| 873 | case CMD_GET_ALLOWED_CARRIERS: |
| 874 | request = (MainThreadRequest) msg.obj; |
| 875 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 876 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 877 | break; |
| 878 | |
| 879 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 880 | ar = (AsyncResult) msg.obj; |
| 881 | request = (MainThreadRequest) ar.userObj; |
| 882 | if (ar.exception == null && ar.result != null) { |
| 883 | request.result = ar.result; |
| 884 | } else { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 885 | request.result = new IllegalStateException( |
| 886 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 887 | if (ar.result == null) { |
| 888 | loge("getAllowedCarriers: Empty response"); |
| 889 | } else if (ar.exception instanceof CommandException) { |
| 890 | loge("getAllowedCarriers: CommandException: " + |
| 891 | ar.exception); |
| 892 | } else { |
| 893 | loge("getAllowedCarriers: Unknown exception"); |
| 894 | } |
| 895 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 896 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 897 | break; |
| 898 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 899 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 900 | ar = (AsyncResult) msg.obj; |
| 901 | request = (MainThreadRequest) ar.userObj; |
| 902 | if (ar.exception == null && ar.result != null) { |
| 903 | request.result = ar.result; |
| 904 | } else { |
| 905 | request.result = new IllegalArgumentException( |
| 906 | "Failed to retrieve Forbidden Plmns"); |
| 907 | if (ar.result == null) { |
| 908 | loge("getForbiddenPlmns: Empty response"); |
| 909 | } else { |
| 910 | loge("getForbiddenPlmns: Unknown exception"); |
| 911 | } |
| 912 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 913 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 914 | break; |
| 915 | |
| 916 | case CMD_GET_FORBIDDEN_PLMNS: |
| 917 | request = (MainThreadRequest) msg.obj; |
| 918 | uiccCard = getUiccCardFromRequest(request); |
| 919 | if (uiccCard == null) { |
| 920 | loge("getForbiddenPlmns() UiccCard is null"); |
| 921 | request.result = new IllegalArgumentException( |
| 922 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 923 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 924 | break; |
| 925 | } |
| 926 | Integer appType = (Integer) request.argument; |
| 927 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 928 | if (uiccApp == null) { |
| 929 | loge("getForbiddenPlmns() no app with specified type -- " |
| 930 | + appType); |
| 931 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 932 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 933 | break; |
| 934 | } else { |
| 935 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 936 | + " specified type -- " + appType); |
| 937 | } |
| 938 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 939 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 940 | onCompleted); |
| 941 | break; |
| 942 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 943 | case CMD_SWITCH_SLOTS: |
| 944 | request = (MainThreadRequest) msg.obj; |
| 945 | int[] physicalSlots = (int[]) request.argument; |
| 946 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 947 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 948 | break; |
| 949 | |
| 950 | case EVENT_SWITCH_SLOTS_DONE: |
| 951 | ar = (AsyncResult) msg.obj; |
| 952 | request = (MainThreadRequest) ar.userObj; |
| 953 | request.result = (ar.exception == null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 954 | notifyRequester(request); |
| 955 | break; |
| 956 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 957 | request = (MainThreadRequest) msg.obj; |
| 958 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 959 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 960 | break; |
| 961 | |
| 962 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 963 | ar = (AsyncResult) msg.obj; |
| 964 | request = (MainThreadRequest) ar.userObj; |
| 965 | if (ar.exception != null) { |
| 966 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 967 | } else { |
| 968 | int mode = ((int[]) ar.result)[0]; |
| 969 | if (mode == 0) { |
| 970 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 971 | } else { |
| 972 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 973 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 974 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 975 | notifyRequester(request); |
| 976 | break; |
| 977 | case CMD_GET_CDMA_ROAMING_MODE: |
| 978 | request = (MainThreadRequest) msg.obj; |
| 979 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 980 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 981 | break; |
| 982 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 983 | ar = (AsyncResult) msg.obj; |
| 984 | request = (MainThreadRequest) ar.userObj; |
| 985 | if (ar.exception != null) { |
| 986 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 987 | } else { |
| 988 | request.result = ((int[]) ar.result)[0]; |
| 989 | } |
| 990 | notifyRequester(request); |
| 991 | break; |
| 992 | case CMD_SET_CDMA_ROAMING_MODE: |
| 993 | request = (MainThreadRequest) msg.obj; |
| 994 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 995 | int mode = (int) request.argument; |
| 996 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 997 | break; |
| 998 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 999 | ar = (AsyncResult) msg.obj; |
| 1000 | request = (MainThreadRequest) ar.userObj; |
| 1001 | request.result = ar.exception == null; |
| 1002 | notifyRequester(request); |
| 1003 | break; |
| 1004 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1005 | request = (MainThreadRequest) msg.obj; |
| 1006 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1007 | int subscriptionMode = (int) request.argument; |
| 1008 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1009 | break; |
| 1010 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1011 | ar = (AsyncResult) msg.obj; |
| 1012 | request = (MainThreadRequest) ar.userObj; |
| 1013 | request.result = ar.exception == null; |
| 1014 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1015 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1016 | case CMD_GET_ALL_CELL_INFO: |
| 1017 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1018 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1019 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1020 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1021 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1022 | ar = (AsyncResult) msg.obj; |
| 1023 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1024 | // If a timeout occurs, the response will be null |
| 1025 | request.result = (ar.exception == null && ar.result != null) |
| 1026 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1027 | synchronized (request) { |
| 1028 | request.notifyAll(); |
| 1029 | } |
| 1030 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1031 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1032 | request = (MainThreadRequest) msg.obj; |
| 1033 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1034 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1035 | break; |
| 1036 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1037 | ar = (AsyncResult) msg.obj; |
| 1038 | request = (MainThreadRequest) ar.userObj; |
| 1039 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1040 | try { |
| 1041 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1042 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1043 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1044 | new android.os.ParcelableException(ar.exception)); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1045 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1046 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1047 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1048 | } else { |
| 1049 | // use the result as returned |
| 1050 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1051 | } |
| 1052 | } catch (RemoteException re) { |
| 1053 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1054 | } |
| 1055 | break; |
| 1056 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1057 | request = (MainThreadRequest) msg.obj; |
| 1058 | WorkSource ws = (WorkSource) request.argument; |
| 1059 | Phone phone = getPhoneFromRequest(request); |
| 1060 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1061 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1062 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1063 | ar = (AsyncResult) msg.obj; |
| 1064 | request = (MainThreadRequest) ar.userObj; |
| 1065 | if (ar.exception == null) { |
| 1066 | request.result = ar.result; |
| 1067 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1068 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1069 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1070 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1071 | } |
| 1072 | |
| 1073 | synchronized (request) { |
| 1074 | request.notifyAll(); |
| 1075 | } |
| 1076 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1077 | case CMD_MODEM_REBOOT: |
| 1078 | request = (MainThreadRequest) msg.obj; |
| 1079 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1080 | defaultPhone.rebootModem(onCompleted); |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1081 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1082 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1083 | handleNullReturnEvent(msg, "rebootModem"); |
| 1084 | break; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1085 | case CMD_REQUEST_ENABLE_MODEM: |
| 1086 | request = (MainThreadRequest) msg.obj; |
| 1087 | boolean enable = (boolean) request.argument; |
| 1088 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
| 1089 | PhoneConfigurationManager.getInstance() |
| 1090 | .enablePhone(request.phone, enable, onCompleted); |
| 1091 | break; |
| 1092 | case EVENT_ENABLE_MODEM_DONE: |
| 1093 | ar = (AsyncResult) msg.obj; |
| 1094 | request = (MainThreadRequest) ar.userObj; |
| 1095 | request.result = (ar.exception == null); |
| 1096 | notifyRequester(request); |
| 1097 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1098 | default: |
| 1099 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1100 | break; |
| 1101 | } |
| 1102 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1103 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1104 | private void notifyRequester(MainThreadRequest request) { |
| 1105 | synchronized (request) { |
| 1106 | request.notifyAll(); |
| 1107 | } |
| 1108 | } |
| 1109 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1110 | private void handleNullReturnEvent(Message msg, String command) { |
| 1111 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1112 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1113 | if (ar.exception == null) { |
| 1114 | request.result = true; |
| 1115 | } else { |
| 1116 | request.result = false; |
| 1117 | if (ar.exception instanceof CommandException) { |
| 1118 | loge(command + ": CommandException: " + ar.exception); |
| 1119 | } else { |
| 1120 | loge(command + ": Unknown exception"); |
| 1121 | } |
| 1122 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1123 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1124 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | /** |
| 1128 | * Posts the specified command to be executed on the main thread, |
| 1129 | * waits for the request to complete, and returns the result. |
| 1130 | * @see #sendRequestAsync |
| 1131 | */ |
| 1132 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1133 | return sendRequest( |
| 1134 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | /** |
| 1138 | * Posts the specified command to be executed on the main thread, |
| 1139 | * waits for the request to complete, and returns the result. |
| 1140 | * @see #sendRequestAsync |
| 1141 | */ |
| 1142 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1143 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1144 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -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 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1152 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1153 | return sendRequest(command, argument, subId, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 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 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1161 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1162 | return sendRequest(command, argument, subId, null, workSource); |
| 1163 | } |
| 1164 | |
| 1165 | /** |
| 1166 | * Posts the specified command to be executed on the main thread, |
| 1167 | * waits for the request to complete, and returns the result. |
| 1168 | * @see #sendRequestAsync |
| 1169 | */ |
| 1170 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1171 | return sendRequest( |
| 1172 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1173 | } |
| 1174 | |
| 1175 | /** |
| 1176 | * Posts the specified command to be executed on the main thread, |
| 1177 | * waits for the request to complete, and returns the result. |
| 1178 | * @see #sendRequestAsync |
| 1179 | */ |
| 1180 | private Object sendRequest( |
| 1181 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1182 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1183 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1184 | } |
| 1185 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1186 | MainThreadRequest request = null; |
| 1187 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1188 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1189 | } else if (phone != null) { |
| 1190 | request = new MainThreadRequest(argument, phone, workSource); |
| 1191 | } else { |
| 1192 | request = new MainThreadRequest(argument, subId, workSource); |
| 1193 | } |
| 1194 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1195 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1196 | msg.sendToTarget(); |
| 1197 | |
| 1198 | // Wait for the request to complete |
| 1199 | synchronized (request) { |
| 1200 | while (request.result == null) { |
| 1201 | try { |
| 1202 | request.wait(); |
| 1203 | } catch (InterruptedException e) { |
| 1204 | // Do nothing, go back and wait until the request is complete |
| 1205 | } |
| 1206 | } |
| 1207 | } |
| 1208 | return request.result; |
| 1209 | } |
| 1210 | |
| 1211 | /** |
| 1212 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1213 | * Posts the specified command to be executed on the main thread, and |
| 1214 | * returns immediately. |
| 1215 | * @see #sendRequest |
| 1216 | */ |
| 1217 | private void sendRequestAsync(int command) { |
| 1218 | mMainThreadHandler.sendEmptyMessage(command); |
| 1219 | } |
| 1220 | |
| 1221 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1222 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1223 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1224 | */ |
| 1225 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1226 | sendRequestAsync(command, argument, null, null); |
| 1227 | } |
| 1228 | |
| 1229 | /** |
| 1230 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1231 | * @see {@link #sendRequest(int,Object)} |
| 1232 | */ |
| 1233 | private void sendRequestAsync( |
| 1234 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1235 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1236 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1237 | msg.sendToTarget(); |
| 1238 | } |
| 1239 | |
| 1240 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1241 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1242 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1243 | */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1244 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1245 | synchronized (PhoneInterfaceManager.class) { |
| 1246 | if (sInstance == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1247 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1248 | } else { |
| 1249 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1250 | } |
| 1251 | return sInstance; |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1256 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1257 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1258 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1259 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1260 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1261 | mMainThreadHandler = new MainThreadHandler(); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1262 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1263 | mTelephonySharedPreferences = |
| 1264 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1265 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1266 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1267 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1268 | publish(); |
| 1269 | } |
| 1270 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1271 | private Phone getDefaultPhone() { |
| 1272 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1273 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1274 | } |
| 1275 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1276 | private void publish() { |
| 1277 | if (DBG) log("publish: " + this); |
| 1278 | |
| 1279 | ServiceManager.addService("phone", this); |
| 1280 | } |
| 1281 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1282 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 1283 | return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1284 | ? getDefaultPhone() : getPhone(request.subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1285 | } |
| 1286 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1287 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1288 | Phone phone = getPhoneFromRequest(request); |
| 1289 | return phone == null ? null : |
| 1290 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1291 | } |
| 1292 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1293 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1294 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1295 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1296 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1297 | |
| 1298 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1299 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1300 | } |
| 1301 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1302 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1303 | if (DBG) log("dial: " + number); |
| 1304 | // No permission check needed here: This is just a wrapper around the |
| 1305 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1306 | // the UI before it does anything. |
| 1307 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1308 | final long identity = Binder.clearCallingIdentity(); |
| 1309 | try { |
| 1310 | String url = createTelUrl(number); |
| 1311 | if (url == null) { |
| 1312 | return; |
| 1313 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1314 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1315 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1316 | PhoneConstants.State state = mCM.getState(subId); |
| 1317 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1318 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1319 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1320 | mApp.startActivity(intent); |
| 1321 | } |
| 1322 | } finally { |
| 1323 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1328 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1331 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1332 | if (DBG) log("call: " + number); |
| 1333 | |
| 1334 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1335 | // need to do a permission check since we're calling startActivity() |
| 1336 | // from the context of the phone app. |
| 1337 | enforceCallPermission(); |
| 1338 | |
| 1339 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1340 | != AppOpsManager.MODE_ALLOWED) { |
| 1341 | return; |
| 1342 | } |
| 1343 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1344 | final long identity = Binder.clearCallingIdentity(); |
| 1345 | try { |
| 1346 | String url = createTelUrl(number); |
| 1347 | if (url == null) { |
| 1348 | return; |
| 1349 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1350 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1351 | boolean isValid = false; |
| 1352 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1353 | if (slist != null) { |
| 1354 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1355 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1356 | isValid = true; |
| 1357 | break; |
| 1358 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1359 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1360 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1361 | if (!isValid) { |
| 1362 | return; |
| 1363 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1364 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1365 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1366 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1367 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1368 | mApp.startActivity(intent); |
| 1369 | } finally { |
| 1370 | Binder.restoreCallingIdentity(identity); |
| 1371 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1372 | } |
| 1373 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1374 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1375 | return supplyPinForSubscriber(getDefaultSubscription(), 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 supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1379 | int [] resultArray = supplyPinReportResultForSubscriber(subId, 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 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1384 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1385 | } |
| 1386 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1387 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1388 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1389 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1390 | } |
| 1391 | |
| 1392 | /** {@hide} */ |
| 1393 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1394 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1395 | } |
| 1396 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1397 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1398 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1399 | |
| 1400 | final long identity = Binder.clearCallingIdentity(); |
| 1401 | try { |
| 1402 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1403 | checkSimPin.start(); |
| 1404 | return checkSimPin.unlockSim(null, pin); |
| 1405 | } finally { |
| 1406 | Binder.restoreCallingIdentity(identity); |
| 1407 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1410 | /** {@hide} */ |
| 1411 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1412 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1413 | } |
| 1414 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1415 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1416 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1417 | |
| 1418 | final long identity = Binder.clearCallingIdentity(); |
| 1419 | try { |
| 1420 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1421 | checkSimPuk.start(); |
| 1422 | return checkSimPuk.unlockSim(puk, pin); |
| 1423 | } finally { |
| 1424 | Binder.restoreCallingIdentity(identity); |
| 1425 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1429 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1430 | * a synchronous one. |
| 1431 | */ |
| 1432 | private static class UnlockSim extends Thread { |
| 1433 | |
| 1434 | private final IccCard mSimCard; |
| 1435 | |
| 1436 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1437 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1438 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1439 | |
| 1440 | // For replies from SimCard interface |
| 1441 | private Handler mHandler; |
| 1442 | |
| 1443 | // For async handler to identify request type |
| 1444 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1445 | |
| 1446 | public UnlockSim(IccCard simCard) { |
| 1447 | mSimCard = simCard; |
| 1448 | } |
| 1449 | |
| 1450 | @Override |
| 1451 | public void run() { |
| 1452 | Looper.prepare(); |
| 1453 | synchronized (UnlockSim.this) { |
| 1454 | mHandler = new Handler() { |
| 1455 | @Override |
| 1456 | public void handleMessage(Message msg) { |
| 1457 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1458 | switch (msg.what) { |
| 1459 | case SUPPLY_PIN_COMPLETE: |
| 1460 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1461 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1462 | mRetryCount = msg.arg1; |
| 1463 | if (ar.exception != null) { |
| 1464 | if (ar.exception instanceof CommandException && |
| 1465 | ((CommandException)(ar.exception)).getCommandError() |
| 1466 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1467 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1468 | } else { |
| 1469 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1470 | } |
| 1471 | } else { |
| 1472 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1473 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1474 | mDone = true; |
| 1475 | UnlockSim.this.notifyAll(); |
| 1476 | } |
| 1477 | break; |
| 1478 | } |
| 1479 | } |
| 1480 | }; |
| 1481 | UnlockSim.this.notifyAll(); |
| 1482 | } |
| 1483 | Looper.loop(); |
| 1484 | } |
| 1485 | |
| 1486 | /* |
| 1487 | * Use PIN or PUK to unlock SIM card |
| 1488 | * |
| 1489 | * If PUK is null, unlock SIM card with PIN |
| 1490 | * |
| 1491 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1492 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1493 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1494 | |
| 1495 | while (mHandler == null) { |
| 1496 | try { |
| 1497 | wait(); |
| 1498 | } catch (InterruptedException e) { |
| 1499 | Thread.currentThread().interrupt(); |
| 1500 | } |
| 1501 | } |
| 1502 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1503 | |
| 1504 | if (puk == null) { |
| 1505 | mSimCard.supplyPin(pin, callback); |
| 1506 | } else { |
| 1507 | mSimCard.supplyPuk(puk, pin, callback); |
| 1508 | } |
| 1509 | |
| 1510 | while (!mDone) { |
| 1511 | try { |
| 1512 | Log.d(LOG_TAG, "wait for done"); |
| 1513 | wait(); |
| 1514 | } catch (InterruptedException e) { |
| 1515 | // Restore the interrupted status |
| 1516 | Thread.currentThread().interrupt(); |
| 1517 | } |
| 1518 | } |
| 1519 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1520 | int[] resultArray = new int[2]; |
| 1521 | resultArray[0] = mResult; |
| 1522 | resultArray[1] = mRetryCount; |
| 1523 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1524 | } |
| 1525 | } |
| 1526 | |
| 1527 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1528 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1529 | |
| 1530 | } |
| 1531 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1532 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1533 | // No permission check needed here: this call is harmless, and it's |
| 1534 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1535 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1536 | final long identity = Binder.clearCallingIdentity(); |
| 1537 | try { |
| 1538 | final Phone phone = getPhone(subId); |
| 1539 | if (phone != null) { |
| 1540 | phone.updateServiceLocation(); |
| 1541 | } |
| 1542 | } finally { |
| 1543 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1544 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1545 | } |
| 1546 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1547 | @Override |
| 1548 | public boolean isRadioOn(String callingPackage) { |
| 1549 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1552 | @Override |
| 1553 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1554 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1555 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1556 | return false; |
| 1557 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1558 | |
| 1559 | final long identity = Binder.clearCallingIdentity(); |
| 1560 | try { |
| 1561 | return isRadioOnForSubscriber(subId); |
| 1562 | } finally { |
| 1563 | Binder.restoreCallingIdentity(identity); |
| 1564 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1568 | final long identity = Binder.clearCallingIdentity(); |
| 1569 | try { |
| 1570 | final Phone phone = getPhone(subId); |
| 1571 | if (phone != null) { |
| 1572 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1573 | } else { |
| 1574 | return false; |
| 1575 | } |
| 1576 | } finally { |
| 1577 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1578 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1582 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1583 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1584 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1585 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1586 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1587 | |
| 1588 | final long identity = Binder.clearCallingIdentity(); |
| 1589 | try { |
| 1590 | final Phone phone = getPhone(subId); |
| 1591 | if (phone != null) { |
| 1592 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1593 | } |
| 1594 | } finally { |
| 1595 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1596 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1600 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1601 | } |
| 1602 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1603 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1604 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1605 | |
| 1606 | final long identity = Binder.clearCallingIdentity(); |
| 1607 | try { |
| 1608 | final Phone phone = getPhone(subId); |
| 1609 | if (phone == null) { |
| 1610 | return false; |
| 1611 | } |
| 1612 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1613 | toggleRadioOnOffForSubscriber(subId); |
| 1614 | } |
| 1615 | return true; |
| 1616 | } finally { |
| 1617 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1618 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1619 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1620 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1621 | public boolean needMobileRadioShutdown() { |
| 1622 | /* |
| 1623 | * If any of the Radios are available, it will need to be |
| 1624 | * shutdown. So return true if any Radio is available. |
| 1625 | */ |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1626 | final long identity = Binder.clearCallingIdentity(); |
| 1627 | try { |
| 1628 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1629 | Phone phone = PhoneFactory.getPhone(i); |
| 1630 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1631 | } |
| 1632 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1633 | return false; |
| 1634 | } finally { |
| 1635 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1636 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1637 | } |
| 1638 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1639 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1640 | public void shutdownMobileRadios() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1641 | enforceModifyPermission(); |
| 1642 | |
| 1643 | final long identity = Binder.clearCallingIdentity(); |
| 1644 | try { |
| 1645 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1646 | logv("Shutting down Phone " + i); |
| 1647 | shutdownRadioUsingPhoneId(i); |
| 1648 | } |
| 1649 | } finally { |
| 1650 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1651 | } |
| 1652 | } |
| 1653 | |
| 1654 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1655 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1656 | if (phone != null && phone.isRadioAvailable()) { |
| 1657 | phone.shutdownRadio(); |
| 1658 | } |
| 1659 | } |
| 1660 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1661 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1662 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1663 | |
| 1664 | final long identity = Binder.clearCallingIdentity(); |
| 1665 | try { |
| 1666 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1667 | if (defaultPhone != null) { |
| 1668 | defaultPhone.setRadioPower(turnOn); |
| 1669 | return true; |
| 1670 | } else { |
| 1671 | loge("There's no default phone."); |
| 1672 | return false; |
| 1673 | } |
| 1674 | } finally { |
| 1675 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1676 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1677 | } |
| 1678 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1679 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1680 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1681 | |
| 1682 | final long identity = Binder.clearCallingIdentity(); |
| 1683 | try { |
| 1684 | final Phone phone = getPhone(subId); |
| 1685 | if (phone != null) { |
| 1686 | phone.setRadioPower(turnOn); |
| 1687 | return true; |
| 1688 | } else { |
| 1689 | return false; |
| 1690 | } |
| 1691 | } finally { |
| 1692 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1693 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1694 | } |
| 1695 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1696 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1697 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1698 | public boolean enableDataConnectivity() { |
| 1699 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1700 | |
| 1701 | final long identity = Binder.clearCallingIdentity(); |
| 1702 | try { |
| 1703 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1704 | final Phone phone = getPhone(subId); |
| 1705 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1706 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1707 | return true; |
| 1708 | } else { |
| 1709 | return false; |
| 1710 | } |
| 1711 | } finally { |
| 1712 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1713 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1716 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1717 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1718 | public boolean disableDataConnectivity() { |
| 1719 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1720 | |
| 1721 | final long identity = Binder.clearCallingIdentity(); |
| 1722 | try { |
| 1723 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1724 | final Phone phone = getPhone(subId); |
| 1725 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1726 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1727 | return true; |
| 1728 | } else { |
| 1729 | return false; |
| 1730 | } |
| 1731 | } finally { |
| 1732 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1733 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1734 | } |
| 1735 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1736 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1737 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1738 | final long identity = Binder.clearCallingIdentity(); |
| 1739 | try { |
| 1740 | final Phone phone = getPhone(subId); |
| 1741 | if (phone != null) { |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1742 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1743 | } else { |
| 1744 | return false; |
| 1745 | } |
| 1746 | } finally { |
| 1747 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1748 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1752 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1753 | } |
| 1754 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1755 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1756 | enforceCallPermission(); |
| 1757 | |
| 1758 | final long identity = Binder.clearCallingIdentity(); |
| 1759 | try { |
| 1760 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1761 | return; |
| 1762 | } |
| 1763 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1764 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1765 | } finally { |
| 1766 | Binder.restoreCallingIdentity(identity); |
| 1767 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1768 | }; |
| 1769 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1770 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1771 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1772 | |
| 1773 | final long identity = Binder.clearCallingIdentity(); |
| 1774 | try { |
| 1775 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1776 | return false; |
| 1777 | } |
| 1778 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1779 | } finally { |
| 1780 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1781 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1782 | } |
| 1783 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1784 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1785 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1788 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1789 | final long identity = Binder.clearCallingIdentity(); |
| 1790 | try { |
| 1791 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1792 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1793 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1794 | } finally { |
| 1795 | Binder.restoreCallingIdentity(identity); |
| 1796 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1797 | } |
| 1798 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1799 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1800 | public int getDataState() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1801 | final long identity = Binder.clearCallingIdentity(); |
| 1802 | try { |
| 1803 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1804 | if (phone != null) { |
| 1805 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1806 | } else { |
| 1807 | return PhoneConstantConversions.convertDataState( |
| 1808 | PhoneConstants.DataState.DISCONNECTED); |
| 1809 | } |
| 1810 | } finally { |
| 1811 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1812 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1813 | } |
| 1814 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1815 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1816 | public int getDataActivity() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1817 | final long identity = Binder.clearCallingIdentity(); |
| 1818 | try { |
| 1819 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1820 | if (phone != null) { |
| 1821 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1822 | } else { |
| 1823 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1824 | } |
| 1825 | } finally { |
| 1826 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1827 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1831 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1832 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1833 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1834 | if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage, |
| 1835 | Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1836 | return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1837 | } |
| 1838 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1839 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1840 | final long identity = Binder.clearCallingIdentity(); |
| 1841 | try { |
| 1842 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1843 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1844 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1845 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1846 | cl.fillInNotifierBundle(data); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1847 | return data; |
| 1848 | } finally { |
| 1849 | Binder.restoreCallingIdentity(identity); |
| 1850 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1851 | } |
| 1852 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1853 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1854 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1855 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1856 | // registered cell info, so return a NULL country instead. |
| 1857 | final long identity = Binder.clearCallingIdentity(); |
| 1858 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1859 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1860 | // Get default phone in this case. |
| 1861 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1862 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1863 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1864 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1865 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1866 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1867 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1868 | return ""; |
| 1869 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1870 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1871 | if (phone != null) { |
| 1872 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 1873 | if (sst != null) { |
| 1874 | LocaleTracker lt = sst.getLocaleTracker(); |
| 1875 | if (lt != null) { |
| 1876 | return lt.getCurrentCountry(); |
| 1877 | } |
| 1878 | } |
| 1879 | } |
| 1880 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1881 | } finally { |
| 1882 | Binder.restoreCallingIdentity(identity); |
| 1883 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1887 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1888 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1889 | } |
| 1890 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1891 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1892 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1893 | mApp.enforceCallingOrSelfPermission( |
| 1894 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1895 | |
| 1896 | final long identity = Binder.clearCallingIdentity(); |
| 1897 | try { |
| 1898 | final Phone phone = getPhone(subId); |
| 1899 | if (phone != null) { |
| 1900 | phone.enableLocationUpdates(); |
| 1901 | } |
| 1902 | } finally { |
| 1903 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1904 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | @Override |
| 1908 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1909 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1910 | } |
| 1911 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1912 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1913 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1914 | mApp.enforceCallingOrSelfPermission( |
| 1915 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1916 | |
| 1917 | final long identity = Binder.clearCallingIdentity(); |
| 1918 | try { |
| 1919 | final Phone phone = getPhone(subId); |
| 1920 | if (phone != null) { |
| 1921 | phone.disableLocationUpdates(); |
| 1922 | } |
| 1923 | } finally { |
| 1924 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1925 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1926 | } |
| 1927 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1928 | /** |
| 1929 | * Returns the target SDK version number for a given package name. |
| 1930 | * |
| 1931 | * @return target SDK if the package is found or INT_MAX. |
| 1932 | */ |
| 1933 | private int getTargetSdk(String packageName) { |
| 1934 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1935 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo( |
| 1936 | packageName, 0); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1937 | if (ai != null) return ai.targetSdkVersion; |
| 1938 | } catch (PackageManager.NameNotFoundException unexpected) { |
| 1939 | } |
| 1940 | return Integer.MAX_VALUE; |
| 1941 | } |
| 1942 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1943 | @Override |
| 1944 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1945 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 1946 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 1947 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 1948 | throw new SecurityException( |
| 1949 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 1950 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 1951 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1952 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 1953 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 1954 | return null; |
| 1955 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1956 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1957 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1958 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1959 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 1960 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1961 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1962 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 1963 | for (CellInfo ci : info) { |
| 1964 | if (ci instanceof CellInfoGsm) { |
| 1965 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 1966 | } else if (ci instanceof CellInfoWcdma) { |
| 1967 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 1968 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1969 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1970 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1973 | private List<CellInfo> getCachedCellInfo() { |
| 1974 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 1975 | for (Phone phone : PhoneFactory.getPhones()) { |
| 1976 | List<CellInfo> info = phone.getAllCellInfo(); |
| 1977 | if (info != null) cellInfos.addAll(info); |
| 1978 | } |
| 1979 | return cellInfos; |
| 1980 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1981 | |
| 1982 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1983 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1984 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1985 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1986 | if (!LocationAccessPolicy.canAccessCellLocation(mApp, |
Svet Ganov | 4af6628 | 2018-03-07 19:57:05 -0800 | [diff] [blame] | 1987 | callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1988 | return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1989 | } |
| 1990 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1991 | final int targetSdk = getTargetSdk(callingPackage); |
| 1992 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 1993 | return getCachedCellInfo(); |
| 1994 | } |
| 1995 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1996 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1997 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1998 | final long identity = Binder.clearCallingIdentity(); |
| 1999 | try { |
| 2000 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2001 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2002 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2003 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2004 | if (info != null) cellInfos.addAll(info); |
| 2005 | } |
| 2006 | return cellInfos; |
| 2007 | } finally { |
| 2008 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2009 | } |
| 2010 | } |
| 2011 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2012 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2013 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2014 | requestCellInfoUpdateInternal( |
| 2015 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2016 | } |
| 2017 | |
| 2018 | @Override |
| 2019 | public void requestCellInfoUpdateWithWorkSource( |
| 2020 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2021 | enforceModifyPermission(); |
| 2022 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2023 | } |
| 2024 | |
| 2025 | private void requestCellInfoUpdateInternal( |
| 2026 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2027 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2028 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2029 | if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage, |
| 2030 | Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2031 | return; |
| 2032 | } |
| 2033 | |
| 2034 | final Phone phone = getPhone(subId); |
| 2035 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2036 | |
| 2037 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2038 | } |
| 2039 | |
| 2040 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2041 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2042 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2043 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2044 | |
| 2045 | final long identity = Binder.clearCallingIdentity(); |
| 2046 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2047 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2048 | } finally { |
| 2049 | Binder.restoreCallingIdentity(identity); |
| 2050 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2051 | } |
| 2052 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2053 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2054 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2055 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2056 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2057 | return null; |
| 2058 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2059 | int subId = phone.getSubId(); |
| 2060 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2061 | mApp, subId, callingPackage, "getImeiForSlot")) { |
| 2062 | return null; |
| 2063 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2064 | |
| 2065 | final long identity = Binder.clearCallingIdentity(); |
| 2066 | try { |
| 2067 | return phone.getImei(); |
| 2068 | } finally { |
| 2069 | Binder.restoreCallingIdentity(identity); |
| 2070 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2074 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2075 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2076 | String tac = null; |
| 2077 | if (phone != null) { |
| 2078 | String imei = phone.getImei(); |
| 2079 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2080 | } |
| 2081 | return tac; |
| 2082 | } |
| 2083 | |
| 2084 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2085 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2086 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2087 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2088 | return null; |
| 2089 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2090 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2091 | int subId = phone.getSubId(); |
| 2092 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2093 | mApp, subId, callingPackage, "getMeidForSlot")) { |
| 2094 | return null; |
| 2095 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2096 | |
| 2097 | final long identity = Binder.clearCallingIdentity(); |
| 2098 | try { |
| 2099 | return phone.getMeid(); |
| 2100 | } finally { |
| 2101 | Binder.restoreCallingIdentity(identity); |
| 2102 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2103 | } |
| 2104 | |
| 2105 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2106 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2107 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2108 | String manufacturerCode = null; |
| 2109 | if (phone != null) { |
| 2110 | String meid = phone.getMeid(); |
| 2111 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2112 | } |
| 2113 | return manufacturerCode; |
| 2114 | } |
| 2115 | |
| 2116 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2117 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2118 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2119 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2120 | return null; |
| 2121 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2122 | int subId = phone.getSubId(); |
| 2123 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2124 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2125 | return null; |
| 2126 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2127 | |
| 2128 | final long identity = Binder.clearCallingIdentity(); |
| 2129 | try { |
| 2130 | return phone.getDeviceSvn(); |
| 2131 | } finally { |
| 2132 | Binder.restoreCallingIdentity(identity); |
| 2133 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2134 | } |
| 2135 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2136 | @Override |
| 2137 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2138 | final long identity = Binder.clearCallingIdentity(); |
| 2139 | try { |
| 2140 | final Phone phone = getPhone(subId); |
| 2141 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2142 | } finally { |
| 2143 | Binder.restoreCallingIdentity(identity); |
| 2144 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2145 | } |
| 2146 | |
| 2147 | @Override |
| 2148 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2149 | final long identity = Binder.clearCallingIdentity(); |
| 2150 | try { |
| 2151 | final Phone phone = getPhone(subId); |
| 2152 | return phone == null ? null : phone.getCarrierName(); |
| 2153 | } finally { |
| 2154 | Binder.restoreCallingIdentity(identity); |
| 2155 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2156 | } |
| 2157 | |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2158 | @Override |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2159 | public int getSubscriptionPreciseCarrierId(int subId) { |
| 2160 | final long identity = Binder.clearCallingIdentity(); |
| 2161 | try { |
| 2162 | final Phone phone = getPhone(subId); |
| 2163 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
| 2164 | : phone.getPreciseCarrierId(); |
| 2165 | } finally { |
| 2166 | Binder.restoreCallingIdentity(identity); |
| 2167 | } |
| 2168 | } |
| 2169 | |
| 2170 | @Override |
| 2171 | public String getSubscriptionPreciseCarrierName(int subId) { |
| 2172 | final long identity = Binder.clearCallingIdentity(); |
| 2173 | try { |
| 2174 | final Phone phone = getPhone(subId); |
| 2175 | return phone == null ? null : phone.getPreciseCarrierName(); |
| 2176 | } finally { |
| 2177 | Binder.restoreCallingIdentity(identity); |
| 2178 | } |
| 2179 | } |
| 2180 | |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2181 | @Override |
chen xu | 4ca4e69 | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2182 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2183 | if (!isSubscriptionMccMnc) { |
| 2184 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2185 | } |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2186 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2187 | if (phone == null) { |
| 2188 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2189 | } |
| 2190 | final long identity = Binder.clearCallingIdentity(); |
| 2191 | try { |
| 2192 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2193 | } finally { |
| 2194 | Binder.restoreCallingIdentity(identity); |
| 2195 | } |
| 2196 | } |
| 2197 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2198 | // |
| 2199 | // Internal helper methods. |
| 2200 | // |
| 2201 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2202 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2203 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2204 | * |
| 2205 | * @throws SecurityException if the caller does not have the required permission |
| 2206 | */ |
| 2207 | private void enforceModifyPermission() { |
| 2208 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2209 | } |
| 2210 | |
| 2211 | /** |
| 2212 | * Make sure the caller has the CALL_PHONE permission. |
| 2213 | * |
| 2214 | * @throws SecurityException if the caller does not have the required permission |
| 2215 | */ |
| 2216 | private void enforceCallPermission() { |
| 2217 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2218 | } |
| 2219 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2220 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2221 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2222 | "ConnectivityService"); |
| 2223 | } |
| 2224 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2225 | private String createTelUrl(String number) { |
| 2226 | if (TextUtils.isEmpty(number)) { |
| 2227 | return null; |
| 2228 | } |
| 2229 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2230 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2231 | } |
| 2232 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2233 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2234 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2235 | } |
| 2236 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2237 | private static void logv(String msg) { |
| 2238 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2239 | } |
| 2240 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2241 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2242 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2243 | } |
| 2244 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2245 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2246 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2247 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2248 | } |
| 2249 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2250 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2251 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2252 | final long identity = Binder.clearCallingIdentity(); |
| 2253 | try { |
| 2254 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2255 | if (phone == null) { |
| 2256 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2257 | } else { |
| 2258 | return phone.getPhoneType(); |
| 2259 | } |
| 2260 | } finally { |
| 2261 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2262 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2263 | } |
| 2264 | |
| 2265 | /** |
| 2266 | * Returns the CDMA ERI icon index to display |
| 2267 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2268 | @Override |
| 2269 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2270 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2271 | } |
| 2272 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2273 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2274 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2275 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2276 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2277 | return -1; |
| 2278 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2279 | |
| 2280 | final long identity = Binder.clearCallingIdentity(); |
| 2281 | try { |
| 2282 | final Phone phone = getPhone(subId); |
| 2283 | if (phone != null) { |
| 2284 | return phone.getCdmaEriIconIndex(); |
| 2285 | } else { |
| 2286 | return -1; |
| 2287 | } |
| 2288 | } finally { |
| 2289 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2290 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | /** |
| 2294 | * Returns the CDMA ERI icon mode, |
| 2295 | * 0 - ON |
| 2296 | * 1 - FLASHING |
| 2297 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2298 | @Override |
| 2299 | public int getCdmaEriIconMode(String callingPackage) { |
| 2300 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2301 | } |
| 2302 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2303 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2304 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2305 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2306 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2307 | return -1; |
| 2308 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2309 | |
| 2310 | final long identity = Binder.clearCallingIdentity(); |
| 2311 | try { |
| 2312 | final Phone phone = getPhone(subId); |
| 2313 | if (phone != null) { |
| 2314 | return phone.getCdmaEriIconMode(); |
| 2315 | } else { |
| 2316 | return -1; |
| 2317 | } |
| 2318 | } finally { |
| 2319 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2320 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | /** |
| 2324 | * Returns the CDMA ERI text, |
| 2325 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2326 | @Override |
| 2327 | public String getCdmaEriText(String callingPackage) { |
| 2328 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2329 | } |
| 2330 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2331 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2332 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2333 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2334 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2335 | return null; |
| 2336 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2337 | |
| 2338 | final long identity = Binder.clearCallingIdentity(); |
| 2339 | try { |
| 2340 | final Phone phone = getPhone(subId); |
| 2341 | if (phone != null) { |
| 2342 | return phone.getCdmaEriText(); |
| 2343 | } else { |
| 2344 | return null; |
| 2345 | } |
| 2346 | } finally { |
| 2347 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2348 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2349 | } |
| 2350 | |
| 2351 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2352 | * Returns the CDMA MDN. |
| 2353 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2354 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2355 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2356 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2357 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2358 | |
| 2359 | final long identity = Binder.clearCallingIdentity(); |
| 2360 | try { |
| 2361 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2362 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2363 | return phone.getLine1Number(); |
| 2364 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2365 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2366 | return null; |
| 2367 | } |
| 2368 | } finally { |
| 2369 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2370 | } |
| 2371 | } |
| 2372 | |
| 2373 | /** |
| 2374 | * Returns the CDMA MIN. |
| 2375 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2376 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2377 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2378 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2379 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2380 | |
| 2381 | final long identity = Binder.clearCallingIdentity(); |
| 2382 | try { |
| 2383 | final Phone phone = getPhone(subId); |
| 2384 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2385 | return phone.getCdmaMin(); |
| 2386 | } else { |
| 2387 | return null; |
| 2388 | } |
| 2389 | } finally { |
| 2390 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2391 | } |
| 2392 | } |
| 2393 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2394 | @Override |
| 2395 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2396 | INumberVerificationCallback callback, String callingPackage) { |
| 2397 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2398 | != PERMISSION_GRANTED) { |
| 2399 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2400 | } |
| 2401 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2402 | |
| 2403 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2404 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2405 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2406 | } |
| 2407 | |
| 2408 | if (range == null) { |
| 2409 | throw new NullPointerException("Range must be non-null"); |
| 2410 | } |
| 2411 | |
| 2412 | timeoutMillis = Math.min(timeoutMillis, |
| 2413 | TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS); |
| 2414 | |
| 2415 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2416 | } |
| 2417 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2418 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2419 | * Returns true if CDMA provisioning needs to run. |
| 2420 | */ |
| 2421 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2422 | final long identity = Binder.clearCallingIdentity(); |
| 2423 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2424 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2425 | } finally { |
| 2426 | Binder.restoreCallingIdentity(identity); |
| 2427 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2428 | } |
| 2429 | |
| 2430 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2431 | * Sets the voice mail number of a given subId. |
| 2432 | */ |
| 2433 | @Override |
| 2434 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2435 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2436 | |
| 2437 | final long identity = Binder.clearCallingIdentity(); |
| 2438 | try { |
| 2439 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2440 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2441 | return success; |
| 2442 | } finally { |
| 2443 | Binder.restoreCallingIdentity(identity); |
| 2444 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2445 | } |
| 2446 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2447 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2448 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2449 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2450 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2451 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2452 | throw new SecurityException("caller must be system dialer"); |
| 2453 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2454 | |
| 2455 | final long identity = Binder.clearCallingIdentity(); |
| 2456 | try { |
| 2457 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2458 | if (phoneAccountHandle == null) { |
| 2459 | return null; |
| 2460 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2461 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2462 | } finally { |
| 2463 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2464 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2465 | } |
| 2466 | |
| 2467 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2468 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2469 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2470 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2471 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2472 | return null; |
| 2473 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2474 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2475 | final long identity = Binder.clearCallingIdentity(); |
| 2476 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2477 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2478 | } finally { |
| 2479 | Binder.restoreCallingIdentity(identity); |
| 2480 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2484 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2485 | VisualVoicemailSmsFilterSettings settings) { |
| 2486 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2487 | |
| 2488 | final long identity = Binder.clearCallingIdentity(); |
| 2489 | try { |
| 2490 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2491 | mApp, callingPackage, subId, settings); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2492 | } finally { |
| 2493 | Binder.restoreCallingIdentity(identity); |
| 2494 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2495 | } |
| 2496 | |
| 2497 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2498 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2499 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2500 | |
| 2501 | final long identity = Binder.clearCallingIdentity(); |
| 2502 | try { |
| 2503 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2504 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2505 | } finally { |
| 2506 | Binder.restoreCallingIdentity(identity); |
| 2507 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2508 | } |
| 2509 | |
| 2510 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2511 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2512 | String callingPackage, int subId) { |
| 2513 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2514 | |
| 2515 | final long identity = Binder.clearCallingIdentity(); |
| 2516 | try { |
| 2517 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2518 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2519 | } finally { |
| 2520 | Binder.restoreCallingIdentity(identity); |
| 2521 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2525 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2526 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2527 | |
| 2528 | final long identity = Binder.clearCallingIdentity(); |
| 2529 | try { |
| 2530 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2531 | mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2532 | } finally { |
| 2533 | Binder.restoreCallingIdentity(identity); |
| 2534 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | @Override |
| 2538 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2539 | String number, int port, String text, PendingIntent sentIntent) { |
| 2540 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2541 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2542 | enforceSendSmsPermission(); |
| 2543 | // Make the calls as the phone process. |
| 2544 | final long identity = Binder.clearCallingIdentity(); |
| 2545 | try { |
| 2546 | SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); |
| 2547 | if (port == 0) { |
| 2548 | smsManager.sendTextMessageWithSelfPermissions(number, null, text, |
| 2549 | sentIntent, null, false); |
| 2550 | } else { |
| 2551 | byte[] data = text.getBytes(StandardCharsets.UTF_8); |
| 2552 | smsManager.sendDataMessageWithSelfPermissions(number, null, |
| 2553 | (short) port, data, sentIntent, null); |
| 2554 | } |
| 2555 | } finally { |
| 2556 | Binder.restoreCallingIdentity(identity); |
| 2557 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2558 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2559 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2560 | * Sets the voice activation state of a given subId. |
| 2561 | */ |
| 2562 | @Override |
| 2563 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2564 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2565 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2566 | |
| 2567 | final long identity = Binder.clearCallingIdentity(); |
| 2568 | try { |
| 2569 | final Phone phone = getPhone(subId); |
| 2570 | if (phone != null) { |
| 2571 | phone.setVoiceActivationState(activationState); |
| 2572 | } else { |
| 2573 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2574 | } |
| 2575 | } finally { |
| 2576 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2577 | } |
| 2578 | } |
| 2579 | |
| 2580 | /** |
| 2581 | * Sets the data activation state of a given subId. |
| 2582 | */ |
| 2583 | @Override |
| 2584 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2585 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2586 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2587 | |
| 2588 | final long identity = Binder.clearCallingIdentity(); |
| 2589 | try { |
| 2590 | final Phone phone = getPhone(subId); |
| 2591 | if (phone != null) { |
| 2592 | phone.setDataActivationState(activationState); |
| 2593 | } else { |
| 2594 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2595 | } |
| 2596 | } finally { |
| 2597 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2598 | } |
| 2599 | } |
| 2600 | |
| 2601 | /** |
| 2602 | * Returns the voice activation state of a given subId. |
| 2603 | */ |
| 2604 | @Override |
| 2605 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2606 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2607 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2608 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2609 | final long identity = Binder.clearCallingIdentity(); |
| 2610 | try { |
| 2611 | if (phone != null) { |
| 2612 | return phone.getVoiceActivationState(); |
| 2613 | } else { |
| 2614 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2615 | } |
| 2616 | } finally { |
| 2617 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2618 | } |
| 2619 | } |
| 2620 | |
| 2621 | /** |
| 2622 | * Returns the data activation state of a given subId. |
| 2623 | */ |
| 2624 | @Override |
| 2625 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2626 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2627 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2628 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2629 | final long identity = Binder.clearCallingIdentity(); |
| 2630 | try { |
| 2631 | if (phone != null) { |
| 2632 | return phone.getDataActivationState(); |
| 2633 | } else { |
| 2634 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2635 | } |
| 2636 | } finally { |
| 2637 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2638 | } |
| 2639 | } |
| 2640 | |
| 2641 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2642 | * Returns the unread count of voicemails for a subId |
| 2643 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2644 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2645 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2646 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2647 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2648 | return 0; |
| 2649 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2650 | final long identity = Binder.clearCallingIdentity(); |
| 2651 | try { |
| 2652 | final Phone phone = getPhone(subId); |
| 2653 | if (phone != null) { |
| 2654 | return phone.getVoiceMessageCount(); |
| 2655 | } else { |
| 2656 | return 0; |
| 2657 | } |
| 2658 | } finally { |
| 2659 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2660 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2661 | } |
| 2662 | |
| 2663 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2664 | * returns true, if the device is in a state where both voice and data |
| 2665 | * are supported simultaneously. This can change based on location or network condition. |
| 2666 | */ |
| 2667 | @Override |
| 2668 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2669 | final long identity = Binder.clearCallingIdentity(); |
| 2670 | try { |
| 2671 | final Phone phone = getPhone(subId); |
| 2672 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2673 | } finally { |
| 2674 | Binder.restoreCallingIdentity(identity); |
| 2675 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2676 | } |
| 2677 | |
| 2678 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2679 | * Send the dialer code if called from the current default dialer or the caller has |
| 2680 | * carrier privilege. |
| 2681 | * @param inputCode The dialer code to send |
| 2682 | */ |
| 2683 | @Override |
| 2684 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2685 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2686 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2687 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2688 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2689 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2690 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2691 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2692 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2693 | |
| 2694 | final long identity = Binder.clearCallingIdentity(); |
| 2695 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2696 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2697 | } finally { |
| 2698 | Binder.restoreCallingIdentity(identity); |
| 2699 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2700 | } |
| 2701 | |
| 2702 | /** |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2703 | * Returns the data network type. |
| 2704 | * Legacy call, permission-free. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2705 | * |
| 2706 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 2707 | */ |
| 2708 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2709 | public int getNetworkType() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2710 | final long identity = Binder.clearCallingIdentity(); |
| 2711 | try { |
| 2712 | final Phone phone = getPhone(getDefaultSubscription()); |
| 2713 | if (phone != null) { |
| 2714 | return phone.getServiceState().getDataNetworkType(); |
| 2715 | } else { |
| 2716 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2717 | } |
| 2718 | } finally { |
| 2719 | Binder.restoreCallingIdentity(identity); |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2720 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2721 | } |
| 2722 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2723 | @Override |
| 2724 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2725 | if (!isActiveSubscription(subId)) { |
| 2726 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2727 | } |
| 2728 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2729 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2730 | } |
| 2731 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2732 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2733 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2734 | throws RemoteException { |
| 2735 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2736 | final long token = Binder.clearCallingIdentity(); |
| 2737 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2738 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2739 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2740 | .addRegistrationCallbackForSubscription(c, subId); |
| 2741 | } finally { |
| 2742 | Binder.restoreCallingIdentity(token); |
| 2743 | } |
| 2744 | } |
| 2745 | |
| 2746 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2747 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2748 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2749 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2750 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2751 | } |
| 2752 | Binder.withCleanCallingIdentity(() -> { |
| 2753 | try { |
| 2754 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2755 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2756 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2757 | } catch (IllegalArgumentException e) { |
| 2758 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2759 | + "is inactive, ignoring unregister."); |
| 2760 | // If the subscription is no longer active, just return, since the callback |
| 2761 | // will already have been removed internally. |
| 2762 | } |
| 2763 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2764 | } |
| 2765 | |
| 2766 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2767 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2768 | throws RemoteException { |
| 2769 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2770 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2771 | final long token = Binder.clearCallingIdentity(); |
| 2772 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2773 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2774 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2775 | } finally { |
| 2776 | Binder.restoreCallingIdentity(token); |
| 2777 | } |
| 2778 | } |
| 2779 | |
| 2780 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2781 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2782 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2783 | |
| 2784 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2785 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2786 | } |
| 2787 | Binder.withCleanCallingIdentity(() -> { |
| 2788 | try { |
| 2789 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2790 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2791 | .removeCapabilitiesCallbackForSubscription(c, subId); |
| 2792 | } catch (IllegalArgumentException e) { |
| 2793 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2794 | + "is inactive, ignoring unregister."); |
| 2795 | // If the subscription is no longer active, just return, since the callback |
| 2796 | // will already have been removed internally. |
| 2797 | } |
| 2798 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2799 | } |
| 2800 | |
| 2801 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2802 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2803 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2804 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2805 | final long token = Binder.clearCallingIdentity(); |
| 2806 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2807 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2808 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2809 | } catch (ImsException e) { |
| 2810 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2811 | return false; |
| 2812 | } finally { |
| 2813 | Binder.restoreCallingIdentity(token); |
| 2814 | } |
| 2815 | } |
| 2816 | |
| 2817 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2818 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2819 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2820 | final long token = Binder.clearCallingIdentity(); |
| 2821 | try { |
| 2822 | Phone phone = getPhone(subId); |
| 2823 | if (phone == null) return false; |
| 2824 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2825 | } finally { |
| 2826 | Binder.restoreCallingIdentity(token); |
| 2827 | } |
| 2828 | } |
| 2829 | |
| 2830 | @Override |
| 2831 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2832 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2833 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2834 | final long token = Binder.clearCallingIdentity(); |
| 2835 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2836 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2837 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2838 | } finally { |
| 2839 | Binder.restoreCallingIdentity(token); |
| 2840 | } |
| 2841 | } |
| 2842 | |
| 2843 | @Override |
| 2844 | public void setAdvancedCallingSetting(int subId, boolean isEnabled) { |
| 2845 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2846 | "setAdvancedCallingSetting"); |
| 2847 | final long identity = Binder.clearCallingIdentity(); |
| 2848 | try { |
| 2849 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2850 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2851 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 2852 | } finally { |
| 2853 | Binder.restoreCallingIdentity(identity); |
| 2854 | } |
| 2855 | } |
| 2856 | |
| 2857 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2858 | public boolean isVtSettingEnabled(int subId) { |
| 2859 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2860 | final long identity = Binder.clearCallingIdentity(); |
| 2861 | try { |
| 2862 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2863 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2864 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2865 | } finally { |
| 2866 | Binder.restoreCallingIdentity(identity); |
| 2867 | } |
| 2868 | } |
| 2869 | |
| 2870 | @Override |
| 2871 | public void setVtSetting(int subId, boolean isEnabled) { |
| 2872 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2873 | "setVtSetting"); |
| 2874 | final long identity = Binder.clearCallingIdentity(); |
| 2875 | try { |
| 2876 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2877 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2878 | } finally { |
| 2879 | Binder.restoreCallingIdentity(identity); |
| 2880 | } |
| 2881 | } |
| 2882 | |
| 2883 | @Override |
| 2884 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 2885 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 2886 | final long identity = Binder.clearCallingIdentity(); |
| 2887 | try { |
| 2888 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2889 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2890 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 2891 | } finally { |
| 2892 | Binder.restoreCallingIdentity(identity); |
| 2893 | } |
| 2894 | } |
| 2895 | |
| 2896 | @Override |
| 2897 | public void setVoWiFiSetting(int subId, boolean isEnabled) { |
| 2898 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2899 | "setVoWiFiSetting"); |
| 2900 | final long identity = Binder.clearCallingIdentity(); |
| 2901 | try { |
| 2902 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2903 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2904 | } finally { |
| 2905 | Binder.restoreCallingIdentity(identity); |
| 2906 | } |
| 2907 | } |
| 2908 | |
| 2909 | @Override |
| 2910 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 2911 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 2912 | final long identity = Binder.clearCallingIdentity(); |
| 2913 | try { |
| 2914 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2915 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2916 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 2917 | } finally { |
| 2918 | Binder.restoreCallingIdentity(identity); |
| 2919 | } |
| 2920 | } |
| 2921 | |
| 2922 | @Override |
| 2923 | public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) { |
| 2924 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2925 | "setVoWiFiRoamingSetting"); |
| 2926 | final long identity = Binder.clearCallingIdentity(); |
| 2927 | try { |
| 2928 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2929 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2930 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 2931 | } finally { |
| 2932 | Binder.restoreCallingIdentity(identity); |
| 2933 | } |
| 2934 | } |
| 2935 | |
| 2936 | @Override |
| 2937 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 2938 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2939 | "setVoWiFiNonPersistent"); |
| 2940 | final long identity = Binder.clearCallingIdentity(); |
| 2941 | try { |
| 2942 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2943 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2944 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
| 2945 | } finally { |
| 2946 | Binder.restoreCallingIdentity(identity); |
| 2947 | } |
| 2948 | } |
| 2949 | |
| 2950 | @Override |
| 2951 | public int getVoWiFiModeSetting(int subId) { |
| 2952 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 2953 | final long identity = Binder.clearCallingIdentity(); |
| 2954 | try { |
| 2955 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2956 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2957 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 2958 | } finally { |
| 2959 | Binder.restoreCallingIdentity(identity); |
| 2960 | } |
| 2961 | } |
| 2962 | |
| 2963 | @Override |
| 2964 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 2965 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2966 | "setVoWiFiModeSetting"); |
| 2967 | final long identity = Binder.clearCallingIdentity(); |
| 2968 | try { |
| 2969 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2970 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2971 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 2972 | } finally { |
| 2973 | Binder.restoreCallingIdentity(identity); |
| 2974 | } |
| 2975 | } |
| 2976 | |
| 2977 | @Override |
| 2978 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 2979 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 2980 | final long identity = Binder.clearCallingIdentity(); |
| 2981 | try { |
| 2982 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2983 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2984 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 2985 | } finally { |
| 2986 | Binder.restoreCallingIdentity(identity); |
| 2987 | } |
| 2988 | } |
| 2989 | |
| 2990 | @Override |
| 2991 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 2992 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2993 | "setVoWiFiRoamingModeSetting"); |
| 2994 | final long identity = Binder.clearCallingIdentity(); |
| 2995 | try { |
| 2996 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2997 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2998 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 2999 | } finally { |
| 3000 | Binder.restoreCallingIdentity(identity); |
| 3001 | } |
| 3002 | } |
| 3003 | |
| 3004 | @Override |
| 3005 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3006 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3007 | "setRttCapabilityEnabled"); |
| 3008 | final long identity = Binder.clearCallingIdentity(); |
| 3009 | try { |
| 3010 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3011 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3012 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3013 | } finally { |
| 3014 | Binder.restoreCallingIdentity(identity); |
| 3015 | } |
| 3016 | } |
| 3017 | |
| 3018 | @Override |
| 3019 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3020 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3021 | final long identity = Binder.clearCallingIdentity(); |
| 3022 | try { |
| 3023 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3024 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3025 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 3026 | } finally { |
| 3027 | Binder.restoreCallingIdentity(identity); |
| 3028 | } |
| 3029 | } |
| 3030 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3031 | @Override |
| 3032 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3033 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3034 | final long identity = Binder.clearCallingIdentity(); |
| 3035 | try { |
| 3036 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3037 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3038 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3039 | } finally { |
| 3040 | Binder.restoreCallingIdentity(identity); |
| 3041 | } |
| 3042 | } |
| 3043 | |
| 3044 | @Override |
| 3045 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3046 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3047 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3048 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3049 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3050 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3051 | try { |
| 3052 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3053 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3054 | .removeProvisioningCallbackForSubscription(callback, subId); |
| 3055 | } catch (IllegalArgumentException e) { |
| 3056 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3057 | + "is inactive, ignoring unregister."); |
| 3058 | // If the subscription is no longer active, just return, since the callback will already |
| 3059 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3060 | } finally { |
| 3061 | Binder.restoreCallingIdentity(identity); |
| 3062 | } |
| 3063 | } |
| 3064 | |
| 3065 | @Override |
| 3066 | public int getImsProvisioningInt(int subId, int key) { |
| 3067 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3068 | final long identity = Binder.clearCallingIdentity(); |
| 3069 | try { |
| 3070 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3071 | return ImsManager.getInstance(mApp, |
| 3072 | getSlotIndexOrException(subId)).getConfigInterface().getConfigInt(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3073 | } catch (ImsException e) { |
| 3074 | throw new IllegalArgumentException(e.getMessage()); |
| 3075 | } finally { |
| 3076 | Binder.restoreCallingIdentity(identity); |
| 3077 | } |
| 3078 | } |
| 3079 | |
| 3080 | @Override |
| 3081 | public String getImsProvisioningString(int subId, int key) { |
| 3082 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3083 | final long identity = Binder.clearCallingIdentity(); |
| 3084 | try { |
| 3085 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3086 | return ImsManager.getInstance(mApp, |
| 3087 | getSlotIndexOrException(subId)).getConfigInterface().getConfigString(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3088 | } catch (ImsException e) { |
| 3089 | throw new IllegalArgumentException(e.getMessage()); |
| 3090 | } finally { |
| 3091 | Binder.restoreCallingIdentity(identity); |
| 3092 | } |
| 3093 | } |
| 3094 | |
| 3095 | @Override |
| 3096 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3097 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3098 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3099 | final long identity = Binder.clearCallingIdentity(); |
| 3100 | try { |
| 3101 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3102 | return ImsManager.getInstance(mApp, |
| 3103 | getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3104 | } catch (ImsException e) { |
| 3105 | throw new IllegalArgumentException(e.getMessage()); |
| 3106 | } finally { |
| 3107 | Binder.restoreCallingIdentity(identity); |
| 3108 | } |
| 3109 | } |
| 3110 | |
| 3111 | @Override |
| 3112 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3113 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3114 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3115 | final long identity = Binder.clearCallingIdentity(); |
| 3116 | try { |
| 3117 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3118 | return ImsManager.getInstance(mApp, |
| 3119 | getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3120 | } catch (ImsException e) { |
| 3121 | throw new IllegalArgumentException(e.getMessage()); |
| 3122 | } finally { |
| 3123 | Binder.restoreCallingIdentity(identity); |
| 3124 | } |
| 3125 | } |
| 3126 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3127 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 3128 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3129 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3130 | throw new IllegalArgumentException("Invalid Subscription Id."); |
| 3131 | } |
| 3132 | return slotId; |
| 3133 | } |
| 3134 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3135 | /** |
| 3136 | * Returns the network type for a subId |
| 3137 | */ |
| 3138 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3139 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3140 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3141 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3142 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3143 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3144 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3145 | final long identity = Binder.clearCallingIdentity(); |
| 3146 | try { |
| 3147 | final Phone phone = getPhone(subId); |
| 3148 | if (phone != null) { |
| 3149 | return phone.getServiceState().getDataNetworkType(); |
| 3150 | } else { |
| 3151 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3152 | } |
| 3153 | } finally { |
| 3154 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3155 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3156 | } |
| 3157 | |
| 3158 | /** |
| 3159 | * Returns the data network type |
| 3160 | */ |
| 3161 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3162 | public int getDataNetworkType(String callingPackage) { |
| 3163 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3164 | } |
| 3165 | |
| 3166 | /** |
| 3167 | * Returns the data network type for a subId |
| 3168 | */ |
| 3169 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3170 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3171 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3172 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3173 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3174 | } |
| 3175 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3176 | final long identity = Binder.clearCallingIdentity(); |
| 3177 | try { |
| 3178 | final Phone phone = getPhone(subId); |
| 3179 | if (phone != null) { |
| 3180 | return phone.getServiceState().getDataNetworkType(); |
| 3181 | } else { |
| 3182 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3183 | } |
| 3184 | } finally { |
| 3185 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3186 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3187 | } |
| 3188 | |
| 3189 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3190 | * Returns the Voice network type for a subId |
| 3191 | */ |
| 3192 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3193 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3194 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3195 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3196 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3197 | } |
| 3198 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3199 | final long identity = Binder.clearCallingIdentity(); |
| 3200 | try { |
| 3201 | final Phone phone = getPhone(subId); |
| 3202 | if (phone != null) { |
| 3203 | return phone.getServiceState().getVoiceNetworkType(); |
| 3204 | } else { |
| 3205 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3206 | } |
| 3207 | } finally { |
| 3208 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3209 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3210 | } |
| 3211 | |
| 3212 | /** |
| 3213 | * @return true if a ICC card is present |
| 3214 | */ |
| 3215 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3216 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3217 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3218 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3219 | } |
| 3220 | |
| 3221 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3222 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3223 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3224 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3225 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3226 | final long identity = Binder.clearCallingIdentity(); |
| 3227 | try { |
| 3228 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3229 | if (phone != null) { |
| 3230 | return phone.getIccCard().hasIccCard(); |
| 3231 | } else { |
| 3232 | return false; |
| 3233 | } |
| 3234 | } finally { |
| 3235 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3236 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3237 | } |
| 3238 | |
| 3239 | /** |
| 3240 | * Return if the current radio is LTE on CDMA. This |
| 3241 | * is a tri-state return value as for a period of time |
| 3242 | * the mode may be unknown. |
| 3243 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3244 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3245 | * @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] | 3246 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3247 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3248 | @Override |
| 3249 | public int getLteOnCdmaMode(String callingPackage) { |
| 3250 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3251 | } |
| 3252 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3253 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3254 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3255 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3256 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3257 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3258 | } |
| 3259 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3260 | final long identity = Binder.clearCallingIdentity(); |
| 3261 | try { |
| 3262 | final Phone phone = getPhone(subId); |
| 3263 | if (phone == null) { |
| 3264 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3265 | } else { |
| 3266 | return phone.getLteOnCdmaMode(); |
| 3267 | } |
| 3268 | } finally { |
| 3269 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3270 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3271 | } |
| 3272 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3273 | /** |
| 3274 | * {@hide} |
| 3275 | * Returns Default subId, 0 in the case of single standby. |
| 3276 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3277 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3278 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3279 | } |
| 3280 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3281 | private int getSlotForDefaultSubscription() { |
| 3282 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3283 | } |
| 3284 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3285 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3286 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3287 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3288 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3289 | private boolean isActiveSubscription(int subId) { |
| 3290 | return mSubscriptionController.isActiveSubId(subId); |
| 3291 | } |
| 3292 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3293 | /** |
| 3294 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3295 | */ |
| 3296 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3297 | final long identity = Binder.clearCallingIdentity(); |
| 3298 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3299 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3300 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3301 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3302 | } finally { |
| 3303 | Binder.restoreCallingIdentity(identity); |
| 3304 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3305 | } |
| 3306 | |
| 3307 | /** |
| 3308 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3309 | */ |
| 3310 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3311 | final long identity = Binder.clearCallingIdentity(); |
| 3312 | try { |
| 3313 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3314 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3315 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3316 | } finally { |
| 3317 | Binder.restoreCallingIdentity(identity); |
| 3318 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3319 | } |
| 3320 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3321 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3322 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3323 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3324 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3325 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3326 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3327 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3328 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3329 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3330 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3331 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3332 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3333 | final long identity = Binder.clearCallingIdentity(); |
| 3334 | try { |
| 3335 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3336 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3337 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3338 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3339 | if (bestComponent == null |
| 3340 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3341 | loge("The calling package is not allowed to access ISD-R."); |
| 3342 | throw new SecurityException( |
| 3343 | "The calling package is not allowed to access ISD-R."); |
| 3344 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3345 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3346 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3347 | if (DBG) { |
| 3348 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3349 | } |
| 3350 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
| 3351 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId); |
| 3352 | if (DBG) log("iccOpenLogicalChannel: " + response); |
| 3353 | return response; |
| 3354 | } finally { |
| 3355 | Binder.restoreCallingIdentity(identity); |
| 3356 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3357 | } |
| 3358 | |
| 3359 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3360 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3361 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3362 | mApp, subId, "iccCloseLogicalChannel"); |
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 | final long identity = Binder.clearCallingIdentity(); |
| 3365 | try { |
| 3366 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3367 | if (channel < 0) { |
| 3368 | return false; |
| 3369 | } |
| 3370 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId); |
| 3371 | if (DBG) log("iccCloseLogicalChannel: " + success); |
| 3372 | return success; |
| 3373 | } finally { |
| 3374 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3375 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3379 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3380 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3381 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3382 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3383 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3384 | final long identity = Binder.clearCallingIdentity(); |
| 3385 | try { |
| 3386 | if (DBG) { |
| 3387 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3388 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3389 | + p3 + " data=" + data); |
| 3390 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3391 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3392 | if (channel < 0) { |
| 3393 | return ""; |
| 3394 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3395 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3396 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
| 3397 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId); |
| 3398 | if (DBG) log("iccTransmitApduLogicalChannel: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3399 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3400 | // Append the returned status code to the end of the response payload. |
| 3401 | String s = Integer.toHexString( |
| 3402 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3403 | if (response.payload != null) { |
| 3404 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3405 | } |
| 3406 | return s; |
| 3407 | } finally { |
| 3408 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3409 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3410 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3411 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3412 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3413 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3414 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3415 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3416 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3417 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3418 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3419 | final long identity = Binder.clearCallingIdentity(); |
| 3420 | try { |
| 3421 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3422 | && TextUtils.equals(ISDR_AID, data)) { |
| 3423 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3424 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3425 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3426 | if (bestComponent == null |
| 3427 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3428 | loge("The calling package is not allowed to select ISD-R."); |
| 3429 | throw new SecurityException( |
| 3430 | "The calling package is not allowed to select ISD-R."); |
| 3431 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3432 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3433 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3434 | if (DBG) { |
| 3435 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3436 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3437 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3438 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3439 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
| 3440 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId); |
| 3441 | if (DBG) log("iccTransmitApduBasicChannel: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3442 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3443 | // Append the returned status code to the end of the response payload. |
| 3444 | String s = Integer.toHexString( |
| 3445 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3446 | if (response.payload != null) { |
| 3447 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3448 | } |
| 3449 | return s; |
| 3450 | } finally { |
| 3451 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3452 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3453 | } |
| 3454 | |
| 3455 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3456 | 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] | 3457 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3458 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3459 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3460 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3461 | final long identity = Binder.clearCallingIdentity(); |
| 3462 | try { |
| 3463 | if (DBG) { |
| 3464 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3465 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3466 | } |
| 3467 | |
| 3468 | IccIoResult response = |
| 3469 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3470 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3471 | subId); |
| 3472 | |
| 3473 | if (DBG) { |
| 3474 | log("Exchange SIM_IO [R]" + response); |
| 3475 | } |
| 3476 | |
| 3477 | byte[] result = null; |
| 3478 | int length = 2; |
| 3479 | if (response.payload != null) { |
| 3480 | length = 2 + response.payload.length; |
| 3481 | result = new byte[length]; |
| 3482 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3483 | } else { |
| 3484 | result = new byte[length]; |
| 3485 | } |
| 3486 | |
| 3487 | result[length - 1] = (byte) response.sw2; |
| 3488 | result[length - 2] = (byte) response.sw1; |
| 3489 | return result; |
| 3490 | } finally { |
| 3491 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3492 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3493 | } |
| 3494 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3495 | /** |
| 3496 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 3497 | * on a particular subscription |
| 3498 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3499 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 3500 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3501 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 3502 | return null; |
| 3503 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3504 | |
| 3505 | final long identity = Binder.clearCallingIdentity(); |
| 3506 | try { |
| 3507 | if (appType != TelephonyManager.APPTYPE_USIM |
| 3508 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 3509 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 3510 | return null; |
| 3511 | } |
| 3512 | Object response = sendRequest( |
| 3513 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 3514 | if (response instanceof String[]) { |
| 3515 | return (String[]) response; |
| 3516 | } |
| 3517 | // Response is an Exception of some kind, |
| 3518 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3519 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3520 | } finally { |
| 3521 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3522 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3523 | } |
| 3524 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3525 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3526 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3527 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3528 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3529 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3530 | final long identity = Binder.clearCallingIdentity(); |
| 3531 | try { |
| 3532 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 3533 | if (response.payload == null) { |
| 3534 | return ""; |
| 3535 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3536 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3537 | // Append the returned status code to the end of the response payload. |
| 3538 | String s = Integer.toHexString( |
| 3539 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3540 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3541 | return s; |
| 3542 | } finally { |
| 3543 | Binder.restoreCallingIdentity(identity); |
| 3544 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3545 | } |
| 3546 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3547 | /** |
| 3548 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3549 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3550 | * |
| 3551 | * @param itemID the ID of the item to read |
| 3552 | * @return the NV item as a String, or null on error. |
| 3553 | */ |
| 3554 | @Override |
| 3555 | public String nvReadItem(int itemID) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3556 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3557 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3558 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3559 | |
| 3560 | final long identity = Binder.clearCallingIdentity(); |
| 3561 | try { |
| 3562 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3563 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3564 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 3565 | return value; |
| 3566 | } finally { |
| 3567 | Binder.restoreCallingIdentity(identity); |
| 3568 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3569 | } |
| 3570 | |
| 3571 | /** |
| 3572 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3573 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3574 | * |
| 3575 | * @param itemID the ID of the item to read |
| 3576 | * @param itemValue the value to write, as a String |
| 3577 | * @return true on success; false on any failure |
| 3578 | */ |
| 3579 | @Override |
| 3580 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3581 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3582 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3583 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3584 | |
| 3585 | final long identity = Binder.clearCallingIdentity(); |
| 3586 | try { |
| 3587 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 3588 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3589 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3590 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 3591 | return success; |
| 3592 | } finally { |
| 3593 | Binder.restoreCallingIdentity(identity); |
| 3594 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | /** |
| 3598 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 3599 | * Used for device configuration by some CDMA operators. |
| 3600 | * |
| 3601 | * @param preferredRoamingList byte array containing the new PRL |
| 3602 | * @return true on success; false on any failure |
| 3603 | */ |
| 3604 | @Override |
| 3605 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3606 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3607 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3608 | |
| 3609 | final long identity = Binder.clearCallingIdentity(); |
| 3610 | try { |
| 3611 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 3612 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 3613 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 3614 | return success; |
| 3615 | } finally { |
| 3616 | Binder.restoreCallingIdentity(identity); |
| 3617 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3618 | } |
| 3619 | |
| 3620 | /** |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3621 | * 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] | 3622 | * Used for device configuration by some CDMA operators. |
| 3623 | * |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3624 | * @param slotIndex - device slot. |
| 3625 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3626 | * @return true on success; false on any failure |
| 3627 | */ |
| 3628 | @Override |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3629 | public boolean resetModemConfig(int slotIndex) { |
| 3630 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3631 | if (phone != null) { |
| 3632 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3633 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3634 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3635 | final long identity = Binder.clearCallingIdentity(); |
| 3636 | try { |
| 3637 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 3638 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 3639 | return success; |
| 3640 | } finally { |
| 3641 | Binder.restoreCallingIdentity(identity); |
| 3642 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3643 | } |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3644 | return false; |
| 3645 | } |
| 3646 | |
| 3647 | /** |
| 3648 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 3649 | * |
| 3650 | * @param slotIndex - device slot. |
| 3651 | * |
| 3652 | * @return true on success; false on any failure |
| 3653 | */ |
| 3654 | @Override |
| 3655 | public boolean rebootModem(int slotIndex) { |
| 3656 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3657 | if (phone != null) { |
| 3658 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3659 | mApp, phone.getSubId(), "rebootModem"); |
| 3660 | |
| 3661 | final long identity = Binder.clearCallingIdentity(); |
| 3662 | try { |
| 3663 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 3664 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 3665 | return success; |
| 3666 | } finally { |
| 3667 | Binder.restoreCallingIdentity(identity); |
| 3668 | } |
| 3669 | } |
| 3670 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3671 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3672 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3673 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3674 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3675 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3676 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3677 | return new String[0]; |
| 3678 | } |
| 3679 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3680 | final long identity = Binder.clearCallingIdentity(); |
| 3681 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3682 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3683 | } finally { |
| 3684 | Binder.restoreCallingIdentity(identity); |
| 3685 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3686 | } |
| 3687 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3688 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3689 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 3690 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3691 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3692 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3693 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3694 | |
| 3695 | final long identity = Binder.clearCallingIdentity(); |
| 3696 | try { |
| 3697 | PhoneFactory.getImsResolver().enableIms(slotId); |
| 3698 | } finally { |
| 3699 | Binder.restoreCallingIdentity(identity); |
| 3700 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3701 | } |
| 3702 | |
| 3703 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3704 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 3705 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3706 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3707 | public void disableIms(int slotId) { |
| 3708 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3709 | |
| 3710 | final long identity = Binder.clearCallingIdentity(); |
| 3711 | try { |
| 3712 | PhoneFactory.getImsResolver().disableIms(slotId); |
| 3713 | } finally { |
| 3714 | Binder.restoreCallingIdentity(identity); |
| 3715 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3716 | } |
| 3717 | |
| 3718 | /** |
| 3719 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 3720 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 3721 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 3722 | */ |
| 3723 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3724 | IImsServiceFeatureCallback callback) { |
| 3725 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3726 | |
| 3727 | final long identity = Binder.clearCallingIdentity(); |
| 3728 | try { |
| 3729 | return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback); |
| 3730 | } finally { |
| 3731 | Binder.restoreCallingIdentity(identity); |
| 3732 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3733 | } |
| 3734 | |
| 3735 | /** |
| 3736 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 3737 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 3738 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 3739 | * listener for feature updates. |
| 3740 | */ |
| 3741 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 3742 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3743 | |
| 3744 | final long identity = Binder.clearCallingIdentity(); |
| 3745 | try { |
| 3746 | return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback); |
| 3747 | } finally { |
| 3748 | Binder.restoreCallingIdentity(identity); |
| 3749 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3750 | } |
| 3751 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 3752 | /** |
| 3753 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
| 3754 | * specified. |
| 3755 | */ |
| 3756 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 3757 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3758 | |
| 3759 | final long identity = Binder.clearCallingIdentity(); |
| 3760 | try { |
| 3761 | return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature); |
| 3762 | } finally { |
| 3763 | Binder.restoreCallingIdentity(identity); |
| 3764 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 3765 | } |
| 3766 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3767 | /** |
| 3768 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
| 3769 | * specified. |
| 3770 | */ |
| 3771 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 3772 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3773 | |
| 3774 | final long identity = Binder.clearCallingIdentity(); |
| 3775 | try { |
| 3776 | return PhoneFactory.getImsResolver().getImsConfig(slotId, feature); |
| 3777 | } finally { |
| 3778 | Binder.restoreCallingIdentity(identity); |
| 3779 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3780 | } |
| 3781 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 3782 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 3783 | * Sets the ImsService Package Name that Telephony will bind to. |
| 3784 | * |
| 3785 | * @param slotId the slot ID that the ImsService should bind for. |
| 3786 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 3787 | * ImsService is the device default ImsService. |
| 3788 | * @param packageName The package name of the application that contains the ImsService to bind |
| 3789 | * to. |
| 3790 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 3791 | * @hide |
| 3792 | */ |
| 3793 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 3794 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 3795 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 3796 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 3797 | "setImsService"); |
| 3798 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3799 | final long identity = Binder.clearCallingIdentity(); |
| 3800 | try { |
| 3801 | return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId, |
| 3802 | isCarrierImsService, packageName); |
| 3803 | } finally { |
| 3804 | Binder.restoreCallingIdentity(identity); |
| 3805 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 3806 | } |
| 3807 | |
| 3808 | /** |
| 3809 | * Return the ImsService configuration. |
| 3810 | * |
| 3811 | * @param slotId The slot that the ImsService is associated with. |
| 3812 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 3813 | * the device default. |
| 3814 | * @return the package name of the ImsService configuration. |
| 3815 | */ |
| 3816 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 3817 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 3818 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 3819 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 3820 | "getImsService"); |
| 3821 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3822 | final long identity = Binder.clearCallingIdentity(); |
| 3823 | try { |
| 3824 | return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId, |
| 3825 | isCarrierImsService); |
| 3826 | } finally { |
| 3827 | Binder.restoreCallingIdentity(identity); |
| 3828 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 3829 | } |
| 3830 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3831 | public void setImsRegistrationState(boolean registered) { |
| 3832 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3833 | |
| 3834 | final long identity = Binder.clearCallingIdentity(); |
| 3835 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3836 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3837 | } finally { |
| 3838 | Binder.restoreCallingIdentity(identity); |
| 3839 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3840 | } |
| 3841 | |
| 3842 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3843 | * Set the network selection mode to automatic. |
| 3844 | * |
| 3845 | */ |
| 3846 | @Override |
| 3847 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3848 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3849 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3850 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3851 | if (!isActiveSubscription(subId)) { |
| 3852 | return; |
| 3853 | } |
| 3854 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3855 | final long identity = Binder.clearCallingIdentity(); |
| 3856 | try { |
| 3857 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 3858 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 3859 | } finally { |
| 3860 | Binder.restoreCallingIdentity(identity); |
| 3861 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3862 | } |
| 3863 | |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3864 | /** |
| 3865 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 3866 | * |
| 3867 | * @param subId the id of the subscription. |
| 3868 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 3869 | * the operator to attach to. |
| 3870 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 3871 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 3872 | * normal network selection next time. |
| 3873 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 3874 | */ |
| 3875 | @Override |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3876 | public boolean setNetworkSelectionModeManual( |
| 3877 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3878 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3879 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3880 | |
| 3881 | if (!isActiveSubscription(subId)) { |
| 3882 | return false; |
| 3883 | } |
| 3884 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3885 | final long identity = Binder.clearCallingIdentity(); |
| 3886 | try { |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3887 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3888 | persistSelection); |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3889 | if (DBG) { |
| 3890 | log("setNetworkSelectionModeManual: subId: " + subId |
| 3891 | + " operator: " + operatorInfo); |
| 3892 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3893 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 3894 | } finally { |
| 3895 | Binder.restoreCallingIdentity(identity); |
| 3896 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 3897 | } |
| 3898 | |
| 3899 | /** |
| 3900 | * Scans for available networks. |
| 3901 | */ |
| 3902 | @Override |
| 3903 | public CellNetworkScanResult getCellNetworkScanResults(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3904 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3905 | mApp, subId, "getCellNetworkScanResults"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3906 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3907 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3908 | try { |
| 3909 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3910 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3911 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3912 | } finally { |
| 3913 | Binder.restoreCallingIdentity(identity); |
| 3914 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 3915 | } |
| 3916 | |
| 3917 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3918 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3919 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3920 | * @param subId id of the subscription |
| 3921 | * @param request contains the radio access networks with bands/channels to scan |
| 3922 | * @param messenger callback messenger for scan results or errors |
| 3923 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3924 | * @return the id of the requested scan which can be used to stop the scan. |
| 3925 | */ |
| 3926 | @Override |
| 3927 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
| 3928 | IBinder binder) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3929 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3930 | mApp, subId, "requestNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3931 | |
| 3932 | final long identity = Binder.clearCallingIdentity(); |
| 3933 | try { |
| 3934 | return mNetworkScanRequestTracker.startNetworkScan( |
| 3935 | request, messenger, binder, getPhone(subId)); |
| 3936 | } finally { |
| 3937 | Binder.restoreCallingIdentity(identity); |
| 3938 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3939 | } |
| 3940 | |
| 3941 | /** |
| 3942 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3943 | * |
| 3944 | * @param subId id of the subscription |
| 3945 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3946 | */ |
| 3947 | @Override |
| 3948 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3949 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3950 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3951 | |
| 3952 | final long identity = Binder.clearCallingIdentity(); |
| 3953 | try { |
| 3954 | mNetworkScanRequestTracker.stopNetworkScan(scanId); |
| 3955 | } finally { |
| 3956 | Binder.restoreCallingIdentity(identity); |
| 3957 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3958 | } |
| 3959 | |
| 3960 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 3961 | * Get the calculated preferred network type. |
| 3962 | * Used for debugging incorrect network type. |
| 3963 | * |
| 3964 | * @return the preferred network type, defined in RILConstants.java. |
| 3965 | */ |
| 3966 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3967 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3968 | final Phone defaultPhone = getDefaultPhone(); |
| 3969 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 3970 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3971 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 3972 | } |
| 3973 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3974 | final long identity = Binder.clearCallingIdentity(); |
| 3975 | try { |
| 3976 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3977 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3978 | } finally { |
| 3979 | Binder.restoreCallingIdentity(identity); |
| 3980 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 3981 | } |
| 3982 | |
| 3983 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3984 | * Get the preferred network type. |
| 3985 | * Used for device configuration by some CDMA operators. |
| 3986 | * |
| 3987 | * @return the preferred network type, defined in RILConstants.java. |
| 3988 | */ |
| 3989 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3990 | public int getPreferredNetworkType(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3991 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3992 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3993 | |
| 3994 | final long identity = Binder.clearCallingIdentity(); |
| 3995 | try { |
| 3996 | if (DBG) log("getPreferredNetworkType"); |
| 3997 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 3998 | int networkType = (result != null ? result[0] : -1); |
| 3999 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4000 | return networkType; |
| 4001 | } finally { |
| 4002 | Binder.restoreCallingIdentity(identity); |
| 4003 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4004 | } |
| 4005 | |
| 4006 | /** |
| 4007 | * Set the preferred network type. |
| 4008 | * Used for device configuration by some CDMA operators. |
| 4009 | * |
| 4010 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4011 | * @return true on success; false on any failure. |
| 4012 | */ |
| 4013 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4014 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4015 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4016 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4017 | |
| 4018 | final long identity = Binder.clearCallingIdentity(); |
| 4019 | try { |
| 4020 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4021 | Boolean success = (Boolean) sendRequest( |
| 4022 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4023 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4024 | if (success) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4025 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4026 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4027 | } |
| 4028 | return success; |
| 4029 | } finally { |
| 4030 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4031 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4032 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4033 | |
| 4034 | /** |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4035 | * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning |
Jack Yu | 13db0fe | 2018-10-30 17:41:31 -0700 | [diff] [blame] | 4036 | * SystemProperty to decide whether DUN APN is required for |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4037 | * tethering. |
| 4038 | * |
| 4039 | * @return 0: Not required. 1: required. 2: Not set. |
| 4040 | * @hide |
| 4041 | */ |
| 4042 | @Override |
| 4043 | public int getTetherApnRequired() { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4044 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4045 | |
| 4046 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4047 | final Phone defaultPhone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4048 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4049 | int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4050 | Settings.Global.TETHER_DUN_REQUIRED, 2); |
Jack Yu | 13db0fe | 2018-10-30 17:41:31 -0700 | [diff] [blame] | 4051 | // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4052 | if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4053 | dunRequired = 1; |
| 4054 | } |
| 4055 | return dunRequired; |
| 4056 | } finally { |
| 4057 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4058 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4059 | } |
| 4060 | |
| 4061 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4062 | * Set mobile data enabled |
| 4063 | * Used by the user through settings etc to turn on/off mobile data |
| 4064 | * |
| 4065 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4066 | */ |
| 4067 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4068 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4069 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4070 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4071 | |
| 4072 | final long identity = Binder.clearCallingIdentity(); |
| 4073 | try { |
| 4074 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4075 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4076 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4077 | if (phone != null) { |
| 4078 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4079 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4080 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4081 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4082 | } |
| 4083 | } finally { |
| 4084 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4085 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4086 | } |
| 4087 | |
| 4088 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4089 | * Get the user enabled state of Mobile Data. |
| 4090 | * |
| 4091 | * TODO: remove and use isUserDataEnabled. |
| 4092 | * This can't be removed now because some vendor codes |
| 4093 | * calls through ITelephony directly while they should |
| 4094 | * use TelephonyManager. |
| 4095 | * |
| 4096 | * @return true on enabled |
| 4097 | */ |
| 4098 | @Override |
| 4099 | public boolean getDataEnabled(int subId) { |
| 4100 | return isUserDataEnabled(subId); |
| 4101 | } |
| 4102 | |
| 4103 | /** |
| 4104 | * Get whether mobile data is enabled per user setting. |
| 4105 | * |
| 4106 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4107 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4108 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4109 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4110 | * |
| 4111 | * @return {@code true} if data is enabled else {@code false} |
| 4112 | */ |
| 4113 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4114 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4115 | try { |
| 4116 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4117 | null); |
| 4118 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4119 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4120 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4121 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4122 | |
| 4123 | final long identity = Binder.clearCallingIdentity(); |
| 4124 | try { |
| 4125 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4126 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4127 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4128 | if (phone != null) { |
| 4129 | boolean retVal = phone.isUserDataEnabled(); |
| 4130 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4131 | return retVal; |
| 4132 | } else { |
| 4133 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4134 | return false; |
| 4135 | } |
| 4136 | } finally { |
| 4137 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4138 | } |
| 4139 | } |
| 4140 | |
| 4141 | /** |
| 4142 | * Get whether mobile data is enabled. |
| 4143 | * |
| 4144 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4145 | * whether mobile data is actually enabled. |
| 4146 | * |
| 4147 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4148 | * |
| 4149 | * @return {@code true} if data is enabled else {@code false} |
| 4150 | */ |
| 4151 | @Override |
| 4152 | public boolean isDataEnabled(int subId) { |
| 4153 | try { |
| 4154 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4155 | null); |
| 4156 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4157 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4158 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4159 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4160 | |
| 4161 | final long identity = Binder.clearCallingIdentity(); |
| 4162 | try { |
| 4163 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4164 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4165 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4166 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4167 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4168 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4169 | return retVal; |
| 4170 | } else { |
| 4171 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4172 | return false; |
| 4173 | } |
| 4174 | } finally { |
| 4175 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4176 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4177 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4178 | |
| 4179 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4180 | public int getCarrierPrivilegeStatus(int subId) { |
| 4181 | final Phone phone = getPhone(subId); |
| 4182 | if (phone == null) { |
| 4183 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4184 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4185 | } |
| 4186 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4187 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4188 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4189 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4190 | } |
| 4191 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4192 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4193 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4194 | |
| 4195 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4196 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4197 | final Phone phone = getPhone(subId); |
| 4198 | if (phone == null) { |
| 4199 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4200 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4201 | } |
| 4202 | UiccProfile profile = |
| 4203 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4204 | if (profile == null) { |
| 4205 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4206 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4207 | } |
| 4208 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 4209 | } |
| 4210 | |
| 4211 | @Override |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4212 | public int checkCarrierPrivilegesForPackage(String pkgName) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4213 | final Phone defaultPhone = getDefaultPhone(); |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4214 | if (TextUtils.isEmpty(pkgName)) |
| 4215 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4216 | UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4217 | if (card == null) { |
| 4218 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 4219 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4220 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4221 | return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(), |
| 4222 | pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4223 | } |
| 4224 | |
| 4225 | @Override |
| 4226 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4227 | if (TextUtils.isEmpty(pkgName)) |
| 4228 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4229 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4230 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4231 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4232 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4233 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4234 | continue; |
| 4235 | } |
| 4236 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4237 | result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4238 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4239 | break; |
| 4240 | } |
| 4241 | } |
| 4242 | |
| 4243 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4244 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4245 | |
| 4246 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4247 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4248 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4249 | loge("phoneId " + phoneId + " is not valid."); |
| 4250 | return null; |
| 4251 | } |
| 4252 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4253 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4254 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4255 | return null ; |
| 4256 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4257 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4258 | } |
| 4259 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4260 | @Override |
| 4261 | public List<String> getPackagesWithCarrierPrivileges() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4262 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4263 | List<String> privilegedPackages = new ArrayList<>(); |
| 4264 | List<PackageInfo> packages = null; |
| 4265 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4266 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4267 | if (card == null) { |
| 4268 | // No UICC in that slot. |
| 4269 | continue; |
| 4270 | } |
| 4271 | if (card.hasCarrierPrivilegeRules()) { |
| 4272 | if (packages == null) { |
| 4273 | // Only check packages in user 0 for now |
| 4274 | packages = pm.getInstalledPackagesAsUser( |
| 4275 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4276 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4277 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
| 4278 | } |
| 4279 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4280 | PackageInfo pkgInfo = packages.get(p); |
| 4281 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4282 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| 4283 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4284 | privilegedPackages.add(pkgInfo.packageName); |
| 4285 | } |
| 4286 | } |
| 4287 | } |
| 4288 | } |
| 4289 | return privilegedPackages; |
| 4290 | } |
| 4291 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4292 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4293 | final Phone phone = getPhone(subId); |
| 4294 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4295 | if (card == null) { |
| 4296 | loge("getIccId: No UICC"); |
| 4297 | return null; |
| 4298 | } |
| 4299 | String iccId = card.getIccId(); |
| 4300 | if (TextUtils.isEmpty(iccId)) { |
| 4301 | loge("getIccId: ICC ID is null or empty."); |
| 4302 | return null; |
| 4303 | } |
| 4304 | return iccId; |
| 4305 | } |
| 4306 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4307 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4308 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4309 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4310 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4311 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4312 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4313 | final long identity = Binder.clearCallingIdentity(); |
| 4314 | try { |
| 4315 | final String iccId = getIccId(subId); |
| 4316 | final Phone phone = getPhone(subId); |
| 4317 | if (phone == null) { |
| 4318 | return false; |
| 4319 | } |
| 4320 | final String subscriberId = phone.getSubscriberId(); |
| 4321 | |
| 4322 | if (DBG_MERGE) { |
| 4323 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4324 | + subscriberId + " to " + number); |
| 4325 | } |
| 4326 | |
| 4327 | if (TextUtils.isEmpty(iccId)) { |
| 4328 | return false; |
| 4329 | } |
| 4330 | |
| 4331 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4332 | |
| 4333 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4334 | if (alphaTag == null) { |
| 4335 | editor.remove(alphaTagPrefKey); |
| 4336 | } else { |
| 4337 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4338 | } |
| 4339 | |
| 4340 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4341 | // track all merged IMSIs based on line number |
| 4342 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4343 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4344 | if (number == null) { |
| 4345 | editor.remove(numberPrefKey); |
| 4346 | editor.remove(subscriberPrefKey); |
| 4347 | } else { |
| 4348 | editor.putString(numberPrefKey, number); |
| 4349 | editor.putString(subscriberPrefKey, subscriberId); |
| 4350 | } |
| 4351 | |
| 4352 | editor.commit(); |
| 4353 | return true; |
| 4354 | } finally { |
| 4355 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4356 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4357 | } |
| 4358 | |
| 4359 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4360 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4361 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4362 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4363 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4364 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4365 | return null; |
| 4366 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4367 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4368 | final long identity = Binder.clearCallingIdentity(); |
| 4369 | try { |
| 4370 | String iccId = getIccId(subId); |
| 4371 | if (iccId != null) { |
| 4372 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4373 | if (DBG_MERGE) { |
| 4374 | log("getLine1NumberForDisplay returning " |
| 4375 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 4376 | } |
| 4377 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4378 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4379 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 4380 | return null; |
| 4381 | } finally { |
| 4382 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4383 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4384 | } |
| 4385 | |
| 4386 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4387 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4388 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4389 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4390 | return null; |
| 4391 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4392 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4393 | final long identity = Binder.clearCallingIdentity(); |
| 4394 | try { |
| 4395 | String iccId = getIccId(subId); |
| 4396 | if (iccId != null) { |
| 4397 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4398 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 4399 | } |
| 4400 | return null; |
| 4401 | } finally { |
| 4402 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4403 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4404 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4405 | |
| 4406 | @Override |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4407 | public String[] getMergedSubscriberIds(String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4408 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 4409 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4410 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4411 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 4412 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4413 | return null; |
| 4414 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4415 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4416 | final long identity = Binder.clearCallingIdentity(); |
| 4417 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4418 | final Context context = mApp; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4419 | final TelephonyManager tele = TelephonyManager.from(context); |
| 4420 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 4421 | |
| 4422 | // Figure out what subscribers are currently active |
| 4423 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
| 4424 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 4425 | // the process, where TelephonyManager was instantiated. |
| 4426 | // Otherwise AppOps check will fail. |
| 4427 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4428 | final int[] subIds = sub.getActiveSubscriptionIdList(); |
| 4429 | for (int subId : subIds) { |
| 4430 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 4431 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4432 | |
| 4433 | // First pass, find a number override for an active subscriber |
| 4434 | String mergeNumber = null; |
| 4435 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 4436 | for (String key : prefs.keySet()) { |
| 4437 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 4438 | final String subscriberId = (String) prefs.get(key); |
| 4439 | if (activeSubscriberIds.contains(subscriberId)) { |
| 4440 | final String iccId = key.substring( |
| 4441 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 4442 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4443 | mergeNumber = (String) prefs.get(numberKey); |
| 4444 | if (DBG_MERGE) { |
| 4445 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 4446 | + " for active subscriber " + subscriberId); |
| 4447 | } |
| 4448 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 4449 | break; |
| 4450 | } |
| 4451 | } |
| 4452 | } |
| 4453 | } |
| 4454 | |
| 4455 | // Shortcut when no active merged subscribers |
| 4456 | if (TextUtils.isEmpty(mergeNumber)) { |
| 4457 | return null; |
| 4458 | } |
| 4459 | |
| 4460 | // Second pass, find all subscribers under that line override |
| 4461 | final ArraySet<String> result = new ArraySet<>(); |
| 4462 | for (String key : prefs.keySet()) { |
| 4463 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 4464 | final String number = (String) prefs.get(key); |
| 4465 | if (mergeNumber.equals(number)) { |
| 4466 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 4467 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4468 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 4469 | if (!TextUtils.isEmpty(subscriberId)) { |
| 4470 | result.add(subscriberId); |
| 4471 | } |
| 4472 | } |
| 4473 | } |
| 4474 | } |
| 4475 | |
| 4476 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 4477 | Arrays.sort(resultArray); |
| 4478 | if (DBG_MERGE) { |
| 4479 | Slog.d(LOG_TAG, |
| 4480 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 4481 | } |
| 4482 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4483 | } finally { |
| 4484 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4485 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4486 | } |
| 4487 | |
| 4488 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4489 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4490 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4491 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4492 | |
| 4493 | final long identity = Binder.clearCallingIdentity(); |
| 4494 | try { |
| 4495 | final Phone phone = getPhone(subId); |
| 4496 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 4497 | } finally { |
| 4498 | Binder.restoreCallingIdentity(identity); |
| 4499 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4500 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 4501 | |
| 4502 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4503 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4504 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 4505 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4506 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4507 | |
| 4508 | final long identity = Binder.clearCallingIdentity(); |
| 4509 | try { |
| 4510 | final Phone phone = getPhone(subId); |
| 4511 | if (phone == null) { |
| 4512 | return false; |
| 4513 | } |
| 4514 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 4515 | cdmaNonRoamingList); |
| 4516 | } finally { |
| 4517 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4518 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4519 | } |
| 4520 | |
| 4521 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4522 | @Deprecated |
| 4523 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 4524 | enforceModifyPermission(); |
| 4525 | |
| 4526 | int returnValue = 0; |
| 4527 | try { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4528 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4529 | if(result.exception == null) { |
| 4530 | if (result.result != null) { |
| 4531 | byte[] responseData = (byte[])(result.result); |
| 4532 | if(responseData.length > oemResp.length) { |
| 4533 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 4534 | responseData.length + "bytes. Buffer Size is " + |
| 4535 | oemResp.length + "bytes."); |
| 4536 | } |
| 4537 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 4538 | returnValue = responseData.length; |
| 4539 | } |
| 4540 | } else { |
| 4541 | CommandException ex = (CommandException) result.exception; |
| 4542 | returnValue = ex.getCommandError().ordinal(); |
| 4543 | if(returnValue > 0) returnValue *= -1; |
| 4544 | } |
| 4545 | } catch (RuntimeException e) { |
| 4546 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 4547 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 4548 | if(returnValue > 0) returnValue *= -1; |
| 4549 | } |
| 4550 | |
| 4551 | return returnValue; |
| 4552 | } |
| 4553 | |
| 4554 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4555 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 4556 | try { |
| 4557 | ProxyController.getInstance().setRadioCapability(rafs); |
| 4558 | } catch (RuntimeException e) { |
| 4559 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 4560 | } |
| 4561 | } |
| 4562 | |
| 4563 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4564 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4565 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4566 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4567 | if (phone == null) { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4568 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4569 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4570 | final long identity = Binder.clearCallingIdentity(); |
| 4571 | try { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4572 | TelephonyPermissions |
| 4573 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4574 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 4575 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4576 | } finally { |
| 4577 | Binder.restoreCallingIdentity(identity); |
| 4578 | } |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4579 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4580 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4581 | |
| 4582 | @Override |
| 4583 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4584 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4585 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4586 | |
| 4587 | final long identity = Binder.clearCallingIdentity(); |
| 4588 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4589 | ImsManager.getInstance(defaultPhone.getContext(), |
| 4590 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4591 | } finally { |
| 4592 | Binder.restoreCallingIdentity(identity); |
| 4593 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4594 | } |
| 4595 | |
| 4596 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4597 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4598 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4599 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4600 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4601 | return false; |
| 4602 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4603 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4604 | final long identity = Binder.clearCallingIdentity(); |
| 4605 | try { |
| 4606 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 4607 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 4608 | // In the long run, we may instead need to check if there exists a connection service |
| 4609 | // which can support video calling. |
| 4610 | ImsManager imsManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4611 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4612 | return imsManager.isVtEnabledByPlatform() |
| 4613 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 4614 | && imsManager.isVtEnabledByUser(); |
| 4615 | } finally { |
| 4616 | Binder.restoreCallingIdentity(identity); |
| 4617 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4618 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 4619 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4620 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4621 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 4622 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4623 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4624 | return false; |
| 4625 | } |
| 4626 | |
| 4627 | final long identity = Binder.clearCallingIdentity(); |
| 4628 | try { |
| 4629 | CarrierConfigManager configManager = |
| 4630 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4631 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4632 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 4633 | } finally { |
| 4634 | Binder.restoreCallingIdentity(identity); |
| 4635 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4636 | } |
| 4637 | |
| 4638 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4639 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 4640 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4641 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4642 | return false; |
| 4643 | } |
| 4644 | |
| 4645 | final long identity = Binder.clearCallingIdentity(); |
| 4646 | try { |
| 4647 | CarrierConfigManager configManager = |
| 4648 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4649 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4650 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 4651 | } finally { |
| 4652 | Binder.restoreCallingIdentity(identity); |
| 4653 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4654 | } |
| 4655 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4656 | @Override |
| 4657 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4658 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 4659 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4660 | } |
| 4661 | |
| 4662 | @Override |
| 4663 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4664 | final long identity = Binder.clearCallingIdentity(); |
| 4665 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4666 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4667 | } finally { |
| 4668 | Binder.restoreCallingIdentity(identity); |
| 4669 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4670 | } |
| 4671 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4672 | /** |
| 4673 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 4674 | * support for the feature and device firmware support. |
| 4675 | * |
| 4676 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 4677 | */ |
| 4678 | @Override |
| 4679 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4680 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4681 | final Phone phone = getPhone(subscriptionId); |
| 4682 | if (phone == null) { |
| 4683 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 4684 | return false; |
| 4685 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4686 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4687 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4688 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 4689 | boolean isDeviceSupported = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4690 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4691 | return isCarrierSupported && isDeviceSupported; |
| 4692 | } finally { |
| 4693 | Binder.restoreCallingIdentity(identity); |
| 4694 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 4695 | } |
| 4696 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4697 | /** |
| 4698 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier |
| 4699 | * both also support RTT. |
| 4700 | */ |
| 4701 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4702 | final long identity = Binder.clearCallingIdentity(); |
| 4703 | try { |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4704 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4705 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4706 | } finally { |
| 4707 | Binder.restoreCallingIdentity(identity); |
| 4708 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 4709 | } |
| 4710 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4711 | /** |
| 4712 | * Returns the unique device ID of phone, for example, the IMEI for |
| 4713 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 4714 | * |
| 4715 | * <p>Requires Permission: |
| 4716 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 4717 | */ |
| 4718 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4719 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4720 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4721 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4722 | return null; |
| 4723 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4724 | int subId = phone.getSubId(); |
| 4725 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4726 | mApp, subId, callingPackage, "getDeviceId")) { |
| 4727 | return null; |
| 4728 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4729 | |
| 4730 | final long identity = Binder.clearCallingIdentity(); |
| 4731 | try { |
| 4732 | return phone.getDeviceId(); |
| 4733 | } finally { |
| 4734 | Binder.restoreCallingIdentity(identity); |
| 4735 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4736 | } |
| 4737 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 4738 | /** |
| 4739 | * {@hide} |
| 4740 | * Returns the IMS Registration Status on a particular subid |
| 4741 | * |
| 4742 | * @param subId |
| 4743 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4744 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 4745 | Phone phone = getPhone(subId); |
| 4746 | if (phone != null) { |
| 4747 | return phone.isImsRegistered(); |
| 4748 | } else { |
| 4749 | return false; |
| 4750 | } |
| 4751 | } |
| 4752 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 4753 | @Override |
| 4754 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4755 | final long identity = Binder.clearCallingIdentity(); |
| 4756 | try { |
| 4757 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 4758 | } finally { |
| 4759 | Binder.restoreCallingIdentity(identity); |
| 4760 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 4761 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 4762 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4763 | /** |
| 4764 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 4765 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4766 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4767 | final long identity = Binder.clearCallingIdentity(); |
| 4768 | try { |
| 4769 | Phone phone = getPhone(subId); |
| 4770 | if (phone != null) { |
| 4771 | return phone.isWifiCallingEnabled(); |
| 4772 | } else { |
| 4773 | return false; |
| 4774 | } |
| 4775 | } finally { |
| 4776 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4777 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 4778 | } |
| 4779 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4780 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4781 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 4782 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4783 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4784 | final long identity = Binder.clearCallingIdentity(); |
| 4785 | try { |
| 4786 | Phone phone = getPhone(subId); |
| 4787 | if (phone != null) { |
| 4788 | return phone.isVideoEnabled(); |
| 4789 | } else { |
| 4790 | return false; |
| 4791 | } |
| 4792 | } finally { |
| 4793 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4794 | } |
| 4795 | } |
| 4796 | |
| 4797 | /** |
| 4798 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 4799 | * defined in {@link ImsRegistrationImplBase}. |
| 4800 | */ |
| 4801 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4802 | final long identity = Binder.clearCallingIdentity(); |
| 4803 | try { |
| 4804 | Phone phone = getPhone(subId); |
| 4805 | if (phone != null) { |
| 4806 | return phone.getImsRegistrationTech(); |
| 4807 | } else { |
| 4808 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 4809 | } |
| 4810 | } finally { |
| 4811 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4812 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 4813 | } |
| 4814 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 4815 | @Override |
| 4816 | public void factoryReset(int subId) { |
| 4817 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 4818 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 4819 | return; |
| 4820 | } |
| 4821 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4822 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4823 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4824 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 4825 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 4826 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 4827 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4828 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 4829 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4830 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 4831 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4832 | } |
| 4833 | } finally { |
| 4834 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 4835 | } |
| 4836 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4837 | |
| 4838 | @Override |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame^] | 4839 | public String getSimLocaleForSubscriber(int subId) { |
| 4840 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 4841 | final Phone phone = getPhone(subId); |
| 4842 | if (phone == null) { |
| 4843 | log("getSimLocaleForSubscriber, invalid subId"); |
| 4844 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4845 | final long identity = Binder.clearCallingIdentity(); |
| 4846 | try { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame^] | 4847 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 4848 | phone.getContext().getOpPackageName()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4849 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 4850 | // preferences (EF-PL and EF-LI)... |
| 4851 | final int mcc = info.getMcc(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4852 | String simLanguage = null; |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame^] | 4853 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 4854 | if (localeFromDefaultSim != null) { |
| 4855 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 4856 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 4857 | + localeFromDefaultSim); |
| 4858 | return localeFromDefaultSim.toLanguageTag(); |
| 4859 | } else { |
| 4860 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4861 | } |
| 4862 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4863 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4864 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 4865 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 4866 | // the SIM and carrier preferences does not include a country we add the country |
| 4867 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4868 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4869 | if (mccLocale != null) { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame^] | 4870 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4871 | return mccLocale.toLanguageTag(); |
| 4872 | } |
| 4873 | |
| 4874 | if (DBG) log("No locale found - returning null"); |
| 4875 | return null; |
| 4876 | } finally { |
| 4877 | Binder.restoreCallingIdentity(identity); |
| 4878 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4879 | } |
| 4880 | |
| 4881 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4882 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4883 | } |
| 4884 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4885 | /** |
| 4886 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 4887 | */ |
| 4888 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4889 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4890 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4891 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4892 | private final ModemActivityInfo mLastModemActivityInfo = |
| 4893 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 4894 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4895 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 4896 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 4897 | * representing the state of the modem. |
| 4898 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4899 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 4900 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 4901 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4902 | */ |
| 4903 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 4904 | public void requestModemActivityInfo(ResultReceiver result) { |
| 4905 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4906 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4907 | |
| 4908 | final long identity = Binder.clearCallingIdentity(); |
| 4909 | try { |
| 4910 | ModemActivityInfo ret = null; |
| 4911 | synchronized (mLastModemActivityInfo) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4912 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 4913 | CMD_GET_MODEM_ACTIVITY_INFO, |
| 4914 | null, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4915 | if (isModemActivityInfoValid(info)) { |
| 4916 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 4917 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 4918 | mergedTxTimeMs[i] = |
| 4919 | info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i]; |
| 4920 | } |
| 4921 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 4922 | mLastModemActivityInfo.setSleepTimeMillis( |
| 4923 | info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis()); |
| 4924 | mLastModemActivityInfo.setIdleTimeMillis( |
| 4925 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 4926 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 4927 | mLastModemActivityInfo.setRxTimeMillis( |
| 4928 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 4929 | mLastModemActivityInfo.setEnergyUsed( |
| 4930 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4931 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4932 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 4933 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 4934 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 4935 | mLastModemActivityInfo.getTxTimeMillis(), |
| 4936 | mLastModemActivityInfo.getRxTimeMillis(), |
| 4937 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4938 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4939 | Bundle bundle = new Bundle(); |
| 4940 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 4941 | result.send(0, bundle); |
| 4942 | } finally { |
| 4943 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4944 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4945 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4946 | |
Siddharth Ray | f5d2955 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 4947 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 4948 | // less than total activity duration. |
| 4949 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 4950 | if (info == null) { |
| 4951 | return false; |
| 4952 | } |
| 4953 | int activityDurationMs = |
| 4954 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 4955 | int totalTxTimeMs = 0; |
| 4956 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 4957 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 4958 | } |
| 4959 | return (info.isValid() |
| 4960 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 4961 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 4962 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 4963 | && (totalTxTimeMs <= activityDurationMs)); |
| 4964 | } |
| 4965 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4966 | /** |
| 4967 | * {@hide} |
| 4968 | * Returns the service state information on specified subscription. |
| 4969 | */ |
| 4970 | @Override |
| 4971 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4972 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4973 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4974 | return null; |
| 4975 | } |
| 4976 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4977 | final long identity = Binder.clearCallingIdentity(); |
| 4978 | try { |
| 4979 | final Phone phone = getPhone(subId); |
| 4980 | if (phone == null) { |
| 4981 | return null; |
| 4982 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4983 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4984 | return phone.getServiceState(); |
| 4985 | } finally { |
| 4986 | Binder.restoreCallingIdentity(identity); |
| 4987 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4988 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4989 | |
| 4990 | /** |
| 4991 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 4992 | * |
| 4993 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 4994 | * voicemail ringtone. |
| 4995 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 4996 | * PhoneAccount. |
| 4997 | */ |
| 4998 | @Override |
| 4999 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5000 | final long identity = Binder.clearCallingIdentity(); |
| 5001 | try { |
| 5002 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5003 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5004 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5005 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5006 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5007 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5008 | } finally { |
| 5009 | Binder.restoreCallingIdentity(identity); |
| 5010 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5011 | } |
| 5012 | |
| 5013 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5014 | * Sets the per-account voicemail ringtone. |
| 5015 | * |
| 5016 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5017 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5018 | * |
| 5019 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5020 | * voicemail ringtone. |
| 5021 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5022 | * PhoneAccount. |
| 5023 | */ |
| 5024 | @Override |
| 5025 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5026 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5027 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5028 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5029 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5030 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5031 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5032 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5033 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5034 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5035 | |
| 5036 | final long identity = Binder.clearCallingIdentity(); |
| 5037 | try { |
| 5038 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5039 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5040 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5041 | } |
| 5042 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5043 | } finally { |
| 5044 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5045 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5046 | } |
| 5047 | |
| 5048 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5049 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5050 | * |
| 5051 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5052 | * voicemail vibration setting. |
| 5053 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5054 | */ |
| 5055 | @Override |
| 5056 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5057 | final long identity = Binder.clearCallingIdentity(); |
| 5058 | try { |
| 5059 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5060 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5061 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5062 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5063 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5064 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5065 | } finally { |
| 5066 | Binder.restoreCallingIdentity(identity); |
| 5067 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5068 | } |
| 5069 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5070 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5071 | * Sets the per-account voicemail vibration. |
| 5072 | * |
| 5073 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5074 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5075 | * |
| 5076 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5077 | * voicemail vibration setting. |
| 5078 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5079 | * specific PhoneAccount. |
| 5080 | */ |
| 5081 | @Override |
| 5082 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5083 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5084 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5085 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5086 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5087 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5088 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5089 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5090 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5091 | } |
| 5092 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5093 | final long identity = Binder.clearCallingIdentity(); |
| 5094 | try { |
| 5095 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5096 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5097 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5098 | } |
| 5099 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5100 | } finally { |
| 5101 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5102 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5103 | } |
| 5104 | |
| 5105 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5106 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5107 | * |
| 5108 | * @throws SecurityException if the caller does not have the required permission |
| 5109 | */ |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5110 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5111 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5112 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5113 | } |
| 5114 | |
| 5115 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5116 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5117 | * permission. |
| 5118 | * |
| 5119 | * @throws SecurityException if the caller does not have the required permission |
| 5120 | */ |
| 5121 | private void enforceSendSmsPermission() { |
| 5122 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5123 | } |
| 5124 | |
| 5125 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5126 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5127 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5128 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5129 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5130 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5131 | final long identity = Binder.clearCallingIdentity(); |
| 5132 | try { |
| 5133 | ComponentName componentName = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5134 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5135 | if (componentName == null) { |
| 5136 | throw new SecurityException( |
| 5137 | "Caller not current active visual voicemail package[null]"); |
| 5138 | } |
| 5139 | String vvmPackage = componentName.getPackageName(); |
| 5140 | if (!callingPackage.equals(vvmPackage)) { |
| 5141 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5142 | + vvmPackage + "]"); |
| 5143 | } |
| 5144 | } finally { |
| 5145 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5146 | } |
| 5147 | } |
| 5148 | |
| 5149 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5150 | * Return the application ID for the app type. |
| 5151 | * |
| 5152 | * @param subId the subscription ID that this request applies to. |
| 5153 | * @param appType the uicc app type. |
| 5154 | * @return Application ID for specificied app type, or null if no uicc. |
| 5155 | */ |
| 5156 | @Override |
| 5157 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5158 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5159 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5160 | |
| 5161 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5162 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5163 | if (phone == null) { |
| 5164 | return null; |
| 5165 | } |
| 5166 | String aid = null; |
| 5167 | try { |
| 5168 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5169 | .getApplicationByType(appType).getAid(); |
| 5170 | } catch (Exception e) { |
| 5171 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5172 | } |
| 5173 | return aid; |
| 5174 | } finally { |
| 5175 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5176 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5177 | } |
| 5178 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5179 | /** |
| 5180 | * Return the Electronic Serial Number. |
| 5181 | * |
| 5182 | * @param subId the subscription ID that this request applies to. |
| 5183 | * @return ESN or null if error. |
| 5184 | */ |
| 5185 | @Override |
| 5186 | public String getEsn(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5187 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5188 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5189 | |
| 5190 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5191 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5192 | if (phone == null) { |
| 5193 | return null; |
| 5194 | } |
| 5195 | String esn = null; |
| 5196 | try { |
| 5197 | esn = phone.getEsn(); |
| 5198 | } catch (Exception e) { |
| 5199 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5200 | } |
| 5201 | return esn; |
| 5202 | } finally { |
| 5203 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5204 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5205 | } |
| 5206 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5207 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5208 | * Return the Preferred Roaming List Version. |
| 5209 | * |
| 5210 | * @param subId the subscription ID that this request applies to. |
| 5211 | * @return PRLVersion or null if error. |
| 5212 | */ |
| 5213 | @Override |
| 5214 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5215 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5216 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5217 | |
| 5218 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5219 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5220 | if (phone == null) { |
| 5221 | return null; |
| 5222 | } |
| 5223 | String cdmaPrlVersion = null; |
| 5224 | try { |
| 5225 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 5226 | } catch (Exception e) { |
| 5227 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 5228 | } |
| 5229 | return cdmaPrlVersion; |
| 5230 | } finally { |
| 5231 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5232 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5233 | } |
| 5234 | |
| 5235 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5236 | * Get snapshot of Telephony histograms |
| 5237 | * @return List of Telephony histograms |
| 5238 | * @hide |
| 5239 | */ |
| 5240 | @Override |
| 5241 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5242 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5243 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5244 | |
| 5245 | final long identity = Binder.clearCallingIdentity(); |
| 5246 | try { |
| 5247 | return RIL.getTelephonyRILTimingHistograms(); |
| 5248 | } finally { |
| 5249 | Binder.restoreCallingIdentity(identity); |
| 5250 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5251 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5252 | |
| 5253 | /** |
| 5254 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5255 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 5256 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5257 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5258 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5259 | * @return Integer with the result of the operation, as defined in {@link TelephonyManager}. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5260 | */ |
| 5261 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5262 | @TelephonyManager.SetCarrierRestrictionResult |
| 5263 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5264 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5265 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5266 | |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5267 | if (carrierRestrictionRules == null) { |
| 5268 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5269 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5270 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5271 | final long identity = Binder.clearCallingIdentity(); |
| 5272 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5273 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5274 | workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5275 | } finally { |
| 5276 | Binder.restoreCallingIdentity(identity); |
| 5277 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5278 | } |
| 5279 | |
| 5280 | /** |
| 5281 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5282 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 5283 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5284 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5285 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5286 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5287 | */ |
| 5288 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5289 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5290 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5291 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5292 | |
| 5293 | final long identity = Binder.clearCallingIdentity(); |
| 5294 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5295 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 5296 | if (response instanceof CarrierRestrictionRules) { |
| 5297 | return (CarrierRestrictionRules) response; |
| 5298 | } |
| 5299 | // Response is an Exception of some kind, |
| 5300 | // which is signalled to the user as a NULL retval |
| 5301 | return null; |
| 5302 | } catch (Exception e) { |
| 5303 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 5304 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5305 | } finally { |
| 5306 | Binder.restoreCallingIdentity(identity); |
| 5307 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5308 | } |
| 5309 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5310 | /** |
| 5311 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 5312 | * @param subId the subscription ID that this action applies to. |
| 5313 | * @param enabled control enable or disable metered apns. |
| 5314 | * {@hide} |
| 5315 | */ |
| 5316 | @Override |
| 5317 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 5318 | enforceModifyPermission(); |
| 5319 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5320 | |
| 5321 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5322 | if (phone == null) { |
| 5323 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 5324 | return; |
| 5325 | } |
| 5326 | try { |
| 5327 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 5328 | } catch (Exception e) { |
| 5329 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5330 | } finally { |
| 5331 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5332 | } |
| 5333 | } |
| 5334 | |
| 5335 | /** |
| 5336 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 5337 | * @param subId the subscription ID that this action applies to. |
| 5338 | * @param enabled control enable or disable radio. |
| 5339 | * {@hide} |
| 5340 | */ |
| 5341 | @Override |
| 5342 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 5343 | enforceModifyPermission(); |
| 5344 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5345 | |
| 5346 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5347 | if (phone == null) { |
| 5348 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 5349 | return; |
| 5350 | } |
| 5351 | try { |
| 5352 | phone.carrierActionSetRadioEnabled(enabled); |
| 5353 | } catch (Exception e) { |
| 5354 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5355 | } finally { |
| 5356 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5357 | } |
| 5358 | } |
| 5359 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5360 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5361 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 5362 | * network status based on which carrier apps could apply actions accordingly, |
| 5363 | * enable/disable default url handler for example. |
| 5364 | * |
| 5365 | * @param subId the subscription ID that this action applies to. |
| 5366 | * @param report control start/stop reporting the default network status. |
| 5367 | * {@hide} |
| 5368 | */ |
| 5369 | @Override |
| 5370 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 5371 | enforceModifyPermission(); |
| 5372 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5373 | |
| 5374 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5375 | if (phone == null) { |
| 5376 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 5377 | return; |
| 5378 | } |
| 5379 | try { |
| 5380 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 5381 | } catch (Exception e) { |
| 5382 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5383 | } finally { |
| 5384 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5385 | } |
| 5386 | } |
| 5387 | |
| 5388 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5389 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 5390 | * bug report is being generated. |
| 5391 | */ |
| 5392 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 5393 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5394 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 5395 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 5396 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 5397 | + Binder.getCallingPid() |
| 5398 | + ", uid=" + Binder.getCallingUid() |
| 5399 | + "without permission " |
| 5400 | + android.Manifest.permission.DUMP); |
| 5401 | return; |
| 5402 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5403 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5404 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5405 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5406 | @Override |
| 5407 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 5408 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 5409 | throws RemoteException { |
| 5410 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 5411 | } |
| 5412 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5413 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5414 | * Get aggregated video call data usage since boot. |
| 5415 | * |
| 5416 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 5417 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5418 | * {@hide} |
| 5419 | */ |
| 5420 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5421 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5422 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 5423 | null); |
| 5424 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5425 | final long identity = Binder.clearCallingIdentity(); |
| 5426 | try { |
| 5427 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 5428 | // records the delta with the corresponding network identity. |
| 5429 | // We just return the total video call data usage snapshot since boot. |
| 5430 | Phone phone = getPhone(subId); |
| 5431 | if (phone != null) { |
| 5432 | return phone.getVtDataUsage(perUidStats); |
| 5433 | } |
| 5434 | return null; |
| 5435 | } finally { |
| 5436 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5437 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5438 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5439 | |
| 5440 | /** |
| 5441 | * Policy control of data connection. Usually used when data limit is passed. |
| 5442 | * @param enabled True if enabling the data, otherwise disabling. |
| 5443 | * @param subId Subscription index |
| 5444 | * {@hide} |
| 5445 | */ |
| 5446 | @Override |
| 5447 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 5448 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5449 | |
| 5450 | final long identity = Binder.clearCallingIdentity(); |
| 5451 | try { |
| 5452 | Phone phone = getPhone(subId); |
| 5453 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5454 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5455 | } |
| 5456 | } finally { |
| 5457 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5458 | } |
| 5459 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5460 | |
| 5461 | /** |
| 5462 | * Get Client request stats |
| 5463 | * @return List of Client Request Stats |
| 5464 | * @hide |
| 5465 | */ |
| 5466 | @Override |
| 5467 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5468 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5469 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5470 | return null; |
| 5471 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5472 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5473 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5474 | final long identity = Binder.clearCallingIdentity(); |
| 5475 | try { |
| 5476 | if (phone != null) { |
| 5477 | return phone.getClientRequestStats(); |
| 5478 | } |
| 5479 | |
| 5480 | return null; |
| 5481 | } finally { |
| 5482 | Binder.restoreCallingIdentity(identity); |
| 5483 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5484 | } |
| 5485 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5486 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5487 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5488 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5489 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5490 | |
| 5491 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5492 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5493 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5494 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5495 | * @param state State of SIM (power down, power up, pass through) |
| 5496 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 5497 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 5498 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5499 | * |
| 5500 | **/ |
| 5501 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5502 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5503 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5504 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5505 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5506 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5507 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5508 | final long identity = Binder.clearCallingIdentity(); |
| 5509 | try { |
| 5510 | if (phone != null) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5511 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5512 | } |
| 5513 | } finally { |
| 5514 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5515 | } |
| 5516 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5517 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5518 | private boolean isUssdApiAllowed(int subId) { |
| 5519 | CarrierConfigManager configManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5520 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5521 | if (configManager == null) { |
| 5522 | return false; |
| 5523 | } |
| 5524 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 5525 | if (pb == null) { |
| 5526 | return false; |
| 5527 | } |
| 5528 | return pb.getBoolean( |
| 5529 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 5530 | } |
| 5531 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5532 | /** |
| 5533 | * Check if phone is in emergency callback mode |
| 5534 | * @return true if phone is in emergency callback mode |
| 5535 | * @param subId sub id |
| 5536 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 5537 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5538 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5539 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5540 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5541 | |
| 5542 | final long identity = Binder.clearCallingIdentity(); |
| 5543 | try { |
| 5544 | if (phone != null) { |
| 5545 | return phone.isInEcm(); |
| 5546 | } else { |
| 5547 | return false; |
| 5548 | } |
| 5549 | } finally { |
| 5550 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5551 | } |
| 5552 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5553 | |
| 5554 | /** |
| 5555 | * Get the current signal strength information for the given subscription. |
| 5556 | * Because this information is not updated when the device is in a low power state |
| 5557 | * it should not be relied-upon to be current. |
| 5558 | * @param subId Subscription index |
| 5559 | * @return the most recent cached signal strength info from the modem |
| 5560 | */ |
| 5561 | @Override |
| 5562 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5563 | final long identity = Binder.clearCallingIdentity(); |
| 5564 | try { |
| 5565 | Phone p = getPhone(subId); |
| 5566 | if (p == null) { |
| 5567 | return null; |
| 5568 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5569 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5570 | return p.getSignalStrength(); |
| 5571 | } finally { |
| 5572 | Binder.restoreCallingIdentity(identity); |
| 5573 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5574 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5575 | |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5576 | /** |
chen xu | 907e5a2 | 2018-10-11 13:21:04 -0700 | [diff] [blame] | 5577 | * Get the current modem radio state for the given slot. |
| 5578 | * @param slotIndex slot index. |
| 5579 | * @param callingPackage the name of the package making the call. |
| 5580 | * @return the current radio power state from the modem |
| 5581 | */ |
| 5582 | @Override |
| 5583 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 5584 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5585 | if (phone != null) { |
| 5586 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5587 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 5588 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5589 | } |
| 5590 | |
| 5591 | final long identity = Binder.clearCallingIdentity(); |
| 5592 | try { |
| 5593 | return phone.getRadioPowerState(); |
| 5594 | } finally { |
| 5595 | Binder.restoreCallingIdentity(identity); |
| 5596 | } |
| 5597 | } |
| 5598 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5599 | } |
| 5600 | |
| 5601 | /** |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5602 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 5603 | * |
| 5604 | * <p>Requires one of the following permissions: |
| 5605 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 5606 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 5607 | * privileges. |
| 5608 | * |
| 5609 | * @param subId subscription id |
| 5610 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 5611 | * {@code false}. |
| 5612 | */ |
| 5613 | @Override |
| 5614 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5615 | boolean isEnabled = false; |
| 5616 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5617 | try { |
| 5618 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5619 | null /* message */); |
| 5620 | Phone phone = getPhone(subId); |
| 5621 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5622 | } catch (Exception e) { |
| 5623 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 5624 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5625 | } finally { |
| 5626 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5627 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5628 | return isEnabled; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5629 | } |
| 5630 | |
| 5631 | |
| 5632 | /** |
| 5633 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 5634 | * |
| 5635 | * <p> Requires permission: |
| 5636 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 5637 | * privileges. |
| 5638 | * |
| 5639 | * @param subId subscription id |
| 5640 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 5641 | */ |
| 5642 | @Override |
| 5643 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5644 | final long identity = Binder.clearCallingIdentity(); |
| 5645 | try { |
| 5646 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5647 | mApp, subId, "setDataRoamingEnabled"); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5648 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5649 | Phone phone = getPhone(subId); |
| 5650 | if (phone != null) { |
| 5651 | phone.setDataRoamingEnabled(isEnabled); |
| 5652 | } |
| 5653 | } finally { |
| 5654 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5655 | } |
| 5656 | } |
| 5657 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5658 | @Override |
Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 5659 | public boolean isManualNetworkSelectionAllowed(int subId) { |
| 5660 | boolean isAllowed = true; |
| 5661 | final long identity = Binder.clearCallingIdentity(); |
| 5662 | try { |
| 5663 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 5664 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 5665 | Phone phone = getPhone(subId); |
| 5666 | if (phone != null) { |
| 5667 | isAllowed = phone.isCspPlmnEnabled(); |
| 5668 | } |
| 5669 | } finally { |
| 5670 | Binder.restoreCallingIdentity(identity); |
| 5671 | } |
| 5672 | return isAllowed; |
| 5673 | } |
| 5674 | |
| 5675 | @Override |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 5676 | public UiccCardInfo[] getUiccCardsInfo() { |
| 5677 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
| 5678 | |
| 5679 | final long identity = Binder.clearCallingIdentity(); |
| 5680 | try { |
| 5681 | ArrayList<UiccCardInfo> cards = UiccController.getInstance().getAllUiccCardInfos(); |
| 5682 | return cards.toArray(new UiccCardInfo[cards.size()]); |
| 5683 | } finally { |
| 5684 | Binder.restoreCallingIdentity(identity); |
| 5685 | } |
| 5686 | } |
| 5687 | |
| 5688 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5689 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5690 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5691 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5692 | final long identity = Binder.clearCallingIdentity(); |
| 5693 | try { |
| 5694 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 5695 | if (slots == null) { |
| 5696 | Rlog.i(LOG_TAG, "slots is null."); |
| 5697 | return null; |
| 5698 | } |
| 5699 | |
| 5700 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 5701 | for (int i = 0; i < slots.length; i++) { |
| 5702 | UiccSlot slot = slots[i]; |
| 5703 | if (slot == null) { |
| 5704 | continue; |
| 5705 | } |
| 5706 | |
| 5707 | String cardId; |
| 5708 | UiccCard card = slot.getUiccCard(); |
| 5709 | if (card != null) { |
| 5710 | cardId = card.getCardId(); |
| 5711 | } else { |
| 5712 | cardId = slot.getIccId(); |
| 5713 | } |
| 5714 | |
| 5715 | int cardState = 0; |
| 5716 | switch (slot.getCardState()) { |
| 5717 | case CARDSTATE_ABSENT: |
| 5718 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 5719 | break; |
| 5720 | case CARDSTATE_PRESENT: |
| 5721 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 5722 | break; |
| 5723 | case CARDSTATE_ERROR: |
| 5724 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 5725 | break; |
| 5726 | case CARDSTATE_RESTRICTED: |
| 5727 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 5728 | break; |
| 5729 | default: |
| 5730 | break; |
| 5731 | |
| 5732 | } |
| 5733 | |
| 5734 | infos[i] = new UiccSlotInfo( |
| 5735 | slot.isActive(), |
| 5736 | slot.isEuicc(), |
| 5737 | cardId, |
| 5738 | cardState, |
| 5739 | slot.getPhoneId(), |
| 5740 | slot.isExtendedApduSupported()); |
| 5741 | } |
| 5742 | return infos; |
| 5743 | } finally { |
| 5744 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 5745 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5746 | } |
| 5747 | |
| 5748 | @Override |
| 5749 | public boolean switchSlots(int[] physicalSlots) { |
| 5750 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5751 | |
| 5752 | final long identity = Binder.clearCallingIdentity(); |
| 5753 | try { |
| 5754 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 5755 | } finally { |
| 5756 | Binder.restoreCallingIdentity(identity); |
| 5757 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5758 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 5759 | |
| 5760 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 5761 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
| 5762 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5763 | mApp, subId, callingPackage, "getCardIdForDefaultEuicc")) { |
| 5764 | return TelephonyManager.INVALID_CARD_ID; |
| 5765 | } |
| 5766 | |
| 5767 | final long identity = Binder.clearCallingIdentity(); |
| 5768 | try { |
| 5769 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 5770 | } finally { |
| 5771 | Binder.restoreCallingIdentity(identity); |
| 5772 | } |
| 5773 | } |
| 5774 | |
| 5775 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 5776 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 5777 | enforceModifyPermission(); |
| 5778 | final Phone phone = getPhone(subId); |
| 5779 | if (phone == null) { |
| 5780 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 5781 | return; |
| 5782 | } |
| 5783 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5784 | final long identity = Binder.clearCallingIdentity(); |
| 5785 | try { |
| 5786 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 5787 | } finally { |
| 5788 | Binder.restoreCallingIdentity(identity); |
| 5789 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 5790 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5791 | |
| 5792 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 5793 | * A test API to reload the UICC profile. |
| 5794 | * |
| 5795 | * <p>Requires that the calling app has permission |
| 5796 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5797 | * @hide |
| 5798 | */ |
| 5799 | @Override |
| 5800 | public void refreshUiccProfile(int subId) { |
| 5801 | enforceModifyPermission(); |
| 5802 | |
| 5803 | final long identity = Binder.clearCallingIdentity(); |
| 5804 | try { |
| 5805 | Phone phone = getPhone(subId); |
| 5806 | if (phone == null) { |
| 5807 | return; |
| 5808 | } |
| 5809 | UiccCard uiccCard = phone.getUiccCard(); |
| 5810 | if (uiccCard == null) { |
| 5811 | return; |
| 5812 | } |
| 5813 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 5814 | if (uiccProfile == null) { |
| 5815 | return; |
| 5816 | } |
| 5817 | uiccProfile.refresh(); |
| 5818 | } finally { |
| 5819 | Binder.restoreCallingIdentity(identity); |
| 5820 | } |
| 5821 | } |
| 5822 | |
| 5823 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5824 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 5825 | */ |
| 5826 | private boolean getDefaultDataEnabled() { |
| 5827 | return "true".equalsIgnoreCase( |
| 5828 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 5829 | } |
| 5830 | |
| 5831 | /** |
| 5832 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 5833 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 5834 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 5835 | */ |
| 5836 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 5837 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5838 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5839 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 5840 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 5841 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 5842 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 5843 | return isDataRoamingEnabled; |
| 5844 | } |
| 5845 | |
| 5846 | /** |
| 5847 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 5848 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 5849 | */ |
| 5850 | private int getDefaultNetworkType(int subId) { |
| 5851 | return Integer.parseInt( |
| 5852 | TelephonyManager.getTelephonyProperty( |
| 5853 | mSubscriptionController.getPhoneId(subId), |
| 5854 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 5855 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 5856 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5857 | |
| 5858 | @Override |
| 5859 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
| 5860 | gid1, String gid2, String plmn, String spn) { |
| 5861 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5862 | |
| 5863 | final long identity = Binder.clearCallingIdentity(); |
| 5864 | try { |
| 5865 | final Phone phone = getPhone(subId); |
| 5866 | if (phone == null) { |
| 5867 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 5868 | return; |
| 5869 | } |
| 5870 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn); |
| 5871 | } finally { |
| 5872 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5873 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5874 | } |
| 5875 | |
| 5876 | @Override |
| 5877 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5878 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5879 | |
| 5880 | final long identity = Binder.clearCallingIdentity(); |
| 5881 | try { |
| 5882 | final Phone phone = getPhone(subId); |
| 5883 | if (phone == null) { |
| 5884 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 5885 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 5886 | } |
| 5887 | return phone.getCarrierIdListVersion(); |
| 5888 | } finally { |
| 5889 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5890 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5891 | } |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 5892 | |
| 5893 | @Override |
| 5894 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 5895 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5896 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 5897 | return -1; |
| 5898 | } |
| 5899 | |
| 5900 | final long identity = Binder.clearCallingIdentity(); |
| 5901 | try { |
| 5902 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 5903 | } finally { |
| 5904 | Binder.restoreCallingIdentity(identity); |
| 5905 | } |
| 5906 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5907 | |
| 5908 | @Override |
| 5909 | public int getCdmaRoamingMode(int subId) { |
| 5910 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5911 | mApp, subId, "getCdmaRoamingMode"); |
| 5912 | |
| 5913 | final long identity = Binder.clearCallingIdentity(); |
| 5914 | try { |
| 5915 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 5916 | } finally { |
| 5917 | Binder.restoreCallingIdentity(identity); |
| 5918 | } |
| 5919 | } |
| 5920 | |
| 5921 | @Override |
| 5922 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 5923 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5924 | mApp, subId, "setCdmaRoamingMode"); |
| 5925 | |
| 5926 | final long identity = Binder.clearCallingIdentity(); |
| 5927 | try { |
| 5928 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 5929 | } finally { |
| 5930 | Binder.restoreCallingIdentity(identity); |
| 5931 | } |
| 5932 | } |
| 5933 | |
| 5934 | @Override |
| 5935 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 5936 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5937 | mApp, subId, "setCdmaSubscriptionMode"); |
| 5938 | |
| 5939 | final long identity = Binder.clearCallingIdentity(); |
| 5940 | try { |
| 5941 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 5942 | } finally { |
| 5943 | Binder.restoreCallingIdentity(identity); |
| 5944 | } |
| 5945 | } |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 5946 | |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 5947 | private void ensureUserRunning(int userId) { |
| 5948 | if (!mUserManager.isUserRunning(userId)) { |
| 5949 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 5950 | } |
| 5951 | } |
| 5952 | |
| 5953 | /** |
| 5954 | * Returns a list of SMS apps on a given user. |
| 5955 | * |
| 5956 | * Only the shell user (UID 2000 or 0) can call it. |
| 5957 | * Target user must be running. |
| 5958 | */ |
| 5959 | @Override |
| 5960 | public String[] getSmsApps(int userId) { |
| 5961 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 5962 | ensureUserRunning(userId); |
| 5963 | |
| 5964 | final Collection<SmsApplicationData> apps = |
| 5965 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 5966 | |
| 5967 | String[] ret = new String[apps.size()]; |
| 5968 | int i = 0; |
| 5969 | for (SmsApplicationData app : apps) { |
| 5970 | ret[i++] = app.mPackageName; |
| 5971 | } |
| 5972 | return ret; |
| 5973 | } |
| 5974 | |
| 5975 | /** |
| 5976 | * Returns the default SMS app package name on a given user. |
| 5977 | * |
| 5978 | * Only the shell user (UID 2000 or 0) can call it. |
| 5979 | * Target user must be running. |
| 5980 | */ |
| 5981 | @Override |
| 5982 | public String getDefaultSmsApp(int userId) { |
| 5983 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 5984 | ensureUserRunning(userId); |
| 5985 | |
| 5986 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 5987 | /* updateIfNeeded= */ true, userId); |
| 5988 | return cn == null ? null : cn.getPackageName(); |
| 5989 | } |
| 5990 | |
| 5991 | /** |
| 5992 | * Set a package as the default SMS app on a given user. |
| 5993 | * |
| 5994 | * Only the shell user (UID 2000 or 0) can call it. |
| 5995 | * Target user must be running. |
| 5996 | */ |
| 5997 | @Override |
| 5998 | public void setDefaultSmsApp(int userId, String packageName) { |
| 5999 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6000 | ensureUserRunning(userId); |
| 6001 | |
| 6002 | boolean found = false; |
| 6003 | for (String pkg : getSmsApps(userId)) { |
| 6004 | if (TextUtils.equals(packageName, pkg)) { |
| 6005 | found = true; |
| 6006 | break; |
| 6007 | } |
| 6008 | } |
| 6009 | if (!found) { |
| 6010 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6011 | } |
| 6012 | |
| 6013 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6014 | } |
| 6015 | |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6016 | @Override |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6017 | public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList( |
| 6018 | String callingPackage) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6019 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6020 | mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) { |
| 6021 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6022 | } |
| 6023 | final long identity = Binder.clearCallingIdentity(); |
| 6024 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6025 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6026 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6027 | if (phone.getEmergencyNumberTracker() != null |
| 6028 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6029 | emergencyNumberListInternal.put( |
| 6030 | phone.getSubId(), |
| 6031 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6032 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6033 | } |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6034 | return emergencyNumberListInternal; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6035 | } finally { |
| 6036 | Binder.restoreCallingIdentity(identity); |
| 6037 | } |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6038 | } |
| 6039 | |
| 6040 | @Override |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6041 | public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) { |
| 6042 | final Phone defaultPhone = getDefaultPhone(); |
| 6043 | if (!exactMatch) { |
| 6044 | TelephonyPermissions |
| 6045 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6046 | mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)"); |
| 6047 | } |
| 6048 | final long identity = Binder.clearCallingIdentity(); |
| 6049 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6050 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6051 | if (phone.getEmergencyNumberTracker() != null |
| 6052 | && phone.getEmergencyNumberTracker() != null) { |
| 6053 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 6054 | number, exactMatch)) { |
| 6055 | return true; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6056 | } |
| 6057 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6058 | } |
| 6059 | return false; |
| 6060 | } finally { |
| 6061 | Binder.restoreCallingIdentity(identity); |
| 6062 | } |
| 6063 | } |
| 6064 | |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6065 | @Override |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6066 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6067 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6068 | Phone phone = getPhone(subId); |
| 6069 | if (phone == null) { |
| 6070 | return null; |
| 6071 | } |
| 6072 | final long identity = Binder.clearCallingIdentity(); |
| 6073 | try { |
| 6074 | UiccProfile profile = UiccController.getInstance() |
| 6075 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6076 | if (profile != null) { |
| 6077 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6078 | } |
| 6079 | } finally { |
| 6080 | Binder.restoreCallingIdentity(identity); |
| 6081 | } |
| 6082 | return null; |
| 6083 | } |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6084 | |
| 6085 | /** |
| 6086 | * Enable or disable a modem stack. |
| 6087 | */ |
| 6088 | @Override |
| 6089 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 6090 | enforceModifyPermission(); |
| 6091 | |
| 6092 | final long identity = Binder.clearCallingIdentity(); |
| 6093 | try { |
| 6094 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6095 | if (phone == null) { |
| 6096 | return false; |
| 6097 | } else { |
| 6098 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 6099 | } |
| 6100 | } finally { |
| 6101 | Binder.restoreCallingIdentity(identity); |
| 6102 | } |
| 6103 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6104 | } |