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; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 28 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 29 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 30 | import android.content.pm.PackageManager; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 31 | import android.net.NetworkStats; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 32 | import android.net.Uri; |
| 33 | import android.os.AsyncResult; |
| 34 | import android.os.Binder; |
| 35 | import android.os.Bundle; |
| 36 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 37 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.os.Looper; |
| 39 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 40 | import android.os.Messenger; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 41 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 42 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 43 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.os.ServiceManager; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 45 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 46 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 47 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 48 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 49 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 50 | import android.provider.Settings; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 51 | import android.service.carrier.CarrierIdentifier; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 52 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 53 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 54 | import android.telecom.TelecomManager; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 55 | import android.telephony.CarrierConfigManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 56 | import android.telephony.CellInfo; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 57 | import android.telephony.ClientRequestStats; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 58 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 59 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 60 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 61 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 62 | import android.telephony.NetworkScanRequest; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 63 | import android.telephony.RadioAccessFamily; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 64 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 65 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 66 | import android.telephony.SignalStrength; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 67 | import android.telephony.SmsManager; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 68 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 69 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 70 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 71 | import android.telephony.TelephonyManager; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 72 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 73 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 74 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 75 | import android.telephony.ims.aidl.IImsConfig; |
| 76 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 77 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 78 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 79 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 80 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 81 | import android.util.ArraySet; |
Tyler Gunn | 6707357 | 2018-02-14 14:19:42 -0800 | [diff] [blame] | 82 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 83 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 84 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 85 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 86 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 87 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 88 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 89 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 90 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 91 | import com.android.internal.telephony.CarrierInfoManager; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 92 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 93 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 94 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 95 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 96 | import com.android.internal.telephony.IccCard; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 97 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 98 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 99 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 100 | import com.android.internal.telephony.Phone; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 101 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 102 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 103 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 104 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 105 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 106 | import com.android.internal.telephony.RILConstants; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 107 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 108 | import com.android.internal.telephony.TelephonyPermissions; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 109 | import com.android.internal.telephony.TelephonyProperties; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 110 | import com.android.internal.telephony.euicc.EuiccConnector; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 111 | import com.android.internal.telephony.uicc.IccIoResult; |
| 112 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 113 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 114 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 115 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 116 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 117 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 118 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 119 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 120 | import com.android.internal.util.HexDump; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 121 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 122 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 123 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 124 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 125 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 126 | import java.io.FileDescriptor; |
| 127 | import java.io.PrintWriter; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 128 | import java.nio.charset.StandardCharsets; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 129 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 130 | import java.util.Arrays; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 131 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 132 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 133 | import java.util.Map; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 134 | |
| 135 | /** |
| 136 | * Implementation of the ITelephony interface. |
| 137 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 138 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 139 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 140 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 141 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 142 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 143 | |
| 144 | // Message codes used with mMainThreadHandler |
| 145 | private static final int CMD_HANDLE_PIN_MMI = 1; |
| 146 | private static final int CMD_HANDLE_NEIGHBORING_CELL = 2; |
| 147 | private static final int EVENT_NEIGHBORING_CELL_DONE = 3; |
| 148 | private static final int CMD_ANSWER_RINGING_CALL = 4; |
| 149 | private static final int CMD_END_CALL = 5; // not used yet |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 150 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 151 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 152 | private static final int CMD_OPEN_CHANNEL = 9; |
| 153 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 154 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 155 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 156 | private static final int CMD_NV_READ_ITEM = 13; |
| 157 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 158 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 159 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 160 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 161 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
| 162 | private static final int CMD_NV_RESET_CONFIG = 19; |
| 163 | private static final int EVENT_NV_RESET_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 164 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 165 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 166 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 167 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 168 | private static final int CMD_SEND_ENVELOPE = 25; |
| 169 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 170 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 171 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 172 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 173 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 174 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 175 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 176 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 177 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 178 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 179 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 180 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 181 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 182 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 183 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 184 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 185 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 186 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 187 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 188 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 189 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 190 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 191 | private static final int CMD_SWITCH_SLOTS = 50; |
| 192 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 193 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 194 | // Parameters of select command. |
| 195 | private static final int SELECT_COMMAND = 0xA4; |
| 196 | private static final int SELECT_P1 = 0x04; |
| 197 | private static final int SELECT_P2 = 0; |
| 198 | private static final int SELECT_P3 = 0x10; |
| 199 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 200 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 201 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 202 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 203 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 204 | /** The singleton instance. */ |
| 205 | private static PhoneInterfaceManager sInstance; |
| 206 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 207 | private PhoneGlobals mApp; |
| 208 | private Phone mPhone; |
| 209 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 210 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 211 | private AppOpsManager mAppOps; |
| 212 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 213 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 214 | private SharedPreferences mTelephonySharedPreferences; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 215 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 216 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 217 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 218 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 219 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 220 | // The AID of ISD-R. |
| 221 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 222 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 223 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 224 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 225 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 226 | * A request object to use for transmitting data to an ICC. |
| 227 | */ |
| 228 | private static final class IccAPDUArgument { |
| 229 | public int channel, cla, command, p1, p2, p3; |
| 230 | public String data; |
| 231 | |
| 232 | public IccAPDUArgument(int channel, int cla, int command, |
| 233 | int p1, int p2, int p3, String data) { |
| 234 | this.channel = channel; |
| 235 | this.cla = cla; |
| 236 | this.command = command; |
| 237 | this.p1 = p1; |
| 238 | this.p2 = p2; |
| 239 | this.p3 = p3; |
| 240 | this.data = data; |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 245 | * A request object to use for transmitting data to an ICC. |
| 246 | */ |
| 247 | private static final class ManualNetworkSelectionArgument { |
| 248 | public OperatorInfo operatorInfo; |
| 249 | public boolean persistSelection; |
| 250 | |
| 251 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 252 | this.operatorInfo = operatorInfo; |
| 253 | this.persistSelection = persistSelection; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 258 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 259 | * request after sending. The main thread will notify the request when it is complete. |
| 260 | */ |
| 261 | private static final class MainThreadRequest { |
| 262 | /** The argument to use for the request */ |
| 263 | public Object argument; |
| 264 | /** The result of the request that is run on the main thread */ |
| 265 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 266 | // The subscriber id that this request applies to. Defaults to |
| 267 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 268 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 269 | |
| 270 | public MainThreadRequest(Object argument) { |
| 271 | this.argument = argument; |
| 272 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 273 | |
| 274 | public MainThreadRequest(Object argument, Integer subId) { |
| 275 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 276 | if (subId != null) { |
| 277 | this.subId = subId; |
| 278 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 279 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 282 | private static final class IncomingThirdPartyCallArgs { |
| 283 | public final ComponentName component; |
| 284 | public final String callId; |
| 285 | public final String callerDisplayName; |
| 286 | |
| 287 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 288 | String callerDisplayName) { |
| 289 | this.component = component; |
| 290 | this.callId = callId; |
| 291 | this.callerDisplayName = callerDisplayName; |
| 292 | } |
| 293 | } |
| 294 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 295 | /** |
| 296 | * A handler that processes messages on the main thread in the phone process. Since many |
| 297 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 298 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 299 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 300 | * on, which will be notified when the operation completes and will contain the result of the |
| 301 | * request. |
| 302 | * |
| 303 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 304 | * note that request.result must be set to something non-null for the calling thread to |
| 305 | * unblock. |
| 306 | */ |
| 307 | private final class MainThreadHandler extends Handler { |
| 308 | @Override |
| 309 | public void handleMessage(Message msg) { |
| 310 | MainThreadRequest request; |
| 311 | Message onCompleted; |
| 312 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 313 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 314 | IccAPDUArgument iccArgument; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 315 | |
| 316 | switch (msg.what) { |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 317 | case CMD_HANDLE_USSD_REQUEST: { |
| 318 | request = (MainThreadRequest) msg.obj; |
| 319 | final Phone phone = getPhoneFromRequest(request); |
| 320 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 321 | String ussdRequest = ussdObject.first; |
| 322 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 323 | |
| 324 | if (!isUssdApiAllowed(request.subId)) { |
| 325 | // Carrier does not support use of this API, return failure. |
| 326 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 327 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 328 | Bundle returnData = new Bundle(); |
| 329 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 330 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
| 331 | |
| 332 | request.result = true; |
| 333 | synchronized (request) { |
| 334 | request.notifyAll(); |
| 335 | } |
| 336 | return; |
| 337 | } |
| 338 | |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 339 | try { |
| 340 | request.result = phone != null ? |
| 341 | phone.handleUssdRequest(ussdRequest, wrappedCallback) |
| 342 | : false; |
| 343 | } catch (CallStateException cse) { |
| 344 | request.result = false; |
| 345 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 346 | // Wake up the requesting thread |
| 347 | synchronized (request) { |
| 348 | request.notifyAll(); |
| 349 | } |
| 350 | break; |
| 351 | } |
| 352 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 353 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 354 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 355 | final Phone phone = getPhoneFromRequest(request); |
| 356 | request.result = phone != null ? |
| 357 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 358 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 359 | // Wake up the requesting thread |
| 360 | synchronized (request) { |
| 361 | request.notifyAll(); |
| 362 | } |
| 363 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 364 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 365 | |
| 366 | case CMD_HANDLE_NEIGHBORING_CELL: |
| 367 | request = (MainThreadRequest) msg.obj; |
| 368 | onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE, |
| 369 | request); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 370 | mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 371 | break; |
| 372 | |
| 373 | case EVENT_NEIGHBORING_CELL_DONE: |
| 374 | ar = (AsyncResult) msg.obj; |
| 375 | request = (MainThreadRequest) ar.userObj; |
| 376 | if (ar.exception == null && ar.result != null) { |
| 377 | request.result = ar.result; |
| 378 | } else { |
| 379 | // create an empty list to notify the waiting thread |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 380 | request.result = new ArrayList<NeighboringCellInfo>(0); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 381 | } |
| 382 | // Wake up the requesting thread |
| 383 | synchronized (request) { |
| 384 | request.notifyAll(); |
| 385 | } |
| 386 | break; |
| 387 | |
| 388 | case CMD_ANSWER_RINGING_CALL: |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 389 | request = (MainThreadRequest) msg.obj; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 390 | int answer_subId = request.subId; |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 391 | answerRingingCallInternal(answer_subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 392 | break; |
| 393 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 394 | case CMD_END_CALL: |
| 395 | request = (MainThreadRequest) msg.obj; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 396 | int end_subId = request.subId; |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 397 | final boolean hungUp; |
Anthony Lee | ae4e36d | 2015-05-21 07:17:46 -0700 | [diff] [blame] | 398 | Phone phone = getPhone(end_subId); |
| 399 | if (phone == null) { |
| 400 | if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId); |
| 401 | break; |
| 402 | } |
| 403 | int phoneType = phone.getPhoneType(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 404 | if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { |
| 405 | // CDMA: If the user presses the Power button we treat it as |
| 406 | // ending the complete call session |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 407 | hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId)); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 408 | } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) { |
| 409 | // GSM: End the call as per the Phone state |
| 410 | hungUp = PhoneUtils.hangup(mCM); |
| 411 | } else { |
| 412 | throw new IllegalStateException("Unexpected phone type: " + phoneType); |
| 413 | } |
| 414 | if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up")); |
| 415 | request.result = hungUp; |
| 416 | // Wake up the requesting thread |
| 417 | synchronized (request) { |
| 418 | request.notifyAll(); |
| 419 | } |
| 420 | break; |
| 421 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 422 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 423 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 424 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 425 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 426 | if (uiccCard == null) { |
| 427 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 428 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 429 | synchronized (request) { |
| 430 | request.notifyAll(); |
| 431 | } |
| 432 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 433 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 434 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 435 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 436 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 437 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 438 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 439 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 440 | break; |
| 441 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 442 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 443 | ar = (AsyncResult) msg.obj; |
| 444 | request = (MainThreadRequest) ar.userObj; |
| 445 | if (ar.exception == null && ar.result != null) { |
| 446 | request.result = ar.result; |
| 447 | } else { |
| 448 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 449 | if (ar.result == null) { |
| 450 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 451 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 452 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 453 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 454 | } else { |
| 455 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 456 | } |
| 457 | } |
| 458 | synchronized (request) { |
| 459 | request.notifyAll(); |
| 460 | } |
| 461 | break; |
| 462 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 463 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 464 | request = (MainThreadRequest) msg.obj; |
| 465 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 466 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 467 | if (uiccCard == null) { |
| 468 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 469 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 470 | synchronized (request) { |
| 471 | request.notifyAll(); |
| 472 | } |
| 473 | } else { |
| 474 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 475 | request); |
| 476 | uiccCard.iccTransmitApduBasicChannel( |
| 477 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 478 | iccArgument.p3, iccArgument.data, onCompleted); |
| 479 | } |
| 480 | break; |
| 481 | |
| 482 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 483 | ar = (AsyncResult) msg.obj; |
| 484 | request = (MainThreadRequest) ar.userObj; |
| 485 | if (ar.exception == null && ar.result != null) { |
| 486 | request.result = ar.result; |
| 487 | } else { |
| 488 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 489 | if (ar.result == null) { |
| 490 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 491 | } else if (ar.exception instanceof CommandException) { |
| 492 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 493 | ar.exception); |
| 494 | } else { |
| 495 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 496 | } |
| 497 | } |
| 498 | synchronized (request) { |
| 499 | request.notifyAll(); |
| 500 | } |
| 501 | break; |
| 502 | |
| 503 | case CMD_EXCHANGE_SIM_IO: |
| 504 | request = (MainThreadRequest) msg.obj; |
| 505 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 506 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 507 | if (uiccCard == null) { |
| 508 | loge("iccExchangeSimIO: No UICC"); |
| 509 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 510 | synchronized (request) { |
| 511 | request.notifyAll(); |
| 512 | } |
| 513 | } else { |
| 514 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 515 | request); |
| 516 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 517 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 518 | iccArgument.data, onCompleted); |
| 519 | } |
| 520 | break; |
| 521 | |
| 522 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 523 | ar = (AsyncResult) msg.obj; |
| 524 | request = (MainThreadRequest) ar.userObj; |
| 525 | if (ar.exception == null && ar.result != null) { |
| 526 | request.result = ar.result; |
| 527 | } else { |
| 528 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 529 | } |
| 530 | synchronized (request) { |
| 531 | request.notifyAll(); |
| 532 | } |
| 533 | break; |
| 534 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 535 | case CMD_SEND_ENVELOPE: |
| 536 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 537 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 538 | if (uiccCard == null) { |
| 539 | loge("sendEnvelopeWithStatus: No UICC"); |
| 540 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 541 | synchronized (request) { |
| 542 | request.notifyAll(); |
| 543 | } |
| 544 | } else { |
| 545 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 546 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 547 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 548 | break; |
| 549 | |
| 550 | case EVENT_SEND_ENVELOPE_DONE: |
| 551 | ar = (AsyncResult) msg.obj; |
| 552 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 553 | if (ar.exception == null && ar.result != null) { |
| 554 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 555 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 556 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 557 | if (ar.result == null) { |
| 558 | loge("sendEnvelopeWithStatus: Empty response"); |
| 559 | } else if (ar.exception instanceof CommandException) { |
| 560 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 561 | ar.exception); |
| 562 | } else { |
| 563 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 564 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 565 | } |
| 566 | synchronized (request) { |
| 567 | request.notifyAll(); |
| 568 | } |
| 569 | break; |
| 570 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 571 | case CMD_OPEN_CHANNEL: |
| 572 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 573 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 574 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 575 | if (uiccCard == null) { |
| 576 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 577 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 578 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 579 | synchronized (request) { |
| 580 | request.notifyAll(); |
| 581 | } |
| 582 | } else { |
| 583 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 584 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 585 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 586 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 587 | break; |
| 588 | |
| 589 | case EVENT_OPEN_CHANNEL_DONE: |
| 590 | ar = (AsyncResult) msg.obj; |
| 591 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 592 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 593 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 594 | int[] result = (int[]) ar.result; |
| 595 | int channelId = result[0]; |
| 596 | byte[] selectResponse = null; |
| 597 | if (result.length > 1) { |
| 598 | selectResponse = new byte[result.length - 1]; |
| 599 | for (int i = 1; i < result.length; ++i) { |
| 600 | selectResponse[i - 1] = (byte) result[i]; |
| 601 | } |
| 602 | } |
| 603 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 604 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 605 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 606 | if (ar.result == null) { |
| 607 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 608 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 609 | if (ar.exception != null) { |
| 610 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 611 | } |
| 612 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 613 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 614 | if (ar.exception instanceof CommandException) { |
| 615 | CommandException.Error error = |
| 616 | ((CommandException) (ar.exception)).getCommandError(); |
| 617 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 618 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 619 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 620 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 624 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 625 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 626 | request.result = openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 627 | synchronized (request) { |
| 628 | request.notifyAll(); |
| 629 | } |
| 630 | break; |
| 631 | |
| 632 | case CMD_CLOSE_CHANNEL: |
| 633 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 634 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 635 | if (uiccCard == null) { |
| 636 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 637 | request.result = false; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 638 | synchronized (request) { |
| 639 | request.notifyAll(); |
| 640 | } |
| 641 | } else { |
| 642 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 643 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 644 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 645 | break; |
| 646 | |
| 647 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 648 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 649 | break; |
| 650 | |
| 651 | case CMD_NV_READ_ITEM: |
| 652 | request = (MainThreadRequest) msg.obj; |
| 653 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
| 654 | mPhone.nvReadItem((Integer) request.argument, onCompleted); |
| 655 | break; |
| 656 | |
| 657 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 658 | ar = (AsyncResult) msg.obj; |
| 659 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 660 | if (ar.exception == null && ar.result != null) { |
| 661 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 662 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 663 | request.result = ""; |
| 664 | if (ar.result == null) { |
| 665 | loge("nvReadItem: Empty response"); |
| 666 | } else if (ar.exception instanceof CommandException) { |
| 667 | loge("nvReadItem: CommandException: " + |
| 668 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 669 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 670 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 671 | } |
| 672 | } |
| 673 | synchronized (request) { |
| 674 | request.notifyAll(); |
| 675 | } |
| 676 | break; |
| 677 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 678 | case CMD_NV_WRITE_ITEM: |
| 679 | request = (MainThreadRequest) msg.obj; |
| 680 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 681 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
| 682 | mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted); |
| 683 | break; |
| 684 | |
| 685 | case EVENT_NV_WRITE_ITEM_DONE: |
| 686 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 687 | break; |
| 688 | |
| 689 | case CMD_NV_WRITE_CDMA_PRL: |
| 690 | request = (MainThreadRequest) msg.obj; |
| 691 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
| 692 | mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
| 693 | break; |
| 694 | |
| 695 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 696 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 697 | break; |
| 698 | |
| 699 | case CMD_NV_RESET_CONFIG: |
| 700 | request = (MainThreadRequest) msg.obj; |
| 701 | onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request); |
| 702 | mPhone.nvResetConfig((Integer) request.argument, onCompleted); |
| 703 | break; |
| 704 | |
| 705 | case EVENT_NV_RESET_CONFIG_DONE: |
| 706 | handleNullReturnEvent(msg, "nvResetConfig"); |
| 707 | break; |
| 708 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 709 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 710 | request = (MainThreadRequest) msg.obj; |
| 711 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 712 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 713 | break; |
| 714 | |
| 715 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 716 | ar = (AsyncResult) msg.obj; |
| 717 | request = (MainThreadRequest) ar.userObj; |
| 718 | if (ar.exception == null && ar.result != null) { |
| 719 | request.result = ar.result; // Integer |
| 720 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 721 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 722 | if (ar.result == null) { |
| 723 | loge("getPreferredNetworkType: Empty response"); |
| 724 | } else if (ar.exception instanceof CommandException) { |
| 725 | loge("getPreferredNetworkType: CommandException: " + |
| 726 | ar.exception); |
| 727 | } else { |
| 728 | loge("getPreferredNetworkType: Unknown exception"); |
| 729 | } |
| 730 | } |
| 731 | synchronized (request) { |
| 732 | request.notifyAll(); |
| 733 | } |
| 734 | break; |
| 735 | |
| 736 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 737 | request = (MainThreadRequest) msg.obj; |
| 738 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 739 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 740 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 741 | break; |
| 742 | |
| 743 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 744 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 745 | break; |
| 746 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 747 | case CMD_SET_VOICEMAIL_NUMBER: |
| 748 | request = (MainThreadRequest) msg.obj; |
| 749 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 750 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 751 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 752 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 753 | break; |
| 754 | |
| 755 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 756 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 757 | break; |
| 758 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 759 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 760 | request = (MainThreadRequest) msg.obj; |
| 761 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 762 | request); |
| 763 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 764 | break; |
| 765 | |
| 766 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 767 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 768 | break; |
| 769 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 770 | case CMD_PERFORM_NETWORK_SCAN: |
| 771 | request = (MainThreadRequest) msg.obj; |
| 772 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 773 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 774 | break; |
| 775 | |
| 776 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 777 | ar = (AsyncResult) msg.obj; |
| 778 | request = (MainThreadRequest) ar.userObj; |
| 779 | CellNetworkScanResult cellScanResult; |
| 780 | if (ar.exception == null && ar.result != null) { |
| 781 | cellScanResult = new CellNetworkScanResult( |
| 782 | CellNetworkScanResult.STATUS_SUCCESS, |
| 783 | (List<OperatorInfo>) ar.result); |
| 784 | } else { |
| 785 | if (ar.result == null) { |
| 786 | loge("getCellNetworkScanResults: Empty response"); |
| 787 | } |
| 788 | if (ar.exception != null) { |
| 789 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 790 | } |
| 791 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 792 | if (ar.exception instanceof CommandException) { |
| 793 | CommandException.Error error = |
| 794 | ((CommandException) (ar.exception)).getCommandError(); |
| 795 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 796 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 797 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 798 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 799 | } |
| 800 | } |
| 801 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 802 | } |
| 803 | request.result = cellScanResult; |
| 804 | synchronized (request) { |
| 805 | request.notifyAll(); |
| 806 | } |
| 807 | break; |
| 808 | |
| 809 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 810 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 811 | ManualNetworkSelectionArgument selArg = |
| 812 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 813 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 814 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 815 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 816 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 817 | break; |
| 818 | |
| 819 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
| 820 | handleNullReturnEvent(msg, "setNetworkSelectionModeManual"); |
| 821 | break; |
| 822 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 823 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 824 | request = (MainThreadRequest) msg.obj; |
| 825 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
Prerepa Viswanadham | 61a60ad | 2015-06-08 18:07:51 -0700 | [diff] [blame] | 826 | mPhone.getModemActivityInfo(onCompleted); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 827 | break; |
| 828 | |
| 829 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 830 | ar = (AsyncResult) msg.obj; |
| 831 | request = (MainThreadRequest) ar.userObj; |
| 832 | if (ar.exception == null && ar.result != null) { |
| 833 | request.result = ar.result; |
| 834 | } else { |
| 835 | if (ar.result == null) { |
| 836 | loge("queryModemActivityInfo: Empty response"); |
| 837 | } else if (ar.exception instanceof CommandException) { |
| 838 | loge("queryModemActivityInfo: CommandException: " + |
| 839 | ar.exception); |
| 840 | } else { |
| 841 | loge("queryModemActivityInfo: Unknown exception"); |
| 842 | } |
| 843 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 844 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 845 | if (request.result == null) { |
| 846 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 847 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 848 | synchronized (request) { |
| 849 | request.notifyAll(); |
| 850 | } |
| 851 | break; |
| 852 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 853 | case CMD_SET_ALLOWED_CARRIERS: |
| 854 | request = (MainThreadRequest) msg.obj; |
| 855 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
| 856 | mPhone.setAllowedCarriers( |
| 857 | (List<CarrierIdentifier>) request.argument, |
| 858 | onCompleted); |
| 859 | break; |
| 860 | |
| 861 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 862 | ar = (AsyncResult) msg.obj; |
| 863 | request = (MainThreadRequest) ar.userObj; |
| 864 | if (ar.exception == null && ar.result != null) { |
| 865 | request.result = ar.result; |
| 866 | } else { |
| 867 | if (ar.result == null) { |
| 868 | loge("setAllowedCarriers: Empty response"); |
| 869 | } else if (ar.exception instanceof CommandException) { |
| 870 | loge("setAllowedCarriers: CommandException: " + |
| 871 | ar.exception); |
| 872 | } else { |
| 873 | loge("setAllowedCarriers: Unknown exception"); |
| 874 | } |
| 875 | } |
| 876 | // Result cannot be null. Return -1 on error. |
| 877 | if (request.result == null) { |
| 878 | request.result = new int[]{-1}; |
| 879 | } |
| 880 | synchronized (request) { |
| 881 | request.notifyAll(); |
| 882 | } |
| 883 | break; |
| 884 | |
| 885 | case CMD_GET_ALLOWED_CARRIERS: |
| 886 | request = (MainThreadRequest) msg.obj; |
| 887 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
| 888 | mPhone.getAllowedCarriers(onCompleted); |
| 889 | break; |
| 890 | |
| 891 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 892 | ar = (AsyncResult) msg.obj; |
| 893 | request = (MainThreadRequest) ar.userObj; |
| 894 | if (ar.exception == null && ar.result != null) { |
| 895 | request.result = ar.result; |
| 896 | } else { |
| 897 | if (ar.result == null) { |
| 898 | loge("getAllowedCarriers: Empty response"); |
| 899 | } else if (ar.exception instanceof CommandException) { |
| 900 | loge("getAllowedCarriers: CommandException: " + |
| 901 | ar.exception); |
| 902 | } else { |
| 903 | loge("getAllowedCarriers: Unknown exception"); |
| 904 | } |
| 905 | } |
| 906 | // Result cannot be null. Return empty list of CarrierIdentifier. |
| 907 | if (request.result == null) { |
| 908 | request.result = new ArrayList<CarrierIdentifier>(0); |
| 909 | } |
| 910 | synchronized (request) { |
| 911 | request.notifyAll(); |
| 912 | } |
| 913 | break; |
| 914 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 915 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 916 | ar = (AsyncResult) msg.obj; |
| 917 | request = (MainThreadRequest) ar.userObj; |
| 918 | if (ar.exception == null && ar.result != null) { |
| 919 | request.result = ar.result; |
| 920 | } else { |
| 921 | request.result = new IllegalArgumentException( |
| 922 | "Failed to retrieve Forbidden Plmns"); |
| 923 | if (ar.result == null) { |
| 924 | loge("getForbiddenPlmns: Empty response"); |
| 925 | } else { |
| 926 | loge("getForbiddenPlmns: Unknown exception"); |
| 927 | } |
| 928 | } |
| 929 | synchronized (request) { |
| 930 | request.notifyAll(); |
| 931 | } |
| 932 | break; |
| 933 | |
| 934 | case CMD_GET_FORBIDDEN_PLMNS: |
| 935 | request = (MainThreadRequest) msg.obj; |
| 936 | uiccCard = getUiccCardFromRequest(request); |
| 937 | if (uiccCard == null) { |
| 938 | loge("getForbiddenPlmns() UiccCard is null"); |
| 939 | request.result = new IllegalArgumentException( |
| 940 | "getForbiddenPlmns() UiccCard is null"); |
| 941 | synchronized (request) { |
| 942 | request.notifyAll(); |
| 943 | } |
| 944 | break; |
| 945 | } |
| 946 | Integer appType = (Integer) request.argument; |
| 947 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 948 | if (uiccApp == null) { |
| 949 | loge("getForbiddenPlmns() no app with specified type -- " |
| 950 | + appType); |
| 951 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
| 952 | synchronized (request) { |
| 953 | request.notifyAll(); |
| 954 | } |
| 955 | break; |
| 956 | } else { |
| 957 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 958 | + " specified type -- " + appType); |
| 959 | } |
| 960 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 961 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 962 | onCompleted); |
| 963 | break; |
| 964 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 965 | case CMD_SWITCH_SLOTS: |
| 966 | request = (MainThreadRequest) msg.obj; |
| 967 | int[] physicalSlots = (int[]) request.argument; |
| 968 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 969 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 970 | break; |
| 971 | |
| 972 | case EVENT_SWITCH_SLOTS_DONE: |
| 973 | ar = (AsyncResult) msg.obj; |
| 974 | request = (MainThreadRequest) ar.userObj; |
| 975 | request.result = (ar.exception == null); |
| 976 | synchronized (request) { |
| 977 | request.notifyAll(); |
| 978 | } |
| 979 | break; |
| 980 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 981 | default: |
| 982 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 983 | break; |
| 984 | } |
| 985 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 986 | |
| 987 | private void handleNullReturnEvent(Message msg, String command) { |
| 988 | AsyncResult ar = (AsyncResult) msg.obj; |
| 989 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 990 | if (ar.exception == null) { |
| 991 | request.result = true; |
| 992 | } else { |
| 993 | request.result = false; |
| 994 | if (ar.exception instanceof CommandException) { |
| 995 | loge(command + ": CommandException: " + ar.exception); |
| 996 | } else { |
| 997 | loge(command + ": Unknown exception"); |
| 998 | } |
| 999 | } |
| 1000 | synchronized (request) { |
| 1001 | request.notifyAll(); |
| 1002 | } |
| 1003 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | /** |
| 1007 | * Posts the specified command to be executed on the main thread, |
| 1008 | * waits for the request to complete, and returns the result. |
| 1009 | * @see #sendRequestAsync |
| 1010 | */ |
| 1011 | private Object sendRequest(int command, Object argument) { |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 1012 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | /** |
| 1016 | * Posts the specified command to be executed on the main thread, |
| 1017 | * waits for the request to complete, and returns the result. |
| 1018 | * @see #sendRequestAsync |
| 1019 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1020 | private Object sendRequest(int command, Object argument, Integer subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1021 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1022 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1023 | } |
| 1024 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1025 | MainThreadRequest request = new MainThreadRequest(argument, subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1026 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1027 | msg.sendToTarget(); |
| 1028 | |
| 1029 | // Wait for the request to complete |
| 1030 | synchronized (request) { |
| 1031 | while (request.result == null) { |
| 1032 | try { |
| 1033 | request.wait(); |
| 1034 | } catch (InterruptedException e) { |
| 1035 | // Do nothing, go back and wait until the request is complete |
| 1036 | } |
| 1037 | } |
| 1038 | } |
| 1039 | return request.result; |
| 1040 | } |
| 1041 | |
| 1042 | /** |
| 1043 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1044 | * Posts the specified command to be executed on the main thread, and |
| 1045 | * returns immediately. |
| 1046 | * @see #sendRequest |
| 1047 | */ |
| 1048 | private void sendRequestAsync(int command) { |
| 1049 | mMainThreadHandler.sendEmptyMessage(command); |
| 1050 | } |
| 1051 | |
| 1052 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1053 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
| 1054 | * @see {@link #sendRequest(int,Object)} |
| 1055 | */ |
| 1056 | private void sendRequestAsync(int command, Object argument) { |
| 1057 | MainThreadRequest request = new MainThreadRequest(argument); |
| 1058 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1059 | msg.sendToTarget(); |
| 1060 | } |
| 1061 | |
| 1062 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1063 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1064 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1065 | */ |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 1066 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1067 | synchronized (PhoneInterfaceManager.class) { |
| 1068 | if (sInstance == null) { |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 1069 | sInstance = new PhoneInterfaceManager(app, phone); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1070 | } else { |
| 1071 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1072 | } |
| 1073 | return sInstance; |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | /** Private constructor; @see init() */ |
Sailesh Nepal | 194161e | 2014-07-03 08:57:44 -0700 | [diff] [blame] | 1078 | private PhoneInterfaceManager(PhoneGlobals app, Phone phone) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1079 | mApp = app; |
| 1080 | mPhone = phone; |
| 1081 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1082 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1083 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1084 | mMainThreadHandler = new MainThreadHandler(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 1085 | mTelephonySharedPreferences = |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 1086 | PreferenceManager.getDefaultSharedPreferences(mPhone.getContext()); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1087 | mSubscriptionController = SubscriptionController.getInstance(); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1088 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1089 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1090 | publish(); |
| 1091 | } |
| 1092 | |
| 1093 | private void publish() { |
| 1094 | if (DBG) log("publish: " + this); |
| 1095 | |
| 1096 | ServiceManager.addService("phone", this); |
| 1097 | } |
| 1098 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1099 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 1100 | return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1101 | ? mPhone : getPhone(request.subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1102 | } |
| 1103 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1104 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1105 | Phone phone = getPhoneFromRequest(request); |
| 1106 | return phone == null ? null : |
| 1107 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1108 | } |
| 1109 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1110 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1111 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1112 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1113 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1114 | // |
| 1115 | // Implementation of the ITelephony interface. |
| 1116 | // |
| 1117 | |
| 1118 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1119 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1120 | } |
| 1121 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1122 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1123 | if (DBG) log("dial: " + number); |
| 1124 | // No permission check needed here: This is just a wrapper around the |
| 1125 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1126 | // the UI before it does anything. |
| 1127 | |
| 1128 | String url = createTelUrl(number); |
| 1129 | if (url == null) { |
| 1130 | return; |
| 1131 | } |
| 1132 | |
| 1133 | // PENDING: should we just silently fail if phone is offhook or ringing? |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1134 | PhoneConstants.State state = mCM.getState(subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1135 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1136 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1137 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1138 | mApp.startActivity(intent); |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1143 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1144 | } |
| 1145 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1146 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1147 | if (DBG) log("call: " + number); |
| 1148 | |
| 1149 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1150 | // need to do a permission check since we're calling startActivity() |
| 1151 | // from the context of the phone app. |
| 1152 | enforceCallPermission(); |
| 1153 | |
| 1154 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1155 | != AppOpsManager.MODE_ALLOWED) { |
| 1156 | return; |
| 1157 | } |
| 1158 | |
| 1159 | String url = createTelUrl(number); |
| 1160 | if (url == null) { |
| 1161 | return; |
| 1162 | } |
| 1163 | |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1164 | boolean isValid = false; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 1165 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1166 | if (slist != null) { |
| 1167 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1168 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1169 | isValid = true; |
| 1170 | break; |
| 1171 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1172 | } |
| 1173 | } |
| 1174 | if (isValid == false) { |
| 1175 | return; |
| 1176 | } |
| 1177 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1178 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1179 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1180 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1181 | mApp.startActivity(intent); |
| 1182 | } |
| 1183 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1184 | /** |
| 1185 | * End a call based on call state |
| 1186 | * @return true is a call was ended |
| 1187 | */ |
| 1188 | public boolean endCall() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1189 | return endCallForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | /** |
| 1193 | * End a call based on the call state of the subId |
| 1194 | * @return true is a call was ended |
| 1195 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1196 | public boolean endCallForSubscriber(int subId) { |
Tyler Gunn | 6707357 | 2018-02-14 14:19:42 -0800 | [diff] [blame] | 1197 | if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE) |
| 1198 | != PackageManager.PERMISSION_GRANTED) { |
| 1199 | Log.i(LOG_TAG, "endCall: called without modify phone state."); |
| 1200 | EventLog.writeEvent(0x534e4554, "67862398", -1, ""); |
| 1201 | throw new SecurityException("MODIFY_PHONE_STATE permission required."); |
| 1202 | } |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1203 | return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId)); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | public void answerRingingCall() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1207 | answerRingingCallForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1210 | public void answerRingingCallForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1211 | if (DBG) log("answerRingingCall..."); |
| 1212 | // TODO: there should eventually be a separate "ANSWER_PHONE" permission, |
| 1213 | // but that can probably wait till the big TelephonyManager API overhaul. |
| 1214 | // For now, protect this call with the MODIFY_PHONE_STATE permission. |
| 1215 | enforceModifyPermission(); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1216 | sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId)); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | /** |
| 1220 | * Make the actual telephony calls to implement answerRingingCall(). |
| 1221 | * This should only be called from the main thread of the Phone app. |
| 1222 | * @see #answerRingingCall |
| 1223 | * |
| 1224 | * TODO: it would be nice to return true if we answered the call, or |
| 1225 | * false if there wasn't actually a ringing incoming call, or some |
| 1226 | * other error occurred. (In other words, pass back the return value |
| 1227 | * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().) |
| 1228 | * But that would require calling this method via sendRequest() rather |
| 1229 | * than sendRequestAsync(), and right now we don't actually *need* that |
| 1230 | * return value, so let's just return void for now. |
| 1231 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1232 | private void answerRingingCallInternal(int subId) { |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1233 | final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1234 | if (hasRingingCall) { |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1235 | final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle(); |
| 1236 | final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1237 | if (hasActiveCall && hasHoldingCall) { |
| 1238 | // Both lines are in use! |
| 1239 | // TODO: provide a flag to let the caller specify what |
| 1240 | // policy to use if both lines are in use. (The current |
| 1241 | // behavior is hardwired to "answer incoming, end ongoing", |
| 1242 | // which is how the CALL button is specced to behave.) |
| 1243 | PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall()); |
| 1244 | return; |
| 1245 | } else { |
| 1246 | // answerCall() will automatically hold the current active |
| 1247 | // call, if there is one. |
| 1248 | PhoneUtils.answerCall(mCM.getFirstActiveRingingCall()); |
| 1249 | return; |
| 1250 | } |
| 1251 | } else { |
| 1252 | // No call was ringing. |
| 1253 | return; |
| 1254 | } |
| 1255 | } |
| 1256 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1257 | /** |
Santos Cordon | 5422a8d | 2014-09-12 04:20:56 -0700 | [diff] [blame] | 1258 | * This method is no longer used and can be removed once TelephonyManager stops referring to it. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1259 | */ |
Santos Cordon | 5422a8d | 2014-09-12 04:20:56 -0700 | [diff] [blame] | 1260 | public void silenceRinger() { |
| 1261 | Log.e(LOG_TAG, "silenseRinger not supported"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1264 | @Override |
| 1265 | public boolean isOffhook(String callingPackage) { |
| 1266 | return isOffhookForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1267 | } |
| 1268 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1269 | @Override |
| 1270 | public boolean isOffhookForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1271 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1272 | mApp, subId, callingPackage, "isOffhookForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1273 | return false; |
| 1274 | } |
| 1275 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1276 | final Phone phone = getPhone(subId); |
| 1277 | if (phone != null) { |
| 1278 | return (phone.getState() == PhoneConstants.State.OFFHOOK); |
| 1279 | } else { |
| 1280 | return false; |
| 1281 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1284 | @Override |
| 1285 | public boolean isRinging(String callingPackage) { |
| 1286 | return (isRingingForSubscriber(getDefaultSubscription(), callingPackage)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1287 | } |
| 1288 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1289 | @Override |
| 1290 | public boolean isRingingForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1291 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1292 | mApp, subId, callingPackage, "isRingingForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1293 | return false; |
| 1294 | } |
| 1295 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1296 | final Phone phone = getPhone(subId); |
| 1297 | if (phone != null) { |
| 1298 | return (phone.getState() == PhoneConstants.State.RINGING); |
| 1299 | } else { |
| 1300 | return false; |
| 1301 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1304 | @Override |
| 1305 | public boolean isIdle(String callingPackage) { |
| 1306 | return isIdleForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1307 | } |
| 1308 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1309 | @Override |
| 1310 | public boolean isIdleForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1311 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1312 | mApp, subId, callingPackage, "isIdleForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1313 | return false; |
| 1314 | } |
| 1315 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1316 | final Phone phone = getPhone(subId); |
| 1317 | if (phone != null) { |
| 1318 | return (phone.getState() == PhoneConstants.State.IDLE); |
| 1319 | } else { |
| 1320 | return false; |
| 1321 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1322 | } |
| 1323 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1324 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1325 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1328 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1329 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1330 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1331 | } |
| 1332 | |
| 1333 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1334 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1335 | } |
| 1336 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1337 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1338 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1339 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1340 | } |
| 1341 | |
| 1342 | /** {@hide} */ |
| 1343 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1344 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1347 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1348 | enforceModifyPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1349 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1350 | checkSimPin.start(); |
| 1351 | return checkSimPin.unlockSim(null, pin); |
| 1352 | } |
| 1353 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1354 | /** {@hide} */ |
| 1355 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1356 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1357 | } |
| 1358 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1359 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1360 | enforceModifyPermission(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1361 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1362 | checkSimPuk.start(); |
| 1363 | return checkSimPuk.unlockSim(puk, pin); |
| 1364 | } |
| 1365 | |
| 1366 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1367 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1368 | * a synchronous one. |
| 1369 | */ |
| 1370 | private static class UnlockSim extends Thread { |
| 1371 | |
| 1372 | private final IccCard mSimCard; |
| 1373 | |
| 1374 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1375 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1376 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1377 | |
| 1378 | // For replies from SimCard interface |
| 1379 | private Handler mHandler; |
| 1380 | |
| 1381 | // For async handler to identify request type |
| 1382 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1383 | |
| 1384 | public UnlockSim(IccCard simCard) { |
| 1385 | mSimCard = simCard; |
| 1386 | } |
| 1387 | |
| 1388 | @Override |
| 1389 | public void run() { |
| 1390 | Looper.prepare(); |
| 1391 | synchronized (UnlockSim.this) { |
| 1392 | mHandler = new Handler() { |
| 1393 | @Override |
| 1394 | public void handleMessage(Message msg) { |
| 1395 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1396 | switch (msg.what) { |
| 1397 | case SUPPLY_PIN_COMPLETE: |
| 1398 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1399 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1400 | mRetryCount = msg.arg1; |
| 1401 | if (ar.exception != null) { |
| 1402 | if (ar.exception instanceof CommandException && |
| 1403 | ((CommandException)(ar.exception)).getCommandError() |
| 1404 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1405 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1406 | } else { |
| 1407 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1408 | } |
| 1409 | } else { |
| 1410 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1411 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1412 | mDone = true; |
| 1413 | UnlockSim.this.notifyAll(); |
| 1414 | } |
| 1415 | break; |
| 1416 | } |
| 1417 | } |
| 1418 | }; |
| 1419 | UnlockSim.this.notifyAll(); |
| 1420 | } |
| 1421 | Looper.loop(); |
| 1422 | } |
| 1423 | |
| 1424 | /* |
| 1425 | * Use PIN or PUK to unlock SIM card |
| 1426 | * |
| 1427 | * If PUK is null, unlock SIM card with PIN |
| 1428 | * |
| 1429 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1430 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1431 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1432 | |
| 1433 | while (mHandler == null) { |
| 1434 | try { |
| 1435 | wait(); |
| 1436 | } catch (InterruptedException e) { |
| 1437 | Thread.currentThread().interrupt(); |
| 1438 | } |
| 1439 | } |
| 1440 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1441 | |
| 1442 | if (puk == null) { |
| 1443 | mSimCard.supplyPin(pin, callback); |
| 1444 | } else { |
| 1445 | mSimCard.supplyPuk(puk, pin, callback); |
| 1446 | } |
| 1447 | |
| 1448 | while (!mDone) { |
| 1449 | try { |
| 1450 | Log.d(LOG_TAG, "wait for done"); |
| 1451 | wait(); |
| 1452 | } catch (InterruptedException e) { |
| 1453 | // Restore the interrupted status |
| 1454 | Thread.currentThread().interrupt(); |
| 1455 | } |
| 1456 | } |
| 1457 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1458 | int[] resultArray = new int[2]; |
| 1459 | resultArray[0] = mResult; |
| 1460 | resultArray[1] = mRetryCount; |
| 1461 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1462 | } |
| 1463 | } |
| 1464 | |
| 1465 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1466 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1467 | |
| 1468 | } |
| 1469 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1470 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1471 | // No permission check needed here: this call is harmless, and it's |
| 1472 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1473 | // already intentionally exposed to 3rd parties.) |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1474 | final Phone phone = getPhone(subId); |
| 1475 | if (phone != null) { |
| 1476 | phone.updateServiceLocation(); |
| 1477 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1478 | } |
| 1479 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1480 | @Override |
| 1481 | public boolean isRadioOn(String callingPackage) { |
| 1482 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1483 | } |
| 1484 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1485 | @Override |
| 1486 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1487 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1488 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1489 | return false; |
| 1490 | } |
| 1491 | return isRadioOnForSubscriber(subId); |
| 1492 | } |
| 1493 | |
| 1494 | private boolean isRadioOnForSubscriber(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1495 | final Phone phone = getPhone(subId); |
| 1496 | if (phone != null) { |
| 1497 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1498 | } else { |
| 1499 | return false; |
| 1500 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1504 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1505 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1506 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1507 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1508 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1509 | enforceModifyPermission(); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1510 | final Phone phone = getPhone(subId); |
| 1511 | if (phone != null) { |
| 1512 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1513 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1517 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1518 | } |
| 1519 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1520 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1521 | enforceModifyPermission(); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1522 | final Phone phone = getPhone(subId); |
| 1523 | if (phone == null) { |
| 1524 | return false; |
| 1525 | } |
| 1526 | if ((phone.getServiceState().getState() != |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1527 | ServiceState.STATE_POWER_OFF) != turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1528 | toggleRadioOnOffForSubscriber(subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1529 | } |
| 1530 | return true; |
| 1531 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1532 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1533 | public boolean needMobileRadioShutdown() { |
| 1534 | /* |
| 1535 | * If any of the Radios are available, it will need to be |
| 1536 | * shutdown. So return true if any Radio is available. |
| 1537 | */ |
| 1538 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1539 | Phone phone = PhoneFactory.getPhone(i); |
| 1540 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1541 | } |
| 1542 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1543 | return false; |
| 1544 | } |
| 1545 | |
| 1546 | public void shutdownMobileRadios() { |
| 1547 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1548 | logv("Shutting down Phone " + i); |
| 1549 | shutdownRadioUsingPhoneId(i); |
| 1550 | } |
| 1551 | } |
| 1552 | |
| 1553 | private void shutdownRadioUsingPhoneId(int phoneId) { |
| 1554 | enforceModifyPermission(); |
| 1555 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1556 | if (phone != null && phone.isRadioAvailable()) { |
| 1557 | phone.shutdownRadio(); |
| 1558 | } |
| 1559 | } |
| 1560 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1561 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1562 | enforceModifyPermission(); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1563 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1564 | if (defaultPhone != null) { |
| 1565 | defaultPhone.setRadioPower(turnOn); |
| 1566 | return true; |
| 1567 | } else { |
| 1568 | loge("There's no default phone."); |
| 1569 | return false; |
| 1570 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1571 | } |
| 1572 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1573 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1574 | enforceModifyPermission(); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1575 | final Phone phone = getPhone(subId); |
| 1576 | if (phone != null) { |
| 1577 | phone.setRadioPower(turnOn); |
| 1578 | return true; |
| 1579 | } else { |
| 1580 | return false; |
| 1581 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1584 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1585 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1586 | public boolean enableDataConnectivity() { |
| 1587 | enforceModifyPermission(); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1588 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1589 | final Phone phone = getPhone(subId); |
| 1590 | if (phone != null) { |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 1591 | phone.setUserDataEnabled(true); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1592 | return true; |
| 1593 | } else { |
| 1594 | return false; |
| 1595 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1596 | } |
| 1597 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1598 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1599 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1600 | public boolean disableDataConnectivity() { |
| 1601 | enforceModifyPermission(); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1602 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1603 | final Phone phone = getPhone(subId); |
| 1604 | if (phone != null) { |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 1605 | phone.setUserDataEnabled(false); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1606 | return true; |
| 1607 | } else { |
| 1608 | return false; |
| 1609 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1610 | } |
| 1611 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1612 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1613 | public boolean isDataConnectivityPossible(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1614 | final Phone phone = getPhone(subId); |
| 1615 | if (phone != null) { |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1616 | return phone.isDataAllowed(); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1617 | } else { |
| 1618 | return false; |
| 1619 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1623 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1626 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1627 | enforceCallPermission(); |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1628 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1629 | return; |
| 1630 | } |
| 1631 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1632 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1633 | }; |
| 1634 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1635 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1636 | enforceModifyPermission(); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1637 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1638 | return false; |
| 1639 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1640 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1641 | } |
| 1642 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1643 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1644 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1645 | } |
| 1646 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1647 | public int getCallStateForSlot(int slotIndex) { |
| 1648 | Phone phone = PhoneFactory.getPhone(slotIndex); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1649 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 1650 | PhoneConstantConversions.convertCallState(phone.getState()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1651 | } |
| 1652 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1653 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1654 | public int getDataState() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1655 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1656 | if (phone != null) { |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 1657 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1658 | } else { |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 1659 | return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1660 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1661 | } |
| 1662 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1663 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1664 | public int getDataActivity() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1665 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1666 | if (phone != null) { |
| 1667 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1668 | } else { |
| 1669 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1670 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1674 | public Bundle getCellLocation(String callingPackage) { |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1675 | mPhone.getContext().getSystemService(AppOpsManager.class) |
| 1676 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1677 | if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(), |
Svet Ganov | 4af6628 | 2018-03-07 19:57:05 -0800 | [diff] [blame] | 1678 | callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1679 | return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1680 | } |
| 1681 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1682 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1683 | Bundle data = new Bundle(); |
| 1684 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1685 | if (phone == null) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1686 | return null; |
| 1687 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1688 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1689 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1690 | phone.getCellLocation(workSource).fillInNotifierBundle(data); |
| 1691 | return data; |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1692 | } |
| 1693 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1694 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1695 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1696 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1697 | // registered cell info, so return a NULL country instead. |
| 1698 | final long identity = Binder.clearCallingIdentity(); |
| 1699 | try { |
| 1700 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
| 1701 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1702 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1703 | return ""; |
| 1704 | } |
| 1705 | } finally { |
| 1706 | Binder.restoreCallingIdentity(identity); |
| 1707 | } |
| 1708 | return TelephonyManager.getTelephonyProperty( |
| 1709 | phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, ""); |
| 1710 | } |
| 1711 | |
| 1712 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1713 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1714 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1715 | } |
| 1716 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1717 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1718 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1719 | mApp.enforceCallingOrSelfPermission( |
| 1720 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1721 | final Phone phone = getPhone(subId); |
| 1722 | if (phone != null) { |
| 1723 | phone.enableLocationUpdates(); |
| 1724 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | @Override |
| 1728 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1729 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1730 | } |
| 1731 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1732 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1733 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1734 | mApp.enforceCallingOrSelfPermission( |
| 1735 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1736 | final Phone phone = getPhone(subId); |
| 1737 | if (phone != null) { |
| 1738 | phone.disableLocationUpdates(); |
| 1739 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1740 | } |
| 1741 | |
| 1742 | @Override |
| 1743 | @SuppressWarnings("unchecked") |
| 1744 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1745 | mPhone.getContext().getSystemService(AppOpsManager.class) |
| 1746 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1747 | if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(), |
Svet Ganov | 4af6628 | 2018-03-07 19:57:05 -0800 | [diff] [blame] | 1748 | callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1749 | return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 1753 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 1754 | return null; |
| 1755 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1756 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1757 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1758 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1759 | ArrayList<NeighboringCellInfo> cells = null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1760 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1761 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1762 | try { |
| 1763 | cells = (ArrayList<NeighboringCellInfo>) sendRequest( |
| 1764 | CMD_HANDLE_NEIGHBORING_CELL, workSource, |
| 1765 | SubscriptionManager.INVALID_SUBSCRIPTION_ID); |
| 1766 | } catch (RuntimeException e) { |
| 1767 | Log.e(LOG_TAG, "getNeighboringCellInfo " + e); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1768 | } |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1769 | return cells; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | |
| 1773 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1774 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1775 | mPhone.getContext().getSystemService(AppOpsManager.class) |
| 1776 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1777 | if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(), |
Svet Ganov | 4af6628 | 2018-03-07 19:57:05 -0800 | [diff] [blame] | 1778 | callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1779 | return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1780 | } |
| 1781 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1782 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1783 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1784 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 1785 | for (Phone phone : PhoneFactory.getPhones()) { |
| 1786 | final List<CellInfo> info = phone.getAllCellInfo(workSource); |
| 1787 | if (info != null) cellInfos.addAll(info); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1788 | } |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1789 | return cellInfos; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1790 | } |
| 1791 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1792 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1793 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 1794 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1795 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 1796 | mPhone.setCellInfoListRate(rateInMillis, workSource); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1797 | } |
| 1798 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1799 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1800 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1801 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1802 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1803 | return null; |
| 1804 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1805 | int subId = phone.getSubId(); |
| 1806 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 1807 | mApp, subId, callingPackage, "getImeiForSlot")) { |
| 1808 | return null; |
| 1809 | } |
| 1810 | return phone.getImei(); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 1814 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1815 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1816 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 1817 | return null; |
| 1818 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1819 | int subId = phone.getSubId(); |
| 1820 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 1821 | mApp, subId, callingPackage, "getMeidForSlot")) { |
| 1822 | return null; |
| 1823 | } |
| 1824 | return phone.getMeid(); |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1828 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1829 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1830 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1831 | return null; |
| 1832 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1833 | int subId = phone.getSubId(); |
| 1834 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 1835 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 1836 | return null; |
| 1837 | } |
| 1838 | return phone.getDeviceSvn(); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1839 | } |
| 1840 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 1841 | @Override |
| 1842 | public int getSubscriptionCarrierId(int subId) { |
| 1843 | final Phone phone = getPhone(subId); |
| 1844 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 1845 | } |
| 1846 | |
| 1847 | @Override |
| 1848 | public String getSubscriptionCarrierName(int subId) { |
| 1849 | final Phone phone = getPhone(subId); |
| 1850 | return phone == null ? null : phone.getCarrierName(); |
| 1851 | } |
| 1852 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1853 | // |
| 1854 | // Internal helper methods. |
| 1855 | // |
| 1856 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 1857 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1858 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 1859 | * |
| 1860 | * @throws SecurityException if the caller does not have the required permission |
| 1861 | */ |
| 1862 | private void enforceModifyPermission() { |
| 1863 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 1864 | } |
| 1865 | |
| 1866 | /** |
| 1867 | * Make sure the caller has the CALL_PHONE permission. |
| 1868 | * |
| 1869 | * @throws SecurityException if the caller does not have the required permission |
| 1870 | */ |
| 1871 | private void enforceCallPermission() { |
| 1872 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 1873 | } |
| 1874 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 1875 | private void enforceConnectivityInternalPermission() { |
| 1876 | mApp.enforceCallingOrSelfPermission( |
| 1877 | android.Manifest.permission.CONNECTIVITY_INTERNAL, |
| 1878 | "ConnectivityService"); |
| 1879 | } |
| 1880 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1881 | private String createTelUrl(String number) { |
| 1882 | if (TextUtils.isEmpty(number)) { |
| 1883 | return null; |
| 1884 | } |
| 1885 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1886 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1887 | } |
| 1888 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 1889 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1890 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 1891 | } |
| 1892 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1893 | private static void logv(String msg) { |
| 1894 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 1895 | } |
| 1896 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 1897 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1898 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 1899 | } |
| 1900 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1901 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1902 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1903 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1904 | } |
| 1905 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1906 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1907 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 1908 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1909 | if (phone == null) { |
| 1910 | return PhoneConstants.PHONE_TYPE_NONE; |
| 1911 | } else { |
| 1912 | return phone.getPhoneType(); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1913 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | /** |
| 1917 | * Returns the CDMA ERI icon index to display |
| 1918 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1919 | @Override |
| 1920 | public int getCdmaEriIconIndex(String callingPackage) { |
| 1921 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1922 | } |
| 1923 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1924 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1925 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1926 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1927 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1928 | return -1; |
| 1929 | } |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1930 | final Phone phone = getPhone(subId); |
| 1931 | if (phone != null) { |
| 1932 | return phone.getCdmaEriIconIndex(); |
| 1933 | } else { |
| 1934 | return -1; |
| 1935 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | /** |
| 1939 | * Returns the CDMA ERI icon mode, |
| 1940 | * 0 - ON |
| 1941 | * 1 - FLASHING |
| 1942 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1943 | @Override |
| 1944 | public int getCdmaEriIconMode(String callingPackage) { |
| 1945 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1946 | } |
| 1947 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1948 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1949 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1950 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1951 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1952 | return -1; |
| 1953 | } |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1954 | final Phone phone = getPhone(subId); |
| 1955 | if (phone != null) { |
| 1956 | return phone.getCdmaEriIconMode(); |
| 1957 | } else { |
| 1958 | return -1; |
| 1959 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | /** |
| 1963 | * Returns the CDMA ERI text, |
| 1964 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1965 | @Override |
| 1966 | public String getCdmaEriText(String callingPackage) { |
| 1967 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1968 | } |
| 1969 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1970 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1971 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1972 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1973 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1974 | return null; |
| 1975 | } |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1976 | final Phone phone = getPhone(subId); |
| 1977 | if (phone != null) { |
| 1978 | return phone.getCdmaEriText(); |
| 1979 | } else { |
| 1980 | return null; |
| 1981 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1982 | } |
| 1983 | |
| 1984 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 1985 | * Returns the CDMA MDN. |
| 1986 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1987 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1988 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1989 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1990 | mApp, subId, "getCdmaMdn"); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1991 | final Phone phone = getPhone(subId); |
| 1992 | if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) { |
| 1993 | return phone.getLine1Number(); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 1994 | } else { |
| 1995 | return null; |
| 1996 | } |
| 1997 | } |
| 1998 | |
| 1999 | /** |
| 2000 | * Returns the CDMA MIN. |
| 2001 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2002 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2003 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2004 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2005 | mApp, subId, "getCdmaMin"); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2006 | final Phone phone = getPhone(subId); |
| 2007 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2008 | return phone.getCdmaMin(); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2009 | } else { |
| 2010 | return null; |
| 2011 | } |
| 2012 | } |
| 2013 | |
| 2014 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2015 | * Returns true if CDMA provisioning needs to run. |
| 2016 | */ |
| 2017 | public boolean needsOtaServiceProvisioning() { |
| 2018 | return mPhone.needsOtaServiceProvisioning(); |
| 2019 | } |
| 2020 | |
| 2021 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2022 | * Sets the voice mail number of a given subId. |
| 2023 | */ |
| 2024 | @Override |
| 2025 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2026 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2027 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2028 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2029 | return success; |
| 2030 | } |
| 2031 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2032 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2033 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2034 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2035 | String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage(); |
| 2036 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2037 | throw new SecurityException("caller must be system dialer"); |
| 2038 | } |
| 2039 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2040 | if (phoneAccountHandle == null){ |
| 2041 | return null; |
| 2042 | } |
| 2043 | return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle); |
| 2044 | } |
| 2045 | |
| 2046 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2047 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2048 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2049 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2050 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2051 | return null; |
| 2052 | } |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2053 | final long identity = Binder.clearCallingIdentity(); |
| 2054 | try { |
| 2055 | return RemoteVvmTaskManager |
| 2056 | .getRemotePackage(mPhone.getContext(), subId).getPackageName(); |
| 2057 | } finally { |
| 2058 | Binder.restoreCallingIdentity(identity); |
| 2059 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2063 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2064 | VisualVoicemailSmsFilterSettings settings) { |
| 2065 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2066 | VisualVoicemailSmsFilterConfig |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2067 | .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId, |
| 2068 | settings); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2072 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2073 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2074 | VisualVoicemailSmsFilterConfig |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2075 | .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2076 | } |
| 2077 | |
| 2078 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2079 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2080 | String callingPackage, int subId) { |
| 2081 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2082 | return VisualVoicemailSmsFilterConfig |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2083 | .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2087 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2088 | enforceReadPrivilegedPermission(); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2089 | return VisualVoicemailSmsFilterConfig |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2090 | .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId); |
| 2091 | } |
| 2092 | |
| 2093 | @Override |
| 2094 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2095 | String number, int port, String text, PendingIntent sentIntent) { |
| 2096 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2097 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2098 | enforceSendSmsPermission(); |
| 2099 | // Make the calls as the phone process. |
| 2100 | final long identity = Binder.clearCallingIdentity(); |
| 2101 | try { |
| 2102 | SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); |
| 2103 | if (port == 0) { |
| 2104 | smsManager.sendTextMessageWithSelfPermissions(number, null, text, |
| 2105 | sentIntent, null, false); |
| 2106 | } else { |
| 2107 | byte[] data = text.getBytes(StandardCharsets.UTF_8); |
| 2108 | smsManager.sendDataMessageWithSelfPermissions(number, null, |
| 2109 | (short) port, data, sentIntent, null); |
| 2110 | } |
| 2111 | } finally { |
| 2112 | Binder.restoreCallingIdentity(identity); |
| 2113 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2114 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2115 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2116 | * Sets the voice activation state of a given subId. |
| 2117 | */ |
| 2118 | @Override |
| 2119 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2120 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2121 | mApp, subId, "setVoiceActivationState"); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2122 | final Phone phone = getPhone(subId); |
| 2123 | if (phone != null) { |
| 2124 | phone.setVoiceActivationState(activationState); |
| 2125 | } else { |
| 2126 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2127 | } |
| 2128 | } |
| 2129 | |
| 2130 | /** |
| 2131 | * Sets the data activation state of a given subId. |
| 2132 | */ |
| 2133 | @Override |
| 2134 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2135 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2136 | mApp, subId, "setDataActivationState"); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2137 | final Phone phone = getPhone(subId); |
| 2138 | if (phone != null) { |
| 2139 | phone.setDataActivationState(activationState); |
| 2140 | } else { |
| 2141 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2142 | } |
| 2143 | } |
| 2144 | |
| 2145 | /** |
| 2146 | * Returns the voice activation state of a given subId. |
| 2147 | */ |
| 2148 | @Override |
| 2149 | public int getVoiceActivationState(int subId, String callingPackage) { |
goneil | 799f6e9 | 2017-12-13 12:57:23 -0800 | [diff] [blame] | 2150 | enforceReadPrivilegedPermission(); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2151 | final Phone phone = getPhone(subId); |
| 2152 | if (phone != null) { |
| 2153 | return phone.getVoiceActivationState(); |
| 2154 | } else { |
| 2155 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2156 | } |
| 2157 | } |
| 2158 | |
| 2159 | /** |
| 2160 | * Returns the data activation state of a given subId. |
| 2161 | */ |
| 2162 | @Override |
| 2163 | public int getDataActivationState(int subId, String callingPackage) { |
goneil | 799f6e9 | 2017-12-13 12:57:23 -0800 | [diff] [blame] | 2164 | enforceReadPrivilegedPermission(); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2165 | final Phone phone = getPhone(subId); |
| 2166 | if (phone != null) { |
| 2167 | return phone.getDataActivationState(); |
| 2168 | } else { |
| 2169 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2170 | } |
| 2171 | } |
| 2172 | |
| 2173 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2174 | * Returns the unread count of voicemails |
| 2175 | */ |
| 2176 | public int getVoiceMessageCount() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2177 | return getVoiceMessageCountForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2178 | } |
| 2179 | |
| 2180 | /** |
| 2181 | * Returns the unread count of voicemails for a subId |
| 2182 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2183 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2184 | public int getVoiceMessageCountForSubscriber( int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2185 | final Phone phone = getPhone(subId); |
| 2186 | if (phone != null) { |
| 2187 | return phone.getVoiceMessageCount(); |
| 2188 | } else { |
| 2189 | return 0; |
| 2190 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2191 | } |
| 2192 | |
| 2193 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2194 | * returns true, if the device is in a state where both voice and data |
| 2195 | * are supported simultaneously. This can change based on location or network condition. |
| 2196 | */ |
| 2197 | @Override |
| 2198 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
| 2199 | final Phone phone = getPhone(subId); |
| 2200 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2201 | } |
| 2202 | |
| 2203 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2204 | * Send the dialer code if called from the current default dialer or the caller has |
| 2205 | * carrier privilege. |
| 2206 | * @param inputCode The dialer code to send |
| 2207 | */ |
| 2208 | @Override |
| 2209 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
| 2210 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2211 | String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage(); |
| 2212 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2213 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2214 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2215 | } |
| 2216 | mPhone.sendDialerSpecialCode(inputCode); |
| 2217 | } |
| 2218 | |
| 2219 | /** |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2220 | * Returns the data network type. |
| 2221 | * Legacy call, permission-free. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2222 | * |
| 2223 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 2224 | */ |
| 2225 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2226 | public int getNetworkType() { |
| 2227 | final Phone phone = getPhone(getDefaultSubscription()); |
| 2228 | if (phone != null) { |
| 2229 | return phone.getServiceState().getDataNetworkType(); |
| 2230 | } else { |
| 2231 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2232 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2233 | } |
| 2234 | |
| 2235 | /** |
| 2236 | * Returns the network type for a subId |
| 2237 | */ |
| 2238 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2239 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2240 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2241 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2242 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2243 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2244 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2245 | final Phone phone = getPhone(subId); |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2246 | if (phone != null) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2247 | return phone.getServiceState().getDataNetworkType(); |
| 2248 | } else { |
| 2249 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2250 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2251 | } |
| 2252 | |
| 2253 | /** |
| 2254 | * Returns the data network type |
| 2255 | */ |
| 2256 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2257 | public int getDataNetworkType(String callingPackage) { |
| 2258 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | /** |
| 2262 | * Returns the data network type for a subId |
| 2263 | */ |
| 2264 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2265 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2266 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2267 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2268 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2269 | } |
| 2270 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2271 | final Phone phone = getPhone(subId); |
| 2272 | if (phone != null) { |
| 2273 | return phone.getServiceState().getDataNetworkType(); |
| 2274 | } else { |
| 2275 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2276 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2277 | } |
| 2278 | |
| 2279 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2280 | * Returns the Voice network type for a subId |
| 2281 | */ |
| 2282 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2283 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2284 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2285 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2286 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2287 | } |
| 2288 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2289 | final Phone phone = getPhone(subId); |
| 2290 | if (phone != null) { |
| 2291 | return phone.getServiceState().getVoiceNetworkType(); |
| 2292 | } else { |
| 2293 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2294 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2295 | } |
| 2296 | |
| 2297 | /** |
| 2298 | * @return true if a ICC card is present |
| 2299 | */ |
| 2300 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2301 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2302 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 2303 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2307 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2308 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2309 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2310 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
| 2311 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
fionaxu | 6e6c68b | 2016-06-23 13:31:32 -0700 | [diff] [blame] | 2312 | if (phone != null) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2313 | return phone.getIccCard().hasIccCard(); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 2314 | } else { |
| 2315 | return false; |
| 2316 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | /** |
| 2320 | * Return if the current radio is LTE on CDMA. This |
| 2321 | * is a tri-state return value as for a period of time |
| 2322 | * the mode may be unknown. |
| 2323 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2324 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2325 | * @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] | 2326 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2327 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2328 | @Override |
| 2329 | public int getLteOnCdmaMode(String callingPackage) { |
| 2330 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2331 | } |
| 2332 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2333 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2334 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2335 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2336 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2337 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 2338 | } |
| 2339 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2340 | final Phone phone = getPhone(subId); |
| 2341 | if (phone == null) { |
| 2342 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 2343 | } else { |
| 2344 | return phone.getLteOnCdmaMode(); |
| 2345 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2346 | } |
| 2347 | |
| 2348 | public void setPhone(Phone phone) { |
| 2349 | mPhone = phone; |
| 2350 | } |
| 2351 | |
| 2352 | /** |
| 2353 | * {@hide} |
| 2354 | * Returns Default subId, 0 in the case of single standby. |
| 2355 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2356 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2357 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2358 | } |
| 2359 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2360 | private int getSlotForDefaultSubscription() { |
| 2361 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 2362 | } |
| 2363 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2364 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2365 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2366 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 2367 | |
| 2368 | /** |
| 2369 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 2370 | */ |
| 2371 | public int getWhenToMakeWifiCalls() { |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 2372 | return Settings.System.getInt(mPhone.getContext().getContentResolver(), |
| 2373 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference()); |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 2374 | } |
| 2375 | |
| 2376 | /** |
| 2377 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 2378 | */ |
| 2379 | public void setWhenToMakeWifiCalls(int preference) { |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 2380 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
| 2381 | Settings.System.putInt(mPhone.getContext().getContentResolver(), |
| 2382 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2383 | } |
| 2384 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 2385 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 2386 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 2387 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 2388 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 2389 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2390 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 2391 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 2392 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2393 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2394 | mApp, subId, "iccOpenLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2395 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 2396 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 2397 | // Only allows LPA to open logical channel to ISD-R. |
| 2398 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2399 | ComponentInfo bestComponent = |
| 2400 | EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager()); |
| 2401 | if (bestComponent == null |
| 2402 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 2403 | loge("The calling package is not allowed to access ISD-R."); |
| 2404 | throw new SecurityException("The calling package is not allowed to access ISD-R."); |
| 2405 | } |
| 2406 | } |
| 2407 | |
| 2408 | if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2409 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest( |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 2410 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2411 | if (DBG) log("iccOpenLogicalChannel: " + response); |
| 2412 | return response; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2413 | } |
| 2414 | |
| 2415 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2416 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2417 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2418 | mApp, subId, "iccCloseLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2419 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2420 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2421 | if (channel < 0) { |
| 2422 | return false; |
| 2423 | } |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2424 | Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2425 | if (DBG) log("iccCloseLogicalChannel: " + success); |
| 2426 | return success; |
| 2427 | } |
| 2428 | |
| 2429 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2430 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2431 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2432 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2433 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2434 | |
| 2435 | if (DBG) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2436 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel + |
| 2437 | " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2438 | " data=" + data); |
| 2439 | } |
| 2440 | |
| 2441 | if (channel < 0) { |
| 2442 | return ""; |
| 2443 | } |
| 2444 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2445 | IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2446 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2447 | if (DBG) log("iccTransmitApduLogicalChannel: " + response); |
| 2448 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2449 | // Append the returned status code to the end of the response payload. |
| 2450 | String s = Integer.toHexString( |
| 2451 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 2452 | if (response.payload != null) { |
| 2453 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 2454 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 2455 | return s; |
| 2456 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2457 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 2458 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 2459 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 2460 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2461 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2462 | mApp, subId, "iccTransmitApduBasicChannel"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2463 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 2464 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 2465 | && TextUtils.equals(ISDR_AID, data)) { |
| 2466 | // Only allows LPA to select ISD-R. |
| 2467 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2468 | ComponentInfo bestComponent = |
| 2469 | EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager()); |
| 2470 | if (bestComponent == null |
| 2471 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 2472 | loge("The calling package is not allowed to select ISD-R."); |
| 2473 | throw new SecurityException("The calling package is not allowed to select ISD-R."); |
| 2474 | } |
| 2475 | } |
| 2476 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2477 | if (DBG) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2478 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command |
| 2479 | + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2480 | } |
| 2481 | |
| 2482 | IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2483 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2484 | if (DBG) log("iccTransmitApduBasicChannel: " + response); |
| 2485 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2486 | // Append the returned status code to the end of the response payload. |
| 2487 | String s = Integer.toHexString( |
| 2488 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 2489 | if (response.payload != null) { |
| 2490 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 2491 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2492 | return s; |
| 2493 | } |
| 2494 | |
| 2495 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2496 | 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] | 2497 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2498 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2499 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2500 | |
| 2501 | if (DBG) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2502 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " + |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2503 | p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 2504 | } |
| 2505 | |
| 2506 | IccIoResult response = |
| 2507 | (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO, |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2508 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 2509 | subId); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2510 | |
| 2511 | if (DBG) { |
| 2512 | log("Exchange SIM_IO [R]" + response); |
| 2513 | } |
| 2514 | |
| 2515 | byte[] result = null; |
| 2516 | int length = 2; |
| 2517 | if (response.payload != null) { |
| 2518 | length = 2 + response.payload.length; |
| 2519 | result = new byte[length]; |
| 2520 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 2521 | } else { |
| 2522 | result = new byte[length]; |
| 2523 | } |
| 2524 | |
| 2525 | result[length - 1] = (byte) response.sw2; |
| 2526 | result[length - 2] = (byte) response.sw1; |
| 2527 | return result; |
| 2528 | } |
| 2529 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 2530 | /** |
| 2531 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 2532 | * on a particular subscription |
| 2533 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 2534 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 2535 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2536 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 2537 | return null; |
| 2538 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 2539 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 2540 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 2541 | return null; |
| 2542 | } |
| 2543 | Object response = sendRequest( |
| 2544 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 2545 | if (response instanceof String[]) { |
| 2546 | return (String[]) response; |
| 2547 | } |
| 2548 | // Response is an Exception of some kind, which is signalled to the user as a NULL retval |
| 2549 | return null; |
| 2550 | } |
| 2551 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 2552 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2553 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2554 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2555 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 2556 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2557 | IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 2558 | if (response.payload == null) { |
| 2559 | return ""; |
| 2560 | } |
| 2561 | |
| 2562 | // Append the returned status code to the end of the response payload. |
| 2563 | String s = Integer.toHexString( |
| 2564 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 2565 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 2566 | return s; |
| 2567 | } |
| 2568 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2569 | /** |
| 2570 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 2571 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 2572 | * |
| 2573 | * @param itemID the ID of the item to read |
| 2574 | * @return the NV item as a String, or null on error. |
| 2575 | */ |
| 2576 | @Override |
| 2577 | public String nvReadItem(int itemID) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2578 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2579 | mApp, getDefaultSubscription(), "nvReadItem"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2580 | if (DBG) log("nvReadItem: item " + itemID); |
| 2581 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID); |
| 2582 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 2583 | return value; |
| 2584 | } |
| 2585 | |
| 2586 | /** |
| 2587 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 2588 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 2589 | * |
| 2590 | * @param itemID the ID of the item to read |
| 2591 | * @param itemValue the value to write, as a String |
| 2592 | * @return true on success; false on any failure |
| 2593 | */ |
| 2594 | @Override |
| 2595 | public boolean nvWriteItem(int itemID, String itemValue) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2596 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2597 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2598 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 2599 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
| 2600 | new Pair<Integer, String>(itemID, itemValue)); |
| 2601 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 2602 | return success; |
| 2603 | } |
| 2604 | |
| 2605 | /** |
| 2606 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 2607 | * Used for device configuration by some CDMA operators. |
| 2608 | * |
| 2609 | * @param preferredRoamingList byte array containing the new PRL |
| 2610 | * @return true on success; false on any failure |
| 2611 | */ |
| 2612 | @Override |
| 2613 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2614 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2615 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2616 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 2617 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 2618 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 2619 | return success; |
| 2620 | } |
| 2621 | |
| 2622 | /** |
| 2623 | * Perform the specified type of NV config reset. |
| 2624 | * Used for device configuration by some CDMA operators. |
| 2625 | * |
| 2626 | * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset) |
| 2627 | * @return true on success; false on any failure |
| 2628 | */ |
| 2629 | @Override |
| 2630 | public boolean nvResetConfig(int resetType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2631 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2632 | mApp, getDefaultSubscription(), "nvResetConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2633 | if (DBG) log("nvResetConfig: type " + resetType); |
| 2634 | Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType); |
| 2635 | if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail")); |
| 2636 | return success; |
| 2637 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 2638 | |
| 2639 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2640 | * {@hide} |
| 2641 | * Returns Default sim, 0 in the case of single standby. |
| 2642 | */ |
| 2643 | public int getDefaultSim() { |
| 2644 | //TODO Need to get it from Telephony Devcontroller |
| 2645 | return 0; |
| 2646 | } |
| 2647 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 2648 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2649 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2650 | mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 2651 | return new String[0]; |
| 2652 | } |
| 2653 | |
| 2654 | |
ram | 87fca6f | 2014-07-18 18:58:44 +0530 | [diff] [blame] | 2655 | return mPhone.getPcscfAddress(apnType); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2656 | } |
| 2657 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 2658 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 2659 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 2660 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 2661 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 2662 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 2663 | enforceModifyPermission(); |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 2664 | PhoneFactory.getImsResolver().enableIms(slotId); |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 2665 | } |
| 2666 | |
| 2667 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 2668 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 2669 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 2670 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 2671 | public void disableIms(int slotId) { |
| 2672 | enforceModifyPermission(); |
| 2673 | PhoneFactory.getImsResolver().disableIms(slotId); |
| 2674 | } |
| 2675 | |
| 2676 | /** |
| 2677 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 2678 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 2679 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 2680 | */ |
| 2681 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 2682 | IImsServiceFeatureCallback callback) { |
| 2683 | enforceModifyPermission(); |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 2684 | return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback); |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 2685 | } |
| 2686 | |
| 2687 | /** |
| 2688 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 2689 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 2690 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 2691 | * listener for feature updates. |
| 2692 | */ |
| 2693 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 2694 | enforceModifyPermission(); |
| 2695 | return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback); |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 2696 | } |
| 2697 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 2698 | /** |
| 2699 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
| 2700 | * specified. |
| 2701 | */ |
| 2702 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 2703 | enforceModifyPermission(); |
| 2704 | return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature); |
| 2705 | } |
| 2706 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 2707 | /** |
| 2708 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
| 2709 | * specified. |
| 2710 | */ |
| 2711 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 2712 | enforceModifyPermission(); |
| 2713 | return PhoneFactory.getImsResolver().getImsConfig(slotId, feature); |
| 2714 | } |
| 2715 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 2716 | /** |
Brad Ebinger | 304415d | 2018-03-02 13:43:36 -0800 | [diff] [blame] | 2717 | * @return true if the IMS resolver is busy resolving a binding and should not be considered |
| 2718 | * available, false if the IMS resolver is idle. |
| 2719 | */ |
| 2720 | public boolean isResolvingImsBinding() { |
| 2721 | enforceModifyPermission(); |
| 2722 | return PhoneFactory.getImsResolver().isResolvingBinding(); |
| 2723 | } |
| 2724 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2725 | public void setImsRegistrationState(boolean registered) { |
| 2726 | enforceModifyPermission(); |
| 2727 | mPhone.setImsRegistrationState(registered); |
| 2728 | } |
| 2729 | |
| 2730 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 2731 | * Set the network selection mode to automatic. |
| 2732 | * |
| 2733 | */ |
| 2734 | @Override |
| 2735 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2736 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2737 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 2738 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 2739 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 2740 | } |
| 2741 | |
| 2742 | /** |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 2743 | * Set the network selection mode to manual with the selected carrier. |
| 2744 | */ |
| 2745 | @Override |
yinxu | 6e5abd7 | 2017-12-01 11:35:19 -0800 | [diff] [blame] | 2746 | public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric, |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 2747 | boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2748 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2749 | mApp, subId, "setNetworkSelectionModeManual"); |
yinxu | 6e5abd7 | 2017-12-01 11:35:19 -0800 | [diff] [blame] | 2750 | OperatorInfo operator = new OperatorInfo( |
| 2751 | /* operatorAlphaLong */ "", |
| 2752 | /* operatorAlphaShort */ "", |
| 2753 | operatorNumeric); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 2754 | if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 2755 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator, |
| 2756 | persistSelection); |
| 2757 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 2758 | } |
| 2759 | |
| 2760 | /** |
| 2761 | * Scans for available networks. |
| 2762 | */ |
| 2763 | @Override |
| 2764 | public CellNetworkScanResult getCellNetworkScanResults(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2765 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2766 | mApp, subId, "getCellNetworkScanResults"); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 2767 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
| 2768 | CellNetworkScanResult result = (CellNetworkScanResult) sendRequest( |
| 2769 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
| 2770 | return result; |
| 2771 | } |
| 2772 | |
| 2773 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2774 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 2775 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2776 | * @param subId id of the subscription |
| 2777 | * @param request contains the radio access networks with bands/channels to scan |
| 2778 | * @param messenger callback messenger for scan results or errors |
| 2779 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 2780 | * @return the id of the requested scan which can be used to stop the scan. |
| 2781 | */ |
| 2782 | @Override |
| 2783 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
| 2784 | IBinder binder) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2785 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2786 | mApp, subId, "requestNetworkScan"); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2787 | return mNetworkScanRequestTracker.startNetworkScan( |
| 2788 | request, messenger, binder, getPhone(subId)); |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 2789 | } |
| 2790 | |
| 2791 | /** |
| 2792 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2793 | * |
| 2794 | * @param subId id of the subscription |
| 2795 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 2796 | */ |
| 2797 | @Override |
| 2798 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2799 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2800 | mApp, subId, "stopNetworkScan"); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2801 | mNetworkScanRequestTracker.stopNetworkScan(scanId); |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 2805 | * Get the calculated preferred network type. |
| 2806 | * Used for debugging incorrect network type. |
| 2807 | * |
| 2808 | * @return the preferred network type, defined in RILConstants.java. |
| 2809 | */ |
| 2810 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 2811 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2812 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2813 | mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 2814 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 2815 | } |
| 2816 | |
Amit Mahajan | 43330e0 | 2014-11-18 11:54:45 -0800 | [diff] [blame] | 2817 | return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 2818 | } |
| 2819 | |
| 2820 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 2821 | * Get the preferred network type. |
| 2822 | * Used for device configuration by some CDMA operators. |
| 2823 | * |
| 2824 | * @return the preferred network type, defined in RILConstants.java. |
| 2825 | */ |
| 2826 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 2827 | public int getPreferredNetworkType(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2828 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2829 | mApp, subId, "getPreferredNetworkType"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 2830 | if (DBG) log("getPreferredNetworkType"); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 2831 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 2832 | int networkType = (result != null ? result[0] : -1); |
| 2833 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 2834 | return networkType; |
| 2835 | } |
| 2836 | |
| 2837 | /** |
| 2838 | * Set the preferred network type. |
| 2839 | * Used for device configuration by some CDMA operators. |
| 2840 | * |
| 2841 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 2842 | * @return true on success; false on any failure. |
| 2843 | */ |
| 2844 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 2845 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2846 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2847 | mApp, subId, "setPreferredNetworkType"); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 2848 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 2849 | Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 2850 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 2851 | if (success) { |
| 2852 | Settings.Global.putInt(mPhone.getContext().getContentResolver(), |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 2853 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 2854 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 2855 | return success; |
| 2856 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 2857 | |
| 2858 | /** |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 2859 | * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning |
| 2860 | * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for |
| 2861 | * tethering. |
| 2862 | * |
| 2863 | * @return 0: Not required. 1: required. 2: Not set. |
| 2864 | * @hide |
| 2865 | */ |
| 2866 | @Override |
| 2867 | public int getTetherApnRequired() { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2868 | enforceModifyPermission(); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 2869 | int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(), |
| 2870 | Settings.Global.TETHER_DUN_REQUIRED, 2); |
| 2871 | // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and |
| 2872 | // config_tether_apndata. |
| 2873 | if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) { |
| 2874 | dunRequired = 1; |
| 2875 | } |
| 2876 | return dunRequired; |
| 2877 | } |
| 2878 | |
| 2879 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 2880 | * Set mobile data enabled |
| 2881 | * Used by the user through settings etc to turn on/off mobile data |
| 2882 | * |
| 2883 | * @param enable {@code true} turn turn data on, else {@code false} |
| 2884 | */ |
| 2885 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 2886 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2887 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2888 | mApp, subId, "setUserDataEnabled"); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2889 | int phoneId = mSubscriptionController.getPhoneId(subId); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 2890 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2891 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2892 | if (phone != null) { |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 2893 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
| 2894 | phone.setUserDataEnabled(enable); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2895 | } else { |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 2896 | loge("setUserDataEnabled: no phone for subId=" + subId); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2897 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 2898 | } |
| 2899 | |
| 2900 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 2901 | * Get the user enabled state of Mobile Data. |
| 2902 | * |
| 2903 | * TODO: remove and use isUserDataEnabled. |
| 2904 | * This can't be removed now because some vendor codes |
| 2905 | * calls through ITelephony directly while they should |
| 2906 | * use TelephonyManager. |
| 2907 | * |
| 2908 | * @return true on enabled |
| 2909 | */ |
| 2910 | @Override |
| 2911 | public boolean getDataEnabled(int subId) { |
| 2912 | return isUserDataEnabled(subId); |
| 2913 | } |
| 2914 | |
| 2915 | /** |
| 2916 | * Get whether mobile data is enabled per user setting. |
| 2917 | * |
| 2918 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 2919 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 2920 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 2921 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 2922 | * |
| 2923 | * @return {@code true} if data is enabled else {@code false} |
| 2924 | */ |
| 2925 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 2926 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 2927 | try { |
| 2928 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 2929 | null); |
| 2930 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2931 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2932 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 2933 | } |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2934 | int phoneId = mSubscriptionController.getPhoneId(subId); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 2935 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2936 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2937 | if (phone != null) { |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 2938 | boolean retVal = phone.isUserDataEnabled(); |
| 2939 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2940 | return retVal; |
| 2941 | } else { |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 2942 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 2943 | return false; |
| 2944 | } |
| 2945 | } |
| 2946 | |
| 2947 | /** |
| 2948 | * Get whether mobile data is enabled. |
| 2949 | * |
| 2950 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 2951 | * whether mobile data is actually enabled. |
| 2952 | * |
| 2953 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 2954 | * |
| 2955 | * @return {@code true} if data is enabled else {@code false} |
| 2956 | */ |
| 2957 | @Override |
| 2958 | public boolean isDataEnabled(int subId) { |
| 2959 | try { |
| 2960 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 2961 | null); |
| 2962 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2963 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2964 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 2965 | } |
| 2966 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 2967 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 2968 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2969 | if (phone != null) { |
| 2970 | boolean retVal = phone.isDataEnabled(); |
| 2971 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 2972 | return retVal; |
| 2973 | } else { |
| 2974 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 2975 | return false; |
| 2976 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 2977 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 2978 | |
| 2979 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2980 | public int getCarrierPrivilegeStatus(int subId) { |
| 2981 | final Phone phone = getPhone(subId); |
| 2982 | if (phone == null) { |
| 2983 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 2984 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 2985 | } |
| 2986 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 2987 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 2988 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 2989 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 2990 | } |
| 2991 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2992 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 2993 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 2994 | |
| 2995 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2996 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 2997 | final Phone phone = getPhone(subId); |
| 2998 | if (phone == null) { |
| 2999 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 3000 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 3001 | } |
| 3002 | UiccProfile profile = |
| 3003 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 3004 | if (profile == null) { |
| 3005 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 3006 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 3007 | } |
| 3008 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 3009 | } |
| 3010 | |
| 3011 | @Override |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 3012 | public int checkCarrierPrivilegesForPackage(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 3013 | if (TextUtils.isEmpty(pkgName)) |
| 3014 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Shishir Agrawal | 2140925 | 2015-01-15 23:33:50 -0800 | [diff] [blame] | 3015 | UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 3016 | if (card == null) { |
| 3017 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 3018 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 3019 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 3020 | return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName); |
| 3021 | } |
| 3022 | |
| 3023 | @Override |
| 3024 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 3025 | if (TextUtils.isEmpty(pkgName)) |
| 3026 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 3027 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 3028 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3029 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 3030 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 3031 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 3032 | continue; |
| 3033 | } |
| 3034 | |
| 3035 | result = card.getCarrierPrivilegeStatus( |
| 3036 | mPhone.getContext().getPackageManager(), pkgName); |
| 3037 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 3038 | break; |
| 3039 | } |
| 3040 | } |
| 3041 | |
| 3042 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 3043 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 3044 | |
| 3045 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 3046 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 3047 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 3048 | loge("phoneId " + phoneId + " is not valid."); |
| 3049 | return null; |
| 3050 | } |
| 3051 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 3052 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 3053 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 3054 | return null ; |
| 3055 | } |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 3056 | return card.getCarrierPackageNamesForIntent( |
Svetoslav | 483aff7 | 2015-04-21 14:16:07 -0700 | [diff] [blame] | 3057 | mPhone.getContext().getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 3058 | } |
| 3059 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 3060 | @Override |
| 3061 | public List<String> getPackagesWithCarrierPrivileges() { |
| 3062 | PackageManager pm = mPhone.getContext().getPackageManager(); |
| 3063 | List<String> privilegedPackages = new ArrayList<>(); |
| 3064 | List<PackageInfo> packages = null; |
| 3065 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 3066 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 3067 | if (card == null) { |
| 3068 | // No UICC in that slot. |
| 3069 | continue; |
| 3070 | } |
| 3071 | if (card.hasCarrierPrivilegeRules()) { |
| 3072 | if (packages == null) { |
| 3073 | // Only check packages in user 0 for now |
| 3074 | packages = pm.getInstalledPackagesAsUser( |
| 3075 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 3076 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 3077 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
| 3078 | } |
| 3079 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 3080 | PackageInfo pkgInfo = packages.get(p); |
| 3081 | if (pkgInfo != null && pkgInfo.packageName != null |
| 3082 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| 3083 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 3084 | privilegedPackages.add(pkgInfo.packageName); |
| 3085 | } |
| 3086 | } |
| 3087 | } |
| 3088 | } |
| 3089 | return privilegedPackages; |
| 3090 | } |
| 3091 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3092 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3093 | final Phone phone = getPhone(subId); |
| 3094 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 3095 | if (card == null) { |
| 3096 | loge("getIccId: No UICC"); |
| 3097 | return null; |
| 3098 | } |
| 3099 | String iccId = card.getIccId(); |
| 3100 | if (TextUtils.isEmpty(iccId)) { |
| 3101 | loge("getIccId: ICC ID is null or empty."); |
| 3102 | return null; |
| 3103 | } |
| 3104 | return iccId; |
| 3105 | } |
| 3106 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 3107 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 3108 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 3109 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3110 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3111 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 3112 | |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 3113 | final String iccId = getIccId(subId); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3114 | final Phone phone = getPhone(subId); |
| 3115 | if (phone == null) { |
| 3116 | return false; |
| 3117 | } |
| 3118 | final String subscriberId = phone.getSubscriberId(); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 3119 | |
| 3120 | if (DBG_MERGE) { |
| 3121 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 3122 | + subscriberId + " to " + number); |
| 3123 | } |
| 3124 | |
Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 3125 | if (TextUtils.isEmpty(iccId)) { |
| 3126 | return false; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 3127 | } |
Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 3128 | |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 3129 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3130 | |
| 3131 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 3132 | if (alphaTag == null) { |
| 3133 | editor.remove(alphaTagPrefKey); |
| 3134 | } else { |
| 3135 | editor.putString(alphaTagPrefKey, alphaTag); |
| 3136 | } |
| 3137 | |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 3138 | // Record both the line number and IMSI for this ICCID, since we need to |
| 3139 | // track all merged IMSIs based on line number |
| 3140 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 3141 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 3142 | if (number == null) { |
| 3143 | editor.remove(numberPrefKey); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 3144 | editor.remove(subscriberPrefKey); |
Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 3145 | } else { |
| 3146 | editor.putString(numberPrefKey, number); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 3147 | editor.putString(subscriberPrefKey, subscriberId); |
Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 3148 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 3149 | |
Shishir Agrawal | 495d7e1 | 2014-12-01 11:50:28 -0800 | [diff] [blame] | 3150 | editor.commit(); |
| 3151 | return true; |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 3152 | } |
| 3153 | |
| 3154 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3155 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 3156 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3157 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3158 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 3159 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3160 | return null; |
| 3161 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 3162 | |
| 3163 | String iccId = getIccId(subId); |
| 3164 | if (iccId != null) { |
| 3165 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 3166 | if (DBG_MERGE) { |
| 3167 | log("getLine1NumberForDisplay returning " + |
| 3168 | mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 3169 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 3170 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 3171 | } |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 3172 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 3173 | return null; |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 3174 | } |
| 3175 | |
| 3176 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3177 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3178 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3179 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3180 | return null; |
| 3181 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 3182 | |
| 3183 | String iccId = getIccId(subId); |
| 3184 | if (iccId != null) { |
| 3185 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 3186 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 3187 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 3188 | return null; |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 3189 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 3190 | |
| 3191 | @Override |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 3192 | public String[] getMergedSubscriberIds(String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3193 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 3194 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3195 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3196 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 3197 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 3198 | return null; |
| 3199 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 3200 | final Context context = mPhone.getContext(); |
| 3201 | final TelephonyManager tele = TelephonyManager.from(context); |
| 3202 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 3203 | |
| 3204 | // Figure out what subscribers are currently active |
| 3205 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 3206 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 3207 | // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail. |
| 3208 | final long identity = Binder.clearCallingIdentity(); |
| 3209 | try { |
| 3210 | final int[] subIds = sub.getActiveSubscriptionIdList(); |
| 3211 | for (int subId : subIds) { |
| 3212 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 3213 | } |
| 3214 | } finally { |
| 3215 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 3216 | } |
| 3217 | |
| 3218 | // First pass, find a number override for an active subscriber |
| 3219 | String mergeNumber = null; |
| 3220 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 3221 | for (String key : prefs.keySet()) { |
| 3222 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 3223 | final String subscriberId = (String) prefs.get(key); |
| 3224 | if (activeSubscriberIds.contains(subscriberId)) { |
| 3225 | final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 3226 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 3227 | mergeNumber = (String) prefs.get(numberKey); |
| 3228 | if (DBG_MERGE) { |
| 3229 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 3230 | + " for active subscriber " + subscriberId); |
| 3231 | } |
| 3232 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 3233 | break; |
| 3234 | } |
| 3235 | } |
| 3236 | } |
| 3237 | } |
| 3238 | |
| 3239 | // Shortcut when no active merged subscribers |
| 3240 | if (TextUtils.isEmpty(mergeNumber)) { |
| 3241 | return null; |
| 3242 | } |
| 3243 | |
| 3244 | // Second pass, find all subscribers under that line override |
| 3245 | final ArraySet<String> result = new ArraySet<>(); |
| 3246 | for (String key : prefs.keySet()) { |
| 3247 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 3248 | final String number = (String) prefs.get(key); |
| 3249 | if (mergeNumber.equals(number)) { |
| 3250 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 3251 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 3252 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 3253 | if (!TextUtils.isEmpty(subscriberId)) { |
| 3254 | result.add(subscriberId); |
| 3255 | } |
| 3256 | } |
| 3257 | } |
| 3258 | } |
| 3259 | |
| 3260 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 3261 | Arrays.sort(resultArray); |
| 3262 | if (DBG_MERGE) { |
| 3263 | Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 3264 | } |
| 3265 | return resultArray; |
| 3266 | } |
| 3267 | |
| 3268 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3269 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3270 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3271 | subId, "setOperatorBrandOverride"); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3272 | final Phone phone = getPhone(subId); |
| 3273 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 3274 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 3275 | |
| 3276 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3277 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 3278 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 3279 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3280 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3281 | final Phone phone = getPhone(subId); |
| 3282 | if (phone == null) { |
| 3283 | return false; |
| 3284 | } |
| 3285 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 3286 | cdmaNonRoamingList); |
| 3287 | } |
| 3288 | |
| 3289 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 3290 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 3291 | try { |
| 3292 | ProxyController.getInstance().setRadioCapability(rafs); |
| 3293 | } catch (RuntimeException e) { |
| 3294 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 3295 | } |
| 3296 | } |
| 3297 | |
| 3298 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3299 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3300 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 3301 | if (phone == null) { |
| 3302 | return RadioAccessFamily.RAF_UNKNOWN; |
| 3303 | } |
| 3304 | int subId = phone.getSubId(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3305 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3306 | mApp, subId, callingPackage, "getRadioAccessFamily")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3307 | return RadioAccessFamily.RAF_UNKNOWN; |
| 3308 | } |
| 3309 | |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 3310 | return ProxyController.getInstance().getRadioAccessFamily(phoneId); |
| 3311 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 3312 | |
| 3313 | @Override |
| 3314 | public void enableVideoCalling(boolean enable) { |
| 3315 | enforceModifyPermission(); |
Malcolm Chen | fbf4771 | 2017-12-12 18:19:27 -0800 | [diff] [blame] | 3316 | ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 3317 | } |
| 3318 | |
| 3319 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3320 | public boolean isVideoCallingEnabled(String callingPackage) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 3321 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3322 | mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
| 3323 | return false; |
| 3324 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3325 | |
Andrew Lee | 77527ac | 2014-10-21 16:57:39 -0700 | [diff] [blame] | 3326 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 3327 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 3328 | // In the long run, we may instead need to check if there exists a connection service |
| 3329 | // which can support video calling. |
Malcolm Chen | fbf4771 | 2017-12-12 18:19:27 -0800 | [diff] [blame] | 3330 | ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()); |
| 3331 | return imsManager.isVtEnabledByPlatform() |
| 3332 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 3333 | && imsManager.isVtEnabledByUser(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 3334 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 3335 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 3336 | @Override |
| 3337 | public boolean canChangeDtmfToneLength() { |
Jonathan Basseri | 9504c6b | 2015-06-04 14:23:32 -0700 | [diff] [blame] | 3338 | return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 3339 | } |
| 3340 | |
| 3341 | @Override |
| 3342 | public boolean isWorldPhone() { |
Jonathan Basseri | 9504c6b | 2015-06-04 14:23:32 -0700 | [diff] [blame] | 3343 | return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 3344 | } |
| 3345 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 3346 | @Override |
| 3347 | public boolean isTtyModeSupported() { |
| 3348 | TelecomManager telecomManager = TelecomManager.from(mPhone.getContext()); |
| 3349 | TelephonyManager telephonyManager = |
| 3350 | (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 3351 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 3352 | } |
| 3353 | |
| 3354 | @Override |
| 3355 | public boolean isHearingAidCompatibilitySupported() { |
| 3356 | return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled); |
| 3357 | } |
| 3358 | |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 3359 | public boolean isRttSupported() { |
| 3360 | boolean isCarrierSupported = |
| 3361 | mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 3362 | boolean isDeviceSupported = |
| 3363 | mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
| 3364 | return isCarrierSupported && isDeviceSupported; |
| 3365 | } |
| 3366 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 3367 | /** |
| 3368 | * Returns the unique device ID of phone, for example, the IMEI for |
| 3369 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 3370 | * |
| 3371 | * <p>Requires Permission: |
| 3372 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 3373 | */ |
| 3374 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3375 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 3376 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3377 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 3378 | return null; |
| 3379 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3380 | int subId = phone.getSubId(); |
| 3381 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3382 | mApp, subId, callingPackage, "getDeviceId")) { |
| 3383 | return null; |
| 3384 | } |
| 3385 | return phone.getDeviceId(); |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 3386 | } |
| 3387 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 3388 | /** |
| 3389 | * {@hide} |
| 3390 | * Returns the IMS Registration Status on a particular subid |
| 3391 | * |
| 3392 | * @param subId |
| 3393 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 3394 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 3395 | Phone phone = getPhone(subId); |
| 3396 | if (phone != null) { |
| 3397 | return phone.isImsRegistered(); |
| 3398 | } else { |
| 3399 | return false; |
| 3400 | } |
| 3401 | } |
| 3402 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 3403 | @Override |
| 3404 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
| 3405 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 3406 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 3407 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 3408 | /** |
| 3409 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 3410 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 3411 | public boolean isWifiCallingAvailable(int subId) { |
| 3412 | Phone phone = getPhone(subId); |
| 3413 | if (phone != null) { |
| 3414 | return phone.isWifiCallingEnabled(); |
| 3415 | } else { |
| 3416 | return false; |
| 3417 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 3418 | } |
| 3419 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 3420 | /** |
| 3421 | * @return the VoLTE availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 3422 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 3423 | public boolean isVolteAvailable(int subId) { |
| 3424 | Phone phone = getPhone(subId); |
| 3425 | if (phone != null) { |
| 3426 | return phone.isVolteEnabled(); |
| 3427 | } else { |
| 3428 | return false; |
| 3429 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 3430 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3431 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 3432 | /** |
| 3433 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 3434 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 3435 | public boolean isVideoTelephonyAvailable(int subId) { |
| 3436 | Phone phone = getPhone(subId); |
| 3437 | if (phone != null) { |
| 3438 | return phone.isVideoEnabled(); |
| 3439 | } else { |
| 3440 | return false; |
| 3441 | } |
| 3442 | } |
| 3443 | |
| 3444 | /** |
| 3445 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 3446 | * defined in {@link ImsRegistrationImplBase}. |
| 3447 | */ |
| 3448 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
| 3449 | Phone phone = getPhone(subId); |
| 3450 | if (phone != null) { |
| 3451 | return phone.getImsRegistrationTech(); |
| 3452 | } else { |
| 3453 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 3454 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 3455 | } |
| 3456 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3457 | @Override |
| 3458 | public void factoryReset(int subId) { |
| 3459 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 3460 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 3461 | return; |
| 3462 | } |
| 3463 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 3464 | final long identity = Binder.clearCallingIdentity(); |
| 3465 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 3466 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 3467 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 3468 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 3469 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 3470 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
| 3471 | mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId)); |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 3472 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 3473 | } |
| 3474 | } finally { |
| 3475 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3476 | } |
| 3477 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 3478 | |
| 3479 | @Override |
| 3480 | public String getLocaleFromDefaultSim() { |
| 3481 | // We query all subscriptions instead of just the active ones, because |
| 3482 | // this might be called early on in the provisioning flow when the |
| 3483 | // subscriptions potentially aren't active yet. |
| 3484 | final List<SubscriptionInfo> slist = getAllSubscriptionInfoList(); |
| 3485 | if (slist == null || slist.isEmpty()) { |
| 3486 | return null; |
| 3487 | } |
| 3488 | |
| 3489 | // This function may be called very early, say, from the setup wizard, at |
| 3490 | // which point we won't have a default subscription set. If that's the case |
| 3491 | // we just choose the first, which will be valid in "most cases". |
| 3492 | final int defaultSubId = getDefaultSubscription(); |
| 3493 | SubscriptionInfo info = null; |
| 3494 | if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 3495 | info = slist.get(0); |
| 3496 | } else { |
| 3497 | for (SubscriptionInfo item : slist) { |
| 3498 | if (item.getSubscriptionId() == defaultSubId) { |
| 3499 | info = item; |
| 3500 | break; |
| 3501 | } |
| 3502 | } |
| 3503 | |
| 3504 | if (info == null) { |
| 3505 | return null; |
| 3506 | } |
| 3507 | } |
| 3508 | |
| 3509 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 3510 | // preferences (EF-PL and EF-LI)... |
Tony Hill | 183b2de | 2015-06-24 14:53:58 +0100 | [diff] [blame] | 3511 | final int mcc = info.getMcc(); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 3512 | final Phone defaultPhone = getPhone(info.getSubscriptionId()); |
Narayan Kamath | 011676f | 2015-07-29 12:04:08 +0100 | [diff] [blame] | 3513 | String simLanguage = null; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 3514 | if (defaultPhone != null) { |
| 3515 | final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs(); |
| 3516 | if (localeFromDefaultSim != null) { |
Narayan Kamath | 011676f | 2015-07-29 12:04:08 +0100 | [diff] [blame] | 3517 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
Tony Hill | 183b2de | 2015-06-24 14:53:58 +0100 | [diff] [blame] | 3518 | if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim); |
| 3519 | return localeFromDefaultSim.toLanguageTag(); |
Narayan Kamath | 011676f | 2015-07-29 12:04:08 +0100 | [diff] [blame] | 3520 | } else { |
| 3521 | simLanguage = localeFromDefaultSim.getLanguage(); |
Tony Hill | 183b2de | 2015-06-24 14:53:58 +0100 | [diff] [blame] | 3522 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 3523 | } |
| 3524 | } |
| 3525 | |
Narayan Kamath | 011676f | 2015-07-29 12:04:08 +0100 | [diff] [blame] | 3526 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 3527 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 3528 | // the SIM and carrier preferences does not include a country we add the country |
| 3529 | // determined from the SIM MCC to provide an exact locale. |
| 3530 | final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage); |
Tony Hill | 183b2de | 2015-06-24 14:53:58 +0100 | [diff] [blame] | 3531 | if (mccLocale != null) { |
| 3532 | if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale); |
| 3533 | return mccLocale.toLanguageTag(); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 3534 | } |
| 3535 | |
Tony Hill | 183b2de | 2015-06-24 14:53:58 +0100 | [diff] [blame] | 3536 | if (DBG) log("No locale found - returning null"); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 3537 | return null; |
| 3538 | } |
| 3539 | |
| 3540 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
| 3541 | final long identity = Binder.clearCallingIdentity(); |
| 3542 | try { |
| 3543 | return mSubscriptionController.getAllSubInfoList( |
| 3544 | mPhone.getContext().getOpPackageName()); |
| 3545 | } finally { |
| 3546 | Binder.restoreCallingIdentity(identity); |
| 3547 | } |
| 3548 | } |
| 3549 | |
| 3550 | private List<SubscriptionInfo> getActiveSubscriptionInfoList() { |
| 3551 | final long identity = Binder.clearCallingIdentity(); |
| 3552 | try { |
| 3553 | return mSubscriptionController.getActiveSubscriptionInfoList( |
| 3554 | mPhone.getContext().getOpPackageName()); |
| 3555 | } finally { |
| 3556 | Binder.restoreCallingIdentity(identity); |
| 3557 | } |
| 3558 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 3559 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 3560 | private final ModemActivityInfo mLastModemActivityInfo = |
| 3561 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 3562 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 3563 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 3564 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 3565 | * representing the state of the modem. |
| 3566 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 3567 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 3568 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 3569 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 3570 | */ |
| 3571 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 3572 | public void requestModemActivityInfo(ResultReceiver result) { |
| 3573 | enforceModifyPermission(); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 3574 | ModemActivityInfo ret = null; |
| 3575 | synchronized (mLastModemActivityInfo) { |
| 3576 | ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, |
| 3577 | null); |
| 3578 | if (info != null) { |
| 3579 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 3580 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 3581 | mergedTxTimeMs[i] = |
| 3582 | info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i]; |
| 3583 | } |
| 3584 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 3585 | mLastModemActivityInfo.setSleepTimeMillis( |
| 3586 | info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis()); |
| 3587 | mLastModemActivityInfo.setIdleTimeMillis( |
| 3588 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 3589 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 3590 | mLastModemActivityInfo.setRxTimeMillis( |
| 3591 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 3592 | mLastModemActivityInfo.setEnergyUsed( |
| 3593 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
| 3594 | } |
| 3595 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 3596 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 3597 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 3598 | mLastModemActivityInfo.getTxTimeMillis(), |
| 3599 | mLastModemActivityInfo.getRxTimeMillis(), |
| 3600 | mLastModemActivityInfo.getEnergyUsed()); |
| 3601 | } |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 3602 | Bundle bundle = new Bundle(); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 3603 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 3604 | result.send(0, bundle); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 3605 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 3606 | |
| 3607 | /** |
| 3608 | * {@hide} |
| 3609 | * Returns the service state information on specified subscription. |
| 3610 | */ |
| 3611 | @Override |
| 3612 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
| 3613 | |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3614 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3615 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 3616 | return null; |
| 3617 | } |
| 3618 | |
| 3619 | final Phone phone = getPhone(subId); |
| 3620 | if (phone == null) { |
| 3621 | return null; |
| 3622 | } |
| 3623 | |
| 3624 | return phone.getServiceState(); |
| 3625 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 3626 | |
| 3627 | /** |
| 3628 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 3629 | * |
| 3630 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 3631 | * voicemail ringtone. |
| 3632 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 3633 | * PhoneAccount. |
| 3634 | */ |
| 3635 | @Override |
| 3636 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Ta-wei Yen | 00b4ab5 | 2017-04-11 13:24:26 -0700 | [diff] [blame] | 3637 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 3638 | if (phone == null) { |
Ta-wei Yen | 00b4ab5 | 2017-04-11 13:24:26 -0700 | [diff] [blame] | 3639 | phone = mPhone; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 3640 | } |
| 3641 | |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 3642 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 3643 | } |
| 3644 | |
| 3645 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 3646 | * Sets the per-account voicemail ringtone. |
| 3647 | * |
| 3648 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 3649 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 3650 | * |
| 3651 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 3652 | * voicemail ringtone. |
| 3653 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 3654 | * PhoneAccount. |
| 3655 | */ |
| 3656 | @Override |
| 3657 | public void setVoicemailRingtoneUri(String callingPackage, |
| 3658 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
| 3659 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3660 | if (!TextUtils.equals(callingPackage, |
| 3661 | TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3662 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3663 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 3664 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 3665 | } |
| 3666 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 3667 | if (phone == null){ |
Ta-wei Yen | 00b4ab5 | 2017-04-11 13:24:26 -0700 | [diff] [blame] | 3668 | phone = mPhone; |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 3669 | } |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 3670 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 3671 | } |
| 3672 | |
| 3673 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 3674 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 3675 | * |
| 3676 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 3677 | * voicemail vibration setting. |
| 3678 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 3679 | */ |
| 3680 | @Override |
| 3681 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Ta-wei Yen | 00b4ab5 | 2017-04-11 13:24:26 -0700 | [diff] [blame] | 3682 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 3683 | if (phone == null) { |
Ta-wei Yen | 00b4ab5 | 2017-04-11 13:24:26 -0700 | [diff] [blame] | 3684 | phone = mPhone; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 3685 | } |
| 3686 | |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 3687 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 3688 | } |
| 3689 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 3690 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 3691 | * Sets the per-account voicemail vibration. |
| 3692 | * |
| 3693 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 3694 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 3695 | * |
| 3696 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 3697 | * voicemail vibration setting. |
| 3698 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 3699 | * specific PhoneAccount. |
| 3700 | */ |
| 3701 | @Override |
| 3702 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 3703 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
| 3704 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3705 | if (!TextUtils.equals(callingPackage, |
| 3706 | TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3707 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3708 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 3709 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 3710 | } |
| 3711 | |
| 3712 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 3713 | if (phone == null){ |
Ta-wei Yen | 00b4ab5 | 2017-04-11 13:24:26 -0700 | [diff] [blame] | 3714 | phone = mPhone; |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 3715 | } |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 3716 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 3717 | } |
| 3718 | |
| 3719 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 3720 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 3721 | * |
| 3722 | * @throws SecurityException if the caller does not have the required permission |
| 3723 | */ |
| 3724 | private void enforceReadPrivilegedPermission() { |
| 3725 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 3726 | null); |
| 3727 | } |
| 3728 | |
| 3729 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3730 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 3731 | * permission. |
| 3732 | * |
| 3733 | * @throws SecurityException if the caller does not have the required permission |
| 3734 | */ |
| 3735 | private void enforceSendSmsPermission() { |
| 3736 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 3737 | } |
| 3738 | |
| 3739 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3740 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3741 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3742 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3743 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3744 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Ta-wei Yen | 5d81b0c | 2017-03-03 16:32:26 -0800 | [diff] [blame] | 3745 | ComponentName componentName = |
| 3746 | RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId); |
| 3747 | if(componentName == null) { |
| 3748 | throw new SecurityException("Caller not current active visual voicemail package[null]"); |
| 3749 | } |
| 3750 | String vvmPackage = componentName.getPackageName(); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3751 | if (!callingPackage.equals(vvmPackage)) { |
| 3752 | throw new SecurityException("Caller not current active visual voicemail package[" + |
| 3753 | vvmPackage + "]"); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3754 | } |
| 3755 | } |
| 3756 | |
| 3757 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 3758 | * Return the application ID for the app type. |
| 3759 | * |
| 3760 | * @param subId the subscription ID that this request applies to. |
| 3761 | * @param appType the uicc app type. |
| 3762 | * @return Application ID for specificied app type, or null if no uicc. |
| 3763 | */ |
| 3764 | @Override |
| 3765 | public String getAidForAppType(int subId, int appType) { |
| 3766 | enforceReadPrivilegedPermission(); |
| 3767 | Phone phone = getPhone(subId); |
| 3768 | if (phone == null) { |
| 3769 | return null; |
| 3770 | } |
| 3771 | String aid = null; |
| 3772 | try { |
| 3773 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 3774 | .getApplicationByType(appType).getAid(); |
| 3775 | } catch (Exception e) { |
| 3776 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 3777 | } |
| 3778 | return aid; |
| 3779 | } |
| 3780 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 3781 | /** |
| 3782 | * Return the Electronic Serial Number. |
| 3783 | * |
| 3784 | * @param subId the subscription ID that this request applies to. |
| 3785 | * @return ESN or null if error. |
| 3786 | */ |
| 3787 | @Override |
| 3788 | public String getEsn(int subId) { |
| 3789 | enforceReadPrivilegedPermission(); |
| 3790 | Phone phone = getPhone(subId); |
| 3791 | if (phone == null) { |
| 3792 | return null; |
| 3793 | } |
| 3794 | String esn = null; |
| 3795 | try { |
| 3796 | esn = phone.getEsn(); |
| 3797 | } catch (Exception e) { |
| 3798 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 3799 | } |
| 3800 | return esn; |
| 3801 | } |
| 3802 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 3803 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 3804 | * Return the Preferred Roaming List Version. |
| 3805 | * |
| 3806 | * @param subId the subscription ID that this request applies to. |
| 3807 | * @return PRLVersion or null if error. |
| 3808 | */ |
| 3809 | @Override |
| 3810 | public String getCdmaPrlVersion(int subId) { |
| 3811 | enforceReadPrivilegedPermission(); |
| 3812 | Phone phone = getPhone(subId); |
| 3813 | if (phone == null) { |
| 3814 | return null; |
| 3815 | } |
| 3816 | String cdmaPrlVersion = null; |
| 3817 | try { |
| 3818 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 3819 | } catch (Exception e) { |
| 3820 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 3821 | } |
| 3822 | return cdmaPrlVersion; |
| 3823 | } |
| 3824 | |
| 3825 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 3826 | * Get snapshot of Telephony histograms |
| 3827 | * @return List of Telephony histograms |
| 3828 | * @hide |
| 3829 | */ |
| 3830 | @Override |
| 3831 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3832 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3833 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 3834 | return RIL.getTelephonyRILTimingHistograms(); |
| 3835 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 3836 | |
| 3837 | /** |
| 3838 | * {@hide} |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3839 | * Set the allowed carrier list for slotIndex |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 3840 | * Require system privileges. In the future we may add this to carrier APIs. |
| 3841 | * |
| 3842 | * @return The number of carriers set successfully, should match length of carriers |
| 3843 | */ |
| 3844 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3845 | public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 3846 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3847 | |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 3848 | if (carriers == null) { |
| 3849 | throw new NullPointerException("carriers cannot be null"); |
| 3850 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3851 | |
| 3852 | int subId = SubscriptionManager.getSubId(slotIndex)[0]; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 3853 | int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId); |
| 3854 | return retVal[0]; |
| 3855 | } |
| 3856 | |
| 3857 | /** |
| 3858 | * {@hide} |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3859 | * Get the allowed carrier list for slotIndex. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 3860 | * Require system privileges. In the future we may add this to carrier APIs. |
| 3861 | * |
| 3862 | * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list |
| 3863 | * means all carriers are allowed. |
| 3864 | */ |
| 3865 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3866 | public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 3867 | enforceReadPrivilegedPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3868 | int subId = SubscriptionManager.getSubId(slotIndex)[0]; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 3869 | return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId); |
| 3870 | } |
| 3871 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 3872 | /** |
| 3873 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 3874 | * @param subId the subscription ID that this action applies to. |
| 3875 | * @param enabled control enable or disable metered apns. |
| 3876 | * {@hide} |
| 3877 | */ |
| 3878 | @Override |
| 3879 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 3880 | enforceModifyPermission(); |
| 3881 | final Phone phone = getPhone(subId); |
| 3882 | if (phone == null) { |
| 3883 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 3884 | return; |
| 3885 | } |
| 3886 | try { |
| 3887 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 3888 | } catch (Exception e) { |
| 3889 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
| 3890 | } |
| 3891 | } |
| 3892 | |
| 3893 | /** |
| 3894 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 3895 | * @param subId the subscription ID that this action applies to. |
| 3896 | * @param enabled control enable or disable radio. |
| 3897 | * {@hide} |
| 3898 | */ |
| 3899 | @Override |
| 3900 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 3901 | enforceModifyPermission(); |
| 3902 | final Phone phone = getPhone(subId); |
| 3903 | if (phone == null) { |
| 3904 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 3905 | return; |
| 3906 | } |
| 3907 | try { |
| 3908 | phone.carrierActionSetRadioEnabled(enabled); |
| 3909 | } catch (Exception e) { |
| 3910 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
| 3911 | } |
| 3912 | } |
| 3913 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 3914 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 3915 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 3916 | * network status based on which carrier apps could apply actions accordingly, |
| 3917 | * enable/disable default url handler for example. |
| 3918 | * |
| 3919 | * @param subId the subscription ID that this action applies to. |
| 3920 | * @param report control start/stop reporting the default network status. |
| 3921 | * {@hide} |
| 3922 | */ |
| 3923 | @Override |
| 3924 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 3925 | enforceModifyPermission(); |
| 3926 | final Phone phone = getPhone(subId); |
| 3927 | if (phone == null) { |
| 3928 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 3929 | return; |
| 3930 | } |
| 3931 | try { |
| 3932 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 3933 | } catch (Exception e) { |
| 3934 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
| 3935 | } |
| 3936 | } |
| 3937 | |
| 3938 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 3939 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 3940 | * bug report is being generated. |
| 3941 | */ |
| 3942 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 3943 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 3944 | if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 3945 | != PackageManager.PERMISSION_GRANTED) { |
| 3946 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 3947 | + Binder.getCallingPid() |
| 3948 | + ", uid=" + Binder.getCallingUid() |
| 3949 | + "without permission " |
| 3950 | + android.Manifest.permission.DUMP); |
| 3951 | return; |
| 3952 | } |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 3953 | DumpsysHandler.dump(mPhone.getContext(), fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 3954 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 3955 | |
| 3956 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 3957 | * Get aggregated video call data usage since boot. |
| 3958 | * |
| 3959 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 3960 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 3961 | * {@hide} |
| 3962 | */ |
| 3963 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 3964 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 3965 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 3966 | null); |
| 3967 | |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 3968 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 3969 | // records the delta with the corresponding network identity. We just return the total video |
| 3970 | // call data usage snapshot since boot. |
| 3971 | Phone phone = getPhone(subId); |
| 3972 | if (phone != null) { |
| 3973 | return phone.getVtDataUsage(perUidStats); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 3974 | } |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 3975 | return null; |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 3976 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 3977 | |
| 3978 | /** |
| 3979 | * Policy control of data connection. Usually used when data limit is passed. |
| 3980 | * @param enabled True if enabling the data, otherwise disabling. |
| 3981 | * @param subId Subscription index |
| 3982 | * {@hide} |
| 3983 | */ |
| 3984 | @Override |
| 3985 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 3986 | enforceModifyPermission(); |
| 3987 | Phone phone = getPhone(subId); |
| 3988 | if (phone != null) { |
| 3989 | phone.setPolicyDataEnabled(enabled); |
| 3990 | } |
| 3991 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 3992 | |
| 3993 | /** |
| 3994 | * Get Client request stats |
| 3995 | * @return List of Client Request Stats |
| 3996 | * @hide |
| 3997 | */ |
| 3998 | @Override |
| 3999 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4000 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4001 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 4002 | return null; |
| 4003 | } |
| 4004 | |
| 4005 | Phone phone = getPhone(subId); |
| 4006 | if (phone != null) { |
| 4007 | return phone.getClientRequestStats(); |
| 4008 | } |
| 4009 | |
| 4010 | return null; |
| 4011 | } |
| 4012 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 4013 | private WorkSource getWorkSource(int uid) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 4014 | String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 4015 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 4016 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 4017 | |
| 4018 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 4019 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 4020 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4021 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 4022 | * @param state State of SIM (power down, power up, pass through) |
| 4023 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 4024 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 4025 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 4026 | * |
| 4027 | **/ |
| 4028 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 4029 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 4030 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4031 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4032 | |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 4033 | if (phone != null) { |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 4034 | phone.setSimPowerState(state); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 4035 | } |
| 4036 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 4037 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 4038 | private boolean isUssdApiAllowed(int subId) { |
| 4039 | CarrierConfigManager configManager = |
| 4040 | (CarrierConfigManager) mPhone.getContext().getSystemService( |
| 4041 | Context.CARRIER_CONFIG_SERVICE); |
| 4042 | if (configManager == null) { |
| 4043 | return false; |
| 4044 | } |
| 4045 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 4046 | if (pb == null) { |
| 4047 | return false; |
| 4048 | } |
| 4049 | return pb.getBoolean( |
| 4050 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 4051 | } |
| 4052 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 4053 | /** |
| 4054 | * Check if phone is in emergency callback mode |
| 4055 | * @return true if phone is in emergency callback mode |
| 4056 | * @param subId sub id |
| 4057 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 4058 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 4059 | public boolean getEmergencyCallbackMode(int subId) { |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 4060 | enforceReadPrivilegedPermission(); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 4061 | final Phone phone = getPhone(subId); |
| 4062 | if (phone != null) { |
| 4063 | return phone.isInEcm(); |
| 4064 | } else { |
| 4065 | return false; |
| 4066 | } |
| 4067 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 4068 | |
| 4069 | /** |
| 4070 | * Get the current signal strength information for the given subscription. |
| 4071 | * Because this information is not updated when the device is in a low power state |
| 4072 | * it should not be relied-upon to be current. |
| 4073 | * @param subId Subscription index |
| 4074 | * @return the most recent cached signal strength info from the modem |
| 4075 | */ |
| 4076 | @Override |
| 4077 | public SignalStrength getSignalStrength(int subId) { |
| 4078 | Phone p = getPhone(subId); |
| 4079 | if (p == null) { |
| 4080 | return null; |
| 4081 | } |
| 4082 | |
| 4083 | return p.getSignalStrength(); |
| 4084 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 4085 | |
| 4086 | @Override |
| 4087 | public UiccSlotInfo[] getUiccSlotsInfo() { |
| 4088 | enforceReadPrivilegedPermission(); |
| 4089 | |
| 4090 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame^] | 4091 | if (slots == null) { |
| 4092 | Rlog.i(LOG_TAG, "slots is null."); |
| 4093 | return null; |
| 4094 | } |
| 4095 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 4096 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 4097 | for (int i = 0; i < slots.length; i++) { |
| 4098 | UiccSlot slot = slots[i]; |
| 4099 | |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame^] | 4100 | String cardId = null; |
| 4101 | UiccCard card = slot.getUiccCard(); |
| 4102 | if (card != null) { |
| 4103 | cardId = card.getCardId(); |
| 4104 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 4105 | |
| 4106 | int cardState = 0; |
| 4107 | switch (slot.getCardState()) { |
| 4108 | case CARDSTATE_ABSENT: |
| 4109 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 4110 | break; |
| 4111 | case CARDSTATE_PRESENT: |
| 4112 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 4113 | break; |
| 4114 | case CARDSTATE_ERROR: |
| 4115 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 4116 | break; |
| 4117 | case CARDSTATE_RESTRICTED: |
| 4118 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 4119 | break; |
| 4120 | default: |
| 4121 | break; |
| 4122 | |
| 4123 | } |
| 4124 | |
Qingxi Li | 795c588 | 2018-01-31 13:43:27 -0800 | [diff] [blame] | 4125 | infos[i] = new UiccSlotInfo( |
Qingxi Li | e724537 | 2018-03-07 10:52:26 -0800 | [diff] [blame] | 4126 | slot.isActive(), |
| 4127 | slot.isEuicc(), |
| 4128 | cardId, |
| 4129 | cardState, |
| 4130 | slot.getPhoneId(), |
| 4131 | slot.isExtendedApduSupported()); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 4132 | } |
| 4133 | return infos; |
| 4134 | } |
| 4135 | |
| 4136 | @Override |
| 4137 | public boolean switchSlots(int[] physicalSlots) { |
| 4138 | enforceModifyPermission(); |
| 4139 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 4140 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 4141 | |
| 4142 | @Override |
| 4143 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 4144 | enforceModifyPermission(); |
| 4145 | final Phone phone = getPhone(subId); |
| 4146 | if (phone == null) { |
| 4147 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 4148 | return; |
| 4149 | } |
| 4150 | |
| 4151 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 4152 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 4153 | |
| 4154 | /** |
| 4155 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 4156 | */ |
| 4157 | private boolean getDefaultDataEnabled() { |
| 4158 | return "true".equalsIgnoreCase( |
| 4159 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 4160 | } |
| 4161 | |
| 4162 | /** |
| 4163 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 4164 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 4165 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 4166 | */ |
| 4167 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 4168 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
| 4169 | mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| 4170 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 4171 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 4172 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 4173 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 4174 | return isDataRoamingEnabled; |
| 4175 | } |
| 4176 | |
| 4177 | /** |
| 4178 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 4179 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 4180 | */ |
| 4181 | private int getDefaultNetworkType(int subId) { |
| 4182 | return Integer.parseInt( |
| 4183 | TelephonyManager.getTelephonyProperty( |
| 4184 | mSubscriptionController.getPhoneId(subId), |
| 4185 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 4186 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 4187 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 4188 | |
| 4189 | @Override |
| 4190 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
| 4191 | gid1, String gid2, String plmn, String spn) { |
| 4192 | enforceModifyPermission(); |
| 4193 | final Phone phone = getPhone(subId); |
| 4194 | if (phone == null) { |
| 4195 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 4196 | return; |
| 4197 | } |
| 4198 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn); |
| 4199 | } |
| 4200 | |
| 4201 | @Override |
| 4202 | public int getCarrierIdListVersion(int subId) { |
| 4203 | enforceReadPrivilegedPermission(); |
| 4204 | final Phone phone = getPhone(subId); |
| 4205 | if (phone == null) { |
| 4206 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 4207 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 4208 | } |
| 4209 | return phone.getCarrierIdListVersion(); |
| 4210 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4211 | } |