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