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