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