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