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 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 19 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 20 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 21 | import android.Manifest.permission; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 22 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 23 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 24 | import android.content.ComponentName; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 27 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 28 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 29 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 30 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 31 | import android.content.pm.PackageManager; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 32 | import android.net.NetworkStats; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 33 | import android.net.Uri; |
| 34 | import android.os.AsyncResult; |
| 35 | import android.os.Binder; |
| 36 | import android.os.Bundle; |
| 37 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 38 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 39 | import android.os.Looper; |
| 40 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 41 | import android.os.Messenger; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 42 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 43 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 44 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.ServiceManager; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 46 | import android.os.ShellCallback; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 47 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 48 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 49 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 50 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 51 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 52 | import android.provider.Settings; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 53 | import android.service.carrier.CarrierIdentifier; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 54 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 55 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 56 | import android.telecom.TelecomManager; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 57 | import android.telephony.CarrierConfigManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 58 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 59 | import android.telephony.CellInfoGsm; |
| 60 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 61 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 62 | import android.telephony.ClientRequestStats; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 63 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 64 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 65 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 66 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 67 | import android.telephony.NetworkScanRequest; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 68 | import android.telephony.RadioAccessFamily; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 69 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 70 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 71 | import android.telephony.SignalStrength; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 72 | import android.telephony.SmsManager; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 73 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 74 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 75 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 76 | import android.telephony.TelephonyManager; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 77 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 78 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 79 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 80 | import android.telephony.cdma.CdmaCellLocation; |
| 81 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 82 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 83 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame^] | 84 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 85 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 86 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 87 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 88 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 89 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 90 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 91 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 92 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 93 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 94 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 95 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 96 | import com.android.ims.ImsException; |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 97 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 98 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 99 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 100 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 101 | import com.android.internal.telephony.CarrierInfoManager; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 102 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 103 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 104 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 105 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 106 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 107 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 108 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 109 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 110 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 111 | import com.android.internal.telephony.Phone; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 112 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 113 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 114 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 115 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 116 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 117 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 118 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 119 | import com.android.internal.telephony.ServiceStateTracker; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 120 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 121 | import com.android.internal.telephony.TelephonyPermissions; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 122 | import com.android.internal.telephony.euicc.EuiccConnector; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.uicc.IccIoResult; |
| 124 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 125 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 127 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 129 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 130 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 132 | import com.android.internal.util.HexDump; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 133 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 134 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 135 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 136 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 137 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 138 | import java.io.FileDescriptor; |
| 139 | import java.io.PrintWriter; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 140 | import java.nio.charset.StandardCharsets; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 141 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 142 | import java.util.Arrays; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 143 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 144 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 145 | import java.util.Map; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 146 | |
| 147 | /** |
| 148 | * Implementation of the ITelephony interface. |
| 149 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 150 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 151 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 152 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 153 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 154 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 155 | |
| 156 | // Message codes used with mMainThreadHandler |
| 157 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 158 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 159 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 160 | private static final int CMD_OPEN_CHANNEL = 9; |
| 161 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 162 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 163 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 164 | private static final int CMD_NV_READ_ITEM = 13; |
| 165 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 166 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 167 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 168 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 169 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 170 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 171 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 172 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 173 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 174 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 175 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 176 | private static final int CMD_SEND_ENVELOPE = 25; |
| 177 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 178 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 179 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 180 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 181 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 182 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 183 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 184 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 185 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 186 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 187 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 188 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 189 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 190 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 191 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 192 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 193 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 194 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 195 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 196 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 197 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 198 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 199 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 200 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 201 | private static final int CMD_SWITCH_SLOTS = 50; |
| 202 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 203 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 204 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 205 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 206 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 207 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 208 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 209 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 210 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 211 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 212 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 213 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 214 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 215 | private static final int CMD_MODEM_REBOOT = 64; |
| 216 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 217 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 218 | // Parameters of select command. |
| 219 | private static final int SELECT_COMMAND = 0xA4; |
| 220 | private static final int SELECT_P1 = 0x04; |
| 221 | private static final int SELECT_P2 = 0; |
| 222 | private static final int SELECT_P3 = 0x10; |
| 223 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 224 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 225 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 226 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 227 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 228 | /** The singleton instance. */ |
| 229 | private static PhoneInterfaceManager sInstance; |
| 230 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 231 | private PhoneGlobals mApp; |
| 232 | private Phone mPhone; |
| 233 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 234 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 235 | private AppOpsManager mAppOps; |
| 236 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 237 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 238 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 239 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 240 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 241 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 242 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 243 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 244 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 245 | // The AID of ISD-R. |
| 246 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 247 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 248 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 249 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 250 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 251 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 252 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 253 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 254 | * A request object to use for transmitting data to an ICC. |
| 255 | */ |
| 256 | private static final class IccAPDUArgument { |
| 257 | public int channel, cla, command, p1, p2, p3; |
| 258 | public String data; |
| 259 | |
| 260 | public IccAPDUArgument(int channel, int cla, int command, |
| 261 | int p1, int p2, int p3, String data) { |
| 262 | this.channel = channel; |
| 263 | this.cla = cla; |
| 264 | this.command = command; |
| 265 | this.p1 = p1; |
| 266 | this.p2 = p2; |
| 267 | this.p3 = p3; |
| 268 | this.data = data; |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 273 | * A request object to use for transmitting data to an ICC. |
| 274 | */ |
| 275 | private static final class ManualNetworkSelectionArgument { |
| 276 | public OperatorInfo operatorInfo; |
| 277 | public boolean persistSelection; |
| 278 | |
| 279 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 280 | this.operatorInfo = operatorInfo; |
| 281 | this.persistSelection = persistSelection; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 286 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 287 | * request after sending. The main thread will notify the request when it is complete. |
| 288 | */ |
| 289 | private static final class MainThreadRequest { |
| 290 | /** The argument to use for the request */ |
| 291 | public Object argument; |
| 292 | /** The result of the request that is run on the main thread */ |
| 293 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 294 | // The subscriber id that this request applies to. Defaults to |
| 295 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 296 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 297 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 298 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 299 | public Phone phone; |
| 300 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 301 | public WorkSource workSource; |
| 302 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 303 | public MainThreadRequest(Object argument) { |
| 304 | this.argument = argument; |
| 305 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 306 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 307 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 308 | this.argument = argument; |
| 309 | if (phone != null) { |
| 310 | this.phone = phone; |
| 311 | } |
| 312 | this.workSource = workSource; |
| 313 | } |
| 314 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 315 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 316 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 317 | if (subId != null) { |
| 318 | this.subId = subId; |
| 319 | } |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 320 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 321 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 324 | private static final class IncomingThirdPartyCallArgs { |
| 325 | public final ComponentName component; |
| 326 | public final String callId; |
| 327 | public final String callerDisplayName; |
| 328 | |
| 329 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 330 | String callerDisplayName) { |
| 331 | this.component = component; |
| 332 | this.callId = callId; |
| 333 | this.callerDisplayName = callerDisplayName; |
| 334 | } |
| 335 | } |
| 336 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 337 | /** |
| 338 | * A handler that processes messages on the main thread in the phone process. Since many |
| 339 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 340 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 341 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 342 | * on, which will be notified when the operation completes and will contain the result of the |
| 343 | * request. |
| 344 | * |
| 345 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 346 | * note that request.result must be set to something non-null for the calling thread to |
| 347 | * unblock. |
| 348 | */ |
| 349 | private final class MainThreadHandler extends Handler { |
| 350 | @Override |
| 351 | public void handleMessage(Message msg) { |
| 352 | MainThreadRequest request; |
| 353 | Message onCompleted; |
| 354 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 355 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 356 | IccAPDUArgument iccArgument; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 357 | |
| 358 | switch (msg.what) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 359 | case CMD_HANDLE_USSD_REQUEST: { |
| 360 | request = (MainThreadRequest) msg.obj; |
| 361 | final Phone phone = getPhoneFromRequest(request); |
| 362 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 363 | String ussdRequest = ussdObject.first; |
| 364 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 365 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 366 | if (!isUssdApiAllowed(request.subId)) { |
| 367 | // Carrier does not support use of this API, return failure. |
| 368 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 369 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 370 | Bundle returnData = new Bundle(); |
| 371 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 372 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 373 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 374 | request.result = true; |
| 375 | notifyRequester(request); |
| 376 | return; |
| 377 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 378 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 379 | try { |
| 380 | request.result = phone != null |
| 381 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 382 | } catch (CallStateException cse) { |
| 383 | request.result = false; |
| 384 | } |
| 385 | // Wake up the requesting thread |
| 386 | notifyRequester(request); |
| 387 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 390 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 391 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 392 | final Phone phone = getPhoneFromRequest(request); |
| 393 | request.result = phone != null ? |
| 394 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 395 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 396 | // Wake up the requesting thread |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 397 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 398 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 399 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 400 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 401 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 402 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 403 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 404 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 405 | if (uiccCard == null) { |
| 406 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 407 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 408 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 409 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 410 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 411 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 412 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 413 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 414 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 415 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 416 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 417 | break; |
| 418 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 419 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 420 | ar = (AsyncResult) msg.obj; |
| 421 | request = (MainThreadRequest) ar.userObj; |
| 422 | if (ar.exception == null && ar.result != null) { |
| 423 | request.result = ar.result; |
| 424 | } else { |
| 425 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 426 | if (ar.result == null) { |
| 427 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 428 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 429 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 430 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 431 | } else { |
| 432 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 433 | } |
| 434 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 435 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 436 | break; |
| 437 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 438 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 439 | request = (MainThreadRequest) msg.obj; |
| 440 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 441 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 442 | if (uiccCard == null) { |
| 443 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 444 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 445 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 446 | } else { |
| 447 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 448 | request); |
| 449 | uiccCard.iccTransmitApduBasicChannel( |
| 450 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 451 | iccArgument.p3, iccArgument.data, onCompleted); |
| 452 | } |
| 453 | break; |
| 454 | |
| 455 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 456 | ar = (AsyncResult) msg.obj; |
| 457 | request = (MainThreadRequest) ar.userObj; |
| 458 | if (ar.exception == null && ar.result != null) { |
| 459 | request.result = ar.result; |
| 460 | } else { |
| 461 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 462 | if (ar.result == null) { |
| 463 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 464 | } else if (ar.exception instanceof CommandException) { |
| 465 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 466 | ar.exception); |
| 467 | } else { |
| 468 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 469 | } |
| 470 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 471 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 472 | break; |
| 473 | |
| 474 | case CMD_EXCHANGE_SIM_IO: |
| 475 | request = (MainThreadRequest) msg.obj; |
| 476 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 477 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 478 | if (uiccCard == null) { |
| 479 | loge("iccExchangeSimIO: No UICC"); |
| 480 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 481 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 482 | } else { |
| 483 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 484 | request); |
| 485 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 486 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 487 | iccArgument.data, onCompleted); |
| 488 | } |
| 489 | break; |
| 490 | |
| 491 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 492 | ar = (AsyncResult) msg.obj; |
| 493 | request = (MainThreadRequest) ar.userObj; |
| 494 | if (ar.exception == null && ar.result != null) { |
| 495 | request.result = ar.result; |
| 496 | } else { |
| 497 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 498 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 499 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 500 | break; |
| 501 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 502 | case CMD_SEND_ENVELOPE: |
| 503 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 504 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 505 | if (uiccCard == null) { |
| 506 | loge("sendEnvelopeWithStatus: No UICC"); |
| 507 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 508 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 509 | } else { |
| 510 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 511 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 512 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 513 | break; |
| 514 | |
| 515 | case EVENT_SEND_ENVELOPE_DONE: |
| 516 | ar = (AsyncResult) msg.obj; |
| 517 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 518 | if (ar.exception == null && ar.result != null) { |
| 519 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 520 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 521 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 522 | if (ar.result == null) { |
| 523 | loge("sendEnvelopeWithStatus: Empty response"); |
| 524 | } else if (ar.exception instanceof CommandException) { |
| 525 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 526 | ar.exception); |
| 527 | } else { |
| 528 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 529 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 530 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 531 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 532 | break; |
| 533 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 534 | case CMD_OPEN_CHANNEL: |
| 535 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 536 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 537 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 538 | if (uiccCard == null) { |
| 539 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 540 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 541 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 542 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 543 | } else { |
| 544 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 545 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 546 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 547 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 548 | break; |
| 549 | |
| 550 | case EVENT_OPEN_CHANNEL_DONE: |
| 551 | ar = (AsyncResult) msg.obj; |
| 552 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 553 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 554 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 555 | int[] result = (int[]) ar.result; |
| 556 | int channelId = result[0]; |
| 557 | byte[] selectResponse = null; |
| 558 | if (result.length > 1) { |
| 559 | selectResponse = new byte[result.length - 1]; |
| 560 | for (int i = 1; i < result.length; ++i) { |
| 561 | selectResponse[i - 1] = (byte) result[i]; |
| 562 | } |
| 563 | } |
| 564 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 565 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 566 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 567 | if (ar.result == null) { |
| 568 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 569 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 570 | if (ar.exception != null) { |
| 571 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 572 | } |
| 573 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 574 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 575 | if (ar.exception instanceof CommandException) { |
| 576 | CommandException.Error error = |
| 577 | ((CommandException) (ar.exception)).getCommandError(); |
| 578 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 579 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 580 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 581 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 582 | } |
| 583 | } |
| 584 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 585 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 586 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 587 | request.result = openChannelResp; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 588 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 589 | break; |
| 590 | |
| 591 | case CMD_CLOSE_CHANNEL: |
| 592 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 593 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 594 | if (uiccCard == null) { |
| 595 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 596 | request.result = false; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 597 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 598 | } else { |
| 599 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 600 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 601 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 602 | break; |
| 603 | |
| 604 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 605 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 606 | break; |
| 607 | |
| 608 | case CMD_NV_READ_ITEM: |
| 609 | request = (MainThreadRequest) msg.obj; |
| 610 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 611 | mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 612 | break; |
| 613 | |
| 614 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 615 | ar = (AsyncResult) msg.obj; |
| 616 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 617 | if (ar.exception == null && ar.result != null) { |
| 618 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 619 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 620 | request.result = ""; |
| 621 | if (ar.result == null) { |
| 622 | loge("nvReadItem: Empty response"); |
| 623 | } else if (ar.exception instanceof CommandException) { |
| 624 | loge("nvReadItem: CommandException: " + |
| 625 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 626 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 627 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 628 | } |
| 629 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 630 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 631 | break; |
| 632 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 633 | case CMD_NV_WRITE_ITEM: |
| 634 | request = (MainThreadRequest) msg.obj; |
| 635 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 636 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 637 | mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
| 638 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 639 | break; |
| 640 | |
| 641 | case EVENT_NV_WRITE_ITEM_DONE: |
| 642 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 643 | break; |
| 644 | |
| 645 | case CMD_NV_WRITE_CDMA_PRL: |
| 646 | request = (MainThreadRequest) msg.obj; |
| 647 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
| 648 | mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
| 649 | break; |
| 650 | |
| 651 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 652 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 653 | break; |
| 654 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 655 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 656 | request = (MainThreadRequest) msg.obj; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 657 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
| 658 | mPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 659 | break; |
| 660 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 661 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 662 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 663 | break; |
| 664 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 665 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 666 | request = (MainThreadRequest) msg.obj; |
| 667 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 668 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 669 | break; |
| 670 | |
| 671 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 672 | ar = (AsyncResult) msg.obj; |
| 673 | request = (MainThreadRequest) ar.userObj; |
| 674 | if (ar.exception == null && ar.result != null) { |
| 675 | request.result = ar.result; // Integer |
| 676 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 677 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 678 | if (ar.result == null) { |
| 679 | loge("getPreferredNetworkType: Empty response"); |
| 680 | } else if (ar.exception instanceof CommandException) { |
| 681 | loge("getPreferredNetworkType: CommandException: " + |
| 682 | ar.exception); |
| 683 | } else { |
| 684 | loge("getPreferredNetworkType: Unknown exception"); |
| 685 | } |
| 686 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 687 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 688 | break; |
| 689 | |
| 690 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 691 | request = (MainThreadRequest) msg.obj; |
| 692 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 693 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 694 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 695 | break; |
| 696 | |
| 697 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 698 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 699 | break; |
| 700 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 701 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 702 | request = (MainThreadRequest)msg.obj; |
| 703 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 704 | mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 705 | break; |
| 706 | |
| 707 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 708 | ar = (AsyncResult)msg.obj; |
| 709 | request = (MainThreadRequest)ar.userObj; |
| 710 | request.result = ar; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 711 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 712 | break; |
| 713 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 714 | case CMD_SET_VOICEMAIL_NUMBER: |
| 715 | request = (MainThreadRequest) msg.obj; |
| 716 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 717 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 718 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 719 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 720 | break; |
| 721 | |
| 722 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 723 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 724 | break; |
| 725 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 726 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 727 | request = (MainThreadRequest) msg.obj; |
| 728 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 729 | request); |
| 730 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 731 | break; |
| 732 | |
| 733 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 734 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 735 | break; |
| 736 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 737 | case CMD_PERFORM_NETWORK_SCAN: |
| 738 | request = (MainThreadRequest) msg.obj; |
| 739 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 740 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 741 | break; |
| 742 | |
| 743 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 744 | ar = (AsyncResult) msg.obj; |
| 745 | request = (MainThreadRequest) ar.userObj; |
| 746 | CellNetworkScanResult cellScanResult; |
| 747 | if (ar.exception == null && ar.result != null) { |
| 748 | cellScanResult = new CellNetworkScanResult( |
| 749 | CellNetworkScanResult.STATUS_SUCCESS, |
| 750 | (List<OperatorInfo>) ar.result); |
| 751 | } else { |
| 752 | if (ar.result == null) { |
| 753 | loge("getCellNetworkScanResults: Empty response"); |
| 754 | } |
| 755 | if (ar.exception != null) { |
| 756 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 757 | } |
| 758 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 759 | if (ar.exception instanceof CommandException) { |
| 760 | CommandException.Error error = |
| 761 | ((CommandException) (ar.exception)).getCommandError(); |
| 762 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 763 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 764 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 765 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 766 | } |
| 767 | } |
| 768 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 769 | } |
| 770 | request.result = cellScanResult; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 771 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 772 | break; |
| 773 | |
| 774 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 775 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 776 | ManualNetworkSelectionArgument selArg = |
| 777 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 778 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 779 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 780 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 781 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 782 | break; |
| 783 | |
| 784 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | dd9ac82 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 785 | ar = (AsyncResult) msg.obj; |
| 786 | request = (MainThreadRequest) ar.userObj; |
| 787 | if (ar.exception == null) { |
| 788 | request.result = true; |
| 789 | } else { |
| 790 | request.result = false; |
| 791 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 792 | } |
| 793 | notifyRequester(request); |
| 794 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 795 | break; |
| 796 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 797 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 798 | request = (MainThreadRequest) msg.obj; |
| 799 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 800 | mPhone.getModemActivityInfo(onCompleted, request.workSource); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 801 | break; |
| 802 | |
| 803 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 804 | ar = (AsyncResult) msg.obj; |
| 805 | request = (MainThreadRequest) ar.userObj; |
| 806 | if (ar.exception == null && ar.result != null) { |
| 807 | request.result = ar.result; |
| 808 | } else { |
| 809 | if (ar.result == null) { |
| 810 | loge("queryModemActivityInfo: Empty response"); |
| 811 | } else if (ar.exception instanceof CommandException) { |
| 812 | loge("queryModemActivityInfo: CommandException: " + |
| 813 | ar.exception); |
| 814 | } else { |
| 815 | loge("queryModemActivityInfo: Unknown exception"); |
| 816 | } |
| 817 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 818 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 819 | if (request.result == null) { |
| 820 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 821 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 822 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 823 | break; |
| 824 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 825 | case CMD_SET_ALLOWED_CARRIERS: |
| 826 | request = (MainThreadRequest) msg.obj; |
| 827 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
| 828 | mPhone.setAllowedCarriers( |
| 829 | (List<CarrierIdentifier>) request.argument, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 830 | onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 831 | break; |
| 832 | |
| 833 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 834 | ar = (AsyncResult) msg.obj; |
| 835 | request = (MainThreadRequest) ar.userObj; |
| 836 | if (ar.exception == null && ar.result != null) { |
| 837 | request.result = ar.result; |
| 838 | } else { |
| 839 | if (ar.result == null) { |
| 840 | loge("setAllowedCarriers: Empty response"); |
| 841 | } else if (ar.exception instanceof CommandException) { |
| 842 | loge("setAllowedCarriers: CommandException: " + |
| 843 | ar.exception); |
| 844 | } else { |
| 845 | loge("setAllowedCarriers: Unknown exception"); |
| 846 | } |
| 847 | } |
| 848 | // Result cannot be null. Return -1 on error. |
| 849 | if (request.result == null) { |
| 850 | request.result = new int[]{-1}; |
| 851 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 852 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 853 | break; |
| 854 | |
| 855 | case CMD_GET_ALLOWED_CARRIERS: |
| 856 | request = (MainThreadRequest) msg.obj; |
| 857 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 858 | mPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 859 | break; |
| 860 | |
| 861 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 862 | ar = (AsyncResult) msg.obj; |
| 863 | request = (MainThreadRequest) ar.userObj; |
| 864 | if (ar.exception == null && ar.result != null) { |
| 865 | request.result = ar.result; |
| 866 | } else { |
| 867 | if (ar.result == null) { |
| 868 | loge("getAllowedCarriers: Empty response"); |
| 869 | } else if (ar.exception instanceof CommandException) { |
| 870 | loge("getAllowedCarriers: CommandException: " + |
| 871 | ar.exception); |
| 872 | } else { |
| 873 | loge("getAllowedCarriers: Unknown exception"); |
| 874 | } |
| 875 | } |
| 876 | // Result cannot be null. Return empty list of CarrierIdentifier. |
| 877 | if (request.result == null) { |
| 878 | request.result = new ArrayList<CarrierIdentifier>(0); |
| 879 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 880 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 881 | break; |
| 882 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 883 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 884 | ar = (AsyncResult) msg.obj; |
| 885 | request = (MainThreadRequest) ar.userObj; |
| 886 | if (ar.exception == null && ar.result != null) { |
| 887 | request.result = ar.result; |
| 888 | } else { |
| 889 | request.result = new IllegalArgumentException( |
| 890 | "Failed to retrieve Forbidden Plmns"); |
| 891 | if (ar.result == null) { |
| 892 | loge("getForbiddenPlmns: Empty response"); |
| 893 | } else { |
| 894 | loge("getForbiddenPlmns: Unknown exception"); |
| 895 | } |
| 896 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 897 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 898 | break; |
| 899 | |
| 900 | case CMD_GET_FORBIDDEN_PLMNS: |
| 901 | request = (MainThreadRequest) msg.obj; |
| 902 | uiccCard = getUiccCardFromRequest(request); |
| 903 | if (uiccCard == null) { |
| 904 | loge("getForbiddenPlmns() UiccCard is null"); |
| 905 | request.result = new IllegalArgumentException( |
| 906 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 907 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 908 | break; |
| 909 | } |
| 910 | Integer appType = (Integer) request.argument; |
| 911 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 912 | if (uiccApp == null) { |
| 913 | loge("getForbiddenPlmns() no app with specified type -- " |
| 914 | + appType); |
| 915 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 916 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 917 | break; |
| 918 | } else { |
| 919 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 920 | + " specified type -- " + appType); |
| 921 | } |
| 922 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 923 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 924 | onCompleted); |
| 925 | break; |
| 926 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 927 | case CMD_SWITCH_SLOTS: |
| 928 | request = (MainThreadRequest) msg.obj; |
| 929 | int[] physicalSlots = (int[]) request.argument; |
| 930 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 931 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 932 | break; |
| 933 | |
| 934 | case EVENT_SWITCH_SLOTS_DONE: |
| 935 | ar = (AsyncResult) msg.obj; |
| 936 | request = (MainThreadRequest) ar.userObj; |
| 937 | request.result = (ar.exception == null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 938 | notifyRequester(request); |
| 939 | break; |
| 940 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 941 | request = (MainThreadRequest) msg.obj; |
| 942 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 943 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 944 | break; |
| 945 | |
| 946 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 947 | ar = (AsyncResult) msg.obj; |
| 948 | request = (MainThreadRequest) ar.userObj; |
| 949 | if (ar.exception != null) { |
| 950 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 951 | } else { |
| 952 | int mode = ((int[]) ar.result)[0]; |
| 953 | if (mode == 0) { |
| 954 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 955 | } else { |
| 956 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 957 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 958 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 959 | notifyRequester(request); |
| 960 | break; |
| 961 | case CMD_GET_CDMA_ROAMING_MODE: |
| 962 | request = (MainThreadRequest) msg.obj; |
| 963 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 964 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 965 | break; |
| 966 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 967 | ar = (AsyncResult) msg.obj; |
| 968 | request = (MainThreadRequest) ar.userObj; |
| 969 | if (ar.exception != null) { |
| 970 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 971 | } else { |
| 972 | request.result = ((int[]) ar.result)[0]; |
| 973 | } |
| 974 | notifyRequester(request); |
| 975 | break; |
| 976 | case CMD_SET_CDMA_ROAMING_MODE: |
| 977 | request = (MainThreadRequest) msg.obj; |
| 978 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 979 | int mode = (int) request.argument; |
| 980 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 981 | break; |
| 982 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 983 | ar = (AsyncResult) msg.obj; |
| 984 | request = (MainThreadRequest) ar.userObj; |
| 985 | request.result = ar.exception == null; |
| 986 | notifyRequester(request); |
| 987 | break; |
| 988 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 989 | request = (MainThreadRequest) msg.obj; |
| 990 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 991 | int subscriptionMode = (int) request.argument; |
| 992 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 993 | break; |
| 994 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 995 | ar = (AsyncResult) msg.obj; |
| 996 | request = (MainThreadRequest) ar.userObj; |
| 997 | request.result = ar.exception == null; |
| 998 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 999 | break; |
| 1000 | |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1001 | case CMD_GET_ALL_CELL_INFO: |
| 1002 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1003 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1004 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1005 | break; |
| 1006 | |
| 1007 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1008 | ar = (AsyncResult) msg.obj; |
| 1009 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1010 | // If a timeout occurs, the response will be null |
| 1011 | request.result = (ar.exception == null && ar.result != null) |
| 1012 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1013 | synchronized (request) { |
| 1014 | request.notifyAll(); |
| 1015 | } |
| 1016 | break; |
| 1017 | |
| 1018 | case CMD_GET_CELL_LOCATION: { |
| 1019 | request = (MainThreadRequest) msg.obj; |
| 1020 | WorkSource ws = (WorkSource) request.argument; |
| 1021 | Phone phone = getPhoneFromRequest(request); |
| 1022 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1023 | break; |
| 1024 | } |
| 1025 | |
| 1026 | case EVENT_GET_CELL_LOCATION_DONE: { |
| 1027 | ar = (AsyncResult) msg.obj; |
| 1028 | request = (MainThreadRequest) ar.userObj; |
| 1029 | if (ar.exception == null) { |
| 1030 | request.result = ar.result; |
| 1031 | } else { |
| 1032 | Phone phone = getPhoneFromRequest(request); |
| 1033 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1034 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1035 | } |
| 1036 | |
| 1037 | synchronized (request) { |
| 1038 | request.notifyAll(); |
| 1039 | } |
| 1040 | break; |
| 1041 | } |
| 1042 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1043 | case CMD_MODEM_REBOOT: |
| 1044 | request = (MainThreadRequest) msg.obj; |
| 1045 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
| 1046 | mPhone.rebootModem(onCompleted); |
| 1047 | break; |
| 1048 | |
| 1049 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1050 | handleNullReturnEvent(msg, "rebootModem"); |
| 1051 | break; |
| 1052 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1053 | default: |
| 1054 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1055 | break; |
| 1056 | } |
| 1057 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1058 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1059 | private void notifyRequester(MainThreadRequest request) { |
| 1060 | synchronized (request) { |
| 1061 | request.notifyAll(); |
| 1062 | } |
| 1063 | } |
| 1064 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1065 | private void handleNullReturnEvent(Message msg, String command) { |
| 1066 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1067 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1068 | if (ar.exception == null) { |
| 1069 | request.result = true; |
| 1070 | } else { |
| 1071 | request.result = false; |
| 1072 | if (ar.exception instanceof CommandException) { |
| 1073 | loge(command + ": CommandException: " + ar.exception); |
| 1074 | } else { |
| 1075 | loge(command + ": Unknown exception"); |
| 1076 | } |
| 1077 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1078 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1079 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | /** |
| 1083 | * Posts the specified command to be executed on the main thread, |
| 1084 | * waits for the request to complete, and returns the result. |
| 1085 | * @see #sendRequestAsync |
| 1086 | */ |
| 1087 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1088 | return sendRequest( |
| 1089 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | /** |
| 1093 | * Posts the specified command to be executed on the main thread, |
| 1094 | * waits for the request to complete, and returns the result. |
| 1095 | * @see #sendRequestAsync |
| 1096 | */ |
| 1097 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1098 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1099 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | /** |
| 1103 | * Posts the specified command to be executed on the main thread, |
| 1104 | * waits for the request to complete, and returns the result. |
| 1105 | * @see #sendRequestAsync |
| 1106 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1107 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1108 | return sendRequest(command, argument, subId, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | /** |
| 1112 | * Posts the specified command to be executed on the main thread, |
| 1113 | * waits for the request to complete, and returns the result. |
| 1114 | * @see #sendRequestAsync |
| 1115 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1116 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1117 | return sendRequest(command, argument, subId, null, workSource); |
| 1118 | } |
| 1119 | |
| 1120 | /** |
| 1121 | * Posts the specified command to be executed on the main thread, |
| 1122 | * waits for the request to complete, and returns the result. |
| 1123 | * @see #sendRequestAsync |
| 1124 | */ |
| 1125 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1126 | return sendRequest( |
| 1127 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1128 | } |
| 1129 | |
| 1130 | /** |
| 1131 | * Posts the specified command to be executed on the main thread, |
| 1132 | * waits for the request to complete, and returns the result. |
| 1133 | * @see #sendRequestAsync |
| 1134 | */ |
| 1135 | private Object sendRequest( |
| 1136 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1137 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1138 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1139 | } |
| 1140 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1141 | MainThreadRequest request = null; |
| 1142 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1143 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1144 | } else if (phone != null) { |
| 1145 | request = new MainThreadRequest(argument, phone, workSource); |
| 1146 | } else { |
| 1147 | request = new MainThreadRequest(argument, subId, workSource); |
| 1148 | } |
| 1149 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1150 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1151 | msg.sendToTarget(); |
| 1152 | |
| 1153 | // Wait for the request to complete |
| 1154 | synchronized (request) { |
| 1155 | while (request.result == null) { |
| 1156 | try { |
| 1157 | request.wait(); |
| 1158 | } catch (InterruptedException e) { |
| 1159 | // Do nothing, go back and wait until the request is complete |
| 1160 | } |
| 1161 | } |
| 1162 | } |
| 1163 | return request.result; |
| 1164 | } |
| 1165 | |
| 1166 | /** |
| 1167 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1168 | * Posts the specified command to be executed on the main thread, and |
| 1169 | * returns immediately. |
| 1170 | * @see #sendRequest |
| 1171 | */ |
| 1172 | private void sendRequestAsync(int command) { |
| 1173 | mMainThreadHandler.sendEmptyMessage(command); |
| 1174 | } |
| 1175 | |
| 1176 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1177 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
| 1178 | * @see {@link #sendRequest(int,Object)} |
| 1179 | */ |
| 1180 | private void sendRequestAsync(int command, Object argument) { |
| 1181 | MainThreadRequest request = new MainThreadRequest(argument); |
| 1182 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1183 | msg.sendToTarget(); |
| 1184 | } |
| 1185 | |
| 1186 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1187 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1188 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1189 | */ |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 1190 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1191 | synchronized (PhoneInterfaceManager.class) { |
| 1192 | if (sInstance == null) { |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 1193 | sInstance = new PhoneInterfaceManager(app, phone); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1194 | } else { |
| 1195 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1196 | } |
| 1197 | return sInstance; |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | /** Private constructor; @see init() */ |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 1202 | private PhoneInterfaceManager(PhoneGlobals app, Phone phone) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1203 | mApp = app; |
| 1204 | mPhone = phone; |
| 1205 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1206 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1207 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1208 | mMainThreadHandler = new MainThreadHandler(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 1209 | mTelephonySharedPreferences = |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 1210 | PreferenceManager.getDefaultSharedPreferences(mPhone.getContext()); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1211 | mSubscriptionController = SubscriptionController.getInstance(); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1212 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1213 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1214 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1215 | publish(); |
| 1216 | } |
| 1217 | |
| 1218 | private void publish() { |
| 1219 | if (DBG) log("publish: " + this); |
| 1220 | |
| 1221 | ServiceManager.addService("phone", this); |
| 1222 | } |
| 1223 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1224 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 1225 | return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1226 | ? mPhone : getPhone(request.subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1227 | } |
| 1228 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1229 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1230 | Phone phone = getPhoneFromRequest(request); |
| 1231 | return phone == null ? null : |
| 1232 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1233 | } |
| 1234 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1235 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1236 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1237 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1238 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1239 | |
| 1240 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1241 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1244 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1245 | if (DBG) log("dial: " + number); |
| 1246 | // No permission check needed here: This is just a wrapper around the |
| 1247 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1248 | // the UI before it does anything. |
| 1249 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1250 | final long identity = Binder.clearCallingIdentity(); |
| 1251 | try { |
| 1252 | String url = createTelUrl(number); |
| 1253 | if (url == null) { |
| 1254 | return; |
| 1255 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1256 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1257 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1258 | PhoneConstants.State state = mCM.getState(subId); |
| 1259 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1260 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1261 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1262 | mApp.startActivity(intent); |
| 1263 | } |
| 1264 | } finally { |
| 1265 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1270 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1271 | } |
| 1272 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1273 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1274 | if (DBG) log("call: " + number); |
| 1275 | |
| 1276 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1277 | // need to do a permission check since we're calling startActivity() |
| 1278 | // from the context of the phone app. |
| 1279 | enforceCallPermission(); |
| 1280 | |
| 1281 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1282 | != AppOpsManager.MODE_ALLOWED) { |
| 1283 | return; |
| 1284 | } |
| 1285 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1286 | final long identity = Binder.clearCallingIdentity(); |
| 1287 | try { |
| 1288 | String url = createTelUrl(number); |
| 1289 | if (url == null) { |
| 1290 | return; |
| 1291 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1292 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1293 | boolean isValid = false; |
| 1294 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1295 | if (slist != null) { |
| 1296 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1297 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1298 | isValid = true; |
| 1299 | break; |
| 1300 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1301 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1302 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1303 | if (!isValid) { |
| 1304 | return; |
| 1305 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1306 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1307 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1308 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1309 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1310 | mApp.startActivity(intent); |
| 1311 | } finally { |
| 1312 | Binder.restoreCallingIdentity(identity); |
| 1313 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1316 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1317 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1318 | } |
| 1319 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1320 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1321 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1322 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1323 | } |
| 1324 | |
| 1325 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1326 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1329 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1330 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1331 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1332 | } |
| 1333 | |
| 1334 | /** {@hide} */ |
| 1335 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1336 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1337 | } |
| 1338 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1339 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1340 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1341 | |
| 1342 | final long identity = Binder.clearCallingIdentity(); |
| 1343 | try { |
| 1344 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1345 | checkSimPin.start(); |
| 1346 | return checkSimPin.unlockSim(null, pin); |
| 1347 | } finally { |
| 1348 | Binder.restoreCallingIdentity(identity); |
| 1349 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1350 | } |
| 1351 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1352 | /** {@hide} */ |
| 1353 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1354 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1355 | } |
| 1356 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1357 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1358 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1359 | |
| 1360 | final long identity = Binder.clearCallingIdentity(); |
| 1361 | try { |
| 1362 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1363 | checkSimPuk.start(); |
| 1364 | return checkSimPuk.unlockSim(puk, pin); |
| 1365 | } finally { |
| 1366 | Binder.restoreCallingIdentity(identity); |
| 1367 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1371 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1372 | * a synchronous one. |
| 1373 | */ |
| 1374 | private static class UnlockSim extends Thread { |
| 1375 | |
| 1376 | private final IccCard mSimCard; |
| 1377 | |
| 1378 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1379 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1380 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1381 | |
| 1382 | // For replies from SimCard interface |
| 1383 | private Handler mHandler; |
| 1384 | |
| 1385 | // For async handler to identify request type |
| 1386 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1387 | |
| 1388 | public UnlockSim(IccCard simCard) { |
| 1389 | mSimCard = simCard; |
| 1390 | } |
| 1391 | |
| 1392 | @Override |
| 1393 | public void run() { |
| 1394 | Looper.prepare(); |
| 1395 | synchronized (UnlockSim.this) { |
| 1396 | mHandler = new Handler() { |
| 1397 | @Override |
| 1398 | public void handleMessage(Message msg) { |
| 1399 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1400 | switch (msg.what) { |
| 1401 | case SUPPLY_PIN_COMPLETE: |
| 1402 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1403 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1404 | mRetryCount = msg.arg1; |
| 1405 | if (ar.exception != null) { |
| 1406 | if (ar.exception instanceof CommandException && |
| 1407 | ((CommandException)(ar.exception)).getCommandError() |
| 1408 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1409 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1410 | } else { |
| 1411 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1412 | } |
| 1413 | } else { |
| 1414 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1415 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1416 | mDone = true; |
| 1417 | UnlockSim.this.notifyAll(); |
| 1418 | } |
| 1419 | break; |
| 1420 | } |
| 1421 | } |
| 1422 | }; |
| 1423 | UnlockSim.this.notifyAll(); |
| 1424 | } |
| 1425 | Looper.loop(); |
| 1426 | } |
| 1427 | |
| 1428 | /* |
| 1429 | * Use PIN or PUK to unlock SIM card |
| 1430 | * |
| 1431 | * If PUK is null, unlock SIM card with PIN |
| 1432 | * |
| 1433 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1434 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1435 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1436 | |
| 1437 | while (mHandler == null) { |
| 1438 | try { |
| 1439 | wait(); |
| 1440 | } catch (InterruptedException e) { |
| 1441 | Thread.currentThread().interrupt(); |
| 1442 | } |
| 1443 | } |
| 1444 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1445 | |
| 1446 | if (puk == null) { |
| 1447 | mSimCard.supplyPin(pin, callback); |
| 1448 | } else { |
| 1449 | mSimCard.supplyPuk(puk, pin, callback); |
| 1450 | } |
| 1451 | |
| 1452 | while (!mDone) { |
| 1453 | try { |
| 1454 | Log.d(LOG_TAG, "wait for done"); |
| 1455 | wait(); |
| 1456 | } catch (InterruptedException e) { |
| 1457 | // Restore the interrupted status |
| 1458 | Thread.currentThread().interrupt(); |
| 1459 | } |
| 1460 | } |
| 1461 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1462 | int[] resultArray = new int[2]; |
| 1463 | resultArray[0] = mResult; |
| 1464 | resultArray[1] = mRetryCount; |
| 1465 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1466 | } |
| 1467 | } |
| 1468 | |
| 1469 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1470 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1471 | |
| 1472 | } |
| 1473 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1474 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1475 | // No permission check needed here: this call is harmless, and it's |
| 1476 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1477 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1478 | final long identity = Binder.clearCallingIdentity(); |
| 1479 | try { |
| 1480 | final Phone phone = getPhone(subId); |
| 1481 | if (phone != null) { |
| 1482 | phone.updateServiceLocation(); |
| 1483 | } |
| 1484 | } finally { |
| 1485 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1486 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1487 | } |
| 1488 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1489 | @Override |
| 1490 | public boolean isRadioOn(String callingPackage) { |
| 1491 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1494 | @Override |
| 1495 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1496 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1497 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1498 | return false; |
| 1499 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1500 | |
| 1501 | final long identity = Binder.clearCallingIdentity(); |
| 1502 | try { |
| 1503 | return isRadioOnForSubscriber(subId); |
| 1504 | } finally { |
| 1505 | Binder.restoreCallingIdentity(identity); |
| 1506 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1510 | final long identity = Binder.clearCallingIdentity(); |
| 1511 | try { |
| 1512 | final Phone phone = getPhone(subId); |
| 1513 | if (phone != null) { |
| 1514 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1515 | } else { |
| 1516 | return false; |
| 1517 | } |
| 1518 | } finally { |
| 1519 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1520 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1524 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1525 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1526 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1527 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1528 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1529 | |
| 1530 | final long identity = Binder.clearCallingIdentity(); |
| 1531 | try { |
| 1532 | final Phone phone = getPhone(subId); |
| 1533 | if (phone != null) { |
| 1534 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1535 | } |
| 1536 | } finally { |
| 1537 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1538 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1542 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1543 | } |
| 1544 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1545 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1546 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1547 | |
| 1548 | final long identity = Binder.clearCallingIdentity(); |
| 1549 | try { |
| 1550 | final Phone phone = getPhone(subId); |
| 1551 | if (phone == null) { |
| 1552 | return false; |
| 1553 | } |
| 1554 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1555 | toggleRadioOnOffForSubscriber(subId); |
| 1556 | } |
| 1557 | return true; |
| 1558 | } finally { |
| 1559 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1560 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1561 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1562 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1563 | public boolean needMobileRadioShutdown() { |
| 1564 | /* |
| 1565 | * If any of the Radios are available, it will need to be |
| 1566 | * shutdown. So return true if any Radio is available. |
| 1567 | */ |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1568 | final long identity = Binder.clearCallingIdentity(); |
| 1569 | try { |
| 1570 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1571 | Phone phone = PhoneFactory.getPhone(i); |
| 1572 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1573 | } |
| 1574 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1575 | return false; |
| 1576 | } finally { |
| 1577 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1578 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1581 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1582 | public void shutdownMobileRadios() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1583 | enforceModifyPermission(); |
| 1584 | |
| 1585 | final long identity = Binder.clearCallingIdentity(); |
| 1586 | try { |
| 1587 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1588 | logv("Shutting down Phone " + i); |
| 1589 | shutdownRadioUsingPhoneId(i); |
| 1590 | } |
| 1591 | } finally { |
| 1592 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1593 | } |
| 1594 | } |
| 1595 | |
| 1596 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1597 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1598 | if (phone != null && phone.isRadioAvailable()) { |
| 1599 | phone.shutdownRadio(); |
| 1600 | } |
| 1601 | } |
| 1602 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1603 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -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 defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1609 | if (defaultPhone != null) { |
| 1610 | defaultPhone.setRadioPower(turnOn); |
| 1611 | return true; |
| 1612 | } else { |
| 1613 | loge("There's no default phone."); |
| 1614 | return false; |
| 1615 | } |
| 1616 | } finally { |
| 1617 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1618 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1619 | } |
| 1620 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1621 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1622 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1623 | |
| 1624 | final long identity = Binder.clearCallingIdentity(); |
| 1625 | try { |
| 1626 | final Phone phone = getPhone(subId); |
| 1627 | if (phone != null) { |
| 1628 | phone.setRadioPower(turnOn); |
| 1629 | return true; |
| 1630 | } else { |
| 1631 | return false; |
| 1632 | } |
| 1633 | } finally { |
| 1634 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1635 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1636 | } |
| 1637 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1638 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1639 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1640 | public boolean enableDataConnectivity() { |
| 1641 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1642 | |
| 1643 | final long identity = Binder.clearCallingIdentity(); |
| 1644 | try { |
| 1645 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1646 | final Phone phone = getPhone(subId); |
| 1647 | if (phone != null) { |
| 1648 | phone.setUserDataEnabled(true); |
| 1649 | return true; |
| 1650 | } else { |
| 1651 | return false; |
| 1652 | } |
| 1653 | } finally { |
| 1654 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1655 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1656 | } |
| 1657 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1658 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1659 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1660 | public boolean disableDataConnectivity() { |
| 1661 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1662 | |
| 1663 | final long identity = Binder.clearCallingIdentity(); |
| 1664 | try { |
| 1665 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1666 | final Phone phone = getPhone(subId); |
| 1667 | if (phone != null) { |
| 1668 | phone.setUserDataEnabled(false); |
| 1669 | return true; |
| 1670 | } else { |
| 1671 | return false; |
| 1672 | } |
| 1673 | } finally { |
| 1674 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1675 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1676 | } |
| 1677 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1678 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1679 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1680 | final long identity = Binder.clearCallingIdentity(); |
| 1681 | try { |
| 1682 | final Phone phone = getPhone(subId); |
| 1683 | if (phone != null) { |
| 1684 | return phone.isDataAllowed(); |
| 1685 | } else { |
| 1686 | return false; |
| 1687 | } |
| 1688 | } finally { |
| 1689 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1690 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1694 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1697 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1698 | enforceCallPermission(); |
| 1699 | |
| 1700 | final long identity = Binder.clearCallingIdentity(); |
| 1701 | try { |
| 1702 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1703 | return; |
| 1704 | } |
| 1705 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1706 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1707 | } finally { |
| 1708 | Binder.restoreCallingIdentity(identity); |
| 1709 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1710 | }; |
| 1711 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1712 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1713 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1714 | |
| 1715 | final long identity = Binder.clearCallingIdentity(); |
| 1716 | try { |
| 1717 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1718 | return false; |
| 1719 | } |
| 1720 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1721 | } finally { |
| 1722 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1723 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1724 | } |
| 1725 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1726 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1727 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1728 | } |
| 1729 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1730 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1731 | final long identity = Binder.clearCallingIdentity(); |
| 1732 | try { |
| 1733 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1734 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1735 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1736 | } finally { |
| 1737 | Binder.restoreCallingIdentity(identity); |
| 1738 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1739 | } |
| 1740 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1741 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1742 | public int getDataState() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1743 | final long identity = Binder.clearCallingIdentity(); |
| 1744 | try { |
| 1745 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1746 | if (phone != null) { |
| 1747 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1748 | } else { |
| 1749 | return PhoneConstantConversions.convertDataState( |
| 1750 | PhoneConstants.DataState.DISCONNECTED); |
| 1751 | } |
| 1752 | } finally { |
| 1753 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1754 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1755 | } |
| 1756 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1757 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1758 | public int getDataActivity() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1759 | final long identity = Binder.clearCallingIdentity(); |
| 1760 | try { |
| 1761 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1762 | if (phone != null) { |
| 1763 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1764 | } else { |
| 1765 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1766 | } |
| 1767 | } finally { |
| 1768 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1769 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1773 | public Bundle getCellLocation(String callingPackage) { |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1774 | mPhone.getContext().getSystemService(AppOpsManager.class) |
| 1775 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1776 | if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(), |
Svet Ganov | 4af6628 | 2018-03-07 19:57:05 -0800 | [diff] [blame] | 1777 | callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1778 | return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1781 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1782 | final long identity = Binder.clearCallingIdentity(); |
| 1783 | try { |
| 1784 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1785 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1786 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1787 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1788 | cl.fillInNotifierBundle(data); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1789 | return data; |
| 1790 | } finally { |
| 1791 | Binder.restoreCallingIdentity(identity); |
| 1792 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1793 | } |
| 1794 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1795 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1796 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1797 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1798 | // registered cell info, so return a NULL country instead. |
| 1799 | final long identity = Binder.clearCallingIdentity(); |
| 1800 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1801 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1802 | // Get default phone in this case. |
| 1803 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1804 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1805 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1806 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1807 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1808 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1809 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1810 | return ""; |
| 1811 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1812 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1813 | if (phone != null) { |
| 1814 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 1815 | if (sst != null) { |
| 1816 | LocaleTracker lt = sst.getLocaleTracker(); |
| 1817 | if (lt != null) { |
| 1818 | return lt.getCurrentCountry(); |
| 1819 | } |
| 1820 | } |
| 1821 | } |
| 1822 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1823 | } finally { |
| 1824 | Binder.restoreCallingIdentity(identity); |
| 1825 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1829 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1830 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1831 | } |
| 1832 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1833 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1834 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1835 | mApp.enforceCallingOrSelfPermission( |
| 1836 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1837 | |
| 1838 | final long identity = Binder.clearCallingIdentity(); |
| 1839 | try { |
| 1840 | final Phone phone = getPhone(subId); |
| 1841 | if (phone != null) { |
| 1842 | phone.enableLocationUpdates(); |
| 1843 | } |
| 1844 | } finally { |
| 1845 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1846 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | @Override |
| 1850 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1851 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1852 | } |
| 1853 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1854 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1855 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1856 | mApp.enforceCallingOrSelfPermission( |
| 1857 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1858 | |
| 1859 | final long identity = Binder.clearCallingIdentity(); |
| 1860 | try { |
| 1861 | final Phone phone = getPhone(subId); |
| 1862 | if (phone != null) { |
| 1863 | phone.disableLocationUpdates(); |
| 1864 | } |
| 1865 | } finally { |
| 1866 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1867 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1868 | } |
| 1869 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1870 | /** |
| 1871 | * Returns the target SDK version number for a given package name. |
| 1872 | * |
| 1873 | * @return target SDK if the package is found or INT_MAX. |
| 1874 | */ |
| 1875 | private int getTargetSdk(String packageName) { |
| 1876 | try { |
| 1877 | final ApplicationInfo ai = |
| 1878 | mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0); |
| 1879 | if (ai != null) return ai.targetSdkVersion; |
| 1880 | } catch (PackageManager.NameNotFoundException unexpected) { |
| 1881 | } |
| 1882 | return Integer.MAX_VALUE; |
| 1883 | } |
| 1884 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1885 | @Override |
| 1886 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1887 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 1888 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 1889 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 1890 | throw new SecurityException( |
| 1891 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 1892 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 1893 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1894 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 1895 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 1896 | return null; |
| 1897 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1898 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1899 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1900 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1901 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 1902 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1903 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1904 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 1905 | for (CellInfo ci : info) { |
| 1906 | if (ci instanceof CellInfoGsm) { |
| 1907 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 1908 | } else if (ci instanceof CellInfoWcdma) { |
| 1909 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 1910 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1911 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1912 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1913 | } |
| 1914 | |
| 1915 | |
| 1916 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1917 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1918 | mPhone.getContext().getSystemService(AppOpsManager.class) |
| 1919 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1920 | if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(), |
Svet Ganov | 4af6628 | 2018-03-07 19:57:05 -0800 | [diff] [blame] | 1921 | callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1922 | return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1925 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1926 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1927 | final long identity = Binder.clearCallingIdentity(); |
| 1928 | try { |
| 1929 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 1930 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1931 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1932 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1933 | if (info != null) cellInfos.addAll(info); |
| 1934 | } |
| 1935 | return cellInfos; |
| 1936 | } finally { |
| 1937 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1938 | } |
| 1939 | } |
| 1940 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1941 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1942 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 1943 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1944 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1945 | |
| 1946 | final long identity = Binder.clearCallingIdentity(); |
| 1947 | try { |
| 1948 | mPhone.setCellInfoListRate(rateInMillis, workSource); |
| 1949 | } finally { |
| 1950 | Binder.restoreCallingIdentity(identity); |
| 1951 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1952 | } |
| 1953 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1954 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1955 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1956 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1957 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1958 | return null; |
| 1959 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1960 | int subId = phone.getSubId(); |
| 1961 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 1962 | mApp, subId, callingPackage, "getImeiForSlot")) { |
| 1963 | return null; |
| 1964 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1965 | |
| 1966 | final long identity = Binder.clearCallingIdentity(); |
| 1967 | try { |
| 1968 | return phone.getImei(); |
| 1969 | } finally { |
| 1970 | Binder.restoreCallingIdentity(identity); |
| 1971 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 1975 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 1976 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1977 | String tac = null; |
| 1978 | if (phone != null) { |
| 1979 | String imei = phone.getImei(); |
| 1980 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 1981 | } |
| 1982 | return tac; |
| 1983 | } |
| 1984 | |
| 1985 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 1986 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1987 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1988 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 1989 | return null; |
| 1990 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1991 | int subId = phone.getSubId(); |
| 1992 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 1993 | mApp, subId, callingPackage, "getMeidForSlot")) { |
| 1994 | return null; |
| 1995 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1996 | |
| 1997 | final long identity = Binder.clearCallingIdentity(); |
| 1998 | try { |
| 1999 | return phone.getMeid(); |
| 2000 | } finally { |
| 2001 | Binder.restoreCallingIdentity(identity); |
| 2002 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2006 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2007 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2008 | String manufacturerCode = null; |
| 2009 | if (phone != null) { |
| 2010 | String meid = phone.getMeid(); |
| 2011 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2012 | } |
| 2013 | return manufacturerCode; |
| 2014 | } |
| 2015 | |
| 2016 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2017 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2018 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2019 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2020 | return null; |
| 2021 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2022 | int subId = phone.getSubId(); |
| 2023 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2024 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2025 | return null; |
| 2026 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2027 | |
| 2028 | final long identity = Binder.clearCallingIdentity(); |
| 2029 | try { |
| 2030 | return phone.getDeviceSvn(); |
| 2031 | } finally { |
| 2032 | Binder.restoreCallingIdentity(identity); |
| 2033 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2034 | } |
| 2035 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2036 | @Override |
| 2037 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2038 | final long identity = Binder.clearCallingIdentity(); |
| 2039 | try { |
| 2040 | final Phone phone = getPhone(subId); |
| 2041 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2042 | } finally { |
| 2043 | Binder.restoreCallingIdentity(identity); |
| 2044 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2045 | } |
| 2046 | |
| 2047 | @Override |
| 2048 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2049 | final long identity = Binder.clearCallingIdentity(); |
| 2050 | try { |
| 2051 | final Phone phone = getPhone(subId); |
| 2052 | return phone == null ? null : phone.getCarrierName(); |
| 2053 | } finally { |
| 2054 | Binder.restoreCallingIdentity(identity); |
| 2055 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2056 | } |
| 2057 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2058 | // |
| 2059 | // Internal helper methods. |
| 2060 | // |
| 2061 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2062 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2063 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2064 | * |
| 2065 | * @throws SecurityException if the caller does not have the required permission |
| 2066 | */ |
| 2067 | private void enforceModifyPermission() { |
| 2068 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2069 | } |
| 2070 | |
| 2071 | /** |
| 2072 | * Make sure the caller has the CALL_PHONE permission. |
| 2073 | * |
| 2074 | * @throws SecurityException if the caller does not have the required permission |
| 2075 | */ |
| 2076 | private void enforceCallPermission() { |
| 2077 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2078 | } |
| 2079 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2080 | private void enforceConnectivityInternalPermission() { |
| 2081 | mApp.enforceCallingOrSelfPermission( |
| 2082 | android.Manifest.permission.CONNECTIVITY_INTERNAL, |
| 2083 | "ConnectivityService"); |
| 2084 | } |
| 2085 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2086 | private String createTelUrl(String number) { |
| 2087 | if (TextUtils.isEmpty(number)) { |
| 2088 | return null; |
| 2089 | } |
| 2090 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2091 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2092 | } |
| 2093 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2094 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2095 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2096 | } |
| 2097 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2098 | private static void logv(String msg) { |
| 2099 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2100 | } |
| 2101 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2102 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2103 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2104 | } |
| 2105 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2106 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2107 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2108 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2111 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2112 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2113 | final long identity = Binder.clearCallingIdentity(); |
| 2114 | try { |
| 2115 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2116 | if (phone == null) { |
| 2117 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2118 | } else { |
| 2119 | return phone.getPhoneType(); |
| 2120 | } |
| 2121 | } finally { |
| 2122 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2123 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2124 | } |
| 2125 | |
| 2126 | /** |
| 2127 | * Returns the CDMA ERI icon index to display |
| 2128 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2129 | @Override |
| 2130 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2131 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2132 | } |
| 2133 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2134 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2135 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2136 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2137 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2138 | return -1; |
| 2139 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2140 | |
| 2141 | final long identity = Binder.clearCallingIdentity(); |
| 2142 | try { |
| 2143 | final Phone phone = getPhone(subId); |
| 2144 | if (phone != null) { |
| 2145 | return phone.getCdmaEriIconIndex(); |
| 2146 | } else { |
| 2147 | return -1; |
| 2148 | } |
| 2149 | } finally { |
| 2150 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2151 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2152 | } |
| 2153 | |
| 2154 | /** |
| 2155 | * Returns the CDMA ERI icon mode, |
| 2156 | * 0 - ON |
| 2157 | * 1 - FLASHING |
| 2158 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2159 | @Override |
| 2160 | public int getCdmaEriIconMode(String callingPackage) { |
| 2161 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2162 | } |
| 2163 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2164 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2165 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2166 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2167 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2168 | return -1; |
| 2169 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2170 | |
| 2171 | final long identity = Binder.clearCallingIdentity(); |
| 2172 | try { |
| 2173 | final Phone phone = getPhone(subId); |
| 2174 | if (phone != null) { |
| 2175 | return phone.getCdmaEriIconMode(); |
| 2176 | } else { |
| 2177 | return -1; |
| 2178 | } |
| 2179 | } finally { |
| 2180 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2181 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2182 | } |
| 2183 | |
| 2184 | /** |
| 2185 | * Returns the CDMA ERI text, |
| 2186 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2187 | @Override |
| 2188 | public String getCdmaEriText(String callingPackage) { |
| 2189 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2190 | } |
| 2191 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2192 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2193 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2194 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2195 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2196 | return null; |
| 2197 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2198 | |
| 2199 | final long identity = Binder.clearCallingIdentity(); |
| 2200 | try { |
| 2201 | final Phone phone = getPhone(subId); |
| 2202 | if (phone != null) { |
| 2203 | return phone.getCdmaEriText(); |
| 2204 | } else { |
| 2205 | return null; |
| 2206 | } |
| 2207 | } finally { |
| 2208 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2209 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2210 | } |
| 2211 | |
| 2212 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2213 | * Returns the CDMA MDN. |
| 2214 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2215 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2216 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2217 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2218 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2219 | |
| 2220 | final long identity = Binder.clearCallingIdentity(); |
| 2221 | try { |
| 2222 | final Phone phone = getPhone(subId); |
| 2223 | if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) { |
| 2224 | return phone.getLine1Number(); |
| 2225 | } else { |
| 2226 | return null; |
| 2227 | } |
| 2228 | } finally { |
| 2229 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2230 | } |
| 2231 | } |
| 2232 | |
| 2233 | /** |
| 2234 | * Returns the CDMA MIN. |
| 2235 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2236 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2237 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2238 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2239 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2240 | |
| 2241 | final long identity = Binder.clearCallingIdentity(); |
| 2242 | try { |
| 2243 | final Phone phone = getPhone(subId); |
| 2244 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2245 | return phone.getCdmaMin(); |
| 2246 | } else { |
| 2247 | return null; |
| 2248 | } |
| 2249 | } finally { |
| 2250 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2251 | } |
| 2252 | } |
| 2253 | |
| 2254 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2255 | * Returns true if CDMA provisioning needs to run. |
| 2256 | */ |
| 2257 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2258 | final long identity = Binder.clearCallingIdentity(); |
| 2259 | try { |
| 2260 | return mPhone.needsOtaServiceProvisioning(); |
| 2261 | } finally { |
| 2262 | Binder.restoreCallingIdentity(identity); |
| 2263 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2264 | } |
| 2265 | |
| 2266 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2267 | * Sets the voice mail number of a given subId. |
| 2268 | */ |
| 2269 | @Override |
| 2270 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2271 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2272 | |
| 2273 | final long identity = Binder.clearCallingIdentity(); |
| 2274 | try { |
| 2275 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2276 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2277 | return success; |
| 2278 | } finally { |
| 2279 | Binder.restoreCallingIdentity(identity); |
| 2280 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2281 | } |
| 2282 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2283 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2284 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2285 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2286 | String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage(); |
| 2287 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2288 | throw new SecurityException("caller must be system dialer"); |
| 2289 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2290 | |
| 2291 | final long identity = Binder.clearCallingIdentity(); |
| 2292 | try { |
| 2293 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2294 | if (phoneAccountHandle == null) { |
| 2295 | return null; |
| 2296 | } |
| 2297 | return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle); |
| 2298 | } finally { |
| 2299 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2300 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2304 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2305 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2306 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2307 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2308 | return null; |
| 2309 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2310 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2311 | final long identity = Binder.clearCallingIdentity(); |
| 2312 | try { |
| 2313 | return RemoteVvmTaskManager |
| 2314 | .getRemotePackage(mPhone.getContext(), subId).getPackageName(); |
| 2315 | } finally { |
| 2316 | Binder.restoreCallingIdentity(identity); |
| 2317 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2318 | } |
| 2319 | |
| 2320 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2321 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2322 | VisualVoicemailSmsFilterSettings settings) { |
| 2323 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2324 | |
| 2325 | final long identity = Binder.clearCallingIdentity(); |
| 2326 | try { |
| 2327 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
| 2328 | mPhone.getContext(), callingPackage, subId, settings); |
| 2329 | } finally { |
| 2330 | Binder.restoreCallingIdentity(identity); |
| 2331 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2332 | } |
| 2333 | |
| 2334 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2335 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2336 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2337 | |
| 2338 | final long identity = Binder.clearCallingIdentity(); |
| 2339 | try { |
| 2340 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
| 2341 | mPhone.getContext(), callingPackage, subId); |
| 2342 | } finally { |
| 2343 | Binder.restoreCallingIdentity(identity); |
| 2344 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2348 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2349 | String callingPackage, int subId) { |
| 2350 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2351 | |
| 2352 | final long identity = Binder.clearCallingIdentity(); |
| 2353 | try { |
| 2354 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
| 2355 | mPhone.getContext(), callingPackage, subId); |
| 2356 | } finally { |
| 2357 | Binder.restoreCallingIdentity(identity); |
| 2358 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2362 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2363 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2364 | |
| 2365 | final long identity = Binder.clearCallingIdentity(); |
| 2366 | try { |
| 2367 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
| 2368 | mPhone.getContext(), subId); |
| 2369 | } finally { |
| 2370 | Binder.restoreCallingIdentity(identity); |
| 2371 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2372 | } |
| 2373 | |
| 2374 | @Override |
| 2375 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2376 | String number, int port, String text, PendingIntent sentIntent) { |
| 2377 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2378 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2379 | enforceSendSmsPermission(); |
| 2380 | // Make the calls as the phone process. |
| 2381 | final long identity = Binder.clearCallingIdentity(); |
| 2382 | try { |
| 2383 | SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); |
| 2384 | if (port == 0) { |
| 2385 | smsManager.sendTextMessageWithSelfPermissions(number, null, text, |
| 2386 | sentIntent, null, false); |
| 2387 | } else { |
| 2388 | byte[] data = text.getBytes(StandardCharsets.UTF_8); |
| 2389 | smsManager.sendDataMessageWithSelfPermissions(number, null, |
| 2390 | (short) port, data, sentIntent, null); |
| 2391 | } |
| 2392 | } finally { |
| 2393 | Binder.restoreCallingIdentity(identity); |
| 2394 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2395 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2396 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2397 | * Sets the voice activation state of a given subId. |
| 2398 | */ |
| 2399 | @Override |
| 2400 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2401 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2402 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2403 | |
| 2404 | final long identity = Binder.clearCallingIdentity(); |
| 2405 | try { |
| 2406 | final Phone phone = getPhone(subId); |
| 2407 | if (phone != null) { |
| 2408 | phone.setVoiceActivationState(activationState); |
| 2409 | } else { |
| 2410 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2411 | } |
| 2412 | } finally { |
| 2413 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2414 | } |
| 2415 | } |
| 2416 | |
| 2417 | /** |
| 2418 | * Sets the data activation state of a given subId. |
| 2419 | */ |
| 2420 | @Override |
| 2421 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2422 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2423 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2424 | |
| 2425 | final long identity = Binder.clearCallingIdentity(); |
| 2426 | try { |
| 2427 | final Phone phone = getPhone(subId); |
| 2428 | if (phone != null) { |
| 2429 | phone.setDataActivationState(activationState); |
| 2430 | } else { |
| 2431 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2432 | } |
| 2433 | } finally { |
| 2434 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2435 | } |
| 2436 | } |
| 2437 | |
| 2438 | /** |
| 2439 | * Returns the voice activation state of a given subId. |
| 2440 | */ |
| 2441 | @Override |
| 2442 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2443 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2444 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2445 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2446 | final long identity = Binder.clearCallingIdentity(); |
| 2447 | try { |
| 2448 | if (phone != null) { |
| 2449 | return phone.getVoiceActivationState(); |
| 2450 | } else { |
| 2451 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2452 | } |
| 2453 | } finally { |
| 2454 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2455 | } |
| 2456 | } |
| 2457 | |
| 2458 | /** |
| 2459 | * Returns the data activation state of a given subId. |
| 2460 | */ |
| 2461 | @Override |
| 2462 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2463 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2464 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2465 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2466 | final long identity = Binder.clearCallingIdentity(); |
| 2467 | try { |
| 2468 | if (phone != null) { |
| 2469 | return phone.getDataActivationState(); |
| 2470 | } else { |
| 2471 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2472 | } |
| 2473 | } finally { |
| 2474 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2475 | } |
| 2476 | } |
| 2477 | |
| 2478 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2479 | * Returns the unread count of voicemails |
| 2480 | */ |
| 2481 | public int getVoiceMessageCount() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2482 | return getVoiceMessageCountForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2483 | } |
| 2484 | |
| 2485 | /** |
| 2486 | * Returns the unread count of voicemails for a subId |
| 2487 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2488 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2489 | public int getVoiceMessageCountForSubscriber( int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2490 | final long identity = Binder.clearCallingIdentity(); |
| 2491 | try { |
| 2492 | final Phone phone = getPhone(subId); |
| 2493 | if (phone != null) { |
| 2494 | return phone.getVoiceMessageCount(); |
| 2495 | } else { |
| 2496 | return 0; |
| 2497 | } |
| 2498 | } finally { |
| 2499 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2500 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2501 | } |
| 2502 | |
| 2503 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2504 | * returns true, if the device is in a state where both voice and data |
| 2505 | * are supported simultaneously. This can change based on location or network condition. |
| 2506 | */ |
| 2507 | @Override |
| 2508 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2509 | final long identity = Binder.clearCallingIdentity(); |
| 2510 | try { |
| 2511 | final Phone phone = getPhone(subId); |
| 2512 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2513 | } finally { |
| 2514 | Binder.restoreCallingIdentity(identity); |
| 2515 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2519 | * Send the dialer code if called from the current default dialer or the caller has |
| 2520 | * carrier privilege. |
| 2521 | * @param inputCode The dialer code to send |
| 2522 | */ |
| 2523 | @Override |
| 2524 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
| 2525 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2526 | String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage(); |
| 2527 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2528 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2529 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2530 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2531 | |
| 2532 | final long identity = Binder.clearCallingIdentity(); |
| 2533 | try { |
| 2534 | mPhone.sendDialerSpecialCode(inputCode); |
| 2535 | } finally { |
| 2536 | Binder.restoreCallingIdentity(identity); |
| 2537 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | /** |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2541 | * Returns the data network type. |
| 2542 | * Legacy call, permission-free. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2543 | * |
| 2544 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 2545 | */ |
| 2546 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2547 | public int getNetworkType() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2548 | final long identity = Binder.clearCallingIdentity(); |
| 2549 | try { |
| 2550 | final Phone phone = getPhone(getDefaultSubscription()); |
| 2551 | if (phone != null) { |
| 2552 | return phone.getServiceState().getDataNetworkType(); |
| 2553 | } else { |
| 2554 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2555 | } |
| 2556 | } finally { |
| 2557 | Binder.restoreCallingIdentity(identity); |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2558 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2559 | } |
| 2560 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2561 | @Override |
| 2562 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2563 | if (!isActiveSubscription(subId)) { |
| 2564 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2565 | } |
| 2566 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2567 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2568 | } |
| 2569 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2570 | @Override |
| 2571 | public void addImsRegistrationCallback(int subId, IImsRegistrationCallback c, |
| 2572 | String callingPackage) throws RemoteException { |
| 2573 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2574 | "addImsRegistrationCallback")) { |
| 2575 | return; |
| 2576 | } |
| 2577 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2578 | final long token = Binder.clearCallingIdentity(); |
| 2579 | try { |
| 2580 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 2581 | .addRegistrationCallbackForSubscription(c, subId); |
| 2582 | } finally { |
| 2583 | Binder.restoreCallingIdentity(token); |
| 2584 | } |
| 2585 | } |
| 2586 | |
| 2587 | @Override |
| 2588 | public void removeImsRegistrationCallback(int subId, IImsRegistrationCallback c, |
| 2589 | String callingPackage) { |
| 2590 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2591 | "removeImsRegistrationCallback")) { |
| 2592 | return; |
| 2593 | } |
| 2594 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2595 | Binder.withCleanCallingIdentity(() -> |
| 2596 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 2597 | .removeRegistrationCallbackForSubscription(c, subId)); |
| 2598 | } |
| 2599 | |
| 2600 | @Override |
| 2601 | public void addMmTelCapabilityCallback(int subId, IImsCapabilityCallback c, |
| 2602 | String callingPackage) throws RemoteException { |
| 2603 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2604 | "addMmTelCapabilityCallback")) { |
| 2605 | return; |
| 2606 | } |
| 2607 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2608 | final long token = Binder.clearCallingIdentity(); |
| 2609 | try { |
| 2610 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 2611 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2612 | } finally { |
| 2613 | Binder.restoreCallingIdentity(token); |
| 2614 | } |
| 2615 | } |
| 2616 | |
| 2617 | @Override |
| 2618 | public void removeMmTelCapabilityCallback(int subId, IImsCapabilityCallback c, |
| 2619 | String callingPackage) { |
| 2620 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2621 | "removeMmTelCapabilityCallback")) { |
| 2622 | return; |
| 2623 | } |
| 2624 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2625 | Binder.withCleanCallingIdentity(() -> |
| 2626 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 2627 | .removeCapabilitiesCallbackForSubscription(c, subId)); |
| 2628 | } |
| 2629 | |
| 2630 | @Override |
| 2631 | public boolean isCapable(int subId, int capability, int regTech, String callingPackage) { |
| 2632 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2633 | "isCapable")) { |
| 2634 | return false; |
| 2635 | } |
| 2636 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2637 | final long token = Binder.clearCallingIdentity(); |
| 2638 | try { |
| 2639 | return ImsManager.getInstance(mPhone.getContext(), |
| 2640 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2641 | } catch (ImsException e) { |
| 2642 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2643 | return false; |
| 2644 | } finally { |
| 2645 | Binder.restoreCallingIdentity(token); |
| 2646 | } |
| 2647 | } |
| 2648 | |
| 2649 | @Override |
| 2650 | public boolean isAvailable(int subId, int capability, int regTech, String callingPackage) { |
| 2651 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2652 | "isAvailable")) { |
| 2653 | return false; |
| 2654 | } |
| 2655 | final long token = Binder.clearCallingIdentity(); |
| 2656 | try { |
| 2657 | Phone phone = getPhone(subId); |
| 2658 | if (phone == null) return false; |
| 2659 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2660 | } finally { |
| 2661 | Binder.restoreCallingIdentity(token); |
| 2662 | } |
| 2663 | } |
| 2664 | |
| 2665 | @Override |
| 2666 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2667 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2668 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2669 | final long token = Binder.clearCallingIdentity(); |
| 2670 | try { |
| 2671 | return ImsManager.getInstance(mPhone.getContext(), |
| 2672 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2673 | } finally { |
| 2674 | Binder.restoreCallingIdentity(token); |
| 2675 | } |
| 2676 | } |
| 2677 | |
| 2678 | @Override |
| 2679 | public void setAdvancedCallingSetting(int subId, boolean isEnabled) { |
| 2680 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2681 | "setAdvancedCallingSetting"); |
| 2682 | final long identity = Binder.clearCallingIdentity(); |
| 2683 | try { |
| 2684 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2685 | ImsManager.getInstance(mPhone.getContext(), |
| 2686 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 2687 | } finally { |
| 2688 | Binder.restoreCallingIdentity(identity); |
| 2689 | } |
| 2690 | } |
| 2691 | |
| 2692 | @Override |
| 2693 | public boolean isVtSettingEnabled(int subId, String callingPackage) { |
| 2694 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2695 | "isVtSettingEnabled")) { |
| 2696 | return false; |
| 2697 | } |
| 2698 | final long identity = Binder.clearCallingIdentity(); |
| 2699 | try { |
| 2700 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2701 | return ImsManager.getInstance(mPhone.getContext(), |
| 2702 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2703 | } finally { |
| 2704 | Binder.restoreCallingIdentity(identity); |
| 2705 | } |
| 2706 | } |
| 2707 | |
| 2708 | @Override |
| 2709 | public void setVtSetting(int subId, boolean isEnabled) { |
| 2710 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2711 | "setVtSetting"); |
| 2712 | final long identity = Binder.clearCallingIdentity(); |
| 2713 | try { |
| 2714 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2715 | ImsManager.getInstance(mPhone.getContext(), |
| 2716 | getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
| 2717 | } finally { |
| 2718 | Binder.restoreCallingIdentity(identity); |
| 2719 | } |
| 2720 | } |
| 2721 | |
| 2722 | @Override |
| 2723 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 2724 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 2725 | final long identity = Binder.clearCallingIdentity(); |
| 2726 | try { |
| 2727 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2728 | return ImsManager.getInstance(mPhone.getContext(), |
| 2729 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 2730 | } finally { |
| 2731 | Binder.restoreCallingIdentity(identity); |
| 2732 | } |
| 2733 | } |
| 2734 | |
| 2735 | @Override |
| 2736 | public void setVoWiFiSetting(int subId, boolean isEnabled) { |
| 2737 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2738 | "setVoWiFiSetting"); |
| 2739 | final long identity = Binder.clearCallingIdentity(); |
| 2740 | try { |
| 2741 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2742 | ImsManager.getInstance(mPhone.getContext(), |
| 2743 | getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
| 2744 | } finally { |
| 2745 | Binder.restoreCallingIdentity(identity); |
| 2746 | } |
| 2747 | } |
| 2748 | |
| 2749 | @Override |
| 2750 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 2751 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 2752 | final long identity = Binder.clearCallingIdentity(); |
| 2753 | try { |
| 2754 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2755 | return ImsManager.getInstance(mPhone.getContext(), |
| 2756 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 2757 | } finally { |
| 2758 | Binder.restoreCallingIdentity(identity); |
| 2759 | } |
| 2760 | } |
| 2761 | |
| 2762 | @Override |
| 2763 | public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) { |
| 2764 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2765 | "setVoWiFiRoamingSetting"); |
| 2766 | final long identity = Binder.clearCallingIdentity(); |
| 2767 | try { |
| 2768 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2769 | ImsManager.getInstance(mPhone.getContext(), |
| 2770 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 2771 | } finally { |
| 2772 | Binder.restoreCallingIdentity(identity); |
| 2773 | } |
| 2774 | } |
| 2775 | |
| 2776 | @Override |
| 2777 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 2778 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2779 | "setVoWiFiNonPersistent"); |
| 2780 | final long identity = Binder.clearCallingIdentity(); |
| 2781 | try { |
| 2782 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2783 | ImsManager.getInstance(mPhone.getContext(), |
| 2784 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
| 2785 | } finally { |
| 2786 | Binder.restoreCallingIdentity(identity); |
| 2787 | } |
| 2788 | } |
| 2789 | |
| 2790 | @Override |
| 2791 | public int getVoWiFiModeSetting(int subId) { |
| 2792 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 2793 | final long identity = Binder.clearCallingIdentity(); |
| 2794 | try { |
| 2795 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2796 | return ImsManager.getInstance(mPhone.getContext(), |
| 2797 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 2798 | } finally { |
| 2799 | Binder.restoreCallingIdentity(identity); |
| 2800 | } |
| 2801 | } |
| 2802 | |
| 2803 | @Override |
| 2804 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 2805 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2806 | "setVoWiFiModeSetting"); |
| 2807 | final long identity = Binder.clearCallingIdentity(); |
| 2808 | try { |
| 2809 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2810 | ImsManager.getInstance(mPhone.getContext(), |
| 2811 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 2812 | } finally { |
| 2813 | Binder.restoreCallingIdentity(identity); |
| 2814 | } |
| 2815 | } |
| 2816 | |
| 2817 | @Override |
| 2818 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 2819 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 2820 | final long identity = Binder.clearCallingIdentity(); |
| 2821 | try { |
| 2822 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2823 | return ImsManager.getInstance(mPhone.getContext(), |
| 2824 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 2825 | } finally { |
| 2826 | Binder.restoreCallingIdentity(identity); |
| 2827 | } |
| 2828 | } |
| 2829 | |
| 2830 | @Override |
| 2831 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 2832 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2833 | "setVoWiFiRoamingModeSetting"); |
| 2834 | final long identity = Binder.clearCallingIdentity(); |
| 2835 | try { |
| 2836 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2837 | ImsManager.getInstance(mPhone.getContext(), |
| 2838 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 2839 | } finally { |
| 2840 | Binder.restoreCallingIdentity(identity); |
| 2841 | } |
| 2842 | } |
| 2843 | |
| 2844 | @Override |
| 2845 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 2846 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2847 | "setRttCapabilityEnabled"); |
| 2848 | final long identity = Binder.clearCallingIdentity(); |
| 2849 | try { |
| 2850 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2851 | ImsManager.getInstance(mPhone.getContext(), |
| 2852 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 2853 | } finally { |
| 2854 | Binder.restoreCallingIdentity(identity); |
| 2855 | } |
| 2856 | } |
| 2857 | |
| 2858 | @Override |
| 2859 | public boolean isTtyOverVolteEnabled(int subId) { |
| 2860 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 2861 | final long identity = Binder.clearCallingIdentity(); |
| 2862 | try { |
| 2863 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2864 | return ImsManager.getInstance(mPhone.getContext(), |
| 2865 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 2866 | } finally { |
| 2867 | Binder.restoreCallingIdentity(identity); |
| 2868 | } |
| 2869 | } |
| 2870 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame^] | 2871 | @Override |
| 2872 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 2873 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 2874 | final long identity = Binder.clearCallingIdentity(); |
| 2875 | try { |
| 2876 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2877 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 2878 | .getConfigInterface().addConfigCallback(callback); |
| 2879 | } catch (ImsException e) { |
| 2880 | throw new IllegalArgumentException(e.getMessage()); |
| 2881 | } finally { |
| 2882 | Binder.restoreCallingIdentity(identity); |
| 2883 | } |
| 2884 | } |
| 2885 | |
| 2886 | @Override |
| 2887 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 2888 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 2889 | final long identity = Binder.clearCallingIdentity(); |
| 2890 | try { |
| 2891 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2892 | ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 2893 | .getConfigInterface().removeConfigCallback(callback); |
| 2894 | } catch (ImsException e) { |
| 2895 | throw new IllegalArgumentException(e.getMessage()); |
| 2896 | } finally { |
| 2897 | Binder.restoreCallingIdentity(identity); |
| 2898 | } |
| 2899 | } |
| 2900 | |
| 2901 | @Override |
| 2902 | public int getImsProvisioningInt(int subId, int key) { |
| 2903 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 2904 | final long identity = Binder.clearCallingIdentity(); |
| 2905 | try { |
| 2906 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2907 | return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 2908 | .getConfigInterface().getConfigInt(key); |
| 2909 | } catch (ImsException e) { |
| 2910 | throw new IllegalArgumentException(e.getMessage()); |
| 2911 | } finally { |
| 2912 | Binder.restoreCallingIdentity(identity); |
| 2913 | } |
| 2914 | } |
| 2915 | |
| 2916 | @Override |
| 2917 | public String getImsProvisioningString(int subId, int key) { |
| 2918 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 2919 | final long identity = Binder.clearCallingIdentity(); |
| 2920 | try { |
| 2921 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2922 | return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 2923 | .getConfigInterface().getConfigString(key); |
| 2924 | } catch (ImsException e) { |
| 2925 | throw new IllegalArgumentException(e.getMessage()); |
| 2926 | } finally { |
| 2927 | Binder.restoreCallingIdentity(identity); |
| 2928 | } |
| 2929 | } |
| 2930 | |
| 2931 | @Override |
| 2932 | public int setImsProvisioningInt(int subId, int key, int value) { |
| 2933 | enforceReadPrivilegedPermission("setImsProvisioningInt"); |
| 2934 | final long identity = Binder.clearCallingIdentity(); |
| 2935 | try { |
| 2936 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2937 | return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 2938 | .getConfigInterface().setConfig(key, value); |
| 2939 | } catch (ImsException e) { |
| 2940 | throw new IllegalArgumentException(e.getMessage()); |
| 2941 | } finally { |
| 2942 | Binder.restoreCallingIdentity(identity); |
| 2943 | } |
| 2944 | } |
| 2945 | |
| 2946 | @Override |
| 2947 | public int setImsProvisioningString(int subId, int key, String value) { |
| 2948 | enforceReadPrivilegedPermission("setImsProvisioningString"); |
| 2949 | final long identity = Binder.clearCallingIdentity(); |
| 2950 | try { |
| 2951 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2952 | return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId)) |
| 2953 | .getConfigInterface().setConfig(key, value); |
| 2954 | } catch (ImsException e) { |
| 2955 | throw new IllegalArgumentException(e.getMessage()); |
| 2956 | } finally { |
| 2957 | Binder.restoreCallingIdentity(identity); |
| 2958 | } |
| 2959 | } |
| 2960 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2961 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 2962 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 2963 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 2964 | throw new IllegalArgumentException("Invalid Subscription Id."); |
| 2965 | } |
| 2966 | return slotId; |
| 2967 | } |
| 2968 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2969 | /** |
| 2970 | * Returns the network type for a subId |
| 2971 | */ |
| 2972 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2973 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2974 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2975 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2976 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2977 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2978 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2979 | final long identity = Binder.clearCallingIdentity(); |
| 2980 | try { |
| 2981 | final Phone phone = getPhone(subId); |
| 2982 | if (phone != null) { |
| 2983 | return phone.getServiceState().getDataNetworkType(); |
| 2984 | } else { |
| 2985 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2986 | } |
| 2987 | } finally { |
| 2988 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2989 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2990 | } |
| 2991 | |
| 2992 | /** |
| 2993 | * Returns the data network type |
| 2994 | */ |
| 2995 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2996 | public int getDataNetworkType(String callingPackage) { |
| 2997 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2998 | } |
| 2999 | |
| 3000 | /** |
| 3001 | * Returns the data network type for a subId |
| 3002 | */ |
| 3003 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3004 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3005 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3006 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3007 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3008 | } |
| 3009 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3010 | final long identity = Binder.clearCallingIdentity(); |
| 3011 | try { |
| 3012 | final Phone phone = getPhone(subId); |
| 3013 | if (phone != null) { |
| 3014 | return phone.getServiceState().getDataNetworkType(); |
| 3015 | } else { |
| 3016 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3017 | } |
| 3018 | } finally { |
| 3019 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3020 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3021 | } |
| 3022 | |
| 3023 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3024 | * Returns the Voice network type for a subId |
| 3025 | */ |
| 3026 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3027 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3028 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3029 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3030 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3031 | } |
| 3032 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3033 | final long identity = Binder.clearCallingIdentity(); |
| 3034 | try { |
| 3035 | final Phone phone = getPhone(subId); |
| 3036 | if (phone != null) { |
| 3037 | return phone.getServiceState().getVoiceNetworkType(); |
| 3038 | } else { |
| 3039 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3040 | } |
| 3041 | } finally { |
| 3042 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3043 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3044 | } |
| 3045 | |
| 3046 | /** |
| 3047 | * @return true if a ICC card is present |
| 3048 | */ |
| 3049 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3050 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3051 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3052 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3053 | } |
| 3054 | |
| 3055 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3056 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3057 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3058 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3059 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3060 | final long identity = Binder.clearCallingIdentity(); |
| 3061 | try { |
| 3062 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3063 | if (phone != null) { |
| 3064 | return phone.getIccCard().hasIccCard(); |
| 3065 | } else { |
| 3066 | return false; |
| 3067 | } |
| 3068 | } finally { |
| 3069 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3070 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3071 | } |
| 3072 | |
| 3073 | /** |
| 3074 | * Return if the current radio is LTE on CDMA. This |
| 3075 | * is a tri-state return value as for a period of time |
| 3076 | * the mode may be unknown. |
| 3077 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3078 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3079 | * @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] | 3080 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3081 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3082 | @Override |
| 3083 | public int getLteOnCdmaMode(String callingPackage) { |
| 3084 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3085 | } |
| 3086 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3087 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3088 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3089 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3090 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3091 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3092 | } |
| 3093 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3094 | final long identity = Binder.clearCallingIdentity(); |
| 3095 | try { |
| 3096 | final Phone phone = getPhone(subId); |
| 3097 | if (phone == null) { |
| 3098 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3099 | } else { |
| 3100 | return phone.getLteOnCdmaMode(); |
| 3101 | } |
| 3102 | } finally { |
| 3103 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3104 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3105 | } |
| 3106 | |
| 3107 | public void setPhone(Phone phone) { |
| 3108 | mPhone = phone; |
| 3109 | } |
| 3110 | |
| 3111 | /** |
| 3112 | * {@hide} |
| 3113 | * Returns Default subId, 0 in the case of single standby. |
| 3114 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3115 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3116 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3117 | } |
| 3118 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3119 | private int getSlotForDefaultSubscription() { |
| 3120 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3121 | } |
| 3122 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3123 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3124 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3125 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3126 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3127 | private boolean isActiveSubscription(int subId) { |
| 3128 | return mSubscriptionController.isActiveSubId(subId); |
| 3129 | } |
| 3130 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3131 | /** |
| 3132 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3133 | */ |
| 3134 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3135 | final long identity = Binder.clearCallingIdentity(); |
| 3136 | try { |
| 3137 | return Settings.System.getInt(mPhone.getContext().getContentResolver(), |
| 3138 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3139 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3140 | } finally { |
| 3141 | Binder.restoreCallingIdentity(identity); |
| 3142 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3143 | } |
| 3144 | |
| 3145 | /** |
| 3146 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3147 | */ |
| 3148 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3149 | final long identity = Binder.clearCallingIdentity(); |
| 3150 | try { |
| 3151 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
| 3152 | Settings.System.putInt(mPhone.getContext().getContentResolver(), |
| 3153 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3154 | } finally { |
| 3155 | Binder.restoreCallingIdentity(identity); |
| 3156 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3157 | } |
| 3158 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3159 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3160 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3161 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3162 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3163 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3164 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3165 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3166 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3167 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3168 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3169 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3170 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3171 | final long identity = Binder.clearCallingIdentity(); |
| 3172 | try { |
| 3173 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3174 | // Only allows LPA to open logical channel to ISD-R. |
| 3175 | ComponentInfo bestComponent = |
| 3176 | EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager()); |
| 3177 | if (bestComponent == null |
| 3178 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3179 | loge("The calling package is not allowed to access ISD-R."); |
| 3180 | throw new SecurityException( |
| 3181 | "The calling package is not allowed to access ISD-R."); |
| 3182 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3183 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3184 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3185 | if (DBG) { |
| 3186 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3187 | } |
| 3188 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
| 3189 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId); |
| 3190 | if (DBG) log("iccOpenLogicalChannel: " + response); |
| 3191 | return response; |
| 3192 | } finally { |
| 3193 | Binder.restoreCallingIdentity(identity); |
| 3194 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3195 | } |
| 3196 | |
| 3197 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3198 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3199 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3200 | mApp, subId, "iccCloseLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3201 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3202 | final long identity = Binder.clearCallingIdentity(); |
| 3203 | try { |
| 3204 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3205 | if (channel < 0) { |
| 3206 | return false; |
| 3207 | } |
| 3208 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId); |
| 3209 | if (DBG) log("iccCloseLogicalChannel: " + success); |
| 3210 | return success; |
| 3211 | } finally { |
| 3212 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3213 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3214 | } |
| 3215 | |
| 3216 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3217 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3218 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3219 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3220 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3221 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3222 | final long identity = Binder.clearCallingIdentity(); |
| 3223 | try { |
| 3224 | if (DBG) { |
| 3225 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3226 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3227 | + p3 + " data=" + data); |
| 3228 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3229 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3230 | if (channel < 0) { |
| 3231 | return ""; |
| 3232 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3233 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3234 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
| 3235 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId); |
| 3236 | if (DBG) log("iccTransmitApduLogicalChannel: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3237 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3238 | // Append the returned status code to the end of the response payload. |
| 3239 | String s = Integer.toHexString( |
| 3240 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3241 | if (response.payload != null) { |
| 3242 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3243 | } |
| 3244 | return s; |
| 3245 | } finally { |
| 3246 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3247 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3248 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3249 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3250 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3251 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3252 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3253 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3254 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3255 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3256 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3257 | final long identity = Binder.clearCallingIdentity(); |
| 3258 | try { |
| 3259 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3260 | && TextUtils.equals(ISDR_AID, data)) { |
| 3261 | // Only allows LPA to select ISD-R. |
| 3262 | ComponentInfo bestComponent = |
| 3263 | EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager()); |
| 3264 | if (bestComponent == null |
| 3265 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3266 | loge("The calling package is not allowed to select ISD-R."); |
| 3267 | throw new SecurityException( |
| 3268 | "The calling package is not allowed to select ISD-R."); |
| 3269 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3270 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3271 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3272 | if (DBG) { |
| 3273 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3274 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3275 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3276 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3277 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
| 3278 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId); |
| 3279 | if (DBG) log("iccTransmitApduBasicChannel: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3280 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3281 | // Append the returned status code to the end of the response payload. |
| 3282 | String s = Integer.toHexString( |
| 3283 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3284 | if (response.payload != null) { |
| 3285 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3286 | } |
| 3287 | return s; |
| 3288 | } finally { |
| 3289 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3290 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3291 | } |
| 3292 | |
| 3293 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3294 | 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] | 3295 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3296 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3297 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3298 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3299 | final long identity = Binder.clearCallingIdentity(); |
| 3300 | try { |
| 3301 | if (DBG) { |
| 3302 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3303 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3304 | } |
| 3305 | |
| 3306 | IccIoResult response = |
| 3307 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3308 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3309 | subId); |
| 3310 | |
| 3311 | if (DBG) { |
| 3312 | log("Exchange SIM_IO [R]" + response); |
| 3313 | } |
| 3314 | |
| 3315 | byte[] result = null; |
| 3316 | int length = 2; |
| 3317 | if (response.payload != null) { |
| 3318 | length = 2 + response.payload.length; |
| 3319 | result = new byte[length]; |
| 3320 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3321 | } else { |
| 3322 | result = new byte[length]; |
| 3323 | } |
| 3324 | |
| 3325 | result[length - 1] = (byte) response.sw2; |
| 3326 | result[length - 2] = (byte) response.sw1; |
| 3327 | return result; |
| 3328 | } finally { |
| 3329 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3330 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3331 | } |
| 3332 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3333 | /** |
| 3334 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 3335 | * on a particular subscription |
| 3336 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3337 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 3338 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3339 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 3340 | return null; |
| 3341 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3342 | |
| 3343 | final long identity = Binder.clearCallingIdentity(); |
| 3344 | try { |
| 3345 | if (appType != TelephonyManager.APPTYPE_USIM |
| 3346 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 3347 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 3348 | return null; |
| 3349 | } |
| 3350 | Object response = sendRequest( |
| 3351 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 3352 | if (response instanceof String[]) { |
| 3353 | return (String[]) response; |
| 3354 | } |
| 3355 | // Response is an Exception of some kind, |
| 3356 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3357 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3358 | } finally { |
| 3359 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3360 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3361 | } |
| 3362 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3363 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3364 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3365 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3366 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3367 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3368 | final long identity = Binder.clearCallingIdentity(); |
| 3369 | try { |
| 3370 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 3371 | if (response.payload == null) { |
| 3372 | return ""; |
| 3373 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3374 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3375 | // Append the returned status code to the end of the response payload. |
| 3376 | String s = Integer.toHexString( |
| 3377 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3378 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3379 | return s; |
| 3380 | } finally { |
| 3381 | Binder.restoreCallingIdentity(identity); |
| 3382 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3383 | } |
| 3384 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3385 | /** |
| 3386 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3387 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3388 | * |
| 3389 | * @param itemID the ID of the item to read |
| 3390 | * @return the NV item as a String, or null on error. |
| 3391 | */ |
| 3392 | @Override |
| 3393 | public String nvReadItem(int itemID) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3394 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3395 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3396 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3397 | |
| 3398 | final long identity = Binder.clearCallingIdentity(); |
| 3399 | try { |
| 3400 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3401 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3402 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 3403 | return value; |
| 3404 | } finally { |
| 3405 | Binder.restoreCallingIdentity(identity); |
| 3406 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | /** |
| 3410 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3411 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3412 | * |
| 3413 | * @param itemID the ID of the item to read |
| 3414 | * @param itemValue the value to write, as a String |
| 3415 | * @return true on success; false on any failure |
| 3416 | */ |
| 3417 | @Override |
| 3418 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3419 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3420 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3421 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3422 | |
| 3423 | final long identity = Binder.clearCallingIdentity(); |
| 3424 | try { |
| 3425 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 3426 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3427 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3428 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 3429 | return success; |
| 3430 | } finally { |
| 3431 | Binder.restoreCallingIdentity(identity); |
| 3432 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3433 | } |
| 3434 | |
| 3435 | /** |
| 3436 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 3437 | * Used for device configuration by some CDMA operators. |
| 3438 | * |
| 3439 | * @param preferredRoamingList byte array containing the new PRL |
| 3440 | * @return true on success; false on any failure |
| 3441 | */ |
| 3442 | @Override |
| 3443 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3444 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3445 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3446 | |
| 3447 | final long identity = Binder.clearCallingIdentity(); |
| 3448 | try { |
| 3449 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 3450 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 3451 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 3452 | return success; |
| 3453 | } finally { |
| 3454 | Binder.restoreCallingIdentity(identity); |
| 3455 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3456 | } |
| 3457 | |
| 3458 | /** |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3459 | * 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] | 3460 | * Used for device configuration by some CDMA operators. |
| 3461 | * |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3462 | * @param slotIndex - device slot. |
| 3463 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3464 | * @return true on success; false on any failure |
| 3465 | */ |
| 3466 | @Override |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3467 | public boolean resetModemConfig(int slotIndex) { |
| 3468 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3469 | if (phone != null) { |
| 3470 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3471 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3472 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3473 | final long identity = Binder.clearCallingIdentity(); |
| 3474 | try { |
| 3475 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 3476 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 3477 | return success; |
| 3478 | } finally { |
| 3479 | Binder.restoreCallingIdentity(identity); |
| 3480 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3481 | } |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3482 | return false; |
| 3483 | } |
| 3484 | |
| 3485 | /** |
| 3486 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 3487 | * |
| 3488 | * @param slotIndex - device slot. |
| 3489 | * |
| 3490 | * @return true on success; false on any failure |
| 3491 | */ |
| 3492 | @Override |
| 3493 | public boolean rebootModem(int slotIndex) { |
| 3494 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3495 | if (phone != null) { |
| 3496 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3497 | mApp, phone.getSubId(), "rebootModem"); |
| 3498 | |
| 3499 | final long identity = Binder.clearCallingIdentity(); |
| 3500 | try { |
| 3501 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 3502 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 3503 | return success; |
| 3504 | } finally { |
| 3505 | Binder.restoreCallingIdentity(identity); |
| 3506 | } |
| 3507 | } |
| 3508 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3509 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3510 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3511 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3512 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3513 | mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3514 | return new String[0]; |
| 3515 | } |
| 3516 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3517 | final long identity = Binder.clearCallingIdentity(); |
| 3518 | try { |
| 3519 | return mPhone.getPcscfAddress(apnType); |
| 3520 | } finally { |
| 3521 | Binder.restoreCallingIdentity(identity); |
| 3522 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3523 | } |
| 3524 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3525 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3526 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 3527 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3528 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3529 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3530 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3531 | |
| 3532 | final long identity = Binder.clearCallingIdentity(); |
| 3533 | try { |
| 3534 | PhoneFactory.getImsResolver().enableIms(slotId); |
| 3535 | } finally { |
| 3536 | Binder.restoreCallingIdentity(identity); |
| 3537 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3538 | } |
| 3539 | |
| 3540 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3541 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 3542 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3543 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3544 | public void disableIms(int slotId) { |
| 3545 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3546 | |
| 3547 | final long identity = Binder.clearCallingIdentity(); |
| 3548 | try { |
| 3549 | PhoneFactory.getImsResolver().disableIms(slotId); |
| 3550 | } finally { |
| 3551 | Binder.restoreCallingIdentity(identity); |
| 3552 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3553 | } |
| 3554 | |
| 3555 | /** |
| 3556 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 3557 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 3558 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 3559 | */ |
| 3560 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3561 | IImsServiceFeatureCallback callback) { |
| 3562 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3563 | |
| 3564 | final long identity = Binder.clearCallingIdentity(); |
| 3565 | try { |
| 3566 | return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback); |
| 3567 | } finally { |
| 3568 | Binder.restoreCallingIdentity(identity); |
| 3569 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3570 | } |
| 3571 | |
| 3572 | /** |
| 3573 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 3574 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 3575 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 3576 | * listener for feature updates. |
| 3577 | */ |
| 3578 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 3579 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3580 | |
| 3581 | final long identity = Binder.clearCallingIdentity(); |
| 3582 | try { |
| 3583 | return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback); |
| 3584 | } finally { |
| 3585 | Binder.restoreCallingIdentity(identity); |
| 3586 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3587 | } |
| 3588 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 3589 | /** |
| 3590 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
| 3591 | * specified. |
| 3592 | */ |
| 3593 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 3594 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3595 | |
| 3596 | final long identity = Binder.clearCallingIdentity(); |
| 3597 | try { |
| 3598 | return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature); |
| 3599 | } finally { |
| 3600 | Binder.restoreCallingIdentity(identity); |
| 3601 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 3602 | } |
| 3603 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3604 | /** |
| 3605 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
| 3606 | * specified. |
| 3607 | */ |
| 3608 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 3609 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3610 | |
| 3611 | final long identity = Binder.clearCallingIdentity(); |
| 3612 | try { |
| 3613 | return PhoneFactory.getImsResolver().getImsConfig(slotId, feature); |
| 3614 | } finally { |
| 3615 | Binder.restoreCallingIdentity(identity); |
| 3616 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3617 | } |
| 3618 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 3619 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 3620 | * Sets the ImsService Package Name that Telephony will bind to. |
| 3621 | * |
| 3622 | * @param slotId the slot ID that the ImsService should bind for. |
| 3623 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 3624 | * ImsService is the device default ImsService. |
| 3625 | * @param packageName The package name of the application that contains the ImsService to bind |
| 3626 | * to. |
| 3627 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 3628 | * @hide |
| 3629 | */ |
| 3630 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 3631 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 3632 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 3633 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 3634 | "setImsService"); |
| 3635 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3636 | final long identity = Binder.clearCallingIdentity(); |
| 3637 | try { |
| 3638 | return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId, |
| 3639 | isCarrierImsService, packageName); |
| 3640 | } finally { |
| 3641 | Binder.restoreCallingIdentity(identity); |
| 3642 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 3643 | } |
| 3644 | |
| 3645 | /** |
| 3646 | * Return the ImsService configuration. |
| 3647 | * |
| 3648 | * @param slotId The slot that the ImsService is associated with. |
| 3649 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 3650 | * the device default. |
| 3651 | * @return the package name of the ImsService configuration. |
| 3652 | */ |
| 3653 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 3654 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 3655 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 3656 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 3657 | "getImsService"); |
| 3658 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3659 | final long identity = Binder.clearCallingIdentity(); |
| 3660 | try { |
| 3661 | return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId, |
| 3662 | isCarrierImsService); |
| 3663 | } finally { |
| 3664 | Binder.restoreCallingIdentity(identity); |
| 3665 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 3666 | } |
| 3667 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3668 | public void setImsRegistrationState(boolean registered) { |
| 3669 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3670 | |
| 3671 | final long identity = Binder.clearCallingIdentity(); |
| 3672 | try { |
| 3673 | mPhone.setImsRegistrationState(registered); |
| 3674 | } finally { |
| 3675 | Binder.restoreCallingIdentity(identity); |
| 3676 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3677 | } |
| 3678 | |
| 3679 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3680 | * Set the network selection mode to automatic. |
| 3681 | * |
| 3682 | */ |
| 3683 | @Override |
| 3684 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3685 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3686 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3687 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3688 | if (!isActiveSubscription(subId)) { |
| 3689 | return; |
| 3690 | } |
| 3691 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3692 | final long identity = Binder.clearCallingIdentity(); |
| 3693 | try { |
| 3694 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 3695 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 3696 | } finally { |
| 3697 | Binder.restoreCallingIdentity(identity); |
| 3698 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3699 | } |
| 3700 | |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3701 | /** |
| 3702 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 3703 | * |
| 3704 | * @param subId the id of the subscription. |
| 3705 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 3706 | * the operator to attach to. |
| 3707 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 3708 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 3709 | * normal network selection next time. |
| 3710 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 3711 | */ |
| 3712 | @Override |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3713 | public boolean setNetworkSelectionModeManual( |
| 3714 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3715 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3716 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3717 | |
| 3718 | if (!isActiveSubscription(subId)) { |
| 3719 | return false; |
| 3720 | } |
| 3721 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3722 | final long identity = Binder.clearCallingIdentity(); |
| 3723 | try { |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3724 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3725 | persistSelection); |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 3726 | if (DBG) { |
| 3727 | log("setNetworkSelectionModeManual: subId: " + subId |
| 3728 | + " operator: " + operatorInfo); |
| 3729 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3730 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 3731 | } finally { |
| 3732 | Binder.restoreCallingIdentity(identity); |
| 3733 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 3734 | } |
| 3735 | |
| 3736 | /** |
| 3737 | * Scans for available networks. |
| 3738 | */ |
| 3739 | @Override |
| 3740 | public CellNetworkScanResult getCellNetworkScanResults(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3741 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3742 | mApp, subId, "getCellNetworkScanResults"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3743 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3744 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3745 | try { |
| 3746 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3747 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3748 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3749 | } finally { |
| 3750 | Binder.restoreCallingIdentity(identity); |
| 3751 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 3752 | } |
| 3753 | |
| 3754 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3755 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3756 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3757 | * @param subId id of the subscription |
| 3758 | * @param request contains the radio access networks with bands/channels to scan |
| 3759 | * @param messenger callback messenger for scan results or errors |
| 3760 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3761 | * @return the id of the requested scan which can be used to stop the scan. |
| 3762 | */ |
| 3763 | @Override |
| 3764 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
| 3765 | IBinder binder) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3766 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3767 | mApp, subId, "requestNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3768 | |
| 3769 | final long identity = Binder.clearCallingIdentity(); |
| 3770 | try { |
| 3771 | return mNetworkScanRequestTracker.startNetworkScan( |
| 3772 | request, messenger, binder, getPhone(subId)); |
| 3773 | } finally { |
| 3774 | Binder.restoreCallingIdentity(identity); |
| 3775 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3776 | } |
| 3777 | |
| 3778 | /** |
| 3779 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 3780 | * |
| 3781 | * @param subId id of the subscription |
| 3782 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3783 | */ |
| 3784 | @Override |
| 3785 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3786 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3787 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3788 | |
| 3789 | final long identity = Binder.clearCallingIdentity(); |
| 3790 | try { |
| 3791 | mNetworkScanRequestTracker.stopNetworkScan(scanId); |
| 3792 | } finally { |
| 3793 | Binder.restoreCallingIdentity(identity); |
| 3794 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 3795 | } |
| 3796 | |
| 3797 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 3798 | * Get the calculated preferred network type. |
| 3799 | * Used for debugging incorrect network type. |
| 3800 | * |
| 3801 | * @return the preferred network type, defined in RILConstants.java. |
| 3802 | */ |
| 3803 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3804 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3805 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3806 | mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3807 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 3808 | } |
| 3809 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3810 | final long identity = Binder.clearCallingIdentity(); |
| 3811 | try { |
| 3812 | // FIXME: need to get SubId from somewhere. |
| 3813 | return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); |
| 3814 | } finally { |
| 3815 | Binder.restoreCallingIdentity(identity); |
| 3816 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 3817 | } |
| 3818 | |
| 3819 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3820 | * Get the preferred network type. |
| 3821 | * Used for device configuration by some CDMA operators. |
| 3822 | * |
| 3823 | * @return the preferred network type, defined in RILConstants.java. |
| 3824 | */ |
| 3825 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3826 | public int getPreferredNetworkType(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3827 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3828 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3829 | |
| 3830 | final long identity = Binder.clearCallingIdentity(); |
| 3831 | try { |
| 3832 | if (DBG) log("getPreferredNetworkType"); |
| 3833 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 3834 | int networkType = (result != null ? result[0] : -1); |
| 3835 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 3836 | return networkType; |
| 3837 | } finally { |
| 3838 | Binder.restoreCallingIdentity(identity); |
| 3839 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3840 | } |
| 3841 | |
| 3842 | /** |
| 3843 | * Set the preferred network type. |
| 3844 | * Used for device configuration by some CDMA operators. |
| 3845 | * |
| 3846 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 3847 | * @return true on success; false on any failure. |
| 3848 | */ |
| 3849 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 3850 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3851 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3852 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3853 | |
| 3854 | final long identity = Binder.clearCallingIdentity(); |
| 3855 | try { |
| 3856 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 3857 | Boolean success = (Boolean) sendRequest( |
| 3858 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 3859 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 3860 | if (success) { |
| 3861 | Settings.Global.putInt(mPhone.getContext().getContentResolver(), |
| 3862 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 3863 | } |
| 3864 | return success; |
| 3865 | } finally { |
| 3866 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 3867 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3868 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 3869 | |
| 3870 | /** |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 3871 | * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning |
Jack Yu | 13db0fe | 2018-10-30 17:41:31 -0700 | [diff] [blame] | 3872 | * SystemProperty to decide whether DUN APN is required for |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 3873 | * tethering. |
| 3874 | * |
| 3875 | * @return 0: Not required. 1: required. 2: Not set. |
| 3876 | * @hide |
| 3877 | */ |
| 3878 | @Override |
| 3879 | public int getTetherApnRequired() { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3880 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3881 | |
| 3882 | final long identity = Binder.clearCallingIdentity(); |
| 3883 | try { |
| 3884 | int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(), |
| 3885 | Settings.Global.TETHER_DUN_REQUIRED, 2); |
Jack Yu | 13db0fe | 2018-10-30 17:41:31 -0700 | [diff] [blame] | 3886 | // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3887 | if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) { |
| 3888 | dunRequired = 1; |
| 3889 | } |
| 3890 | return dunRequired; |
| 3891 | } finally { |
| 3892 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 3893 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 3894 | } |
| 3895 | |
| 3896 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 3897 | * Set mobile data enabled |
| 3898 | * Used by the user through settings etc to turn on/off mobile data |
| 3899 | * |
| 3900 | * @param enable {@code true} turn turn data on, else {@code false} |
| 3901 | */ |
| 3902 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 3903 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3904 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3905 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3906 | |
| 3907 | final long identity = Binder.clearCallingIdentity(); |
| 3908 | try { |
| 3909 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 3910 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 3911 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3912 | if (phone != null) { |
| 3913 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
| 3914 | phone.setUserDataEnabled(enable); |
| 3915 | } else { |
| 3916 | loge("setUserDataEnabled: no phone for subId=" + subId); |
| 3917 | } |
| 3918 | } finally { |
| 3919 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 3920 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 3921 | } |
| 3922 | |
| 3923 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 3924 | * Get the user enabled state of Mobile Data. |
| 3925 | * |
| 3926 | * TODO: remove and use isUserDataEnabled. |
| 3927 | * This can't be removed now because some vendor codes |
| 3928 | * calls through ITelephony directly while they should |
| 3929 | * use TelephonyManager. |
| 3930 | * |
| 3931 | * @return true on enabled |
| 3932 | */ |
| 3933 | @Override |
| 3934 | public boolean getDataEnabled(int subId) { |
| 3935 | return isUserDataEnabled(subId); |
| 3936 | } |
| 3937 | |
| 3938 | /** |
| 3939 | * Get whether mobile data is enabled per user setting. |
| 3940 | * |
| 3941 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 3942 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 3943 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 3944 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 3945 | * |
| 3946 | * @return {@code true} if data is enabled else {@code false} |
| 3947 | */ |
| 3948 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 3949 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 3950 | try { |
| 3951 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 3952 | null); |
| 3953 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3954 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3955 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 3956 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3957 | |
| 3958 | final long identity = Binder.clearCallingIdentity(); |
| 3959 | try { |
| 3960 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 3961 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 3962 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3963 | if (phone != null) { |
| 3964 | boolean retVal = phone.isUserDataEnabled(); |
| 3965 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 3966 | return retVal; |
| 3967 | } else { |
| 3968 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 3969 | return false; |
| 3970 | } |
| 3971 | } finally { |
| 3972 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 3973 | } |
| 3974 | } |
| 3975 | |
| 3976 | /** |
| 3977 | * Get whether mobile data is enabled. |
| 3978 | * |
| 3979 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 3980 | * whether mobile data is actually enabled. |
| 3981 | * |
| 3982 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 3983 | * |
| 3984 | * @return {@code true} if data is enabled else {@code false} |
| 3985 | */ |
| 3986 | @Override |
| 3987 | public boolean isDataEnabled(int subId) { |
| 3988 | try { |
| 3989 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 3990 | null); |
| 3991 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3992 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3993 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 3994 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3995 | |
| 3996 | final long identity = Binder.clearCallingIdentity(); |
| 3997 | try { |
| 3998 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 3999 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4000 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4001 | if (phone != null) { |
| 4002 | boolean retVal = phone.isDataEnabled(); |
| 4003 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4004 | return retVal; |
| 4005 | } else { |
| 4006 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4007 | return false; |
| 4008 | } |
| 4009 | } finally { |
| 4010 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4011 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4012 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4013 | |
| 4014 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4015 | public int getCarrierPrivilegeStatus(int subId) { |
| 4016 | final Phone phone = getPhone(subId); |
| 4017 | if (phone == null) { |
| 4018 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4019 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4020 | } |
| 4021 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4022 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4023 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4024 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4025 | } |
| 4026 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4027 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4028 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4029 | |
| 4030 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4031 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4032 | final Phone phone = getPhone(subId); |
| 4033 | if (phone == null) { |
| 4034 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4035 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4036 | } |
| 4037 | UiccProfile profile = |
| 4038 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4039 | if (profile == null) { |
| 4040 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4041 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4042 | } |
| 4043 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 4044 | } |
| 4045 | |
| 4046 | @Override |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4047 | public int checkCarrierPrivilegesForPackage(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4048 | if (TextUtils.isEmpty(pkgName)) |
| 4049 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Shishir Agrawal | 2140925 | 2015-01-15 23:33:50 -0800 | [diff] [blame] | 4050 | UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4051 | if (card == null) { |
| 4052 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 4053 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4054 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4055 | return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName); |
| 4056 | } |
| 4057 | |
| 4058 | @Override |
| 4059 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4060 | if (TextUtils.isEmpty(pkgName)) |
| 4061 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4062 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4063 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4064 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4065 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4066 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4067 | continue; |
| 4068 | } |
| 4069 | |
| 4070 | result = card.getCarrierPrivilegeStatus( |
| 4071 | mPhone.getContext().getPackageManager(), pkgName); |
| 4072 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4073 | break; |
| 4074 | } |
| 4075 | } |
| 4076 | |
| 4077 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4078 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4079 | |
| 4080 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4081 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4082 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4083 | loge("phoneId " + phoneId + " is not valid."); |
| 4084 | return null; |
| 4085 | } |
| 4086 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4087 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4088 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4089 | return null ; |
| 4090 | } |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4091 | return card.getCarrierPackageNamesForIntent( |
Svetoslav | 483aff7 | 2015-04-21 14:16:07 -0700 | [diff] [blame] | 4092 | mPhone.getContext().getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4093 | } |
| 4094 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4095 | @Override |
| 4096 | public List<String> getPackagesWithCarrierPrivileges() { |
| 4097 | PackageManager pm = mPhone.getContext().getPackageManager(); |
| 4098 | List<String> privilegedPackages = new ArrayList<>(); |
| 4099 | List<PackageInfo> packages = null; |
| 4100 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4101 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4102 | if (card == null) { |
| 4103 | // No UICC in that slot. |
| 4104 | continue; |
| 4105 | } |
| 4106 | if (card.hasCarrierPrivilegeRules()) { |
| 4107 | if (packages == null) { |
| 4108 | // Only check packages in user 0 for now |
| 4109 | packages = pm.getInstalledPackagesAsUser( |
| 4110 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4111 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4112 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
| 4113 | } |
| 4114 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4115 | PackageInfo pkgInfo = packages.get(p); |
| 4116 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4117 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| 4118 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4119 | privilegedPackages.add(pkgInfo.packageName); |
| 4120 | } |
| 4121 | } |
| 4122 | } |
| 4123 | } |
| 4124 | return privilegedPackages; |
| 4125 | } |
| 4126 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4127 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4128 | final Phone phone = getPhone(subId); |
| 4129 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4130 | if (card == null) { |
| 4131 | loge("getIccId: No UICC"); |
| 4132 | return null; |
| 4133 | } |
| 4134 | String iccId = card.getIccId(); |
| 4135 | if (TextUtils.isEmpty(iccId)) { |
| 4136 | loge("getIccId: ICC ID is null or empty."); |
| 4137 | return null; |
| 4138 | } |
| 4139 | return iccId; |
| 4140 | } |
| 4141 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4142 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4143 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4144 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4145 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4146 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4147 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4148 | final long identity = Binder.clearCallingIdentity(); |
| 4149 | try { |
| 4150 | final String iccId = getIccId(subId); |
| 4151 | final Phone phone = getPhone(subId); |
| 4152 | if (phone == null) { |
| 4153 | return false; |
| 4154 | } |
| 4155 | final String subscriberId = phone.getSubscriberId(); |
| 4156 | |
| 4157 | if (DBG_MERGE) { |
| 4158 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4159 | + subscriberId + " to " + number); |
| 4160 | } |
| 4161 | |
| 4162 | if (TextUtils.isEmpty(iccId)) { |
| 4163 | return false; |
| 4164 | } |
| 4165 | |
| 4166 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4167 | |
| 4168 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4169 | if (alphaTag == null) { |
| 4170 | editor.remove(alphaTagPrefKey); |
| 4171 | } else { |
| 4172 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4173 | } |
| 4174 | |
| 4175 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4176 | // track all merged IMSIs based on line number |
| 4177 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4178 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4179 | if (number == null) { |
| 4180 | editor.remove(numberPrefKey); |
| 4181 | editor.remove(subscriberPrefKey); |
| 4182 | } else { |
| 4183 | editor.putString(numberPrefKey, number); |
| 4184 | editor.putString(subscriberPrefKey, subscriberId); |
| 4185 | } |
| 4186 | |
| 4187 | editor.commit(); |
| 4188 | return true; |
| 4189 | } finally { |
| 4190 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4191 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4192 | } |
| 4193 | |
| 4194 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4195 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4196 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4197 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4198 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4199 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4200 | return null; |
| 4201 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4202 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4203 | final long identity = Binder.clearCallingIdentity(); |
| 4204 | try { |
| 4205 | String iccId = getIccId(subId); |
| 4206 | if (iccId != null) { |
| 4207 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4208 | if (DBG_MERGE) { |
| 4209 | log("getLine1NumberForDisplay returning " |
| 4210 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 4211 | } |
| 4212 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4213 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4214 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 4215 | return null; |
| 4216 | } finally { |
| 4217 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4218 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4219 | } |
| 4220 | |
| 4221 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4222 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4223 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4224 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4225 | return null; |
| 4226 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4227 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4228 | final long identity = Binder.clearCallingIdentity(); |
| 4229 | try { |
| 4230 | String iccId = getIccId(subId); |
| 4231 | if (iccId != null) { |
| 4232 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4233 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 4234 | } |
| 4235 | return null; |
| 4236 | } finally { |
| 4237 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4238 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4239 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4240 | |
| 4241 | @Override |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4242 | public String[] getMergedSubscriberIds(String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4243 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 4244 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4245 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4246 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 4247 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4248 | return null; |
| 4249 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4250 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4251 | final long identity = Binder.clearCallingIdentity(); |
| 4252 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4253 | final Context context = mPhone.getContext(); |
| 4254 | final TelephonyManager tele = TelephonyManager.from(context); |
| 4255 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 4256 | |
| 4257 | // Figure out what subscribers are currently active |
| 4258 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
| 4259 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 4260 | // the process, where TelephonyManager was instantiated. |
| 4261 | // Otherwise AppOps check will fail. |
| 4262 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4263 | final int[] subIds = sub.getActiveSubscriptionIdList(); |
| 4264 | for (int subId : subIds) { |
| 4265 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 4266 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4267 | |
| 4268 | // First pass, find a number override for an active subscriber |
| 4269 | String mergeNumber = null; |
| 4270 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 4271 | for (String key : prefs.keySet()) { |
| 4272 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 4273 | final String subscriberId = (String) prefs.get(key); |
| 4274 | if (activeSubscriberIds.contains(subscriberId)) { |
| 4275 | final String iccId = key.substring( |
| 4276 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 4277 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4278 | mergeNumber = (String) prefs.get(numberKey); |
| 4279 | if (DBG_MERGE) { |
| 4280 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 4281 | + " for active subscriber " + subscriberId); |
| 4282 | } |
| 4283 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 4284 | break; |
| 4285 | } |
| 4286 | } |
| 4287 | } |
| 4288 | } |
| 4289 | |
| 4290 | // Shortcut when no active merged subscribers |
| 4291 | if (TextUtils.isEmpty(mergeNumber)) { |
| 4292 | return null; |
| 4293 | } |
| 4294 | |
| 4295 | // Second pass, find all subscribers under that line override |
| 4296 | final ArraySet<String> result = new ArraySet<>(); |
| 4297 | for (String key : prefs.keySet()) { |
| 4298 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 4299 | final String number = (String) prefs.get(key); |
| 4300 | if (mergeNumber.equals(number)) { |
| 4301 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 4302 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4303 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 4304 | if (!TextUtils.isEmpty(subscriberId)) { |
| 4305 | result.add(subscriberId); |
| 4306 | } |
| 4307 | } |
| 4308 | } |
| 4309 | } |
| 4310 | |
| 4311 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 4312 | Arrays.sort(resultArray); |
| 4313 | if (DBG_MERGE) { |
| 4314 | Slog.d(LOG_TAG, |
| 4315 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 4316 | } |
| 4317 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4318 | } finally { |
| 4319 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4320 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4321 | } |
| 4322 | |
| 4323 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4324 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4325 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4326 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4327 | |
| 4328 | final long identity = Binder.clearCallingIdentity(); |
| 4329 | try { |
| 4330 | final Phone phone = getPhone(subId); |
| 4331 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 4332 | } finally { |
| 4333 | Binder.restoreCallingIdentity(identity); |
| 4334 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4335 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 4336 | |
| 4337 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4338 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4339 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 4340 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4341 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4342 | |
| 4343 | final long identity = Binder.clearCallingIdentity(); |
| 4344 | try { |
| 4345 | final Phone phone = getPhone(subId); |
| 4346 | if (phone == null) { |
| 4347 | return false; |
| 4348 | } |
| 4349 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 4350 | cdmaNonRoamingList); |
| 4351 | } finally { |
| 4352 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4353 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4354 | } |
| 4355 | |
| 4356 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4357 | @Deprecated |
| 4358 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 4359 | enforceModifyPermission(); |
| 4360 | |
| 4361 | int returnValue = 0; |
| 4362 | try { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4363 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4364 | if(result.exception == null) { |
| 4365 | if (result.result != null) { |
| 4366 | byte[] responseData = (byte[])(result.result); |
| 4367 | if(responseData.length > oemResp.length) { |
| 4368 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 4369 | responseData.length + "bytes. Buffer Size is " + |
| 4370 | oemResp.length + "bytes."); |
| 4371 | } |
| 4372 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 4373 | returnValue = responseData.length; |
| 4374 | } |
| 4375 | } else { |
| 4376 | CommandException ex = (CommandException) result.exception; |
| 4377 | returnValue = ex.getCommandError().ordinal(); |
| 4378 | if(returnValue > 0) returnValue *= -1; |
| 4379 | } |
| 4380 | } catch (RuntimeException e) { |
| 4381 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 4382 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 4383 | if(returnValue > 0) returnValue *= -1; |
| 4384 | } |
| 4385 | |
| 4386 | return returnValue; |
| 4387 | } |
| 4388 | |
| 4389 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4390 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 4391 | try { |
| 4392 | ProxyController.getInstance().setRadioCapability(rafs); |
| 4393 | } catch (RuntimeException e) { |
| 4394 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 4395 | } |
| 4396 | } |
| 4397 | |
| 4398 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4399 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4400 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4401 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4402 | if (phone == null) { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4403 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4404 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4405 | final long identity = Binder.clearCallingIdentity(); |
| 4406 | try { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4407 | TelephonyPermissions |
| 4408 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4409 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 4410 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4411 | } finally { |
| 4412 | Binder.restoreCallingIdentity(identity); |
| 4413 | } |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4414 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4415 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4416 | |
| 4417 | @Override |
| 4418 | public void enableVideoCalling(boolean enable) { |
| 4419 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4420 | |
| 4421 | final long identity = Binder.clearCallingIdentity(); |
| 4422 | try { |
| 4423 | ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable); |
| 4424 | } finally { |
| 4425 | Binder.restoreCallingIdentity(identity); |
| 4426 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4427 | } |
| 4428 | |
| 4429 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4430 | public boolean isVideoCallingEnabled(String callingPackage) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4431 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4432 | mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
| 4433 | return false; |
| 4434 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4435 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4436 | final long identity = Binder.clearCallingIdentity(); |
| 4437 | try { |
| 4438 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 4439 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 4440 | // In the long run, we may instead need to check if there exists a connection service |
| 4441 | // which can support video calling. |
| 4442 | ImsManager imsManager = |
| 4443 | ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()); |
| 4444 | return imsManager.isVtEnabledByPlatform() |
| 4445 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 4446 | && imsManager.isVtEnabledByUser(); |
| 4447 | } finally { |
| 4448 | Binder.restoreCallingIdentity(identity); |
| 4449 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4450 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 4451 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4452 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4453 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 4454 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4455 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4456 | return false; |
| 4457 | } |
| 4458 | |
| 4459 | final long identity = Binder.clearCallingIdentity(); |
| 4460 | try { |
| 4461 | CarrierConfigManager configManager = |
| 4462 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| 4463 | return configManager.getConfigForSubId(mPhone.getSubId()) |
| 4464 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 4465 | } finally { |
| 4466 | Binder.restoreCallingIdentity(identity); |
| 4467 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4468 | } |
| 4469 | |
| 4470 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4471 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 4472 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4473 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4474 | return false; |
| 4475 | } |
| 4476 | |
| 4477 | final long identity = Binder.clearCallingIdentity(); |
| 4478 | try { |
| 4479 | CarrierConfigManager configManager = |
| 4480 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| 4481 | return configManager.getConfigForSubId(mPhone.getSubId()) |
| 4482 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 4483 | } finally { |
| 4484 | Binder.restoreCallingIdentity(identity); |
| 4485 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4486 | } |
| 4487 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4488 | @Override |
| 4489 | public boolean isTtyModeSupported() { |
| 4490 | TelecomManager telecomManager = TelecomManager.from(mPhone.getContext()); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 4491 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4492 | } |
| 4493 | |
| 4494 | @Override |
| 4495 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4496 | final long identity = Binder.clearCallingIdentity(); |
| 4497 | try { |
| 4498 | return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled); |
| 4499 | } finally { |
| 4500 | Binder.restoreCallingIdentity(identity); |
| 4501 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4502 | } |
| 4503 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4504 | /** |
| 4505 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 4506 | * support for the feature and device firmware support. |
| 4507 | * |
| 4508 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 4509 | */ |
| 4510 | @Override |
| 4511 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4512 | final long identity = Binder.clearCallingIdentity(); |
| 4513 | try { |
| 4514 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId( |
| 4515 | mPhone.getSubId()).getBoolean( |
| 4516 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 4517 | boolean isDeviceSupported = |
| 4518 | mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
| 4519 | return isCarrierSupported && isDeviceSupported; |
| 4520 | } finally { |
| 4521 | Binder.restoreCallingIdentity(identity); |
| 4522 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 4523 | } |
| 4524 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4525 | /** |
| 4526 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier |
| 4527 | * both also support RTT. |
| 4528 | */ |
| 4529 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4530 | final long identity = Binder.clearCallingIdentity(); |
| 4531 | try { |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4532 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4533 | mPhone.getContext().getContentResolver(), |
| 4534 | Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 4535 | } finally { |
| 4536 | Binder.restoreCallingIdentity(identity); |
| 4537 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 4538 | } |
| 4539 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4540 | /** |
| 4541 | * Returns the unique device ID of phone, for example, the IMEI for |
| 4542 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 4543 | * |
| 4544 | * <p>Requires Permission: |
| 4545 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 4546 | */ |
| 4547 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4548 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4549 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4550 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4551 | return null; |
| 4552 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4553 | int subId = phone.getSubId(); |
| 4554 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4555 | mApp, subId, callingPackage, "getDeviceId")) { |
| 4556 | return null; |
| 4557 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4558 | |
| 4559 | final long identity = Binder.clearCallingIdentity(); |
| 4560 | try { |
| 4561 | return phone.getDeviceId(); |
| 4562 | } finally { |
| 4563 | Binder.restoreCallingIdentity(identity); |
| 4564 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 4565 | } |
| 4566 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 4567 | /** |
| 4568 | * {@hide} |
| 4569 | * Returns the IMS Registration Status on a particular subid |
| 4570 | * |
| 4571 | * @param subId |
| 4572 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4573 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 4574 | Phone phone = getPhone(subId); |
| 4575 | if (phone != null) { |
| 4576 | return phone.isImsRegistered(); |
| 4577 | } else { |
| 4578 | return false; |
| 4579 | } |
| 4580 | } |
| 4581 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 4582 | @Override |
| 4583 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4584 | final long identity = Binder.clearCallingIdentity(); |
| 4585 | try { |
| 4586 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 4587 | } finally { |
| 4588 | Binder.restoreCallingIdentity(identity); |
| 4589 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 4590 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 4591 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4592 | /** |
| 4593 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 4594 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4595 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4596 | final long identity = Binder.clearCallingIdentity(); |
| 4597 | try { |
| 4598 | Phone phone = getPhone(subId); |
| 4599 | if (phone != null) { |
| 4600 | return phone.isWifiCallingEnabled(); |
| 4601 | } else { |
| 4602 | return false; |
| 4603 | } |
| 4604 | } finally { |
| 4605 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4606 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 4607 | } |
| 4608 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4609 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4610 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 4611 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4612 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4613 | final long identity = Binder.clearCallingIdentity(); |
| 4614 | try { |
| 4615 | Phone phone = getPhone(subId); |
| 4616 | if (phone != null) { |
| 4617 | return phone.isVideoEnabled(); |
| 4618 | } else { |
| 4619 | return false; |
| 4620 | } |
| 4621 | } finally { |
| 4622 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4623 | } |
| 4624 | } |
| 4625 | |
| 4626 | /** |
| 4627 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 4628 | * defined in {@link ImsRegistrationImplBase}. |
| 4629 | */ |
| 4630 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4631 | final long identity = Binder.clearCallingIdentity(); |
| 4632 | try { |
| 4633 | Phone phone = getPhone(subId); |
| 4634 | if (phone != null) { |
| 4635 | return phone.getImsRegistrationTech(); |
| 4636 | } else { |
| 4637 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 4638 | } |
| 4639 | } finally { |
| 4640 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 4641 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 4642 | } |
| 4643 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 4644 | @Override |
| 4645 | public void factoryReset(int subId) { |
| 4646 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 4647 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 4648 | return; |
| 4649 | } |
| 4650 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4651 | final long identity = Binder.clearCallingIdentity(); |
| 4652 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 4653 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 4654 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 4655 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4656 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 4657 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
| 4658 | mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId)); |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 4659 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 4660 | } |
| 4661 | } finally { |
| 4662 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 4663 | } |
| 4664 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4665 | |
| 4666 | @Override |
| 4667 | public String getLocaleFromDefaultSim() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4668 | final long identity = Binder.clearCallingIdentity(); |
| 4669 | try { |
| 4670 | // We query all subscriptions instead of just the active ones, because |
| 4671 | // this might be called early on in the provisioning flow when the |
| 4672 | // subscriptions potentially aren't active yet. |
| 4673 | final List<SubscriptionInfo> slist = getAllSubscriptionInfoList(); |
| 4674 | if (slist == null || slist.isEmpty()) { |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4675 | return null; |
| 4676 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4677 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4678 | // This function may be called very early, say, from the setup wizard, at |
| 4679 | // which point we won't have a default subscription set. If that's the case |
| 4680 | // we just choose the first, which will be valid in "most cases". |
| 4681 | final int defaultSubId = getDefaultSubscription(); |
| 4682 | SubscriptionInfo info = null; |
| 4683 | if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 4684 | info = slist.get(0); |
| 4685 | } else { |
| 4686 | for (SubscriptionInfo item : slist) { |
| 4687 | if (item.getSubscriptionId() == defaultSubId) { |
| 4688 | info = item; |
| 4689 | break; |
| 4690 | } |
| 4691 | } |
| 4692 | |
| 4693 | if (info == null) { |
| 4694 | return null; |
Tony Hill | 183b2de | 2015-06-24 14:53:58 +0100 | [diff] [blame] | 4695 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4696 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4697 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4698 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 4699 | // preferences (EF-PL and EF-LI)... |
| 4700 | final int mcc = info.getMcc(); |
| 4701 | final Phone defaultPhone = getPhone(info.getSubscriptionId()); |
| 4702 | String simLanguage = null; |
| 4703 | if (defaultPhone != null) { |
| 4704 | final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs(); |
| 4705 | if (localeFromDefaultSim != null) { |
| 4706 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 4707 | if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim); |
| 4708 | return localeFromDefaultSim.toLanguageTag(); |
| 4709 | } else { |
| 4710 | simLanguage = localeFromDefaultSim.getLanguage(); |
| 4711 | } |
| 4712 | } |
| 4713 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4714 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4715 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 4716 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 4717 | // the SIM and carrier preferences does not include a country we add the country |
| 4718 | // determined from the SIM MCC to provide an exact locale. |
| 4719 | final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, |
| 4720 | simLanguage); |
| 4721 | if (mccLocale != null) { |
| 4722 | if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale); |
| 4723 | return mccLocale.toLanguageTag(); |
| 4724 | } |
| 4725 | |
| 4726 | if (DBG) log("No locale found - returning null"); |
| 4727 | return null; |
| 4728 | } finally { |
| 4729 | Binder.restoreCallingIdentity(identity); |
| 4730 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4731 | } |
| 4732 | |
| 4733 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4734 | return mSubscriptionController.getAllSubInfoList( |
| 4735 | mPhone.getContext().getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4736 | } |
| 4737 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4738 | /** |
| 4739 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 4740 | */ |
| 4741 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
| 4742 | return mSubscriptionController.getActiveSubscriptionInfoList( |
| 4743 | mPhone.getContext().getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 4744 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4745 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4746 | private final ModemActivityInfo mLastModemActivityInfo = |
| 4747 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 4748 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4749 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 4750 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 4751 | * representing the state of the modem. |
| 4752 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4753 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 4754 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 4755 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4756 | */ |
| 4757 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 4758 | public void requestModemActivityInfo(ResultReceiver result) { |
| 4759 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4760 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4761 | |
| 4762 | final long identity = Binder.clearCallingIdentity(); |
| 4763 | try { |
| 4764 | ModemActivityInfo ret = null; |
| 4765 | synchronized (mLastModemActivityInfo) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4766 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 4767 | CMD_GET_MODEM_ACTIVITY_INFO, |
| 4768 | null, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4769 | if (isModemActivityInfoValid(info)) { |
| 4770 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 4771 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 4772 | mergedTxTimeMs[i] = |
| 4773 | info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i]; |
| 4774 | } |
| 4775 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 4776 | mLastModemActivityInfo.setSleepTimeMillis( |
| 4777 | info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis()); |
| 4778 | mLastModemActivityInfo.setIdleTimeMillis( |
| 4779 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 4780 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 4781 | mLastModemActivityInfo.setRxTimeMillis( |
| 4782 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 4783 | mLastModemActivityInfo.setEnergyUsed( |
| 4784 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4785 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4786 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 4787 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 4788 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 4789 | mLastModemActivityInfo.getTxTimeMillis(), |
| 4790 | mLastModemActivityInfo.getRxTimeMillis(), |
| 4791 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4792 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4793 | Bundle bundle = new Bundle(); |
| 4794 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 4795 | result.send(0, bundle); |
| 4796 | } finally { |
| 4797 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 4798 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 4799 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4800 | |
Siddharth Ray | f5d2955 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 4801 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 4802 | // less than total activity duration. |
| 4803 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 4804 | if (info == null) { |
| 4805 | return false; |
| 4806 | } |
| 4807 | int activityDurationMs = |
| 4808 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 4809 | int totalTxTimeMs = 0; |
| 4810 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 4811 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 4812 | } |
| 4813 | return (info.isValid() |
| 4814 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 4815 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 4816 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 4817 | && (totalTxTimeMs <= activityDurationMs)); |
| 4818 | } |
| 4819 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4820 | /** |
| 4821 | * {@hide} |
| 4822 | * Returns the service state information on specified subscription. |
| 4823 | */ |
| 4824 | @Override |
| 4825 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4826 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4827 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4828 | return null; |
| 4829 | } |
| 4830 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4831 | final long identity = Binder.clearCallingIdentity(); |
| 4832 | try { |
| 4833 | final Phone phone = getPhone(subId); |
| 4834 | if (phone == null) { |
| 4835 | return null; |
| 4836 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4837 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4838 | return phone.getServiceState(); |
| 4839 | } finally { |
| 4840 | Binder.restoreCallingIdentity(identity); |
| 4841 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 4842 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4843 | |
| 4844 | /** |
| 4845 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 4846 | * |
| 4847 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 4848 | * voicemail ringtone. |
| 4849 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 4850 | * PhoneAccount. |
| 4851 | */ |
| 4852 | @Override |
| 4853 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4854 | final long identity = Binder.clearCallingIdentity(); |
| 4855 | try { |
| 4856 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 4857 | if (phone == null) { |
| 4858 | phone = mPhone; |
| 4859 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4860 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4861 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 4862 | } finally { |
| 4863 | Binder.restoreCallingIdentity(identity); |
| 4864 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4865 | } |
| 4866 | |
| 4867 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 4868 | * Sets the per-account voicemail ringtone. |
| 4869 | * |
| 4870 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 4871 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 4872 | * |
| 4873 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 4874 | * voicemail ringtone. |
| 4875 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 4876 | * PhoneAccount. |
| 4877 | */ |
| 4878 | @Override |
| 4879 | public void setVoicemailRingtoneUri(String callingPackage, |
| 4880 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
| 4881 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4882 | if (!TextUtils.equals(callingPackage, |
| 4883 | TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4884 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4885 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 4886 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 4887 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4888 | |
| 4889 | final long identity = Binder.clearCallingIdentity(); |
| 4890 | try { |
| 4891 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 4892 | if (phone == null) { |
| 4893 | phone = mPhone; |
| 4894 | } |
| 4895 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 4896 | } finally { |
| 4897 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 4898 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 4899 | } |
| 4900 | |
| 4901 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4902 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 4903 | * |
| 4904 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 4905 | * voicemail vibration setting. |
| 4906 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 4907 | */ |
| 4908 | @Override |
| 4909 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4910 | final long identity = Binder.clearCallingIdentity(); |
| 4911 | try { |
| 4912 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 4913 | if (phone == null) { |
| 4914 | phone = mPhone; |
| 4915 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4916 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4917 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 4918 | } finally { |
| 4919 | Binder.restoreCallingIdentity(identity); |
| 4920 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 4921 | } |
| 4922 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 4923 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 4924 | * Sets the per-account voicemail vibration. |
| 4925 | * |
| 4926 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 4927 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 4928 | * |
| 4929 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 4930 | * voicemail vibration setting. |
| 4931 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 4932 | * specific PhoneAccount. |
| 4933 | */ |
| 4934 | @Override |
| 4935 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 4936 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
| 4937 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4938 | if (!TextUtils.equals(callingPackage, |
| 4939 | TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4940 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4941 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 4942 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 4943 | } |
| 4944 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4945 | final long identity = Binder.clearCallingIdentity(); |
| 4946 | try { |
| 4947 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 4948 | if (phone == null) { |
| 4949 | phone = mPhone; |
| 4950 | } |
| 4951 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 4952 | } finally { |
| 4953 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 4954 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 4955 | } |
| 4956 | |
| 4957 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 4958 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 4959 | * |
| 4960 | * @throws SecurityException if the caller does not have the required permission |
| 4961 | */ |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4962 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 4963 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4964 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 4965 | } |
| 4966 | |
| 4967 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4968 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 4969 | * permission. |
| 4970 | * |
| 4971 | * @throws SecurityException if the caller does not have the required permission |
| 4972 | */ |
| 4973 | private void enforceSendSmsPermission() { |
| 4974 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 4975 | } |
| 4976 | |
| 4977 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4978 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4979 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4980 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4981 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4982 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4983 | final long identity = Binder.clearCallingIdentity(); |
| 4984 | try { |
| 4985 | ComponentName componentName = |
| 4986 | RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId); |
| 4987 | if (componentName == null) { |
| 4988 | throw new SecurityException( |
| 4989 | "Caller not current active visual voicemail package[null]"); |
| 4990 | } |
| 4991 | String vvmPackage = componentName.getPackageName(); |
| 4992 | if (!callingPackage.equals(vvmPackage)) { |
| 4993 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 4994 | + vvmPackage + "]"); |
| 4995 | } |
| 4996 | } finally { |
| 4997 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4998 | } |
| 4999 | } |
| 5000 | |
| 5001 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5002 | * Return the application ID for the app type. |
| 5003 | * |
| 5004 | * @param subId the subscription ID that this request applies to. |
| 5005 | * @param appType the uicc app type. |
| 5006 | * @return Application ID for specificied app type, or null if no uicc. |
| 5007 | */ |
| 5008 | @Override |
| 5009 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5010 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5011 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5012 | |
| 5013 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5014 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5015 | if (phone == null) { |
| 5016 | return null; |
| 5017 | } |
| 5018 | String aid = null; |
| 5019 | try { |
| 5020 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5021 | .getApplicationByType(appType).getAid(); |
| 5022 | } catch (Exception e) { |
| 5023 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5024 | } |
| 5025 | return aid; |
| 5026 | } finally { |
| 5027 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5028 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5029 | } |
| 5030 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5031 | /** |
| 5032 | * Return the Electronic Serial Number. |
| 5033 | * |
| 5034 | * @param subId the subscription ID that this request applies to. |
| 5035 | * @return ESN or null if error. |
| 5036 | */ |
| 5037 | @Override |
| 5038 | public String getEsn(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5039 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5040 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5041 | |
| 5042 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5043 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5044 | if (phone == null) { |
| 5045 | return null; |
| 5046 | } |
| 5047 | String esn = null; |
| 5048 | try { |
| 5049 | esn = phone.getEsn(); |
| 5050 | } catch (Exception e) { |
| 5051 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5052 | } |
| 5053 | return esn; |
| 5054 | } finally { |
| 5055 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5056 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5057 | } |
| 5058 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5059 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5060 | * Return the Preferred Roaming List Version. |
| 5061 | * |
| 5062 | * @param subId the subscription ID that this request applies to. |
| 5063 | * @return PRLVersion or null if error. |
| 5064 | */ |
| 5065 | @Override |
| 5066 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5067 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5068 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5069 | |
| 5070 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5071 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5072 | if (phone == null) { |
| 5073 | return null; |
| 5074 | } |
| 5075 | String cdmaPrlVersion = null; |
| 5076 | try { |
| 5077 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 5078 | } catch (Exception e) { |
| 5079 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 5080 | } |
| 5081 | return cdmaPrlVersion; |
| 5082 | } finally { |
| 5083 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5084 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5085 | } |
| 5086 | |
| 5087 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5088 | * Get snapshot of Telephony histograms |
| 5089 | * @return List of Telephony histograms |
| 5090 | * @hide |
| 5091 | */ |
| 5092 | @Override |
| 5093 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5095 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5096 | |
| 5097 | final long identity = Binder.clearCallingIdentity(); |
| 5098 | try { |
| 5099 | return RIL.getTelephonyRILTimingHistograms(); |
| 5100 | } finally { |
| 5101 | Binder.restoreCallingIdentity(identity); |
| 5102 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5103 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5104 | |
| 5105 | /** |
| 5106 | * {@hide} |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5107 | * Set the allowed carrier list for slotIndex |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5108 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5109 | * |
| 5110 | * @return The number of carriers set successfully, should match length of carriers |
| 5111 | */ |
| 5112 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5113 | public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5114 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5115 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5116 | |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5117 | if (carriers == null) { |
| 5118 | throw new NullPointerException("carriers cannot be null"); |
| 5119 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5120 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5121 | final long identity = Binder.clearCallingIdentity(); |
| 5122 | try { |
| 5123 | int subId = SubscriptionManager.getSubId(slotIndex)[0]; |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5124 | int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId, |
| 5125 | workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5126 | return retVal[0]; |
| 5127 | } finally { |
| 5128 | Binder.restoreCallingIdentity(identity); |
| 5129 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5130 | } |
| 5131 | |
| 5132 | /** |
| 5133 | * {@hide} |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5134 | * Get the allowed carrier list for slotIndex. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5135 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5136 | * |
| 5137 | * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list |
| 5138 | * means all carriers are allowed. |
| 5139 | */ |
| 5140 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5141 | public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5142 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5143 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5144 | |
| 5145 | final long identity = Binder.clearCallingIdentity(); |
| 5146 | try { |
| 5147 | int subId = SubscriptionManager.getSubId(slotIndex)[0]; |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5148 | return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId, |
| 5149 | workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5150 | } finally { |
| 5151 | Binder.restoreCallingIdentity(identity); |
| 5152 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5153 | } |
| 5154 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5155 | /** |
| 5156 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 5157 | * @param subId the subscription ID that this action applies to. |
| 5158 | * @param enabled control enable or disable metered apns. |
| 5159 | * {@hide} |
| 5160 | */ |
| 5161 | @Override |
| 5162 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 5163 | enforceModifyPermission(); |
| 5164 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5165 | |
| 5166 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5167 | if (phone == null) { |
| 5168 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 5169 | return; |
| 5170 | } |
| 5171 | try { |
| 5172 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 5173 | } catch (Exception e) { |
| 5174 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5175 | } finally { |
| 5176 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5177 | } |
| 5178 | } |
| 5179 | |
| 5180 | /** |
| 5181 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 5182 | * @param subId the subscription ID that this action applies to. |
| 5183 | * @param enabled control enable or disable radio. |
| 5184 | * {@hide} |
| 5185 | */ |
| 5186 | @Override |
| 5187 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 5188 | enforceModifyPermission(); |
| 5189 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5190 | |
| 5191 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5192 | if (phone == null) { |
| 5193 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 5194 | return; |
| 5195 | } |
| 5196 | try { |
| 5197 | phone.carrierActionSetRadioEnabled(enabled); |
| 5198 | } catch (Exception e) { |
| 5199 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5200 | } finally { |
| 5201 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5202 | } |
| 5203 | } |
| 5204 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5205 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5206 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 5207 | * network status based on which carrier apps could apply actions accordingly, |
| 5208 | * enable/disable default url handler for example. |
| 5209 | * |
| 5210 | * @param subId the subscription ID that this action applies to. |
| 5211 | * @param report control start/stop reporting the default network status. |
| 5212 | * {@hide} |
| 5213 | */ |
| 5214 | @Override |
| 5215 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 5216 | enforceModifyPermission(); |
| 5217 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5218 | |
| 5219 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5220 | if (phone == null) { |
| 5221 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 5222 | return; |
| 5223 | } |
| 5224 | try { |
| 5225 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 5226 | } catch (Exception e) { |
| 5227 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5228 | } finally { |
| 5229 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5230 | } |
| 5231 | } |
| 5232 | |
| 5233 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5234 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 5235 | * bug report is being generated. |
| 5236 | */ |
| 5237 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 5238 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 5239 | if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 5240 | != PackageManager.PERMISSION_GRANTED) { |
| 5241 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 5242 | + Binder.getCallingPid() |
| 5243 | + ", uid=" + Binder.getCallingUid() |
| 5244 | + "without permission " |
| 5245 | + android.Manifest.permission.DUMP); |
| 5246 | return; |
| 5247 | } |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 5248 | DumpsysHandler.dump(mPhone.getContext(), fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5249 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5250 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5251 | @Override |
| 5252 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 5253 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 5254 | throws RemoteException { |
| 5255 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 5256 | } |
| 5257 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5258 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5259 | * Get aggregated video call data usage since boot. |
| 5260 | * |
| 5261 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 5262 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5263 | * {@hide} |
| 5264 | */ |
| 5265 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5266 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5267 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 5268 | null); |
| 5269 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5270 | final long identity = Binder.clearCallingIdentity(); |
| 5271 | try { |
| 5272 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 5273 | // records the delta with the corresponding network identity. |
| 5274 | // We just return the total video call data usage snapshot since boot. |
| 5275 | Phone phone = getPhone(subId); |
| 5276 | if (phone != null) { |
| 5277 | return phone.getVtDataUsage(perUidStats); |
| 5278 | } |
| 5279 | return null; |
| 5280 | } finally { |
| 5281 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5282 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5283 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5284 | |
| 5285 | /** |
| 5286 | * Policy control of data connection. Usually used when data limit is passed. |
| 5287 | * @param enabled True if enabling the data, otherwise disabling. |
| 5288 | * @param subId Subscription index |
| 5289 | * {@hide} |
| 5290 | */ |
| 5291 | @Override |
| 5292 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 5293 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5294 | |
| 5295 | final long identity = Binder.clearCallingIdentity(); |
| 5296 | try { |
| 5297 | Phone phone = getPhone(subId); |
| 5298 | if (phone != null) { |
| 5299 | phone.setPolicyDataEnabled(enabled); |
| 5300 | } |
| 5301 | } finally { |
| 5302 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5303 | } |
| 5304 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5305 | |
| 5306 | /** |
| 5307 | * Get Client request stats |
| 5308 | * @return List of Client Request Stats |
| 5309 | * @hide |
| 5310 | */ |
| 5311 | @Override |
| 5312 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5313 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5314 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5315 | return null; |
| 5316 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5317 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5318 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5319 | final long identity = Binder.clearCallingIdentity(); |
| 5320 | try { |
| 5321 | if (phone != null) { |
| 5322 | return phone.getClientRequestStats(); |
| 5323 | } |
| 5324 | |
| 5325 | return null; |
| 5326 | } finally { |
| 5327 | Binder.restoreCallingIdentity(identity); |
| 5328 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5329 | } |
| 5330 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5331 | private WorkSource getWorkSource(int uid) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5332 | String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5333 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5334 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5335 | |
| 5336 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5337 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5338 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5339 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5340 | * @param state State of SIM (power down, power up, pass through) |
| 5341 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 5342 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 5343 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5344 | * |
| 5345 | **/ |
| 5346 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5347 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5348 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5349 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5350 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5351 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5352 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5353 | final long identity = Binder.clearCallingIdentity(); |
| 5354 | try { |
| 5355 | if (phone != null) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5356 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5357 | } |
| 5358 | } finally { |
| 5359 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5360 | } |
| 5361 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5362 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5363 | private boolean isUssdApiAllowed(int subId) { |
| 5364 | CarrierConfigManager configManager = |
| 5365 | (CarrierConfigManager) mPhone.getContext().getSystemService( |
| 5366 | Context.CARRIER_CONFIG_SERVICE); |
| 5367 | if (configManager == null) { |
| 5368 | return false; |
| 5369 | } |
| 5370 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 5371 | if (pb == null) { |
| 5372 | return false; |
| 5373 | } |
| 5374 | return pb.getBoolean( |
| 5375 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 5376 | } |
| 5377 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5378 | /** |
| 5379 | * Check if phone is in emergency callback mode |
| 5380 | * @return true if phone is in emergency callback mode |
| 5381 | * @param subId sub id |
| 5382 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 5383 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5384 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5385 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5386 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5387 | |
| 5388 | final long identity = Binder.clearCallingIdentity(); |
| 5389 | try { |
| 5390 | if (phone != null) { |
| 5391 | return phone.isInEcm(); |
| 5392 | } else { |
| 5393 | return false; |
| 5394 | } |
| 5395 | } finally { |
| 5396 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5397 | } |
| 5398 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5399 | |
| 5400 | /** |
| 5401 | * Get the current signal strength information for the given subscription. |
| 5402 | * Because this information is not updated when the device is in a low power state |
| 5403 | * it should not be relied-upon to be current. |
| 5404 | * @param subId Subscription index |
| 5405 | * @return the most recent cached signal strength info from the modem |
| 5406 | */ |
| 5407 | @Override |
| 5408 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5409 | final long identity = Binder.clearCallingIdentity(); |
| 5410 | try { |
| 5411 | Phone p = getPhone(subId); |
| 5412 | if (p == null) { |
| 5413 | return null; |
| 5414 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5415 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5416 | return p.getSignalStrength(); |
| 5417 | } finally { |
| 5418 | Binder.restoreCallingIdentity(identity); |
| 5419 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5420 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5421 | |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5422 | /** |
chen xu | 907e5a2 | 2018-10-11 13:21:04 -0700 | [diff] [blame] | 5423 | * Get the current modem radio state for the given slot. |
| 5424 | * @param slotIndex slot index. |
| 5425 | * @param callingPackage the name of the package making the call. |
| 5426 | * @return the current radio power state from the modem |
| 5427 | */ |
| 5428 | @Override |
| 5429 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 5430 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5431 | if (phone != null) { |
| 5432 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5433 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 5434 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5435 | } |
| 5436 | |
| 5437 | final long identity = Binder.clearCallingIdentity(); |
| 5438 | try { |
| 5439 | return phone.getRadioPowerState(); |
| 5440 | } finally { |
| 5441 | Binder.restoreCallingIdentity(identity); |
| 5442 | } |
| 5443 | } |
| 5444 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5445 | } |
| 5446 | |
| 5447 | /** |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5448 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 5449 | * |
| 5450 | * <p>Requires one of the following permissions: |
| 5451 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 5452 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 5453 | * privileges. |
| 5454 | * |
| 5455 | * @param subId subscription id |
| 5456 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 5457 | * {@code false}. |
| 5458 | */ |
| 5459 | @Override |
| 5460 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5461 | boolean isEnabled = false; |
| 5462 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5463 | try { |
| 5464 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5465 | null /* message */); |
| 5466 | Phone phone = getPhone(subId); |
| 5467 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5468 | } catch (Exception e) { |
| 5469 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 5470 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5471 | } finally { |
| 5472 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5473 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5474 | return isEnabled; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5475 | } |
| 5476 | |
| 5477 | |
| 5478 | /** |
| 5479 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 5480 | * |
| 5481 | * <p> Requires permission: |
| 5482 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 5483 | * privileges. |
| 5484 | * |
| 5485 | * @param subId subscription id |
| 5486 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 5487 | */ |
| 5488 | @Override |
| 5489 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5490 | final long identity = Binder.clearCallingIdentity(); |
| 5491 | try { |
| 5492 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5493 | mApp, subId, "setDataRoamingEnabled"); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5494 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5495 | Phone phone = getPhone(subId); |
| 5496 | if (phone != null) { |
| 5497 | phone.setDataRoamingEnabled(isEnabled); |
| 5498 | } |
| 5499 | } finally { |
| 5500 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5501 | } |
| 5502 | } |
| 5503 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5504 | @Override |
Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 5505 | public boolean isManualNetworkSelectionAllowed(int subId) { |
| 5506 | boolean isAllowed = true; |
| 5507 | final long identity = Binder.clearCallingIdentity(); |
| 5508 | try { |
| 5509 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 5510 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 5511 | Phone phone = getPhone(subId); |
| 5512 | if (phone != null) { |
| 5513 | isAllowed = phone.isCspPlmnEnabled(); |
| 5514 | } |
| 5515 | } finally { |
| 5516 | Binder.restoreCallingIdentity(identity); |
| 5517 | } |
| 5518 | return isAllowed; |
| 5519 | } |
| 5520 | |
| 5521 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5522 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5523 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5524 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5525 | final long identity = Binder.clearCallingIdentity(); |
| 5526 | try { |
| 5527 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 5528 | if (slots == null) { |
| 5529 | Rlog.i(LOG_TAG, "slots is null."); |
| 5530 | return null; |
| 5531 | } |
| 5532 | |
| 5533 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 5534 | for (int i = 0; i < slots.length; i++) { |
| 5535 | UiccSlot slot = slots[i]; |
| 5536 | if (slot == null) { |
| 5537 | continue; |
| 5538 | } |
| 5539 | |
| 5540 | String cardId; |
| 5541 | UiccCard card = slot.getUiccCard(); |
| 5542 | if (card != null) { |
| 5543 | cardId = card.getCardId(); |
| 5544 | } else { |
| 5545 | cardId = slot.getIccId(); |
| 5546 | } |
| 5547 | |
| 5548 | int cardState = 0; |
| 5549 | switch (slot.getCardState()) { |
| 5550 | case CARDSTATE_ABSENT: |
| 5551 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 5552 | break; |
| 5553 | case CARDSTATE_PRESENT: |
| 5554 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 5555 | break; |
| 5556 | case CARDSTATE_ERROR: |
| 5557 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 5558 | break; |
| 5559 | case CARDSTATE_RESTRICTED: |
| 5560 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 5561 | break; |
| 5562 | default: |
| 5563 | break; |
| 5564 | |
| 5565 | } |
| 5566 | |
| 5567 | infos[i] = new UiccSlotInfo( |
| 5568 | slot.isActive(), |
| 5569 | slot.isEuicc(), |
| 5570 | cardId, |
| 5571 | cardState, |
| 5572 | slot.getPhoneId(), |
| 5573 | slot.isExtendedApduSupported()); |
| 5574 | } |
| 5575 | return infos; |
| 5576 | } finally { |
| 5577 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 5578 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5579 | } |
| 5580 | |
| 5581 | @Override |
| 5582 | public boolean switchSlots(int[] physicalSlots) { |
| 5583 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5584 | |
| 5585 | final long identity = Binder.clearCallingIdentity(); |
| 5586 | try { |
| 5587 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 5588 | } finally { |
| 5589 | Binder.restoreCallingIdentity(identity); |
| 5590 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5591 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 5592 | |
| 5593 | @Override |
| 5594 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 5595 | enforceModifyPermission(); |
| 5596 | final Phone phone = getPhone(subId); |
| 5597 | if (phone == null) { |
| 5598 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 5599 | return; |
| 5600 | } |
| 5601 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5602 | final long identity = Binder.clearCallingIdentity(); |
| 5603 | try { |
| 5604 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 5605 | } finally { |
| 5606 | Binder.restoreCallingIdentity(identity); |
| 5607 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 5608 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5609 | |
| 5610 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 5611 | * A test API to reload the UICC profile. |
| 5612 | * |
| 5613 | * <p>Requires that the calling app has permission |
| 5614 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5615 | * @hide |
| 5616 | */ |
| 5617 | @Override |
| 5618 | public void refreshUiccProfile(int subId) { |
| 5619 | enforceModifyPermission(); |
| 5620 | |
| 5621 | final long identity = Binder.clearCallingIdentity(); |
| 5622 | try { |
| 5623 | Phone phone = getPhone(subId); |
| 5624 | if (phone == null) { |
| 5625 | return; |
| 5626 | } |
| 5627 | UiccCard uiccCard = phone.getUiccCard(); |
| 5628 | if (uiccCard == null) { |
| 5629 | return; |
| 5630 | } |
| 5631 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 5632 | if (uiccProfile == null) { |
| 5633 | return; |
| 5634 | } |
| 5635 | uiccProfile.refresh(); |
| 5636 | } finally { |
| 5637 | Binder.restoreCallingIdentity(identity); |
| 5638 | } |
| 5639 | } |
| 5640 | |
| 5641 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5642 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 5643 | */ |
| 5644 | private boolean getDefaultDataEnabled() { |
| 5645 | return "true".equalsIgnoreCase( |
| 5646 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 5647 | } |
| 5648 | |
| 5649 | /** |
| 5650 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 5651 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 5652 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 5653 | */ |
| 5654 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 5655 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
| 5656 | mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| 5657 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 5658 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 5659 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 5660 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 5661 | return isDataRoamingEnabled; |
| 5662 | } |
| 5663 | |
| 5664 | /** |
| 5665 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 5666 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 5667 | */ |
| 5668 | private int getDefaultNetworkType(int subId) { |
| 5669 | return Integer.parseInt( |
| 5670 | TelephonyManager.getTelephonyProperty( |
| 5671 | mSubscriptionController.getPhoneId(subId), |
| 5672 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 5673 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 5674 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5675 | |
| 5676 | @Override |
| 5677 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
| 5678 | gid1, String gid2, String plmn, String spn) { |
| 5679 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5680 | |
| 5681 | final long identity = Binder.clearCallingIdentity(); |
| 5682 | try { |
| 5683 | final Phone phone = getPhone(subId); |
| 5684 | if (phone == null) { |
| 5685 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 5686 | return; |
| 5687 | } |
| 5688 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn); |
| 5689 | } finally { |
| 5690 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5691 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5692 | } |
| 5693 | |
| 5694 | @Override |
| 5695 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5696 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5697 | |
| 5698 | final long identity = Binder.clearCallingIdentity(); |
| 5699 | try { |
| 5700 | final Phone phone = getPhone(subId); |
| 5701 | if (phone == null) { |
| 5702 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 5703 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 5704 | } |
| 5705 | return phone.getCarrierIdListVersion(); |
| 5706 | } finally { |
| 5707 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5708 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 5709 | } |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 5710 | |
| 5711 | @Override |
| 5712 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 5713 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5714 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 5715 | return -1; |
| 5716 | } |
| 5717 | |
| 5718 | final long identity = Binder.clearCallingIdentity(); |
| 5719 | try { |
| 5720 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 5721 | } finally { |
| 5722 | Binder.restoreCallingIdentity(identity); |
| 5723 | } |
| 5724 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5725 | |
| 5726 | @Override |
| 5727 | public int getCdmaRoamingMode(int subId) { |
| 5728 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5729 | mApp, subId, "getCdmaRoamingMode"); |
| 5730 | |
| 5731 | final long identity = Binder.clearCallingIdentity(); |
| 5732 | try { |
| 5733 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 5734 | } finally { |
| 5735 | Binder.restoreCallingIdentity(identity); |
| 5736 | } |
| 5737 | } |
| 5738 | |
| 5739 | @Override |
| 5740 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 5741 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5742 | mApp, subId, "setCdmaRoamingMode"); |
| 5743 | |
| 5744 | final long identity = Binder.clearCallingIdentity(); |
| 5745 | try { |
| 5746 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 5747 | } finally { |
| 5748 | Binder.restoreCallingIdentity(identity); |
| 5749 | } |
| 5750 | } |
| 5751 | |
| 5752 | @Override |
| 5753 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 5754 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5755 | mApp, subId, "setCdmaSubscriptionMode"); |
| 5756 | |
| 5757 | final long identity = Binder.clearCallingIdentity(); |
| 5758 | try { |
| 5759 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 5760 | } finally { |
| 5761 | Binder.restoreCallingIdentity(identity); |
| 5762 | } |
| 5763 | } |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 5764 | |
| 5765 | @Override |
| 5766 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 5767 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 5768 | Phone phone = getPhone(subId); |
| 5769 | if (phone == null) { |
| 5770 | return null; |
| 5771 | } |
| 5772 | final long identity = Binder.clearCallingIdentity(); |
| 5773 | try { |
| 5774 | UiccProfile profile = UiccController.getInstance() |
| 5775 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 5776 | if (profile != null) { |
| 5777 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 5778 | } |
| 5779 | } finally { |
| 5780 | Binder.restoreCallingIdentity(identity); |
| 5781 | } |
| 5782 | return null; |
| 5783 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5784 | } |