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