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