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