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