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 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 22 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 23 | import android.Manifest.permission; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 24 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 25 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 26 | import android.content.ComponentName; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.content.Context; |
| 28 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 29 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 30 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 31 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 32 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 33 | import android.content.pm.PackageManager; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 34 | import android.net.NetworkStats; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 35 | import android.net.Uri; |
| 36 | import android.os.AsyncResult; |
| 37 | import android.os.Binder; |
| 38 | import android.os.Bundle; |
| 39 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 40 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.os.Looper; |
| 42 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 43 | import android.os.Messenger; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 44 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 45 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 46 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 47 | import android.os.ServiceManager; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 48 | import android.os.ShellCallback; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 49 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 51 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 52 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 53 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 54 | import android.provider.Settings; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 55 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 56 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 57 | import android.telecom.TelecomManager; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 58 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 59 | import android.telephony.CarrierRestrictionRules; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 60 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 61 | import android.telephony.CellInfoGsm; |
| 62 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 63 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 64 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 65 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 66 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 67 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 68 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 69 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 70 | import android.telephony.NetworkScanRequest; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 71 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 72 | import android.telephony.RadioAccessFamily; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 73 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 74 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 75 | import android.telephony.SignalStrength; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 76 | import android.telephony.SmsManager; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 77 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 78 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 79 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 80 | import android.telephony.TelephonyManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 81 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 82 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 83 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 84 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 85 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 86 | import android.telephony.data.ApnSetting; |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 87 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 88 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 89 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 90 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 91 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 92 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 93 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 94 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 95 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 96 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 97 | import android.telephony.ims.feature.MmTelFeature; |
| 98 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 99 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 100 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 101 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 102 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 103 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 104 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 105 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 106 | import com.android.ims.ImsException; |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 107 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 108 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 109 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 110 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 111 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 112 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 113 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 114 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 115 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 116 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 117 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 118 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 119 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 120 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 121 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 122 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.Phone; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 125 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.ServiceStateTracker; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.SmsApplication; |
| 133 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 135 | import com.android.internal.telephony.TelephonyPermissions; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.euicc.EuiccConnector; |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.uicc.IccIoResult; |
| 140 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 141 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 146 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 148 | import com.android.internal.util.HexDump; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 149 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 150 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 151 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 152 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 153 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 154 | import java.io.FileDescriptor; |
| 155 | import java.io.PrintWriter; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 156 | import java.nio.charset.StandardCharsets; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 157 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 158 | import java.util.Arrays; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 159 | import java.util.Collection; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 160 | import java.util.HashMap; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 161 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 162 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 163 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 164 | import java.util.Map; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 165 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 166 | |
| 167 | /** |
| 168 | * Implementation of the ITelephony interface. |
| 169 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 170 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 171 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 172 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 173 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 174 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 175 | |
| 176 | // Message codes used with mMainThreadHandler |
| 177 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 178 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 179 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 180 | private static final int CMD_OPEN_CHANNEL = 9; |
| 181 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 182 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 183 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 184 | private static final int CMD_NV_READ_ITEM = 13; |
| 185 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 186 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 187 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 188 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 189 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 190 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 191 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 192 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 193 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 194 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 195 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 196 | private static final int CMD_SEND_ENVELOPE = 25; |
| 197 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 198 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 199 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 200 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 201 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 202 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 203 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 204 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 205 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 206 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 207 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 208 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 209 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 210 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 211 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 212 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 213 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 214 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 215 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 216 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 217 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 218 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 219 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 220 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 221 | private static final int CMD_SWITCH_SLOTS = 50; |
| 222 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 223 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 224 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 225 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 226 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 227 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 228 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 229 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 230 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 231 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 232 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 233 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 234 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 235 | private static final int CMD_MODEM_REBOOT = 64; |
| 236 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 237 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 238 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 239 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 240 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 241 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 242 | // Parameters of select command. |
| 243 | private static final int SELECT_COMMAND = 0xA4; |
| 244 | private static final int SELECT_P1 = 0x04; |
| 245 | private static final int SELECT_P2 = 0; |
| 246 | private static final int SELECT_P3 = 0x10; |
| 247 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 248 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 249 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 250 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 251 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 252 | /** The singleton instance. */ |
| 253 | private static PhoneInterfaceManager sInstance; |
| 254 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 255 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 256 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 257 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 258 | private AppOpsManager mAppOps; |
| 259 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 260 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 261 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 262 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 263 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 264 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 265 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 266 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 267 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 268 | |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 269 | // String to store multi SIM allowed |
| 270 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 271 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 272 | // The AID of ISD-R. |
| 273 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 274 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 275 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 276 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 277 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 278 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 279 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 280 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 281 | * A request object to use for transmitting data to an ICC. |
| 282 | */ |
| 283 | private static final class IccAPDUArgument { |
| 284 | public int channel, cla, command, p1, p2, p3; |
| 285 | public String data; |
| 286 | |
| 287 | public IccAPDUArgument(int channel, int cla, int command, |
| 288 | int p1, int p2, int p3, String data) { |
| 289 | this.channel = channel; |
| 290 | this.cla = cla; |
| 291 | this.command = command; |
| 292 | this.p1 = p1; |
| 293 | this.p2 = p2; |
| 294 | this.p3 = p3; |
| 295 | this.data = data; |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 300 | * A request object to use for transmitting data to an ICC. |
| 301 | */ |
| 302 | private static final class ManualNetworkSelectionArgument { |
| 303 | public OperatorInfo operatorInfo; |
| 304 | public boolean persistSelection; |
| 305 | |
| 306 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 307 | this.operatorInfo = operatorInfo; |
| 308 | this.persistSelection = persistSelection; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 313 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 314 | * request after sending. The main thread will notify the request when it is complete. |
| 315 | */ |
| 316 | private static final class MainThreadRequest { |
| 317 | /** The argument to use for the request */ |
| 318 | public Object argument; |
| 319 | /** The result of the request that is run on the main thread */ |
| 320 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 321 | // The subscriber id that this request applies to. Defaults to |
| 322 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 323 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 324 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 325 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 326 | public Phone phone; |
| 327 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 328 | public WorkSource workSource; |
| 329 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 330 | public MainThreadRequest(Object argument) { |
| 331 | this.argument = argument; |
| 332 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 333 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 334 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 335 | this.argument = argument; |
| 336 | if (phone != null) { |
| 337 | this.phone = phone; |
| 338 | } |
| 339 | this.workSource = workSource; |
| 340 | } |
| 341 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 342 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 343 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 344 | if (subId != null) { |
| 345 | this.subId = subId; |
| 346 | } |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 347 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 348 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 351 | private static final class IncomingThirdPartyCallArgs { |
| 352 | public final ComponentName component; |
| 353 | public final String callId; |
| 354 | public final String callerDisplayName; |
| 355 | |
| 356 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 357 | String callerDisplayName) { |
| 358 | this.component = component; |
| 359 | this.callId = callId; |
| 360 | this.callerDisplayName = callerDisplayName; |
| 361 | } |
| 362 | } |
| 363 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 364 | /** |
| 365 | * A handler that processes messages on the main thread in the phone process. Since many |
| 366 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 367 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 368 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 369 | * on, which will be notified when the operation completes and will contain the result of the |
| 370 | * request. |
| 371 | * |
| 372 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 373 | * note that request.result must be set to something non-null for the calling thread to |
| 374 | * unblock. |
| 375 | */ |
| 376 | private final class MainThreadHandler extends Handler { |
| 377 | @Override |
| 378 | public void handleMessage(Message msg) { |
| 379 | MainThreadRequest request; |
| 380 | Message onCompleted; |
| 381 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 382 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 383 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 384 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 385 | |
| 386 | switch (msg.what) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 387 | case CMD_HANDLE_USSD_REQUEST: { |
| 388 | request = (MainThreadRequest) msg.obj; |
| 389 | final Phone phone = getPhoneFromRequest(request); |
| 390 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 391 | String ussdRequest = ussdObject.first; |
| 392 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 393 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 394 | if (!isUssdApiAllowed(request.subId)) { |
| 395 | // Carrier does not support use of this API, return failure. |
| 396 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 397 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 398 | Bundle returnData = new Bundle(); |
| 399 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 400 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 401 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 402 | request.result = true; |
| 403 | notifyRequester(request); |
| 404 | return; |
| 405 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 406 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 407 | try { |
| 408 | request.result = phone != null |
| 409 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 410 | } catch (CallStateException cse) { |
| 411 | request.result = false; |
| 412 | } |
| 413 | // Wake up the requesting thread |
| 414 | notifyRequester(request); |
| 415 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 418 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 419 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 420 | final Phone phone = getPhoneFromRequest(request); |
| 421 | request.result = phone != null ? |
| 422 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 423 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 424 | // Wake up the requesting thread |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 425 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 426 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 427 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 428 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 429 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 430 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 431 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 432 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 433 | if (uiccCard == null) { |
| 434 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 435 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 436 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 437 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 438 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 439 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 440 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 441 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 442 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 443 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 444 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 445 | break; |
| 446 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 447 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 448 | ar = (AsyncResult) msg.obj; |
| 449 | request = (MainThreadRequest) ar.userObj; |
| 450 | if (ar.exception == null && ar.result != null) { |
| 451 | request.result = ar.result; |
| 452 | } else { |
| 453 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 454 | if (ar.result == null) { |
| 455 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 456 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 457 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 458 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 459 | } else { |
| 460 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 461 | } |
| 462 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 463 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 464 | break; |
| 465 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 466 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 467 | request = (MainThreadRequest) msg.obj; |
| 468 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 469 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 470 | if (uiccCard == null) { |
| 471 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 472 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 473 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 474 | } else { |
| 475 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 476 | request); |
| 477 | uiccCard.iccTransmitApduBasicChannel( |
| 478 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 479 | iccArgument.p3, iccArgument.data, onCompleted); |
| 480 | } |
| 481 | break; |
| 482 | |
| 483 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 484 | ar = (AsyncResult) msg.obj; |
| 485 | request = (MainThreadRequest) ar.userObj; |
| 486 | if (ar.exception == null && ar.result != null) { |
| 487 | request.result = ar.result; |
| 488 | } else { |
| 489 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 490 | if (ar.result == null) { |
| 491 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 492 | } else if (ar.exception instanceof CommandException) { |
| 493 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 494 | ar.exception); |
| 495 | } else { |
| 496 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 497 | } |
| 498 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 499 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 500 | break; |
| 501 | |
| 502 | case CMD_EXCHANGE_SIM_IO: |
| 503 | request = (MainThreadRequest) msg.obj; |
| 504 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 505 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 506 | if (uiccCard == null) { |
| 507 | loge("iccExchangeSimIO: No UICC"); |
| 508 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 509 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 510 | } else { |
| 511 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 512 | request); |
| 513 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 514 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 515 | iccArgument.data, onCompleted); |
| 516 | } |
| 517 | break; |
| 518 | |
| 519 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 520 | ar = (AsyncResult) msg.obj; |
| 521 | request = (MainThreadRequest) ar.userObj; |
| 522 | if (ar.exception == null && ar.result != null) { |
| 523 | request.result = ar.result; |
| 524 | } else { |
| 525 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 526 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 527 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 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); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 536 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 537 | } else { |
| 538 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 539 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 540 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 541 | break; |
| 542 | |
| 543 | case EVENT_SEND_ENVELOPE_DONE: |
| 544 | ar = (AsyncResult) msg.obj; |
| 545 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 546 | if (ar.exception == null && ar.result != null) { |
| 547 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 548 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 549 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 550 | if (ar.result == null) { |
| 551 | loge("sendEnvelopeWithStatus: Empty response"); |
| 552 | } else if (ar.exception instanceof CommandException) { |
| 553 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 554 | ar.exception); |
| 555 | } else { |
| 556 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 557 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 558 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 559 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 560 | break; |
| 561 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 562 | case CMD_OPEN_CHANNEL: |
| 563 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 564 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 565 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 566 | if (uiccCard == null) { |
| 567 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 568 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 569 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 570 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 571 | } else { |
| 572 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 573 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 574 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 575 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 576 | break; |
| 577 | |
| 578 | case EVENT_OPEN_CHANNEL_DONE: |
| 579 | ar = (AsyncResult) msg.obj; |
| 580 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 581 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 582 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 583 | int[] result = (int[]) ar.result; |
| 584 | int channelId = result[0]; |
| 585 | byte[] selectResponse = null; |
| 586 | if (result.length > 1) { |
| 587 | selectResponse = new byte[result.length - 1]; |
| 588 | for (int i = 1; i < result.length; ++i) { |
| 589 | selectResponse[i - 1] = (byte) result[i]; |
| 590 | } |
| 591 | } |
| 592 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 593 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 594 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 595 | if (ar.result == null) { |
| 596 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 597 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 598 | if (ar.exception != null) { |
| 599 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 600 | } |
| 601 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 602 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 603 | if (ar.exception instanceof CommandException) { |
| 604 | CommandException.Error error = |
| 605 | ((CommandException) (ar.exception)).getCommandError(); |
| 606 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 607 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 608 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 609 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 610 | } |
| 611 | } |
| 612 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 613 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 614 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 615 | request.result = openChannelResp; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 616 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 617 | break; |
| 618 | |
| 619 | case CMD_CLOSE_CHANNEL: |
| 620 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 621 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 622 | if (uiccCard == null) { |
| 623 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 624 | request.result = false; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 625 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 626 | } else { |
| 627 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 628 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 629 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 630 | break; |
| 631 | |
| 632 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 633 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 634 | break; |
| 635 | |
| 636 | case CMD_NV_READ_ITEM: |
| 637 | request = (MainThreadRequest) msg.obj; |
| 638 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 639 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 640 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 641 | break; |
| 642 | |
| 643 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 644 | ar = (AsyncResult) msg.obj; |
| 645 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 646 | if (ar.exception == null && ar.result != null) { |
| 647 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 648 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 649 | request.result = ""; |
| 650 | if (ar.result == null) { |
| 651 | loge("nvReadItem: Empty response"); |
| 652 | } else if (ar.exception instanceof CommandException) { |
| 653 | loge("nvReadItem: CommandException: " + |
| 654 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 655 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 656 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 657 | } |
| 658 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 659 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 660 | break; |
| 661 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 662 | case CMD_NV_WRITE_ITEM: |
| 663 | request = (MainThreadRequest) msg.obj; |
| 664 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 665 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 666 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 667 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 668 | break; |
| 669 | |
| 670 | case EVENT_NV_WRITE_ITEM_DONE: |
| 671 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 672 | break; |
| 673 | |
| 674 | case CMD_NV_WRITE_CDMA_PRL: |
| 675 | request = (MainThreadRequest) msg.obj; |
| 676 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 677 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 678 | break; |
| 679 | |
| 680 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 681 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 682 | break; |
| 683 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 684 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 685 | request = (MainThreadRequest) msg.obj; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 686 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 687 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 688 | break; |
| 689 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 690 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 691 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 692 | break; |
| 693 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 694 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 695 | request = (MainThreadRequest) msg.obj; |
| 696 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 697 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 698 | break; |
| 699 | |
| 700 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 701 | ar = (AsyncResult) msg.obj; |
| 702 | request = (MainThreadRequest) ar.userObj; |
| 703 | if (ar.exception == null && ar.result != null) { |
| 704 | request.result = ar.result; // Integer |
| 705 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 706 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 707 | if (ar.result == null) { |
| 708 | loge("getPreferredNetworkType: Empty response"); |
| 709 | } else if (ar.exception instanceof CommandException) { |
| 710 | loge("getPreferredNetworkType: CommandException: " + |
| 711 | ar.exception); |
| 712 | } else { |
| 713 | loge("getPreferredNetworkType: Unknown exception"); |
| 714 | } |
| 715 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 716 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 717 | break; |
| 718 | |
| 719 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 720 | request = (MainThreadRequest) msg.obj; |
| 721 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 722 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 723 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 724 | break; |
| 725 | |
| 726 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 727 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 728 | break; |
| 729 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 730 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 731 | request = (MainThreadRequest)msg.obj; |
| 732 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 733 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 734 | break; |
| 735 | |
| 736 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 737 | ar = (AsyncResult)msg.obj; |
| 738 | request = (MainThreadRequest)ar.userObj; |
| 739 | request.result = ar; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 740 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 741 | break; |
| 742 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 743 | case CMD_SET_VOICEMAIL_NUMBER: |
| 744 | request = (MainThreadRequest) msg.obj; |
| 745 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 746 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 747 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 748 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 749 | break; |
| 750 | |
| 751 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 752 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 753 | break; |
| 754 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 755 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 756 | request = (MainThreadRequest) msg.obj; |
| 757 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 758 | request); |
| 759 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 760 | break; |
| 761 | |
| 762 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 763 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 764 | break; |
| 765 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 766 | case CMD_PERFORM_NETWORK_SCAN: |
| 767 | request = (MainThreadRequest) msg.obj; |
| 768 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 769 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 770 | break; |
| 771 | |
| 772 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 773 | ar = (AsyncResult) msg.obj; |
| 774 | request = (MainThreadRequest) ar.userObj; |
| 775 | CellNetworkScanResult cellScanResult; |
| 776 | if (ar.exception == null && ar.result != null) { |
| 777 | cellScanResult = new CellNetworkScanResult( |
| 778 | CellNetworkScanResult.STATUS_SUCCESS, |
| 779 | (List<OperatorInfo>) ar.result); |
| 780 | } else { |
| 781 | if (ar.result == null) { |
| 782 | loge("getCellNetworkScanResults: Empty response"); |
| 783 | } |
| 784 | if (ar.exception != null) { |
| 785 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 786 | } |
| 787 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 788 | if (ar.exception instanceof CommandException) { |
| 789 | CommandException.Error error = |
| 790 | ((CommandException) (ar.exception)).getCommandError(); |
| 791 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 792 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 793 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 794 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 795 | } |
| 796 | } |
| 797 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 798 | } |
| 799 | request.result = cellScanResult; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 800 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 801 | break; |
| 802 | |
| 803 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 804 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 805 | ManualNetworkSelectionArgument selArg = |
| 806 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 807 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 808 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 809 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 810 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 811 | break; |
| 812 | |
| 813 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | dd9ac82 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 814 | ar = (AsyncResult) msg.obj; |
| 815 | request = (MainThreadRequest) ar.userObj; |
| 816 | if (ar.exception == null) { |
| 817 | request.result = true; |
| 818 | } else { |
| 819 | request.result = false; |
| 820 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 821 | } |
| 822 | notifyRequester(request); |
| 823 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 824 | break; |
| 825 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 826 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 827 | request = (MainThreadRequest) msg.obj; |
| 828 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 829 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 830 | break; |
| 831 | |
| 832 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 833 | ar = (AsyncResult) msg.obj; |
| 834 | request = (MainThreadRequest) ar.userObj; |
| 835 | if (ar.exception == null && ar.result != null) { |
| 836 | request.result = ar.result; |
| 837 | } else { |
| 838 | if (ar.result == null) { |
| 839 | loge("queryModemActivityInfo: Empty response"); |
| 840 | } else if (ar.exception instanceof CommandException) { |
| 841 | loge("queryModemActivityInfo: CommandException: " + |
| 842 | ar.exception); |
| 843 | } else { |
| 844 | loge("queryModemActivityInfo: Unknown exception"); |
| 845 | } |
| 846 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 847 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 848 | if (request.result == null) { |
| 849 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 850 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 851 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 852 | break; |
| 853 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 854 | case CMD_SET_ALLOWED_CARRIERS: |
| 855 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 856 | CarrierRestrictionRules argument = |
| 857 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 858 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 859 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 860 | break; |
| 861 | |
| 862 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 863 | ar = (AsyncResult) msg.obj; |
| 864 | request = (MainThreadRequest) ar.userObj; |
| 865 | if (ar.exception == null && ar.result != null) { |
| 866 | request.result = ar.result; |
| 867 | } else { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 868 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 869 | if (ar.exception instanceof CommandException) { |
| 870 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 871 | CommandException.Error error = |
| 872 | ((CommandException) (ar.exception)).getCommandError(); |
| 873 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 874 | request.result = |
| 875 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 876 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 877 | } else { |
| 878 | loge("setAllowedCarriers: Unknown exception"); |
| 879 | } |
| 880 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 881 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 882 | break; |
| 883 | |
| 884 | case CMD_GET_ALLOWED_CARRIERS: |
| 885 | request = (MainThreadRequest) msg.obj; |
| 886 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 887 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 888 | break; |
| 889 | |
| 890 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 891 | ar = (AsyncResult) msg.obj; |
| 892 | request = (MainThreadRequest) ar.userObj; |
| 893 | if (ar.exception == null && ar.result != null) { |
| 894 | request.result = ar.result; |
| 895 | } else { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 896 | request.result = new IllegalStateException( |
| 897 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 898 | if (ar.result == null) { |
| 899 | loge("getAllowedCarriers: Empty response"); |
| 900 | } else if (ar.exception instanceof CommandException) { |
| 901 | loge("getAllowedCarriers: CommandException: " + |
| 902 | ar.exception); |
| 903 | } else { |
| 904 | loge("getAllowedCarriers: Unknown exception"); |
| 905 | } |
| 906 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 907 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 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 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 924 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 925 | break; |
| 926 | |
| 927 | case CMD_GET_FORBIDDEN_PLMNS: |
| 928 | request = (MainThreadRequest) msg.obj; |
| 929 | uiccCard = getUiccCardFromRequest(request); |
| 930 | if (uiccCard == null) { |
| 931 | loge("getForbiddenPlmns() UiccCard is null"); |
| 932 | request.result = new IllegalArgumentException( |
| 933 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 934 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 935 | break; |
| 936 | } |
| 937 | Integer appType = (Integer) request.argument; |
| 938 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 939 | if (uiccApp == null) { |
| 940 | loge("getForbiddenPlmns() no app with specified type -- " |
| 941 | + appType); |
| 942 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 943 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 944 | break; |
| 945 | } else { |
| 946 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 947 | + " specified type -- " + appType); |
| 948 | } |
| 949 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 950 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 951 | onCompleted); |
| 952 | break; |
| 953 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 954 | case CMD_SWITCH_SLOTS: |
| 955 | request = (MainThreadRequest) msg.obj; |
| 956 | int[] physicalSlots = (int[]) request.argument; |
| 957 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 958 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 959 | break; |
| 960 | |
| 961 | case EVENT_SWITCH_SLOTS_DONE: |
| 962 | ar = (AsyncResult) msg.obj; |
| 963 | request = (MainThreadRequest) ar.userObj; |
| 964 | request.result = (ar.exception == null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 965 | notifyRequester(request); |
| 966 | break; |
| 967 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 968 | request = (MainThreadRequest) msg.obj; |
| 969 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 970 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 971 | break; |
| 972 | |
| 973 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 974 | ar = (AsyncResult) msg.obj; |
| 975 | request = (MainThreadRequest) ar.userObj; |
| 976 | if (ar.exception != null) { |
| 977 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 978 | } else { |
| 979 | int mode = ((int[]) ar.result)[0]; |
| 980 | if (mode == 0) { |
| 981 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 982 | } else { |
| 983 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 984 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 985 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 986 | notifyRequester(request); |
| 987 | break; |
| 988 | case CMD_GET_CDMA_ROAMING_MODE: |
| 989 | request = (MainThreadRequest) msg.obj; |
| 990 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 991 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 992 | break; |
| 993 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 994 | ar = (AsyncResult) msg.obj; |
| 995 | request = (MainThreadRequest) ar.userObj; |
| 996 | if (ar.exception != null) { |
| 997 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 998 | } else { |
| 999 | request.result = ((int[]) ar.result)[0]; |
| 1000 | } |
| 1001 | notifyRequester(request); |
| 1002 | break; |
| 1003 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1004 | request = (MainThreadRequest) msg.obj; |
| 1005 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1006 | int mode = (int) request.argument; |
| 1007 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1008 | break; |
| 1009 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1010 | ar = (AsyncResult) msg.obj; |
| 1011 | request = (MainThreadRequest) ar.userObj; |
| 1012 | request.result = ar.exception == null; |
| 1013 | notifyRequester(request); |
| 1014 | break; |
| 1015 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1016 | request = (MainThreadRequest) msg.obj; |
| 1017 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1018 | int subscriptionMode = (int) request.argument; |
| 1019 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1020 | break; |
| 1021 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1022 | ar = (AsyncResult) msg.obj; |
| 1023 | request = (MainThreadRequest) ar.userObj; |
| 1024 | request.result = ar.exception == null; |
| 1025 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1026 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1027 | case CMD_GET_ALL_CELL_INFO: |
| 1028 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1029 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1030 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1031 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1032 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1033 | ar = (AsyncResult) msg.obj; |
| 1034 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1035 | // If a timeout occurs, the response will be null |
| 1036 | request.result = (ar.exception == null && ar.result != null) |
| 1037 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1038 | synchronized (request) { |
| 1039 | request.notifyAll(); |
| 1040 | } |
| 1041 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1042 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1043 | request = (MainThreadRequest) msg.obj; |
| 1044 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1045 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1046 | break; |
| 1047 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1048 | ar = (AsyncResult) msg.obj; |
| 1049 | request = (MainThreadRequest) ar.userObj; |
| 1050 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1051 | try { |
| 1052 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1053 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1054 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1055 | new android.os.ParcelableException(ar.exception)); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1056 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1057 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1058 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1059 | } else { |
| 1060 | // use the result as returned |
| 1061 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1062 | } |
| 1063 | } catch (RemoteException re) { |
| 1064 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1065 | } |
| 1066 | break; |
| 1067 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1068 | request = (MainThreadRequest) msg.obj; |
| 1069 | WorkSource ws = (WorkSource) request.argument; |
| 1070 | Phone phone = getPhoneFromRequest(request); |
| 1071 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1072 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1073 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1074 | ar = (AsyncResult) msg.obj; |
| 1075 | request = (MainThreadRequest) ar.userObj; |
| 1076 | if (ar.exception == null) { |
| 1077 | request.result = ar.result; |
| 1078 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1079 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1080 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1081 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1082 | } |
| 1083 | |
| 1084 | synchronized (request) { |
| 1085 | request.notifyAll(); |
| 1086 | } |
| 1087 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1088 | case CMD_MODEM_REBOOT: |
| 1089 | request = (MainThreadRequest) msg.obj; |
| 1090 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1091 | defaultPhone.rebootModem(onCompleted); |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1092 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1093 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1094 | handleNullReturnEvent(msg, "rebootModem"); |
| 1095 | break; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1096 | case CMD_REQUEST_ENABLE_MODEM: |
| 1097 | request = (MainThreadRequest) msg.obj; |
| 1098 | boolean enable = (boolean) request.argument; |
| 1099 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
| 1100 | PhoneConfigurationManager.getInstance() |
| 1101 | .enablePhone(request.phone, enable, onCompleted); |
| 1102 | break; |
| 1103 | case EVENT_ENABLE_MODEM_DONE: |
| 1104 | ar = (AsyncResult) msg.obj; |
| 1105 | request = (MainThreadRequest) ar.userObj; |
| 1106 | request.result = (ar.exception == null); |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 1107 | updateModemStateMetrics(); |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1108 | notifyRequester(request); |
| 1109 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1110 | default: |
| 1111 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1112 | break; |
| 1113 | } |
| 1114 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1115 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1116 | private void notifyRequester(MainThreadRequest request) { |
| 1117 | synchronized (request) { |
| 1118 | request.notifyAll(); |
| 1119 | } |
| 1120 | } |
| 1121 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1122 | private void handleNullReturnEvent(Message msg, String command) { |
| 1123 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1124 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1125 | if (ar.exception == null) { |
| 1126 | request.result = true; |
| 1127 | } else { |
| 1128 | request.result = false; |
| 1129 | if (ar.exception instanceof CommandException) { |
| 1130 | loge(command + ": CommandException: " + ar.exception); |
| 1131 | } else { |
| 1132 | loge(command + ": Unknown exception"); |
| 1133 | } |
| 1134 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1135 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1136 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | /** |
| 1140 | * Posts the specified command to be executed on the main thread, |
| 1141 | * waits for the request to complete, and returns the result. |
| 1142 | * @see #sendRequestAsync |
| 1143 | */ |
| 1144 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1145 | return sendRequest( |
| 1146 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | /** |
| 1150 | * Posts the specified command to be executed on the main thread, |
| 1151 | * waits for the request to complete, and returns the result. |
| 1152 | * @see #sendRequestAsync |
| 1153 | */ |
| 1154 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1155 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1156 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | /** |
| 1160 | * Posts the specified command to be executed on the main thread, |
| 1161 | * waits for the request to complete, and returns the result. |
| 1162 | * @see #sendRequestAsync |
| 1163 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1164 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1165 | return sendRequest(command, argument, subId, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | /** |
| 1169 | * Posts the specified command to be executed on the main thread, |
| 1170 | * waits for the request to complete, and returns the result. |
| 1171 | * @see #sendRequestAsync |
| 1172 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1173 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1174 | return sendRequest(command, argument, subId, null, workSource); |
| 1175 | } |
| 1176 | |
| 1177 | /** |
| 1178 | * Posts the specified command to be executed on the main thread, |
| 1179 | * waits for the request to complete, and returns the result. |
| 1180 | * @see #sendRequestAsync |
| 1181 | */ |
| 1182 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1183 | return sendRequest( |
| 1184 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1185 | } |
| 1186 | |
| 1187 | /** |
| 1188 | * Posts the specified command to be executed on the main thread, |
| 1189 | * waits for the request to complete, and returns the result. |
| 1190 | * @see #sendRequestAsync |
| 1191 | */ |
| 1192 | private Object sendRequest( |
| 1193 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1194 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1195 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1196 | } |
| 1197 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1198 | MainThreadRequest request = null; |
| 1199 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1200 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1201 | } else if (phone != null) { |
| 1202 | request = new MainThreadRequest(argument, phone, workSource); |
| 1203 | } else { |
| 1204 | request = new MainThreadRequest(argument, subId, workSource); |
| 1205 | } |
| 1206 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1207 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1208 | msg.sendToTarget(); |
| 1209 | |
| 1210 | // Wait for the request to complete |
| 1211 | synchronized (request) { |
| 1212 | while (request.result == null) { |
| 1213 | try { |
| 1214 | request.wait(); |
| 1215 | } catch (InterruptedException e) { |
| 1216 | // Do nothing, go back and wait until the request is complete |
| 1217 | } |
| 1218 | } |
| 1219 | } |
| 1220 | return request.result; |
| 1221 | } |
| 1222 | |
| 1223 | /** |
| 1224 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1225 | * Posts the specified command to be executed on the main thread, and |
| 1226 | * returns immediately. |
| 1227 | * @see #sendRequest |
| 1228 | */ |
| 1229 | private void sendRequestAsync(int command) { |
| 1230 | mMainThreadHandler.sendEmptyMessage(command); |
| 1231 | } |
| 1232 | |
| 1233 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1234 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1235 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1236 | */ |
| 1237 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1238 | sendRequestAsync(command, argument, null, null); |
| 1239 | } |
| 1240 | |
| 1241 | /** |
| 1242 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1243 | * @see {@link #sendRequest(int,Object)} |
| 1244 | */ |
| 1245 | private void sendRequestAsync( |
| 1246 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1247 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1248 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1249 | msg.sendToTarget(); |
| 1250 | } |
| 1251 | |
| 1252 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1253 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1254 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1255 | */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1256 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1257 | synchronized (PhoneInterfaceManager.class) { |
| 1258 | if (sInstance == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1259 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1260 | } else { |
| 1261 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1262 | } |
| 1263 | return sInstance; |
| 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1268 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1269 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1270 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1271 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1272 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1273 | mMainThreadHandler = new MainThreadHandler(); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1274 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1275 | mTelephonySharedPreferences = |
| 1276 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1277 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1278 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1279 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1280 | publish(); |
| 1281 | } |
| 1282 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1283 | private Phone getDefaultPhone() { |
| 1284 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1285 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1286 | } |
| 1287 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1288 | private void publish() { |
| 1289 | if (DBG) log("publish: " + this); |
| 1290 | |
| 1291 | ServiceManager.addService("phone", this); |
| 1292 | } |
| 1293 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1294 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 1295 | return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1296 | ? getDefaultPhone() : getPhone(request.subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1297 | } |
| 1298 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1299 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1300 | Phone phone = getPhoneFromRequest(request); |
| 1301 | return phone == null ? null : |
| 1302 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1303 | } |
| 1304 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1305 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1306 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1307 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1308 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1309 | |
| 1310 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1311 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1312 | } |
| 1313 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1314 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1315 | if (DBG) log("dial: " + number); |
| 1316 | // No permission check needed here: This is just a wrapper around the |
| 1317 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1318 | // the UI before it does anything. |
| 1319 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1320 | final long identity = Binder.clearCallingIdentity(); |
| 1321 | try { |
| 1322 | String url = createTelUrl(number); |
| 1323 | if (url == null) { |
| 1324 | return; |
| 1325 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1326 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1327 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1328 | PhoneConstants.State state = mCM.getState(subId); |
| 1329 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1330 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1331 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1332 | mApp.startActivity(intent); |
| 1333 | } |
| 1334 | } finally { |
| 1335 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1340 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1341 | } |
| 1342 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1343 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1344 | if (DBG) log("call: " + number); |
| 1345 | |
| 1346 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1347 | // need to do a permission check since we're calling startActivity() |
| 1348 | // from the context of the phone app. |
| 1349 | enforceCallPermission(); |
| 1350 | |
| 1351 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1352 | != AppOpsManager.MODE_ALLOWED) { |
| 1353 | return; |
| 1354 | } |
| 1355 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1356 | final long identity = Binder.clearCallingIdentity(); |
| 1357 | try { |
| 1358 | String url = createTelUrl(number); |
| 1359 | if (url == null) { |
| 1360 | return; |
| 1361 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1362 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1363 | boolean isValid = false; |
| 1364 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1365 | if (slist != null) { |
| 1366 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1367 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1368 | isValid = true; |
| 1369 | break; |
| 1370 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1371 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1372 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1373 | if (!isValid) { |
| 1374 | return; |
| 1375 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1376 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1377 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1378 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1379 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1380 | mApp.startActivity(intent); |
| 1381 | } finally { |
| 1382 | Binder.restoreCallingIdentity(identity); |
| 1383 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1384 | } |
| 1385 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1386 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1387 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1390 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1391 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1392 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1393 | } |
| 1394 | |
| 1395 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1396 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1397 | } |
| 1398 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1399 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1400 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1401 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1402 | } |
| 1403 | |
| 1404 | /** {@hide} */ |
| 1405 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1406 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1409 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1410 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1411 | |
| 1412 | final long identity = Binder.clearCallingIdentity(); |
| 1413 | try { |
| 1414 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1415 | checkSimPin.start(); |
| 1416 | return checkSimPin.unlockSim(null, pin); |
| 1417 | } finally { |
| 1418 | Binder.restoreCallingIdentity(identity); |
| 1419 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1422 | /** {@hide} */ |
| 1423 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1424 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1425 | } |
| 1426 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1427 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1428 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1429 | |
| 1430 | final long identity = Binder.clearCallingIdentity(); |
| 1431 | try { |
| 1432 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1433 | checkSimPuk.start(); |
| 1434 | return checkSimPuk.unlockSim(puk, pin); |
| 1435 | } finally { |
| 1436 | Binder.restoreCallingIdentity(identity); |
| 1437 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1441 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1442 | * a synchronous one. |
| 1443 | */ |
| 1444 | private static class UnlockSim extends Thread { |
| 1445 | |
| 1446 | private final IccCard mSimCard; |
| 1447 | |
| 1448 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1449 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1450 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1451 | |
| 1452 | // For replies from SimCard interface |
| 1453 | private Handler mHandler; |
| 1454 | |
| 1455 | // For async handler to identify request type |
| 1456 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1457 | |
| 1458 | public UnlockSim(IccCard simCard) { |
| 1459 | mSimCard = simCard; |
| 1460 | } |
| 1461 | |
| 1462 | @Override |
| 1463 | public void run() { |
| 1464 | Looper.prepare(); |
| 1465 | synchronized (UnlockSim.this) { |
| 1466 | mHandler = new Handler() { |
| 1467 | @Override |
| 1468 | public void handleMessage(Message msg) { |
| 1469 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1470 | switch (msg.what) { |
| 1471 | case SUPPLY_PIN_COMPLETE: |
| 1472 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1473 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1474 | mRetryCount = msg.arg1; |
| 1475 | if (ar.exception != null) { |
| 1476 | if (ar.exception instanceof CommandException && |
| 1477 | ((CommandException)(ar.exception)).getCommandError() |
| 1478 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1479 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1480 | } else { |
| 1481 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1482 | } |
| 1483 | } else { |
| 1484 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1485 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1486 | mDone = true; |
| 1487 | UnlockSim.this.notifyAll(); |
| 1488 | } |
| 1489 | break; |
| 1490 | } |
| 1491 | } |
| 1492 | }; |
| 1493 | UnlockSim.this.notifyAll(); |
| 1494 | } |
| 1495 | Looper.loop(); |
| 1496 | } |
| 1497 | |
| 1498 | /* |
| 1499 | * Use PIN or PUK to unlock SIM card |
| 1500 | * |
| 1501 | * If PUK is null, unlock SIM card with PIN |
| 1502 | * |
| 1503 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1504 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1505 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1506 | |
| 1507 | while (mHandler == null) { |
| 1508 | try { |
| 1509 | wait(); |
| 1510 | } catch (InterruptedException e) { |
| 1511 | Thread.currentThread().interrupt(); |
| 1512 | } |
| 1513 | } |
| 1514 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1515 | |
| 1516 | if (puk == null) { |
| 1517 | mSimCard.supplyPin(pin, callback); |
| 1518 | } else { |
| 1519 | mSimCard.supplyPuk(puk, pin, callback); |
| 1520 | } |
| 1521 | |
| 1522 | while (!mDone) { |
| 1523 | try { |
| 1524 | Log.d(LOG_TAG, "wait for done"); |
| 1525 | wait(); |
| 1526 | } catch (InterruptedException e) { |
| 1527 | // Restore the interrupted status |
| 1528 | Thread.currentThread().interrupt(); |
| 1529 | } |
| 1530 | } |
| 1531 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1532 | int[] resultArray = new int[2]; |
| 1533 | resultArray[0] = mResult; |
| 1534 | resultArray[1] = mRetryCount; |
| 1535 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1536 | } |
| 1537 | } |
| 1538 | |
| 1539 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1540 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1541 | |
| 1542 | } |
| 1543 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1544 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1545 | // No permission check needed here: this call is harmless, and it's |
| 1546 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1547 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1548 | final long identity = Binder.clearCallingIdentity(); |
| 1549 | try { |
| 1550 | final Phone phone = getPhone(subId); |
| 1551 | if (phone != null) { |
| 1552 | phone.updateServiceLocation(); |
| 1553 | } |
| 1554 | } finally { |
| 1555 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1556 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1557 | } |
| 1558 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1559 | @Override |
| 1560 | public boolean isRadioOn(String callingPackage) { |
| 1561 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1562 | } |
| 1563 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1564 | @Override |
| 1565 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1566 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1567 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1568 | return false; |
| 1569 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1570 | |
| 1571 | final long identity = Binder.clearCallingIdentity(); |
| 1572 | try { |
| 1573 | return isRadioOnForSubscriber(subId); |
| 1574 | } finally { |
| 1575 | Binder.restoreCallingIdentity(identity); |
| 1576 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1580 | final long identity = Binder.clearCallingIdentity(); |
| 1581 | try { |
| 1582 | final Phone phone = getPhone(subId); |
| 1583 | if (phone != null) { |
| 1584 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1585 | } else { |
| 1586 | return false; |
| 1587 | } |
| 1588 | } finally { |
| 1589 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1590 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1594 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1595 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1596 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1597 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1598 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1599 | |
| 1600 | final long identity = Binder.clearCallingIdentity(); |
| 1601 | try { |
| 1602 | final Phone phone = getPhone(subId); |
| 1603 | if (phone != null) { |
| 1604 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1605 | } |
| 1606 | } finally { |
| 1607 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1608 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1609 | } |
| 1610 | |
| 1611 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1612 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1613 | } |
| 1614 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1615 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1616 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1617 | |
| 1618 | final long identity = Binder.clearCallingIdentity(); |
| 1619 | try { |
| 1620 | final Phone phone = getPhone(subId); |
| 1621 | if (phone == null) { |
| 1622 | return false; |
| 1623 | } |
| 1624 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1625 | toggleRadioOnOffForSubscriber(subId); |
| 1626 | } |
| 1627 | return true; |
| 1628 | } finally { |
| 1629 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1630 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1631 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1632 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1633 | public boolean needMobileRadioShutdown() { |
| 1634 | /* |
| 1635 | * If any of the Radios are available, it will need to be |
| 1636 | * shutdown. So return true if any Radio is available. |
| 1637 | */ |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1638 | final long identity = Binder.clearCallingIdentity(); |
| 1639 | try { |
| 1640 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1641 | Phone phone = PhoneFactory.getPhone(i); |
| 1642 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1643 | } |
| 1644 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1645 | return false; |
| 1646 | } finally { |
| 1647 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1648 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1649 | } |
| 1650 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1651 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1652 | public void shutdownMobileRadios() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1653 | enforceModifyPermission(); |
| 1654 | |
| 1655 | final long identity = Binder.clearCallingIdentity(); |
| 1656 | try { |
| 1657 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1658 | logv("Shutting down Phone " + i); |
| 1659 | shutdownRadioUsingPhoneId(i); |
| 1660 | } |
| 1661 | } finally { |
| 1662 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1663 | } |
| 1664 | } |
| 1665 | |
| 1666 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1667 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1668 | if (phone != null && phone.isRadioAvailable()) { |
| 1669 | phone.shutdownRadio(); |
| 1670 | } |
| 1671 | } |
| 1672 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1673 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1674 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1675 | |
| 1676 | final long identity = Binder.clearCallingIdentity(); |
| 1677 | try { |
| 1678 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1679 | if (defaultPhone != null) { |
| 1680 | defaultPhone.setRadioPower(turnOn); |
| 1681 | return true; |
| 1682 | } else { |
| 1683 | loge("There's no default phone."); |
| 1684 | return false; |
| 1685 | } |
| 1686 | } finally { |
| 1687 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1688 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1689 | } |
| 1690 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1691 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1692 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1693 | |
| 1694 | final long identity = Binder.clearCallingIdentity(); |
| 1695 | try { |
| 1696 | final Phone phone = getPhone(subId); |
| 1697 | if (phone != null) { |
| 1698 | phone.setRadioPower(turnOn); |
| 1699 | return true; |
| 1700 | } else { |
| 1701 | return false; |
| 1702 | } |
| 1703 | } finally { |
| 1704 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1705 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1706 | } |
| 1707 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1708 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1709 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1710 | public boolean enableDataConnectivity() { |
| 1711 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1712 | |
| 1713 | final long identity = Binder.clearCallingIdentity(); |
| 1714 | try { |
| 1715 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1716 | final Phone phone = getPhone(subId); |
| 1717 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1718 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1719 | return true; |
| 1720 | } else { |
| 1721 | return false; |
| 1722 | } |
| 1723 | } finally { |
| 1724 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1725 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1726 | } |
| 1727 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1728 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1729 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1730 | public boolean disableDataConnectivity() { |
| 1731 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1732 | |
| 1733 | final long identity = Binder.clearCallingIdentity(); |
| 1734 | try { |
| 1735 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1736 | final Phone phone = getPhone(subId); |
| 1737 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1738 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1739 | return true; |
| 1740 | } else { |
| 1741 | return false; |
| 1742 | } |
| 1743 | } finally { |
| 1744 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1745 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1746 | } |
| 1747 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1748 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1749 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1750 | final long identity = Binder.clearCallingIdentity(); |
| 1751 | try { |
| 1752 | final Phone phone = getPhone(subId); |
| 1753 | if (phone != null) { |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1754 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1755 | } else { |
| 1756 | return false; |
| 1757 | } |
| 1758 | } finally { |
| 1759 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1760 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1764 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1767 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1768 | enforceCallPermission(); |
| 1769 | |
| 1770 | final long identity = Binder.clearCallingIdentity(); |
| 1771 | try { |
| 1772 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1773 | return; |
| 1774 | } |
| 1775 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1776 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1777 | } finally { |
| 1778 | Binder.restoreCallingIdentity(identity); |
| 1779 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1780 | }; |
| 1781 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1782 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1783 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1784 | |
| 1785 | final long identity = Binder.clearCallingIdentity(); |
| 1786 | try { |
| 1787 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1788 | return false; |
| 1789 | } |
| 1790 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1791 | } finally { |
| 1792 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1793 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1794 | } |
| 1795 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1796 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1797 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1798 | } |
| 1799 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1800 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1801 | final long identity = Binder.clearCallingIdentity(); |
| 1802 | try { |
| 1803 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1804 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1805 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1806 | } finally { |
| 1807 | Binder.restoreCallingIdentity(identity); |
| 1808 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1809 | } |
| 1810 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1811 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1812 | public int getDataState() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1813 | final long identity = Binder.clearCallingIdentity(); |
| 1814 | try { |
| 1815 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1816 | if (phone != null) { |
| 1817 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1818 | } else { |
| 1819 | return PhoneConstantConversions.convertDataState( |
| 1820 | PhoneConstants.DataState.DISCONNECTED); |
| 1821 | } |
| 1822 | } finally { |
| 1823 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1824 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1825 | } |
| 1826 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1827 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1828 | public int getDataActivity() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1829 | final long identity = Binder.clearCallingIdentity(); |
| 1830 | try { |
| 1831 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1832 | if (phone != null) { |
| 1833 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1834 | } else { |
| 1835 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1836 | } |
| 1837 | } finally { |
| 1838 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1839 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1840 | } |
| 1841 | |
| 1842 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1843 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1844 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1845 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1846 | if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage, |
| 1847 | Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1848 | return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1849 | } |
| 1850 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1851 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1852 | final long identity = Binder.clearCallingIdentity(); |
| 1853 | try { |
| 1854 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1855 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1856 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1857 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1858 | cl.fillInNotifierBundle(data); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1859 | return data; |
| 1860 | } finally { |
| 1861 | Binder.restoreCallingIdentity(identity); |
| 1862 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1863 | } |
| 1864 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1865 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1866 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1867 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1868 | // registered cell info, so return a NULL country instead. |
| 1869 | final long identity = Binder.clearCallingIdentity(); |
| 1870 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1871 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1872 | // Get default phone in this case. |
| 1873 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1874 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1875 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1876 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1877 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1878 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1879 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1880 | return ""; |
| 1881 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1882 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1883 | if (phone != null) { |
| 1884 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 1885 | if (sst != null) { |
| 1886 | LocaleTracker lt = sst.getLocaleTracker(); |
| 1887 | if (lt != null) { |
| 1888 | return lt.getCurrentCountry(); |
| 1889 | } |
| 1890 | } |
| 1891 | } |
| 1892 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1893 | } finally { |
| 1894 | Binder.restoreCallingIdentity(identity); |
| 1895 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1896 | } |
| 1897 | |
| 1898 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1899 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1900 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1901 | } |
| 1902 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1903 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1904 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1905 | mApp.enforceCallingOrSelfPermission( |
| 1906 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1907 | |
| 1908 | final long identity = Binder.clearCallingIdentity(); |
| 1909 | try { |
| 1910 | final Phone phone = getPhone(subId); |
| 1911 | if (phone != null) { |
| 1912 | phone.enableLocationUpdates(); |
| 1913 | } |
| 1914 | } finally { |
| 1915 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1916 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1917 | } |
| 1918 | |
| 1919 | @Override |
| 1920 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1921 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1922 | } |
| 1923 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1924 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1925 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1926 | mApp.enforceCallingOrSelfPermission( |
| 1927 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1928 | |
| 1929 | final long identity = Binder.clearCallingIdentity(); |
| 1930 | try { |
| 1931 | final Phone phone = getPhone(subId); |
| 1932 | if (phone != null) { |
| 1933 | phone.disableLocationUpdates(); |
| 1934 | } |
| 1935 | } finally { |
| 1936 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1937 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1938 | } |
| 1939 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1940 | /** |
| 1941 | * Returns the target SDK version number for a given package name. |
| 1942 | * |
| 1943 | * @return target SDK if the package is found or INT_MAX. |
| 1944 | */ |
| 1945 | private int getTargetSdk(String packageName) { |
| 1946 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1947 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo( |
| 1948 | packageName, 0); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1949 | if (ai != null) return ai.targetSdkVersion; |
| 1950 | } catch (PackageManager.NameNotFoundException unexpected) { |
| 1951 | } |
| 1952 | return Integer.MAX_VALUE; |
| 1953 | } |
| 1954 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1955 | @Override |
| 1956 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1957 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 1958 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 1959 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 1960 | throw new SecurityException( |
| 1961 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 1962 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 1963 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1964 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 1965 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 1966 | return null; |
| 1967 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1968 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1969 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1970 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1971 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 1972 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1973 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1974 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 1975 | for (CellInfo ci : info) { |
| 1976 | if (ci instanceof CellInfoGsm) { |
| 1977 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 1978 | } else if (ci instanceof CellInfoWcdma) { |
| 1979 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 1980 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1981 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1982 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1983 | } |
| 1984 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1985 | private List<CellInfo> getCachedCellInfo() { |
| 1986 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 1987 | for (Phone phone : PhoneFactory.getPhones()) { |
| 1988 | List<CellInfo> info = phone.getAllCellInfo(); |
| 1989 | if (info != null) cellInfos.addAll(info); |
| 1990 | } |
| 1991 | return cellInfos; |
| 1992 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1993 | |
| 1994 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1995 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1996 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1997 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1998 | if (!LocationAccessPolicy.canAccessCellLocation(mApp, |
Svet Ganov | 4af6628 | 2018-03-07 19:57:05 -0800 | [diff] [blame] | 1999 | callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2000 | return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2001 | } |
| 2002 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2003 | final int targetSdk = getTargetSdk(callingPackage); |
| 2004 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2005 | return getCachedCellInfo(); |
| 2006 | } |
| 2007 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2008 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2009 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2010 | final long identity = Binder.clearCallingIdentity(); |
| 2011 | try { |
| 2012 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2013 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2014 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2015 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2016 | if (info != null) cellInfos.addAll(info); |
| 2017 | } |
| 2018 | return cellInfos; |
| 2019 | } finally { |
| 2020 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2021 | } |
| 2022 | } |
| 2023 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2024 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2025 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2026 | requestCellInfoUpdateInternal( |
| 2027 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2028 | } |
| 2029 | |
| 2030 | @Override |
| 2031 | public void requestCellInfoUpdateWithWorkSource( |
| 2032 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2033 | enforceModifyPermission(); |
| 2034 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2035 | } |
| 2036 | |
| 2037 | private void requestCellInfoUpdateInternal( |
| 2038 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2039 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2040 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2041 | if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage, |
| 2042 | Binder.getCallingUid(), Binder.getCallingPid(), true)) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2043 | return; |
| 2044 | } |
| 2045 | |
| 2046 | final Phone phone = getPhone(subId); |
| 2047 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2048 | |
| 2049 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2050 | } |
| 2051 | |
| 2052 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2053 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2054 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2055 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2056 | |
| 2057 | final long identity = Binder.clearCallingIdentity(); |
| 2058 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2059 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2060 | } finally { |
| 2061 | Binder.restoreCallingIdentity(identity); |
| 2062 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2063 | } |
| 2064 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2065 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2066 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2067 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2068 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2069 | return null; |
| 2070 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2071 | int subId = phone.getSubId(); |
| 2072 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2073 | mApp, subId, callingPackage, "getImeiForSlot")) { |
| 2074 | return null; |
| 2075 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2076 | |
| 2077 | final long identity = Binder.clearCallingIdentity(); |
| 2078 | try { |
| 2079 | return phone.getImei(); |
| 2080 | } finally { |
| 2081 | Binder.restoreCallingIdentity(identity); |
| 2082 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2086 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2087 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2088 | String tac = null; |
| 2089 | if (phone != null) { |
| 2090 | String imei = phone.getImei(); |
| 2091 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2092 | } |
| 2093 | return tac; |
| 2094 | } |
| 2095 | |
| 2096 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2097 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2098 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2099 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2100 | return null; |
| 2101 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2102 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2103 | int subId = phone.getSubId(); |
| 2104 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2105 | mApp, subId, callingPackage, "getMeidForSlot")) { |
| 2106 | return null; |
| 2107 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2108 | |
| 2109 | final long identity = Binder.clearCallingIdentity(); |
| 2110 | try { |
| 2111 | return phone.getMeid(); |
| 2112 | } finally { |
| 2113 | Binder.restoreCallingIdentity(identity); |
| 2114 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2115 | } |
| 2116 | |
| 2117 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2118 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2119 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2120 | String manufacturerCode = null; |
| 2121 | if (phone != null) { |
| 2122 | String meid = phone.getMeid(); |
| 2123 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2124 | } |
| 2125 | return manufacturerCode; |
| 2126 | } |
| 2127 | |
| 2128 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2129 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2130 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2131 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2132 | return null; |
| 2133 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2134 | int subId = phone.getSubId(); |
| 2135 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2136 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2137 | return null; |
| 2138 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2139 | |
| 2140 | final long identity = Binder.clearCallingIdentity(); |
| 2141 | try { |
| 2142 | return phone.getDeviceSvn(); |
| 2143 | } finally { |
| 2144 | Binder.restoreCallingIdentity(identity); |
| 2145 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2146 | } |
| 2147 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2148 | @Override |
| 2149 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2150 | final long identity = Binder.clearCallingIdentity(); |
| 2151 | try { |
| 2152 | final Phone phone = getPhone(subId); |
| 2153 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2154 | } finally { |
| 2155 | Binder.restoreCallingIdentity(identity); |
| 2156 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | @Override |
| 2160 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2161 | final long identity = Binder.clearCallingIdentity(); |
| 2162 | try { |
| 2163 | final Phone phone = getPhone(subId); |
| 2164 | return phone == null ? null : phone.getCarrierName(); |
| 2165 | } finally { |
| 2166 | Binder.restoreCallingIdentity(identity); |
| 2167 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2168 | } |
| 2169 | |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2170 | @Override |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2171 | public int getSubscriptionPreciseCarrierId(int subId) { |
| 2172 | final long identity = Binder.clearCallingIdentity(); |
| 2173 | try { |
| 2174 | final Phone phone = getPhone(subId); |
| 2175 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
| 2176 | : phone.getPreciseCarrierId(); |
| 2177 | } finally { |
| 2178 | Binder.restoreCallingIdentity(identity); |
| 2179 | } |
| 2180 | } |
| 2181 | |
| 2182 | @Override |
| 2183 | public String getSubscriptionPreciseCarrierName(int subId) { |
| 2184 | final long identity = Binder.clearCallingIdentity(); |
| 2185 | try { |
| 2186 | final Phone phone = getPhone(subId); |
| 2187 | return phone == null ? null : phone.getPreciseCarrierName(); |
| 2188 | } finally { |
| 2189 | Binder.restoreCallingIdentity(identity); |
| 2190 | } |
| 2191 | } |
| 2192 | |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2193 | @Override |
chen xu | 4ca4e69 | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2194 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2195 | if (!isSubscriptionMccMnc) { |
| 2196 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2197 | } |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2198 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2199 | if (phone == null) { |
| 2200 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2201 | } |
| 2202 | final long identity = Binder.clearCallingIdentity(); |
| 2203 | try { |
| 2204 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2205 | } finally { |
| 2206 | Binder.restoreCallingIdentity(identity); |
| 2207 | } |
| 2208 | } |
| 2209 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2210 | // |
| 2211 | // Internal helper methods. |
| 2212 | // |
| 2213 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2214 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2215 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2216 | * |
| 2217 | * @throws SecurityException if the caller does not have the required permission |
| 2218 | */ |
| 2219 | private void enforceModifyPermission() { |
| 2220 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2221 | } |
| 2222 | |
| 2223 | /** |
| 2224 | * Make sure the caller has the CALL_PHONE permission. |
| 2225 | * |
| 2226 | * @throws SecurityException if the caller does not have the required permission |
| 2227 | */ |
| 2228 | private void enforceCallPermission() { |
| 2229 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2230 | } |
| 2231 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2232 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2233 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2234 | "ConnectivityService"); |
| 2235 | } |
| 2236 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2237 | private String createTelUrl(String number) { |
| 2238 | if (TextUtils.isEmpty(number)) { |
| 2239 | return null; |
| 2240 | } |
| 2241 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2242 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2243 | } |
| 2244 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2245 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2246 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2247 | } |
| 2248 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2249 | private static void logv(String msg) { |
| 2250 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2251 | } |
| 2252 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2253 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2254 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2255 | } |
| 2256 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2257 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2258 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2259 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2260 | } |
| 2261 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2262 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2263 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2264 | final long identity = Binder.clearCallingIdentity(); |
| 2265 | try { |
| 2266 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2267 | if (phone == null) { |
| 2268 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2269 | } else { |
| 2270 | return phone.getPhoneType(); |
| 2271 | } |
| 2272 | } finally { |
| 2273 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2274 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | /** |
| 2278 | * Returns the CDMA ERI icon index to display |
| 2279 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2280 | @Override |
| 2281 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2282 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2283 | } |
| 2284 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2285 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2286 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2287 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2288 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2289 | return -1; |
| 2290 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2291 | |
| 2292 | final long identity = Binder.clearCallingIdentity(); |
| 2293 | try { |
| 2294 | final Phone phone = getPhone(subId); |
| 2295 | if (phone != null) { |
| 2296 | return phone.getCdmaEriIconIndex(); |
| 2297 | } else { |
| 2298 | return -1; |
| 2299 | } |
| 2300 | } finally { |
| 2301 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2302 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2303 | } |
| 2304 | |
| 2305 | /** |
| 2306 | * Returns the CDMA ERI icon mode, |
| 2307 | * 0 - ON |
| 2308 | * 1 - FLASHING |
| 2309 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2310 | @Override |
| 2311 | public int getCdmaEriIconMode(String callingPackage) { |
| 2312 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2313 | } |
| 2314 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2315 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2316 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2317 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2318 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2319 | return -1; |
| 2320 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2321 | |
| 2322 | final long identity = Binder.clearCallingIdentity(); |
| 2323 | try { |
| 2324 | final Phone phone = getPhone(subId); |
| 2325 | if (phone != null) { |
| 2326 | return phone.getCdmaEriIconMode(); |
| 2327 | } else { |
| 2328 | return -1; |
| 2329 | } |
| 2330 | } finally { |
| 2331 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2332 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2333 | } |
| 2334 | |
| 2335 | /** |
| 2336 | * Returns the CDMA ERI text, |
| 2337 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2338 | @Override |
| 2339 | public String getCdmaEriText(String callingPackage) { |
| 2340 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2341 | } |
| 2342 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2343 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2344 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2345 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2346 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2347 | return null; |
| 2348 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2349 | |
| 2350 | final long identity = Binder.clearCallingIdentity(); |
| 2351 | try { |
| 2352 | final Phone phone = getPhone(subId); |
| 2353 | if (phone != null) { |
| 2354 | return phone.getCdmaEriText(); |
| 2355 | } else { |
| 2356 | return null; |
| 2357 | } |
| 2358 | } finally { |
| 2359 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2360 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2361 | } |
| 2362 | |
| 2363 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2364 | * Returns the CDMA MDN. |
| 2365 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2366 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2367 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2368 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2369 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2370 | |
| 2371 | final long identity = Binder.clearCallingIdentity(); |
| 2372 | try { |
| 2373 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2374 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2375 | return phone.getLine1Number(); |
| 2376 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2377 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2378 | return null; |
| 2379 | } |
| 2380 | } finally { |
| 2381 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2382 | } |
| 2383 | } |
| 2384 | |
| 2385 | /** |
| 2386 | * Returns the CDMA MIN. |
| 2387 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2388 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2389 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2390 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2391 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2392 | |
| 2393 | final long identity = Binder.clearCallingIdentity(); |
| 2394 | try { |
| 2395 | final Phone phone = getPhone(subId); |
| 2396 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2397 | return phone.getCdmaMin(); |
| 2398 | } else { |
| 2399 | return null; |
| 2400 | } |
| 2401 | } finally { |
| 2402 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2403 | } |
| 2404 | } |
| 2405 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2406 | @Override |
| 2407 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2408 | INumberVerificationCallback callback, String callingPackage) { |
| 2409 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2410 | != PERMISSION_GRANTED) { |
| 2411 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2412 | } |
| 2413 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2414 | |
| 2415 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2416 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2417 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2418 | } |
| 2419 | |
| 2420 | if (range == null) { |
| 2421 | throw new NullPointerException("Range must be non-null"); |
| 2422 | } |
| 2423 | |
| 2424 | timeoutMillis = Math.min(timeoutMillis, |
| 2425 | TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS); |
| 2426 | |
| 2427 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2428 | } |
| 2429 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2430 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2431 | * Returns true if CDMA provisioning needs to run. |
| 2432 | */ |
| 2433 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2434 | final long identity = Binder.clearCallingIdentity(); |
| 2435 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2436 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2437 | } finally { |
| 2438 | Binder.restoreCallingIdentity(identity); |
| 2439 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2443 | * Sets the voice mail number of a given subId. |
| 2444 | */ |
| 2445 | @Override |
| 2446 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2447 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2448 | |
| 2449 | final long identity = Binder.clearCallingIdentity(); |
| 2450 | try { |
| 2451 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2452 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2453 | return success; |
| 2454 | } finally { |
| 2455 | Binder.restoreCallingIdentity(identity); |
| 2456 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2457 | } |
| 2458 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2459 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2460 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2461 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2462 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2463 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2464 | throw new SecurityException("caller must be system dialer"); |
| 2465 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2466 | |
| 2467 | final long identity = Binder.clearCallingIdentity(); |
| 2468 | try { |
| 2469 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2470 | if (phoneAccountHandle == null) { |
| 2471 | return null; |
| 2472 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2473 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2474 | } finally { |
| 2475 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2476 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2477 | } |
| 2478 | |
| 2479 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2480 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2481 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2482 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2483 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2484 | return null; |
| 2485 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2486 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2487 | final long identity = Binder.clearCallingIdentity(); |
| 2488 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2489 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2490 | } finally { |
| 2491 | Binder.restoreCallingIdentity(identity); |
| 2492 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2496 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2497 | VisualVoicemailSmsFilterSettings settings) { |
| 2498 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2499 | |
| 2500 | final long identity = Binder.clearCallingIdentity(); |
| 2501 | try { |
| 2502 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2503 | mApp, callingPackage, subId, settings); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2504 | } finally { |
| 2505 | Binder.restoreCallingIdentity(identity); |
| 2506 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2507 | } |
| 2508 | |
| 2509 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2510 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2511 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2512 | |
| 2513 | final long identity = Binder.clearCallingIdentity(); |
| 2514 | try { |
| 2515 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2516 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2517 | } finally { |
| 2518 | Binder.restoreCallingIdentity(identity); |
| 2519 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2520 | } |
| 2521 | |
| 2522 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2523 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2524 | String callingPackage, int subId) { |
| 2525 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2526 | |
| 2527 | final long identity = Binder.clearCallingIdentity(); |
| 2528 | try { |
| 2529 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2530 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2531 | } finally { |
| 2532 | Binder.restoreCallingIdentity(identity); |
| 2533 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2537 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2538 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2539 | |
| 2540 | final long identity = Binder.clearCallingIdentity(); |
| 2541 | try { |
| 2542 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2543 | mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2544 | } finally { |
| 2545 | Binder.restoreCallingIdentity(identity); |
| 2546 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2547 | } |
| 2548 | |
| 2549 | @Override |
| 2550 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2551 | String number, int port, String text, PendingIntent sentIntent) { |
| 2552 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2553 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2554 | enforceSendSmsPermission(); |
| 2555 | // Make the calls as the phone process. |
| 2556 | final long identity = Binder.clearCallingIdentity(); |
| 2557 | try { |
| 2558 | SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); |
| 2559 | if (port == 0) { |
| 2560 | smsManager.sendTextMessageWithSelfPermissions(number, null, text, |
| 2561 | sentIntent, null, false); |
| 2562 | } else { |
| 2563 | byte[] data = text.getBytes(StandardCharsets.UTF_8); |
| 2564 | smsManager.sendDataMessageWithSelfPermissions(number, null, |
| 2565 | (short) port, data, sentIntent, null); |
| 2566 | } |
| 2567 | } finally { |
| 2568 | Binder.restoreCallingIdentity(identity); |
| 2569 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2570 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2571 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2572 | * Sets the voice activation state of a given subId. |
| 2573 | */ |
| 2574 | @Override |
| 2575 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2576 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2577 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2578 | |
| 2579 | final long identity = Binder.clearCallingIdentity(); |
| 2580 | try { |
| 2581 | final Phone phone = getPhone(subId); |
| 2582 | if (phone != null) { |
| 2583 | phone.setVoiceActivationState(activationState); |
| 2584 | } else { |
| 2585 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2586 | } |
| 2587 | } finally { |
| 2588 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2589 | } |
| 2590 | } |
| 2591 | |
| 2592 | /** |
| 2593 | * Sets the data activation state of a given subId. |
| 2594 | */ |
| 2595 | @Override |
| 2596 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2597 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2598 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2599 | |
| 2600 | final long identity = Binder.clearCallingIdentity(); |
| 2601 | try { |
| 2602 | final Phone phone = getPhone(subId); |
| 2603 | if (phone != null) { |
| 2604 | phone.setDataActivationState(activationState); |
| 2605 | } else { |
| 2606 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2607 | } |
| 2608 | } finally { |
| 2609 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2610 | } |
| 2611 | } |
| 2612 | |
| 2613 | /** |
| 2614 | * Returns the voice activation state of a given subId. |
| 2615 | */ |
| 2616 | @Override |
| 2617 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2618 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2619 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2620 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2621 | final long identity = Binder.clearCallingIdentity(); |
| 2622 | try { |
| 2623 | if (phone != null) { |
| 2624 | return phone.getVoiceActivationState(); |
| 2625 | } else { |
| 2626 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2627 | } |
| 2628 | } finally { |
| 2629 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2630 | } |
| 2631 | } |
| 2632 | |
| 2633 | /** |
| 2634 | * Returns the data activation state of a given subId. |
| 2635 | */ |
| 2636 | @Override |
| 2637 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2638 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2639 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2640 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2641 | final long identity = Binder.clearCallingIdentity(); |
| 2642 | try { |
| 2643 | if (phone != null) { |
| 2644 | return phone.getDataActivationState(); |
| 2645 | } else { |
| 2646 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2647 | } |
| 2648 | } finally { |
| 2649 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2650 | } |
| 2651 | } |
| 2652 | |
| 2653 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2654 | * Returns the unread count of voicemails for a subId |
| 2655 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2656 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2657 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2658 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2659 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2660 | return 0; |
| 2661 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2662 | final long identity = Binder.clearCallingIdentity(); |
| 2663 | try { |
| 2664 | final Phone phone = getPhone(subId); |
| 2665 | if (phone != null) { |
| 2666 | return phone.getVoiceMessageCount(); |
| 2667 | } else { |
| 2668 | return 0; |
| 2669 | } |
| 2670 | } finally { |
| 2671 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2672 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2676 | * returns true, if the device is in a state where both voice and data |
| 2677 | * are supported simultaneously. This can change based on location or network condition. |
| 2678 | */ |
| 2679 | @Override |
| 2680 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2681 | final long identity = Binder.clearCallingIdentity(); |
| 2682 | try { |
| 2683 | final Phone phone = getPhone(subId); |
| 2684 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2685 | } finally { |
| 2686 | Binder.restoreCallingIdentity(identity); |
| 2687 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2688 | } |
| 2689 | |
| 2690 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2691 | * Send the dialer code if called from the current default dialer or the caller has |
| 2692 | * carrier privilege. |
| 2693 | * @param inputCode The dialer code to send |
| 2694 | */ |
| 2695 | @Override |
| 2696 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2697 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2698 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2699 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2700 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2701 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2702 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2703 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2704 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2705 | |
| 2706 | final long identity = Binder.clearCallingIdentity(); |
| 2707 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2708 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2709 | } finally { |
| 2710 | Binder.restoreCallingIdentity(identity); |
| 2711 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2712 | } |
| 2713 | |
| 2714 | /** |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2715 | * Returns the data network type. |
| 2716 | * Legacy call, permission-free. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2717 | * |
| 2718 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 2719 | */ |
| 2720 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2721 | public int getNetworkType() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2722 | final long identity = Binder.clearCallingIdentity(); |
| 2723 | try { |
| 2724 | final Phone phone = getPhone(getDefaultSubscription()); |
| 2725 | if (phone != null) { |
| 2726 | return phone.getServiceState().getDataNetworkType(); |
| 2727 | } else { |
| 2728 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2729 | } |
| 2730 | } finally { |
| 2731 | Binder.restoreCallingIdentity(identity); |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2732 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2733 | } |
| 2734 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2735 | @Override |
| 2736 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2737 | if (!isActiveSubscription(subId)) { |
| 2738 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2739 | } |
| 2740 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2741 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2742 | } |
| 2743 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2744 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2745 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2746 | throws RemoteException { |
| 2747 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2748 | final long token = Binder.clearCallingIdentity(); |
| 2749 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2750 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2751 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2752 | .addRegistrationCallbackForSubscription(c, subId); |
| 2753 | } finally { |
| 2754 | Binder.restoreCallingIdentity(token); |
| 2755 | } |
| 2756 | } |
| 2757 | |
| 2758 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2759 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2760 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2761 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2762 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2763 | } |
| 2764 | Binder.withCleanCallingIdentity(() -> { |
| 2765 | try { |
| 2766 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2767 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2768 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2769 | } catch (IllegalArgumentException e) { |
| 2770 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2771 | + "is inactive, ignoring unregister."); |
| 2772 | // If the subscription is no longer active, just return, since the callback |
| 2773 | // will already have been removed internally. |
| 2774 | } |
| 2775 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2776 | } |
| 2777 | |
| 2778 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2779 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2780 | throws RemoteException { |
| 2781 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2782 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2783 | final long token = Binder.clearCallingIdentity(); |
| 2784 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2785 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2786 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2787 | } finally { |
| 2788 | Binder.restoreCallingIdentity(token); |
| 2789 | } |
| 2790 | } |
| 2791 | |
| 2792 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2793 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2794 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2795 | |
| 2796 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2797 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2798 | } |
| 2799 | Binder.withCleanCallingIdentity(() -> { |
| 2800 | try { |
| 2801 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2802 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2803 | .removeCapabilitiesCallbackForSubscription(c, subId); |
| 2804 | } catch (IllegalArgumentException e) { |
| 2805 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2806 | + "is inactive, ignoring unregister."); |
| 2807 | // If the subscription is no longer active, just return, since the callback |
| 2808 | // will already have been removed internally. |
| 2809 | } |
| 2810 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2811 | } |
| 2812 | |
| 2813 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2814 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2815 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2816 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2817 | final long token = Binder.clearCallingIdentity(); |
| 2818 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2819 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2820 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2821 | } catch (ImsException e) { |
| 2822 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2823 | return false; |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2824 | } catch (IllegalArgumentException e) { |
| 2825 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 2826 | return false; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2827 | } finally { |
| 2828 | Binder.restoreCallingIdentity(token); |
| 2829 | } |
| 2830 | } |
| 2831 | |
| 2832 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2833 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2834 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2835 | final long token = Binder.clearCallingIdentity(); |
| 2836 | try { |
| 2837 | Phone phone = getPhone(subId); |
| 2838 | if (phone == null) return false; |
| 2839 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2840 | } finally { |
| 2841 | Binder.restoreCallingIdentity(token); |
| 2842 | } |
| 2843 | } |
| 2844 | |
| 2845 | @Override |
| 2846 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2847 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2848 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2849 | final long token = Binder.clearCallingIdentity(); |
| 2850 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2851 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2852 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2853 | } finally { |
| 2854 | Binder.restoreCallingIdentity(token); |
| 2855 | } |
| 2856 | } |
| 2857 | |
| 2858 | @Override |
| 2859 | public void setAdvancedCallingSetting(int subId, boolean isEnabled) { |
| 2860 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2861 | "setAdvancedCallingSetting"); |
| 2862 | final long identity = Binder.clearCallingIdentity(); |
| 2863 | try { |
| 2864 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2865 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2866 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 2867 | } finally { |
| 2868 | Binder.restoreCallingIdentity(identity); |
| 2869 | } |
| 2870 | } |
| 2871 | |
| 2872 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2873 | public boolean isVtSettingEnabled(int subId) { |
| 2874 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2875 | final long identity = Binder.clearCallingIdentity(); |
| 2876 | try { |
| 2877 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2878 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2879 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2880 | } finally { |
| 2881 | Binder.restoreCallingIdentity(identity); |
| 2882 | } |
| 2883 | } |
| 2884 | |
| 2885 | @Override |
| 2886 | public void setVtSetting(int subId, boolean isEnabled) { |
| 2887 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2888 | "setVtSetting"); |
| 2889 | final long identity = Binder.clearCallingIdentity(); |
| 2890 | try { |
| 2891 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2892 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2893 | } finally { |
| 2894 | Binder.restoreCallingIdentity(identity); |
| 2895 | } |
| 2896 | } |
| 2897 | |
| 2898 | @Override |
| 2899 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 2900 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 2901 | final long identity = Binder.clearCallingIdentity(); |
| 2902 | try { |
| 2903 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2904 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2905 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 2906 | } finally { |
| 2907 | Binder.restoreCallingIdentity(identity); |
| 2908 | } |
| 2909 | } |
| 2910 | |
| 2911 | @Override |
| 2912 | public void setVoWiFiSetting(int subId, boolean isEnabled) { |
| 2913 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2914 | "setVoWiFiSetting"); |
| 2915 | final long identity = Binder.clearCallingIdentity(); |
| 2916 | try { |
| 2917 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2918 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2919 | } finally { |
| 2920 | Binder.restoreCallingIdentity(identity); |
| 2921 | } |
| 2922 | } |
| 2923 | |
| 2924 | @Override |
| 2925 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 2926 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 2927 | final long identity = Binder.clearCallingIdentity(); |
| 2928 | try { |
| 2929 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2930 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2931 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 2932 | } finally { |
| 2933 | Binder.restoreCallingIdentity(identity); |
| 2934 | } |
| 2935 | } |
| 2936 | |
| 2937 | @Override |
| 2938 | public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) { |
| 2939 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2940 | "setVoWiFiRoamingSetting"); |
| 2941 | final long identity = Binder.clearCallingIdentity(); |
| 2942 | try { |
| 2943 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2944 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2945 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 2946 | } finally { |
| 2947 | Binder.restoreCallingIdentity(identity); |
| 2948 | } |
| 2949 | } |
| 2950 | |
| 2951 | @Override |
| 2952 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 2953 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2954 | "setVoWiFiNonPersistent"); |
| 2955 | final long identity = Binder.clearCallingIdentity(); |
| 2956 | try { |
| 2957 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 2958 | boolean isRoaming = TelephonyManager.from( |
| 2959 | getPhone(subId).getContext()).isNetworkRoaming(subId); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2960 | ImsManager.getInstance(mApp, |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 2961 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2962 | } finally { |
| 2963 | Binder.restoreCallingIdentity(identity); |
| 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | @Override |
| 2968 | public int getVoWiFiModeSetting(int subId) { |
| 2969 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 2970 | final long identity = Binder.clearCallingIdentity(); |
| 2971 | try { |
| 2972 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2973 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2974 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 2975 | } finally { |
| 2976 | Binder.restoreCallingIdentity(identity); |
| 2977 | } |
| 2978 | } |
| 2979 | |
| 2980 | @Override |
| 2981 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 2982 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 2983 | "setVoWiFiModeSetting"); |
| 2984 | final long identity = Binder.clearCallingIdentity(); |
| 2985 | try { |
| 2986 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2987 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2988 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 2989 | } finally { |
| 2990 | Binder.restoreCallingIdentity(identity); |
| 2991 | } |
| 2992 | } |
| 2993 | |
| 2994 | @Override |
| 2995 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 2996 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 2997 | final long identity = Binder.clearCallingIdentity(); |
| 2998 | try { |
| 2999 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3000 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3001 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 3002 | } finally { |
| 3003 | Binder.restoreCallingIdentity(identity); |
| 3004 | } |
| 3005 | } |
| 3006 | |
| 3007 | @Override |
| 3008 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3009 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3010 | "setVoWiFiRoamingModeSetting"); |
| 3011 | final long identity = Binder.clearCallingIdentity(); |
| 3012 | try { |
| 3013 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3014 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3015 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 3016 | } finally { |
| 3017 | Binder.restoreCallingIdentity(identity); |
| 3018 | } |
| 3019 | } |
| 3020 | |
| 3021 | @Override |
| 3022 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3023 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3024 | "setRttCapabilityEnabled"); |
| 3025 | final long identity = Binder.clearCallingIdentity(); |
| 3026 | try { |
| 3027 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3028 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3029 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3030 | } finally { |
| 3031 | Binder.restoreCallingIdentity(identity); |
| 3032 | } |
| 3033 | } |
| 3034 | |
| 3035 | @Override |
| 3036 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3037 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3038 | final long identity = Binder.clearCallingIdentity(); |
| 3039 | try { |
| 3040 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3041 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3042 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 3043 | } finally { |
| 3044 | Binder.restoreCallingIdentity(identity); |
| 3045 | } |
| 3046 | } |
| 3047 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3048 | @Override |
| 3049 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3050 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3051 | final long identity = Binder.clearCallingIdentity(); |
| 3052 | try { |
| 3053 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3054 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3055 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3056 | } finally { |
| 3057 | Binder.restoreCallingIdentity(identity); |
| 3058 | } |
| 3059 | } |
| 3060 | |
| 3061 | @Override |
| 3062 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3063 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3064 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3065 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3066 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3067 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3068 | try { |
| 3069 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3070 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3071 | .removeProvisioningCallbackForSubscription(callback, subId); |
| 3072 | } catch (IllegalArgumentException e) { |
| 3073 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3074 | + "is inactive, ignoring unregister."); |
| 3075 | // If the subscription is no longer active, just return, since the callback will already |
| 3076 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3077 | } finally { |
| 3078 | Binder.restoreCallingIdentity(identity); |
| 3079 | } |
| 3080 | } |
| 3081 | |
| 3082 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3083 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3084 | boolean isProvisioned) { |
| 3085 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3086 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3087 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3088 | } |
| 3089 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3090 | "setProvisioningStatusForCapability"); |
| 3091 | final long identity = Binder.clearCallingIdentity(); |
| 3092 | try { |
| 3093 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3094 | Phone phone = getPhone(subId); |
| 3095 | if (phone == null) { |
| 3096 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3097 | + subId); |
| 3098 | return; |
| 3099 | } |
| 3100 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3101 | return; |
| 3102 | } |
| 3103 | |
| 3104 | // this capability requires provisioning, route to the correct API. |
| 3105 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3106 | switch (capability) { |
| 3107 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3108 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3109 | ims.setVolteProvisioned(isProvisioned); |
| 3110 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3111 | ims.setWfcProvisioned(isProvisioned); |
| 3112 | } |
| 3113 | break; |
| 3114 | } |
| 3115 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3116 | // There is currently no difference in VT provisioning type. |
| 3117 | ims.setVtProvisioned(isProvisioned); |
| 3118 | break; |
| 3119 | } |
| 3120 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3121 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3122 | // change the capability of the feature instead if needed. |
| 3123 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3124 | == isProvisioned) { |
| 3125 | // No change in provisioning. |
| 3126 | return; |
| 3127 | } |
| 3128 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3129 | try { |
| 3130 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
| 3131 | } catch (ImsException e) { |
| 3132 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3133 | + ", Exception" + e.getMessage()); |
| 3134 | } |
| 3135 | break; |
| 3136 | } |
| 3137 | default: { |
| 3138 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3139 | + capability + "', which does not require provisioning."); |
| 3140 | } |
| 3141 | } |
| 3142 | |
| 3143 | } finally { |
| 3144 | Binder.restoreCallingIdentity(identity); |
| 3145 | } |
| 3146 | } |
| 3147 | |
| 3148 | @Override |
| 3149 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3150 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3151 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3152 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3153 | } |
| 3154 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3155 | final long identity = Binder.clearCallingIdentity(); |
| 3156 | try { |
| 3157 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3158 | Phone phone = getPhone(subId); |
| 3159 | if (phone == null) { |
| 3160 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3161 | + subId); |
| 3162 | // We will fail with "true" as the provisioning status because this is the default |
| 3163 | // if we do not require provisioning. |
| 3164 | return true; |
| 3165 | } |
| 3166 | |
| 3167 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3168 | return true; |
| 3169 | } |
| 3170 | |
| 3171 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3172 | switch (capability) { |
| 3173 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3174 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3175 | return ims.isVolteProvisionedOnDevice(); |
| 3176 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3177 | return ims.isWfcProvisionedOnDevice(); |
| 3178 | } |
| 3179 | // This should never happen, since we are checking tech above to make sure it |
| 3180 | // is either LTE or IWLAN. |
| 3181 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3182 | + "capability."); |
| 3183 | } |
| 3184 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3185 | // There is currently no difference in VT provisioning type. |
| 3186 | return ims.isVtProvisionedOnDevice(); |
| 3187 | } |
| 3188 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3189 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3190 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3191 | } |
| 3192 | default: { |
| 3193 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3194 | + capability + "', which does not require provisioning."); |
| 3195 | } |
| 3196 | } |
| 3197 | |
| 3198 | } finally { |
| 3199 | Binder.restoreCallingIdentity(identity); |
| 3200 | } |
| 3201 | } |
| 3202 | |
| 3203 | @Override |
| 3204 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3205 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3206 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3207 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3208 | } |
| 3209 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3210 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3211 | return (provisionedBits & capability) > 0; |
| 3212 | } |
| 3213 | |
| 3214 | @Override |
| 3215 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3216 | boolean isProvisioned) { |
| 3217 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3218 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3219 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3220 | } |
| 3221 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3222 | "setProvisioningStatusForCapability"); |
| 3223 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3224 | // If the current provisioning status for capability already matches isProvisioned, |
| 3225 | // do nothing. |
| 3226 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3227 | return; |
| 3228 | } |
| 3229 | if (isProvisioned) { |
| 3230 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3231 | } else { |
| 3232 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3233 | } |
| 3234 | } |
| 3235 | |
| 3236 | /** |
| 3237 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3238 | * technology. The bitfield should mirror the bitfield defined by |
| 3239 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3240 | */ |
| 3241 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3242 | String key = getMmTelProvisioningKey(subId, tech); |
| 3243 | // Default is no capabilities are provisioned. |
| 3244 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3245 | } |
| 3246 | |
| 3247 | /** |
| 3248 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3249 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3250 | * technology specified. |
| 3251 | * |
| 3252 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3253 | */ |
| 3254 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3255 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3256 | String key = getMmTelProvisioningKey(subId, tech); |
| 3257 | editor.putInt(key, newField); |
| 3258 | editor.commit(); |
| 3259 | } |
| 3260 | |
| 3261 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3262 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3263 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3264 | } |
| 3265 | |
| 3266 | /** |
| 3267 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3268 | * carrier associated with the subscription id. |
| 3269 | */ |
| 3270 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3271 | int capability) { |
| 3272 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3273 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3274 | boolean requireUtProvisioning = c.getBoolean( |
| 3275 | // By default, this config is true (even if there is no SIM). We also check to make |
| 3276 | // sure the subscription needs provisioning here, so we do not need to check for |
| 3277 | // the no-SIM case, where we would normally shortcut this to false. |
| 3278 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true) |
| 3279 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3280 | false); |
| 3281 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3282 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3283 | |
| 3284 | // First check to make sure that the capability requires provisioning. |
| 3285 | switch (capability) { |
| 3286 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3287 | // intentional fallthrough |
| 3288 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3289 | if (requireVoiceVtProvisioning) { |
| 3290 | // Voice and Video requires provisioning |
| 3291 | return true; |
| 3292 | } |
| 3293 | break; |
| 3294 | } |
| 3295 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3296 | if (requireUtProvisioning) { |
| 3297 | // UT requires provisioning |
| 3298 | return true; |
| 3299 | } |
| 3300 | break; |
| 3301 | } |
| 3302 | } |
| 3303 | return false; |
| 3304 | } |
| 3305 | |
| 3306 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3307 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3308 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3309 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3310 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3311 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3312 | final long identity = Binder.clearCallingIdentity(); |
| 3313 | try { |
| 3314 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3315 | int slotId = getSlotIndex(subId); |
| 3316 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3317 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3318 | + subId + "' for key:" + key); |
| 3319 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3320 | } |
| 3321 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3322 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3323 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3324 | + subId + "' for key:" + key); |
| 3325 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3326 | } finally { |
| 3327 | Binder.restoreCallingIdentity(identity); |
| 3328 | } |
| 3329 | } |
| 3330 | |
| 3331 | @Override |
| 3332 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3333 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3334 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3335 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3336 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3337 | final long identity = Binder.clearCallingIdentity(); |
| 3338 | try { |
| 3339 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3340 | int slotId = getSlotIndex(subId); |
| 3341 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3342 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3343 | + subId + "' for key:" + key); |
| 3344 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3345 | } |
| 3346 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3347 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3348 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3349 | + subId + "' for key:" + key); |
| 3350 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3351 | } finally { |
| 3352 | Binder.restoreCallingIdentity(identity); |
| 3353 | } |
| 3354 | } |
| 3355 | |
| 3356 | @Override |
| 3357 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3358 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3359 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3360 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3361 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3362 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3363 | final long identity = Binder.clearCallingIdentity(); |
| 3364 | try { |
| 3365 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3366 | int slotId = getSlotIndex(subId); |
| 3367 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3368 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3369 | + subId + "' for key:" + key); |
| 3370 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3371 | } |
| 3372 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3373 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3374 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3375 | + "' for key:" + key); |
| 3376 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3377 | } finally { |
| 3378 | Binder.restoreCallingIdentity(identity); |
| 3379 | } |
| 3380 | } |
| 3381 | |
| 3382 | @Override |
| 3383 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3384 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3385 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3386 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3387 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3388 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3389 | final long identity = Binder.clearCallingIdentity(); |
| 3390 | try { |
| 3391 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3392 | int slotId = getSlotIndex(subId); |
| 3393 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3394 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3395 | + subId + "' for key:" + key); |
| 3396 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3397 | } |
| 3398 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3399 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3400 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3401 | + "' for key:" + key); |
| 3402 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3403 | } finally { |
| 3404 | Binder.restoreCallingIdentity(identity); |
| 3405 | } |
| 3406 | } |
| 3407 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3408 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 3409 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3410 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3411 | throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3412 | } |
| 3413 | return slotId; |
| 3414 | } |
| 3415 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3416 | private int getSlotIndex(int subId) { |
| 3417 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3418 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3419 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3420 | } |
| 3421 | return slotId; |
| 3422 | } |
| 3423 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3424 | /** |
| 3425 | * Returns the network type for a subId |
| 3426 | */ |
| 3427 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3428 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3429 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3430 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3431 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3432 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3433 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3434 | final long identity = Binder.clearCallingIdentity(); |
| 3435 | try { |
| 3436 | final Phone phone = getPhone(subId); |
| 3437 | if (phone != null) { |
| 3438 | return phone.getServiceState().getDataNetworkType(); |
| 3439 | } else { |
| 3440 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3441 | } |
| 3442 | } finally { |
| 3443 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3444 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3445 | } |
| 3446 | |
| 3447 | /** |
| 3448 | * Returns the data network type |
| 3449 | */ |
| 3450 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3451 | public int getDataNetworkType(String callingPackage) { |
| 3452 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3453 | } |
| 3454 | |
| 3455 | /** |
| 3456 | * Returns the data network type for a subId |
| 3457 | */ |
| 3458 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3459 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3460 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3461 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3462 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3463 | } |
| 3464 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3465 | final long identity = Binder.clearCallingIdentity(); |
| 3466 | try { |
| 3467 | final Phone phone = getPhone(subId); |
| 3468 | if (phone != null) { |
| 3469 | return phone.getServiceState().getDataNetworkType(); |
| 3470 | } else { |
| 3471 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3472 | } |
| 3473 | } finally { |
| 3474 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3475 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3476 | } |
| 3477 | |
| 3478 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3479 | * Returns the Voice network type for a subId |
| 3480 | */ |
| 3481 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3482 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3483 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3484 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3485 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3486 | } |
| 3487 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3488 | final long identity = Binder.clearCallingIdentity(); |
| 3489 | try { |
| 3490 | final Phone phone = getPhone(subId); |
| 3491 | if (phone != null) { |
| 3492 | return phone.getServiceState().getVoiceNetworkType(); |
| 3493 | } else { |
| 3494 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3495 | } |
| 3496 | } finally { |
| 3497 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3498 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3499 | } |
| 3500 | |
| 3501 | /** |
| 3502 | * @return true if a ICC card is present |
| 3503 | */ |
| 3504 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3505 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3506 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3507 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3508 | } |
| 3509 | |
| 3510 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3511 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3512 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3513 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3514 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3515 | final long identity = Binder.clearCallingIdentity(); |
| 3516 | try { |
| 3517 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3518 | if (phone != null) { |
| 3519 | return phone.getIccCard().hasIccCard(); |
| 3520 | } else { |
| 3521 | return false; |
| 3522 | } |
| 3523 | } finally { |
| 3524 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3525 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3526 | } |
| 3527 | |
| 3528 | /** |
| 3529 | * Return if the current radio is LTE on CDMA. This |
| 3530 | * is a tri-state return value as for a period of time |
| 3531 | * the mode may be unknown. |
| 3532 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3533 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3534 | * @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] | 3535 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3536 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3537 | @Override |
| 3538 | public int getLteOnCdmaMode(String callingPackage) { |
| 3539 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3540 | } |
| 3541 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3542 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3543 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3544 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3545 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3546 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3547 | } |
| 3548 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3549 | final long identity = Binder.clearCallingIdentity(); |
| 3550 | try { |
| 3551 | final Phone phone = getPhone(subId); |
| 3552 | if (phone == null) { |
| 3553 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3554 | } else { |
| 3555 | return phone.getLteOnCdmaMode(); |
| 3556 | } |
| 3557 | } finally { |
| 3558 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3559 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3560 | } |
| 3561 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3562 | /** |
| 3563 | * {@hide} |
| 3564 | * Returns Default subId, 0 in the case of single standby. |
| 3565 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3566 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3567 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3568 | } |
| 3569 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3570 | private int getSlotForDefaultSubscription() { |
| 3571 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3572 | } |
| 3573 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3574 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3575 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3576 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3577 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3578 | private boolean isActiveSubscription(int subId) { |
| 3579 | return mSubscriptionController.isActiveSubId(subId); |
| 3580 | } |
| 3581 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3582 | /** |
| 3583 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3584 | */ |
| 3585 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3586 | final long identity = Binder.clearCallingIdentity(); |
| 3587 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3588 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3589 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3590 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3591 | } finally { |
| 3592 | Binder.restoreCallingIdentity(identity); |
| 3593 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3594 | } |
| 3595 | |
| 3596 | /** |
| 3597 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3598 | */ |
| 3599 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3600 | final long identity = Binder.clearCallingIdentity(); |
| 3601 | try { |
| 3602 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3603 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3604 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3605 | } finally { |
| 3606 | Binder.restoreCallingIdentity(identity); |
| 3607 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3608 | } |
| 3609 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3610 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3611 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3612 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3613 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3614 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3615 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3616 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3617 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3618 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3619 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3620 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3621 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3622 | final long identity = Binder.clearCallingIdentity(); |
| 3623 | try { |
| 3624 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3625 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3626 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3627 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3628 | if (bestComponent == null |
| 3629 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3630 | loge("The calling package is not allowed to access ISD-R."); |
| 3631 | throw new SecurityException( |
| 3632 | "The calling package is not allowed to access ISD-R."); |
| 3633 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3634 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3635 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3636 | if (DBG) { |
| 3637 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3638 | } |
| 3639 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
| 3640 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId); |
| 3641 | if (DBG) log("iccOpenLogicalChannel: " + response); |
| 3642 | return response; |
| 3643 | } finally { |
| 3644 | Binder.restoreCallingIdentity(identity); |
| 3645 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3646 | } |
| 3647 | |
| 3648 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3649 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3650 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3651 | mApp, subId, "iccCloseLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3652 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3653 | final long identity = Binder.clearCallingIdentity(); |
| 3654 | try { |
| 3655 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3656 | if (channel < 0) { |
| 3657 | return false; |
| 3658 | } |
| 3659 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId); |
| 3660 | if (DBG) log("iccCloseLogicalChannel: " + success); |
| 3661 | return success; |
| 3662 | } finally { |
| 3663 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3664 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3665 | } |
| 3666 | |
| 3667 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3668 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3669 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3670 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3671 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3672 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3673 | final long identity = Binder.clearCallingIdentity(); |
| 3674 | try { |
| 3675 | if (DBG) { |
| 3676 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3677 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3678 | + p3 + " data=" + data); |
| 3679 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3680 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3681 | if (channel < 0) { |
| 3682 | return ""; |
| 3683 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3684 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3685 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
| 3686 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId); |
| 3687 | if (DBG) log("iccTransmitApduLogicalChannel: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3688 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3689 | // Append the returned status code to the end of the response payload. |
| 3690 | String s = Integer.toHexString( |
| 3691 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3692 | if (response.payload != null) { |
| 3693 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3694 | } |
| 3695 | return s; |
| 3696 | } finally { |
| 3697 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3698 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3699 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3700 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3701 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3702 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3703 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3704 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3705 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3706 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3707 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3708 | final long identity = Binder.clearCallingIdentity(); |
| 3709 | try { |
| 3710 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3711 | && TextUtils.equals(ISDR_AID, data)) { |
| 3712 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3713 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3714 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3715 | if (bestComponent == null |
| 3716 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3717 | loge("The calling package is not allowed to select ISD-R."); |
| 3718 | throw new SecurityException( |
| 3719 | "The calling package is not allowed to select ISD-R."); |
| 3720 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3721 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3722 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3723 | if (DBG) { |
| 3724 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3725 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3726 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3727 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3728 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
| 3729 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId); |
| 3730 | if (DBG) log("iccTransmitApduBasicChannel: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3731 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3732 | // Append the returned status code to the end of the response payload. |
| 3733 | String s = Integer.toHexString( |
| 3734 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3735 | if (response.payload != null) { |
| 3736 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3737 | } |
| 3738 | return s; |
| 3739 | } finally { |
| 3740 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3741 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3742 | } |
| 3743 | |
| 3744 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3745 | 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] | 3746 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3747 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3748 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3749 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3750 | final long identity = Binder.clearCallingIdentity(); |
| 3751 | try { |
| 3752 | if (DBG) { |
| 3753 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3754 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3755 | } |
| 3756 | |
| 3757 | IccIoResult response = |
| 3758 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3759 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3760 | subId); |
| 3761 | |
| 3762 | if (DBG) { |
| 3763 | log("Exchange SIM_IO [R]" + response); |
| 3764 | } |
| 3765 | |
| 3766 | byte[] result = null; |
| 3767 | int length = 2; |
| 3768 | if (response.payload != null) { |
| 3769 | length = 2 + response.payload.length; |
| 3770 | result = new byte[length]; |
| 3771 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3772 | } else { |
| 3773 | result = new byte[length]; |
| 3774 | } |
| 3775 | |
| 3776 | result[length - 1] = (byte) response.sw2; |
| 3777 | result[length - 2] = (byte) response.sw1; |
| 3778 | return result; |
| 3779 | } finally { |
| 3780 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3781 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3782 | } |
| 3783 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3784 | /** |
| 3785 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 3786 | * on a particular subscription |
| 3787 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3788 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 3789 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3790 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 3791 | return null; |
| 3792 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3793 | |
| 3794 | final long identity = Binder.clearCallingIdentity(); |
| 3795 | try { |
| 3796 | if (appType != TelephonyManager.APPTYPE_USIM |
| 3797 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 3798 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 3799 | return null; |
| 3800 | } |
| 3801 | Object response = sendRequest( |
| 3802 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 3803 | if (response instanceof String[]) { |
| 3804 | return (String[]) response; |
| 3805 | } |
| 3806 | // Response is an Exception of some kind, |
| 3807 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3808 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3809 | } finally { |
| 3810 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3811 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3812 | } |
| 3813 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3814 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3815 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3816 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3817 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3818 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3819 | final long identity = Binder.clearCallingIdentity(); |
| 3820 | try { |
| 3821 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 3822 | if (response.payload == null) { |
| 3823 | return ""; |
| 3824 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3825 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3826 | // Append the returned status code to the end of the response payload. |
| 3827 | String s = Integer.toHexString( |
| 3828 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3829 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3830 | return s; |
| 3831 | } finally { |
| 3832 | Binder.restoreCallingIdentity(identity); |
| 3833 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3834 | } |
| 3835 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3836 | /** |
| 3837 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3838 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3839 | * |
| 3840 | * @param itemID the ID of the item to read |
| 3841 | * @return the NV item as a String, or null on error. |
| 3842 | */ |
| 3843 | @Override |
| 3844 | public String nvReadItem(int itemID) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3845 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3846 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3847 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3848 | |
| 3849 | final long identity = Binder.clearCallingIdentity(); |
| 3850 | try { |
| 3851 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3852 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3853 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 3854 | return value; |
| 3855 | } finally { |
| 3856 | Binder.restoreCallingIdentity(identity); |
| 3857 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3858 | } |
| 3859 | |
| 3860 | /** |
| 3861 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3862 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3863 | * |
| 3864 | * @param itemID the ID of the item to read |
| 3865 | * @param itemValue the value to write, as a String |
| 3866 | * @return true on success; false on any failure |
| 3867 | */ |
| 3868 | @Override |
| 3869 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3870 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3871 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3872 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3873 | |
| 3874 | final long identity = Binder.clearCallingIdentity(); |
| 3875 | try { |
| 3876 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 3877 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3878 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3879 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 3880 | return success; |
| 3881 | } finally { |
| 3882 | Binder.restoreCallingIdentity(identity); |
| 3883 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3884 | } |
| 3885 | |
| 3886 | /** |
| 3887 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 3888 | * Used for device configuration by some CDMA operators. |
| 3889 | * |
| 3890 | * @param preferredRoamingList byte array containing the new PRL |
| 3891 | * @return true on success; false on any failure |
| 3892 | */ |
| 3893 | @Override |
| 3894 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3895 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3896 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3897 | |
| 3898 | final long identity = Binder.clearCallingIdentity(); |
| 3899 | try { |
| 3900 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 3901 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 3902 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 3903 | return success; |
| 3904 | } finally { |
| 3905 | Binder.restoreCallingIdentity(identity); |
| 3906 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3907 | } |
| 3908 | |
| 3909 | /** |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3910 | * Rollback modem configurations to factory default except some config which are in whitelist. |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3911 | * Used for device configuration by some CDMA operators. |
| 3912 | * |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3913 | * @param slotIndex - device slot. |
| 3914 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3915 | * @return true on success; false on any failure |
| 3916 | */ |
| 3917 | @Override |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3918 | public boolean resetModemConfig(int slotIndex) { |
| 3919 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3920 | if (phone != null) { |
| 3921 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3922 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3923 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3924 | final long identity = Binder.clearCallingIdentity(); |
| 3925 | try { |
| 3926 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 3927 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 3928 | return success; |
| 3929 | } finally { |
| 3930 | Binder.restoreCallingIdentity(identity); |
| 3931 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3932 | } |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3933 | return false; |
| 3934 | } |
| 3935 | |
| 3936 | /** |
| 3937 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 3938 | * |
| 3939 | * @param slotIndex - device slot. |
| 3940 | * |
| 3941 | * @return true on success; false on any failure |
| 3942 | */ |
| 3943 | @Override |
| 3944 | public boolean rebootModem(int slotIndex) { |
| 3945 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3946 | if (phone != null) { |
| 3947 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3948 | mApp, phone.getSubId(), "rebootModem"); |
| 3949 | |
| 3950 | final long identity = Binder.clearCallingIdentity(); |
| 3951 | try { |
| 3952 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 3953 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 3954 | return success; |
| 3955 | } finally { |
| 3956 | Binder.restoreCallingIdentity(identity); |
| 3957 | } |
| 3958 | } |
| 3959 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3960 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3961 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3962 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3963 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3964 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3965 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 3966 | return new String[0]; |
| 3967 | } |
| 3968 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3969 | final long identity = Binder.clearCallingIdentity(); |
| 3970 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3971 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3972 | } finally { |
| 3973 | Binder.restoreCallingIdentity(identity); |
| 3974 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3975 | } |
| 3976 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3977 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3978 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 3979 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3980 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3981 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 3982 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3983 | |
| 3984 | final long identity = Binder.clearCallingIdentity(); |
| 3985 | try { |
| 3986 | PhoneFactory.getImsResolver().enableIms(slotId); |
| 3987 | } finally { |
| 3988 | Binder.restoreCallingIdentity(identity); |
| 3989 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3990 | } |
| 3991 | |
| 3992 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3993 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 3994 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 3995 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 3996 | public void disableIms(int slotId) { |
| 3997 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3998 | |
| 3999 | final long identity = Binder.clearCallingIdentity(); |
| 4000 | try { |
| 4001 | PhoneFactory.getImsResolver().disableIms(slotId); |
| 4002 | } finally { |
| 4003 | Binder.restoreCallingIdentity(identity); |
| 4004 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4005 | } |
| 4006 | |
| 4007 | /** |
| 4008 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4009 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4010 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4011 | */ |
| 4012 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4013 | IImsServiceFeatureCallback callback) { |
| 4014 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4015 | |
| 4016 | final long identity = Binder.clearCallingIdentity(); |
| 4017 | try { |
| 4018 | return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback); |
| 4019 | } finally { |
| 4020 | Binder.restoreCallingIdentity(identity); |
| 4021 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4022 | } |
| 4023 | |
| 4024 | /** |
| 4025 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4026 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4027 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4028 | * listener for feature updates. |
| 4029 | */ |
| 4030 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4031 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4032 | |
| 4033 | final long identity = Binder.clearCallingIdentity(); |
| 4034 | try { |
| 4035 | return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback); |
| 4036 | } finally { |
| 4037 | Binder.restoreCallingIdentity(identity); |
| 4038 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4039 | } |
| 4040 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4041 | /** |
| 4042 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
| 4043 | * specified. |
| 4044 | */ |
| 4045 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4046 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4047 | |
| 4048 | final long identity = Binder.clearCallingIdentity(); |
| 4049 | try { |
| 4050 | return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature); |
| 4051 | } finally { |
| 4052 | Binder.restoreCallingIdentity(identity); |
| 4053 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4054 | } |
| 4055 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4056 | /** |
| 4057 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
| 4058 | * specified. |
| 4059 | */ |
| 4060 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4061 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4062 | |
| 4063 | final long identity = Binder.clearCallingIdentity(); |
| 4064 | try { |
| 4065 | return PhoneFactory.getImsResolver().getImsConfig(slotId, feature); |
| 4066 | } finally { |
| 4067 | Binder.restoreCallingIdentity(identity); |
| 4068 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4069 | } |
| 4070 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4071 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4072 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4073 | * |
| 4074 | * @param slotId the slot ID that the ImsService should bind for. |
| 4075 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4076 | * ImsService is the device default ImsService. |
| 4077 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4078 | * to. |
| 4079 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4080 | * @hide |
| 4081 | */ |
| 4082 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4083 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4084 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4085 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4086 | "setImsService"); |
| 4087 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4088 | final long identity = Binder.clearCallingIdentity(); |
| 4089 | try { |
| 4090 | return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId, |
| 4091 | isCarrierImsService, packageName); |
| 4092 | } finally { |
| 4093 | Binder.restoreCallingIdentity(identity); |
| 4094 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4095 | } |
| 4096 | |
| 4097 | /** |
| 4098 | * Return the ImsService configuration. |
| 4099 | * |
| 4100 | * @param slotId The slot that the ImsService is associated with. |
| 4101 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4102 | * the device default. |
| 4103 | * @return the package name of the ImsService configuration. |
| 4104 | */ |
| 4105 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4106 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4107 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4108 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4109 | "getImsService"); |
| 4110 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4111 | final long identity = Binder.clearCallingIdentity(); |
| 4112 | try { |
| 4113 | return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId, |
| 4114 | isCarrierImsService); |
| 4115 | } finally { |
| 4116 | Binder.restoreCallingIdentity(identity); |
| 4117 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4118 | } |
| 4119 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4120 | public void setImsRegistrationState(boolean registered) { |
| 4121 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4122 | |
| 4123 | final long identity = Binder.clearCallingIdentity(); |
| 4124 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4125 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4126 | } finally { |
| 4127 | Binder.restoreCallingIdentity(identity); |
| 4128 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4129 | } |
| 4130 | |
| 4131 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4132 | * Set the network selection mode to automatic. |
| 4133 | * |
| 4134 | */ |
| 4135 | @Override |
| 4136 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4137 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4138 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4139 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4140 | if (!isActiveSubscription(subId)) { |
| 4141 | return; |
| 4142 | } |
| 4143 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4144 | final long identity = Binder.clearCallingIdentity(); |
| 4145 | try { |
| 4146 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4147 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4148 | } finally { |
| 4149 | Binder.restoreCallingIdentity(identity); |
| 4150 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4151 | } |
| 4152 | |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4153 | /** |
| 4154 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4155 | * |
| 4156 | * @param subId the id of the subscription. |
| 4157 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4158 | * the operator to attach to. |
| 4159 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4160 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4161 | * normal network selection next time. |
| 4162 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4163 | */ |
| 4164 | @Override |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4165 | public boolean setNetworkSelectionModeManual( |
| 4166 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4167 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4168 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4169 | |
| 4170 | if (!isActiveSubscription(subId)) { |
| 4171 | return false; |
| 4172 | } |
| 4173 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4174 | final long identity = Binder.clearCallingIdentity(); |
| 4175 | try { |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4176 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4177 | persistSelection); |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4178 | if (DBG) { |
| 4179 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4180 | + " operator: " + operatorInfo); |
| 4181 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4182 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4183 | } finally { |
| 4184 | Binder.restoreCallingIdentity(identity); |
| 4185 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4186 | } |
| 4187 | |
| 4188 | /** |
| 4189 | * Scans for available networks. |
| 4190 | */ |
| 4191 | @Override |
| 4192 | public CellNetworkScanResult getCellNetworkScanResults(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4193 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4194 | mApp, subId, "getCellNetworkScanResults"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4195 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4196 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4197 | try { |
| 4198 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4199 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4200 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4201 | } finally { |
| 4202 | Binder.restoreCallingIdentity(identity); |
| 4203 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4204 | } |
| 4205 | |
| 4206 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4207 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4208 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4209 | * @param subId id of the subscription |
| 4210 | * @param request contains the radio access networks with bands/channels to scan |
| 4211 | * @param messenger callback messenger for scan results or errors |
| 4212 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4213 | * @return the id of the requested scan which can be used to stop the scan. |
| 4214 | */ |
| 4215 | @Override |
| 4216 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
| 4217 | IBinder binder) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4218 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4219 | mApp, subId, "requestNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4220 | |
| 4221 | final long identity = Binder.clearCallingIdentity(); |
| 4222 | try { |
| 4223 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4224 | request, messenger, binder, getPhone(subId)); |
| 4225 | } finally { |
| 4226 | Binder.restoreCallingIdentity(identity); |
| 4227 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4228 | } |
| 4229 | |
| 4230 | /** |
| 4231 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4232 | * |
| 4233 | * @param subId id of the subscription |
| 4234 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4235 | */ |
| 4236 | @Override |
| 4237 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4238 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4239 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4240 | |
| 4241 | final long identity = Binder.clearCallingIdentity(); |
| 4242 | try { |
| 4243 | mNetworkScanRequestTracker.stopNetworkScan(scanId); |
| 4244 | } finally { |
| 4245 | Binder.restoreCallingIdentity(identity); |
| 4246 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4247 | } |
| 4248 | |
| 4249 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4250 | * Get the calculated preferred network type. |
| 4251 | * Used for debugging incorrect network type. |
| 4252 | * |
| 4253 | * @return the preferred network type, defined in RILConstants.java. |
| 4254 | */ |
| 4255 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4256 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4257 | final Phone defaultPhone = getDefaultPhone(); |
| 4258 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4259 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4260 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4261 | } |
| 4262 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4263 | final long identity = Binder.clearCallingIdentity(); |
| 4264 | try { |
| 4265 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4266 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4267 | } finally { |
| 4268 | Binder.restoreCallingIdentity(identity); |
| 4269 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4270 | } |
| 4271 | |
| 4272 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4273 | * Get the preferred network type. |
| 4274 | * Used for device configuration by some CDMA operators. |
| 4275 | * |
| 4276 | * @return the preferred network type, defined in RILConstants.java. |
| 4277 | */ |
| 4278 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4279 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | 4848cd0 | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4280 | TelephonyPermissions |
| 4281 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4282 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4283 | |
| 4284 | final long identity = Binder.clearCallingIdentity(); |
| 4285 | try { |
| 4286 | if (DBG) log("getPreferredNetworkType"); |
| 4287 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4288 | int networkType = (result != null ? result[0] : -1); |
| 4289 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4290 | return networkType; |
| 4291 | } finally { |
| 4292 | Binder.restoreCallingIdentity(identity); |
| 4293 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4294 | } |
| 4295 | |
| 4296 | /** |
| 4297 | * Set the preferred network type. |
| 4298 | * Used for device configuration by some CDMA operators. |
| 4299 | * |
| 4300 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4301 | * @return true on success; false on any failure. |
| 4302 | */ |
| 4303 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4304 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4305 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4306 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4307 | |
| 4308 | final long identity = Binder.clearCallingIdentity(); |
| 4309 | try { |
| 4310 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4311 | Boolean success = (Boolean) sendRequest( |
| 4312 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4313 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4314 | if (success) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4315 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4316 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4317 | } |
| 4318 | return success; |
| 4319 | } finally { |
| 4320 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4321 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4322 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4323 | |
| 4324 | /** |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4325 | * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning |
Jack Yu | 13db0fe | 2018-10-30 17:41:31 -0700 | [diff] [blame] | 4326 | * SystemProperty to decide whether DUN APN is required for |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4327 | * tethering. |
| 4328 | * |
| 4329 | * @return 0: Not required. 1: required. 2: Not set. |
| 4330 | * @hide |
| 4331 | */ |
| 4332 | @Override |
| 4333 | public int getTetherApnRequired() { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4334 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4335 | |
| 4336 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4337 | final Phone defaultPhone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4338 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4339 | int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4340 | Settings.Global.TETHER_DUN_REQUIRED, 2); |
Jack Yu | 13db0fe | 2018-10-30 17:41:31 -0700 | [diff] [blame] | 4341 | // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4342 | if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4343 | dunRequired = 1; |
| 4344 | } |
| 4345 | return dunRequired; |
| 4346 | } finally { |
| 4347 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4348 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4349 | } |
| 4350 | |
| 4351 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4352 | * Set mobile data enabled |
| 4353 | * Used by the user through settings etc to turn on/off mobile data |
| 4354 | * |
| 4355 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4356 | */ |
| 4357 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4358 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4359 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4360 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4361 | |
| 4362 | final long identity = Binder.clearCallingIdentity(); |
| 4363 | try { |
| 4364 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4365 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4366 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4367 | if (phone != null) { |
| 4368 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4369 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4370 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4371 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4372 | } |
| 4373 | } finally { |
| 4374 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4375 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4376 | } |
| 4377 | |
| 4378 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4379 | * Get the user enabled state of Mobile Data. |
| 4380 | * |
| 4381 | * TODO: remove and use isUserDataEnabled. |
| 4382 | * This can't be removed now because some vendor codes |
| 4383 | * calls through ITelephony directly while they should |
| 4384 | * use TelephonyManager. |
| 4385 | * |
| 4386 | * @return true on enabled |
| 4387 | */ |
| 4388 | @Override |
| 4389 | public boolean getDataEnabled(int subId) { |
| 4390 | return isUserDataEnabled(subId); |
| 4391 | } |
| 4392 | |
| 4393 | /** |
| 4394 | * Get whether mobile data is enabled per user setting. |
| 4395 | * |
| 4396 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4397 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4398 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4399 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4400 | * |
| 4401 | * @return {@code true} if data is enabled else {@code false} |
| 4402 | */ |
| 4403 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4404 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4405 | try { |
| 4406 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4407 | null); |
| 4408 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4409 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4410 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4411 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4412 | |
| 4413 | final long identity = Binder.clearCallingIdentity(); |
| 4414 | try { |
| 4415 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4416 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4417 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4418 | if (phone != null) { |
| 4419 | boolean retVal = phone.isUserDataEnabled(); |
| 4420 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4421 | return retVal; |
| 4422 | } else { |
| 4423 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4424 | return false; |
| 4425 | } |
| 4426 | } finally { |
| 4427 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4428 | } |
| 4429 | } |
| 4430 | |
| 4431 | /** |
| 4432 | * Get whether mobile data is enabled. |
| 4433 | * |
| 4434 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4435 | * whether mobile data is actually enabled. |
| 4436 | * |
| 4437 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4438 | * |
| 4439 | * @return {@code true} if data is enabled else {@code false} |
| 4440 | */ |
| 4441 | @Override |
| 4442 | public boolean isDataEnabled(int subId) { |
| 4443 | try { |
| 4444 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4445 | null); |
| 4446 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4447 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4448 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4449 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4450 | |
| 4451 | final long identity = Binder.clearCallingIdentity(); |
| 4452 | try { |
| 4453 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4454 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4455 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4456 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4457 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4458 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4459 | return retVal; |
| 4460 | } else { |
| 4461 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4462 | return false; |
| 4463 | } |
| 4464 | } finally { |
| 4465 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4466 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4467 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4468 | |
| 4469 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4470 | public int getCarrierPrivilegeStatus(int subId) { |
| 4471 | final Phone phone = getPhone(subId); |
| 4472 | if (phone == null) { |
| 4473 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4474 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4475 | } |
| 4476 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4477 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4478 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4479 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4480 | } |
| 4481 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4482 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4483 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4484 | |
| 4485 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4486 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4487 | final Phone phone = getPhone(subId); |
| 4488 | if (phone == null) { |
| 4489 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4490 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4491 | } |
| 4492 | UiccProfile profile = |
| 4493 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4494 | if (profile == null) { |
| 4495 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4496 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4497 | } |
| 4498 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 4499 | } |
| 4500 | |
| 4501 | @Override |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4502 | public int checkCarrierPrivilegesForPackage(String pkgName) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4503 | final Phone defaultPhone = getDefaultPhone(); |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4504 | if (TextUtils.isEmpty(pkgName)) |
| 4505 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4506 | UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4507 | if (card == null) { |
| 4508 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 4509 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4510 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4511 | return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(), |
| 4512 | pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4513 | } |
| 4514 | |
| 4515 | @Override |
| 4516 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4517 | if (TextUtils.isEmpty(pkgName)) |
| 4518 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4519 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4520 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4521 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4522 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4523 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4524 | continue; |
| 4525 | } |
| 4526 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4527 | result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4528 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4529 | break; |
| 4530 | } |
| 4531 | } |
| 4532 | |
| 4533 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4534 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4535 | |
| 4536 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4537 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4538 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4539 | loge("phoneId " + phoneId + " is not valid."); |
| 4540 | return null; |
| 4541 | } |
| 4542 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4543 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4544 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4545 | return null ; |
| 4546 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4547 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4548 | } |
| 4549 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4550 | @Override |
| 4551 | public List<String> getPackagesWithCarrierPrivileges() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4552 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4553 | List<String> privilegedPackages = new ArrayList<>(); |
| 4554 | List<PackageInfo> packages = null; |
| 4555 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4556 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4557 | if (card == null) { |
| 4558 | // No UICC in that slot. |
| 4559 | continue; |
| 4560 | } |
| 4561 | if (card.hasCarrierPrivilegeRules()) { |
| 4562 | if (packages == null) { |
| 4563 | // Only check packages in user 0 for now |
| 4564 | packages = pm.getInstalledPackagesAsUser( |
| 4565 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4566 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4567 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
| 4568 | } |
| 4569 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4570 | PackageInfo pkgInfo = packages.get(p); |
| 4571 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4572 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| 4573 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4574 | privilegedPackages.add(pkgInfo.packageName); |
| 4575 | } |
| 4576 | } |
| 4577 | } |
| 4578 | } |
| 4579 | return privilegedPackages; |
| 4580 | } |
| 4581 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4582 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4583 | final Phone phone = getPhone(subId); |
| 4584 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4585 | if (card == null) { |
| 4586 | loge("getIccId: No UICC"); |
| 4587 | return null; |
| 4588 | } |
| 4589 | String iccId = card.getIccId(); |
| 4590 | if (TextUtils.isEmpty(iccId)) { |
| 4591 | loge("getIccId: ICC ID is null or empty."); |
| 4592 | return null; |
| 4593 | } |
| 4594 | return iccId; |
| 4595 | } |
| 4596 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4597 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4598 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4599 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4600 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4601 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4602 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4603 | final long identity = Binder.clearCallingIdentity(); |
| 4604 | try { |
| 4605 | final String iccId = getIccId(subId); |
| 4606 | final Phone phone = getPhone(subId); |
| 4607 | if (phone == null) { |
| 4608 | return false; |
| 4609 | } |
| 4610 | final String subscriberId = phone.getSubscriberId(); |
| 4611 | |
| 4612 | if (DBG_MERGE) { |
| 4613 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4614 | + subscriberId + " to " + number); |
| 4615 | } |
| 4616 | |
| 4617 | if (TextUtils.isEmpty(iccId)) { |
| 4618 | return false; |
| 4619 | } |
| 4620 | |
| 4621 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4622 | |
| 4623 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4624 | if (alphaTag == null) { |
| 4625 | editor.remove(alphaTagPrefKey); |
| 4626 | } else { |
| 4627 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4628 | } |
| 4629 | |
| 4630 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4631 | // track all merged IMSIs based on line number |
| 4632 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4633 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4634 | if (number == null) { |
| 4635 | editor.remove(numberPrefKey); |
| 4636 | editor.remove(subscriberPrefKey); |
| 4637 | } else { |
| 4638 | editor.putString(numberPrefKey, number); |
| 4639 | editor.putString(subscriberPrefKey, subscriberId); |
| 4640 | } |
| 4641 | |
| 4642 | editor.commit(); |
| 4643 | return true; |
| 4644 | } finally { |
| 4645 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4646 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4647 | } |
| 4648 | |
| 4649 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4650 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4651 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4652 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4653 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4654 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4655 | return null; |
| 4656 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4657 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4658 | final long identity = Binder.clearCallingIdentity(); |
| 4659 | try { |
| 4660 | String iccId = getIccId(subId); |
| 4661 | if (iccId != null) { |
| 4662 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4663 | if (DBG_MERGE) { |
| 4664 | log("getLine1NumberForDisplay returning " |
| 4665 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 4666 | } |
| 4667 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4668 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4669 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 4670 | return null; |
| 4671 | } finally { |
| 4672 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4673 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4674 | } |
| 4675 | |
| 4676 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4677 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4678 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4679 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4680 | return null; |
| 4681 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4682 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4683 | final long identity = Binder.clearCallingIdentity(); |
| 4684 | try { |
| 4685 | String iccId = getIccId(subId); |
| 4686 | if (iccId != null) { |
| 4687 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4688 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 4689 | } |
| 4690 | return null; |
| 4691 | } finally { |
| 4692 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4693 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4694 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4695 | |
| 4696 | @Override |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4697 | public String[] getMergedSubscriberIds(String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4698 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 4699 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4700 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4701 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 4702 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4703 | return null; |
| 4704 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4705 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4706 | final long identity = Binder.clearCallingIdentity(); |
| 4707 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4708 | final Context context = mApp; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4709 | final TelephonyManager tele = TelephonyManager.from(context); |
| 4710 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 4711 | |
| 4712 | // Figure out what subscribers are currently active |
| 4713 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
| 4714 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 4715 | // the process, where TelephonyManager was instantiated. |
| 4716 | // Otherwise AppOps check will fail. |
| 4717 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4718 | final int[] subIds = sub.getActiveSubscriptionIdList(); |
| 4719 | for (int subId : subIds) { |
| 4720 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 4721 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4722 | |
| 4723 | // First pass, find a number override for an active subscriber |
| 4724 | String mergeNumber = null; |
| 4725 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 4726 | for (String key : prefs.keySet()) { |
| 4727 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 4728 | final String subscriberId = (String) prefs.get(key); |
| 4729 | if (activeSubscriberIds.contains(subscriberId)) { |
| 4730 | final String iccId = key.substring( |
| 4731 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 4732 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4733 | mergeNumber = (String) prefs.get(numberKey); |
| 4734 | if (DBG_MERGE) { |
| 4735 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 4736 | + " for active subscriber " + subscriberId); |
| 4737 | } |
| 4738 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 4739 | break; |
| 4740 | } |
| 4741 | } |
| 4742 | } |
| 4743 | } |
| 4744 | |
| 4745 | // Shortcut when no active merged subscribers |
| 4746 | if (TextUtils.isEmpty(mergeNumber)) { |
| 4747 | return null; |
| 4748 | } |
| 4749 | |
| 4750 | // Second pass, find all subscribers under that line override |
| 4751 | final ArraySet<String> result = new ArraySet<>(); |
| 4752 | for (String key : prefs.keySet()) { |
| 4753 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 4754 | final String number = (String) prefs.get(key); |
| 4755 | if (mergeNumber.equals(number)) { |
| 4756 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 4757 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4758 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 4759 | if (!TextUtils.isEmpty(subscriberId)) { |
| 4760 | result.add(subscriberId); |
| 4761 | } |
| 4762 | } |
| 4763 | } |
| 4764 | } |
| 4765 | |
| 4766 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 4767 | Arrays.sort(resultArray); |
| 4768 | if (DBG_MERGE) { |
| 4769 | Slog.d(LOG_TAG, |
| 4770 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 4771 | } |
| 4772 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4773 | } finally { |
| 4774 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4775 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4776 | } |
| 4777 | |
| 4778 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4779 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4780 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4781 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4782 | |
| 4783 | final long identity = Binder.clearCallingIdentity(); |
| 4784 | try { |
| 4785 | final Phone phone = getPhone(subId); |
| 4786 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 4787 | } finally { |
| 4788 | Binder.restoreCallingIdentity(identity); |
| 4789 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4790 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 4791 | |
| 4792 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4793 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4794 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 4795 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4796 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4797 | |
| 4798 | final long identity = Binder.clearCallingIdentity(); |
| 4799 | try { |
| 4800 | final Phone phone = getPhone(subId); |
| 4801 | if (phone == null) { |
| 4802 | return false; |
| 4803 | } |
| 4804 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 4805 | cdmaNonRoamingList); |
| 4806 | } finally { |
| 4807 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4808 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4809 | } |
| 4810 | |
| 4811 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4812 | @Deprecated |
| 4813 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 4814 | enforceModifyPermission(); |
| 4815 | |
| 4816 | int returnValue = 0; |
| 4817 | try { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4818 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4819 | if(result.exception == null) { |
| 4820 | if (result.result != null) { |
| 4821 | byte[] responseData = (byte[])(result.result); |
| 4822 | if(responseData.length > oemResp.length) { |
| 4823 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 4824 | responseData.length + "bytes. Buffer Size is " + |
| 4825 | oemResp.length + "bytes."); |
| 4826 | } |
| 4827 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 4828 | returnValue = responseData.length; |
| 4829 | } |
| 4830 | } else { |
| 4831 | CommandException ex = (CommandException) result.exception; |
| 4832 | returnValue = ex.getCommandError().ordinal(); |
| 4833 | if(returnValue > 0) returnValue *= -1; |
| 4834 | } |
| 4835 | } catch (RuntimeException e) { |
| 4836 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 4837 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 4838 | if(returnValue > 0) returnValue *= -1; |
| 4839 | } |
| 4840 | |
| 4841 | return returnValue; |
| 4842 | } |
| 4843 | |
| 4844 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4845 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 4846 | try { |
| 4847 | ProxyController.getInstance().setRadioCapability(rafs); |
| 4848 | } catch (RuntimeException e) { |
| 4849 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 4850 | } |
| 4851 | } |
| 4852 | |
| 4853 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4854 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4855 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4856 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4857 | if (phone == null) { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4858 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4859 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4860 | final long identity = Binder.clearCallingIdentity(); |
| 4861 | try { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4862 | TelephonyPermissions |
| 4863 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4864 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 4865 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4866 | } finally { |
| 4867 | Binder.restoreCallingIdentity(identity); |
| 4868 | } |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4869 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4870 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4871 | |
| 4872 | @Override |
| 4873 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4874 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4875 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4876 | |
| 4877 | final long identity = Binder.clearCallingIdentity(); |
| 4878 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4879 | ImsManager.getInstance(defaultPhone.getContext(), |
| 4880 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4881 | } finally { |
| 4882 | Binder.restoreCallingIdentity(identity); |
| 4883 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4884 | } |
| 4885 | |
| 4886 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4887 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4888 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4889 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4890 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4891 | return false; |
| 4892 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4893 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4894 | final long identity = Binder.clearCallingIdentity(); |
| 4895 | try { |
| 4896 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 4897 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 4898 | // In the long run, we may instead need to check if there exists a connection service |
| 4899 | // which can support video calling. |
| 4900 | ImsManager imsManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4901 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4902 | return imsManager.isVtEnabledByPlatform() |
| 4903 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 4904 | && imsManager.isVtEnabledByUser(); |
| 4905 | } finally { |
| 4906 | Binder.restoreCallingIdentity(identity); |
| 4907 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4908 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 4909 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4910 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4911 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 4912 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4913 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4914 | return false; |
| 4915 | } |
| 4916 | |
| 4917 | final long identity = Binder.clearCallingIdentity(); |
| 4918 | try { |
| 4919 | CarrierConfigManager configManager = |
| 4920 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4921 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4922 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 4923 | } finally { |
| 4924 | Binder.restoreCallingIdentity(identity); |
| 4925 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4926 | } |
| 4927 | |
| 4928 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4929 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 4930 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4931 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 4932 | return false; |
| 4933 | } |
| 4934 | |
| 4935 | final long identity = Binder.clearCallingIdentity(); |
| 4936 | try { |
| 4937 | CarrierConfigManager configManager = |
| 4938 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4939 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4940 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 4941 | } finally { |
| 4942 | Binder.restoreCallingIdentity(identity); |
| 4943 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4944 | } |
| 4945 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4946 | @Override |
| 4947 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4948 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 4949 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4950 | } |
| 4951 | |
| 4952 | @Override |
| 4953 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4954 | final long identity = Binder.clearCallingIdentity(); |
| 4955 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4956 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4957 | } finally { |
| 4958 | Binder.restoreCallingIdentity(identity); |
| 4959 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 4960 | } |
| 4961 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4962 | /** |
| 4963 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 4964 | * support for the feature and device firmware support. |
| 4965 | * |
| 4966 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 4967 | */ |
| 4968 | @Override |
| 4969 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4970 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4971 | final Phone phone = getPhone(subscriptionId); |
| 4972 | if (phone == null) { |
| 4973 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 4974 | return false; |
| 4975 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4976 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4977 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4978 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 4979 | boolean isDeviceSupported = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4980 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4981 | return isCarrierSupported && isDeviceSupported; |
| 4982 | } finally { |
| 4983 | Binder.restoreCallingIdentity(identity); |
| 4984 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 4985 | } |
| 4986 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4987 | /** |
| 4988 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier |
| 4989 | * both also support RTT. |
| 4990 | */ |
| 4991 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4992 | final long identity = Binder.clearCallingIdentity(); |
| 4993 | try { |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 4994 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4995 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4996 | } finally { |
| 4997 | Binder.restoreCallingIdentity(identity); |
| 4998 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 4999 | } |
| 5000 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5001 | /** |
| 5002 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5003 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5004 | * |
| 5005 | * <p>Requires Permission: |
| 5006 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5007 | */ |
| 5008 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5009 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5010 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5011 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5012 | return null; |
| 5013 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5014 | int subId = phone.getSubId(); |
| 5015 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5016 | mApp, subId, callingPackage, "getDeviceId")) { |
| 5017 | return null; |
| 5018 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5019 | |
| 5020 | final long identity = Binder.clearCallingIdentity(); |
| 5021 | try { |
| 5022 | return phone.getDeviceId(); |
| 5023 | } finally { |
| 5024 | Binder.restoreCallingIdentity(identity); |
| 5025 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5026 | } |
| 5027 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5028 | /** |
| 5029 | * {@hide} |
| 5030 | * Returns the IMS Registration Status on a particular subid |
| 5031 | * |
| 5032 | * @param subId |
| 5033 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5034 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5035 | Phone phone = getPhone(subId); |
| 5036 | if (phone != null) { |
| 5037 | return phone.isImsRegistered(); |
| 5038 | } else { |
| 5039 | return false; |
| 5040 | } |
| 5041 | } |
| 5042 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5043 | @Override |
| 5044 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5045 | final long identity = Binder.clearCallingIdentity(); |
| 5046 | try { |
| 5047 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5048 | } finally { |
| 5049 | Binder.restoreCallingIdentity(identity); |
| 5050 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5051 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5052 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5053 | /** |
| 5054 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5055 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5056 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5057 | final long identity = Binder.clearCallingIdentity(); |
| 5058 | try { |
| 5059 | Phone phone = getPhone(subId); |
| 5060 | if (phone != null) { |
| 5061 | return phone.isWifiCallingEnabled(); |
| 5062 | } else { |
| 5063 | return false; |
| 5064 | } |
| 5065 | } finally { |
| 5066 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5067 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5068 | } |
| 5069 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5070 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5071 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5072 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5073 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5074 | final long identity = Binder.clearCallingIdentity(); |
| 5075 | try { |
| 5076 | Phone phone = getPhone(subId); |
| 5077 | if (phone != null) { |
| 5078 | return phone.isVideoEnabled(); |
| 5079 | } else { |
| 5080 | return false; |
| 5081 | } |
| 5082 | } finally { |
| 5083 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5084 | } |
| 5085 | } |
| 5086 | |
| 5087 | /** |
| 5088 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5089 | * defined in {@link ImsRegistrationImplBase}. |
| 5090 | */ |
| 5091 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5092 | final long identity = Binder.clearCallingIdentity(); |
| 5093 | try { |
| 5094 | Phone phone = getPhone(subId); |
| 5095 | if (phone != null) { |
| 5096 | return phone.getImsRegistrationTech(); |
| 5097 | } else { |
| 5098 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5099 | } |
| 5100 | } finally { |
| 5101 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5102 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5103 | } |
| 5104 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5105 | @Override |
| 5106 | public void factoryReset(int subId) { |
| 5107 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5108 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5109 | return; |
| 5110 | } |
| 5111 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5112 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5113 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5114 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5115 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5116 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5117 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5118 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5119 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5120 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5121 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5122 | } |
| 5123 | } finally { |
| 5124 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5125 | } |
| 5126 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5127 | |
| 5128 | @Override |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5129 | public String getSimLocaleForSubscriber(int subId) { |
| 5130 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5131 | final Phone phone = getPhone(subId); |
| 5132 | if (phone == null) { |
| 5133 | log("getSimLocaleForSubscriber, invalid subId"); |
Pengquan Meng | 9c29148 | 2019-01-28 16:26:29 -0800 | [diff] [blame] | 5134 | return null; |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5135 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5136 | final long identity = Binder.clearCallingIdentity(); |
| 5137 | try { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5138 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5139 | phone.getContext().getOpPackageName()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5140 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5141 | // preferences (EF-PL and EF-LI)... |
| 5142 | final int mcc = info.getMcc(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5143 | String simLanguage = null; |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5144 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5145 | if (localeFromDefaultSim != null) { |
| 5146 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5147 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5148 | + localeFromDefaultSim); |
| 5149 | return localeFromDefaultSim.toLanguageTag(); |
| 5150 | } else { |
| 5151 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5152 | } |
| 5153 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5154 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5155 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5156 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5157 | // the SIM and carrier preferences does not include a country we add the country |
| 5158 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5159 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5160 | if (mccLocale != null) { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5161 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5162 | return mccLocale.toLanguageTag(); |
| 5163 | } |
| 5164 | |
| 5165 | if (DBG) log("No locale found - returning null"); |
| 5166 | return null; |
| 5167 | } finally { |
| 5168 | Binder.restoreCallingIdentity(identity); |
| 5169 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5170 | } |
| 5171 | |
| 5172 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5173 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5174 | } |
| 5175 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5176 | /** |
| 5177 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5178 | */ |
| 5179 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5180 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5181 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5182 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5183 | private final ModemActivityInfo mLastModemActivityInfo = |
| 5184 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 5185 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5186 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5187 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5188 | * representing the state of the modem. |
| 5189 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5190 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5191 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5192 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5193 | */ |
| 5194 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5195 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5196 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5197 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5198 | |
| 5199 | final long identity = Binder.clearCallingIdentity(); |
| 5200 | try { |
| 5201 | ModemActivityInfo ret = null; |
| 5202 | synchronized (mLastModemActivityInfo) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5203 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5204 | CMD_GET_MODEM_ACTIVITY_INFO, |
| 5205 | null, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5206 | if (isModemActivityInfoValid(info)) { |
| 5207 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 5208 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 5209 | mergedTxTimeMs[i] = |
| 5210 | info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i]; |
| 5211 | } |
| 5212 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 5213 | mLastModemActivityInfo.setSleepTimeMillis( |
| 5214 | info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis()); |
| 5215 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5216 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 5217 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 5218 | mLastModemActivityInfo.setRxTimeMillis( |
| 5219 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 5220 | mLastModemActivityInfo.setEnergyUsed( |
| 5221 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5222 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5223 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5224 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5225 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 5226 | mLastModemActivityInfo.getTxTimeMillis(), |
| 5227 | mLastModemActivityInfo.getRxTimeMillis(), |
| 5228 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5229 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5230 | Bundle bundle = new Bundle(); |
| 5231 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 5232 | result.send(0, bundle); |
| 5233 | } finally { |
| 5234 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5235 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5236 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5237 | |
Siddharth Ray | f5d2955 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5238 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 5239 | // less than total activity duration. |
| 5240 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 5241 | if (info == null) { |
| 5242 | return false; |
| 5243 | } |
| 5244 | int activityDurationMs = |
| 5245 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 5246 | int totalTxTimeMs = 0; |
| 5247 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 5248 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 5249 | } |
| 5250 | return (info.isValid() |
| 5251 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 5252 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 5253 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 5254 | && (totalTxTimeMs <= activityDurationMs)); |
| 5255 | } |
| 5256 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5257 | /** |
| 5258 | * {@hide} |
| 5259 | * Returns the service state information on specified subscription. |
| 5260 | */ |
| 5261 | @Override |
| 5262 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5263 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5264 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5265 | return null; |
| 5266 | } |
| 5267 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5268 | final long identity = Binder.clearCallingIdentity(); |
| 5269 | try { |
| 5270 | final Phone phone = getPhone(subId); |
| 5271 | if (phone == null) { |
| 5272 | return null; |
| 5273 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5274 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5275 | return phone.getServiceState(); |
| 5276 | } finally { |
| 5277 | Binder.restoreCallingIdentity(identity); |
| 5278 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5279 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5280 | |
| 5281 | /** |
| 5282 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5283 | * |
| 5284 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5285 | * voicemail ringtone. |
| 5286 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5287 | * PhoneAccount. |
| 5288 | */ |
| 5289 | @Override |
| 5290 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5291 | final long identity = Binder.clearCallingIdentity(); |
| 5292 | try { |
| 5293 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5294 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5295 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5296 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5297 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5298 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5299 | } finally { |
| 5300 | Binder.restoreCallingIdentity(identity); |
| 5301 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5302 | } |
| 5303 | |
| 5304 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5305 | * Sets the per-account voicemail ringtone. |
| 5306 | * |
| 5307 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5308 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5309 | * |
| 5310 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5311 | * voicemail ringtone. |
| 5312 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5313 | * PhoneAccount. |
| 5314 | */ |
| 5315 | @Override |
| 5316 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5317 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5318 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5319 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5320 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5321 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5322 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5323 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5324 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5325 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5326 | |
| 5327 | final long identity = Binder.clearCallingIdentity(); |
| 5328 | try { |
| 5329 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5330 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5331 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5332 | } |
| 5333 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5334 | } finally { |
| 5335 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5336 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5337 | } |
| 5338 | |
| 5339 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5340 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5341 | * |
| 5342 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5343 | * voicemail vibration setting. |
| 5344 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5345 | */ |
| 5346 | @Override |
| 5347 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5348 | final long identity = Binder.clearCallingIdentity(); |
| 5349 | try { |
| 5350 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5351 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5352 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5353 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5354 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5355 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5356 | } finally { |
| 5357 | Binder.restoreCallingIdentity(identity); |
| 5358 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5359 | } |
| 5360 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5361 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5362 | * Sets the per-account voicemail vibration. |
| 5363 | * |
| 5364 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5365 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5366 | * |
| 5367 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5368 | * voicemail vibration setting. |
| 5369 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5370 | * specific PhoneAccount. |
| 5371 | */ |
| 5372 | @Override |
| 5373 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5374 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5375 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5376 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5377 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5378 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5379 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5380 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5381 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5382 | } |
| 5383 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5384 | final long identity = Binder.clearCallingIdentity(); |
| 5385 | try { |
| 5386 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5387 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5388 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5389 | } |
| 5390 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5391 | } finally { |
| 5392 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5393 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5394 | } |
| 5395 | |
| 5396 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5397 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5398 | * |
| 5399 | * @throws SecurityException if the caller does not have the required permission |
| 5400 | */ |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5401 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5402 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5403 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5404 | } |
| 5405 | |
| 5406 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5407 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5408 | * permission. |
| 5409 | * |
| 5410 | * @throws SecurityException if the caller does not have the required permission |
| 5411 | */ |
| 5412 | private void enforceSendSmsPermission() { |
| 5413 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5414 | } |
| 5415 | |
| 5416 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5417 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5418 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5419 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5420 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5421 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5422 | final long identity = Binder.clearCallingIdentity(); |
| 5423 | try { |
| 5424 | ComponentName componentName = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5425 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5426 | if (componentName == null) { |
| 5427 | throw new SecurityException( |
| 5428 | "Caller not current active visual voicemail package[null]"); |
| 5429 | } |
| 5430 | String vvmPackage = componentName.getPackageName(); |
| 5431 | if (!callingPackage.equals(vvmPackage)) { |
| 5432 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5433 | + vvmPackage + "]"); |
| 5434 | } |
| 5435 | } finally { |
| 5436 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5437 | } |
| 5438 | } |
| 5439 | |
| 5440 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5441 | * Return the application ID for the app type. |
| 5442 | * |
| 5443 | * @param subId the subscription ID that this request applies to. |
| 5444 | * @param appType the uicc app type. |
| 5445 | * @return Application ID for specificied app type, or null if no uicc. |
| 5446 | */ |
| 5447 | @Override |
| 5448 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5449 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5450 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5451 | |
| 5452 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5453 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5454 | if (phone == null) { |
| 5455 | return null; |
| 5456 | } |
| 5457 | String aid = null; |
| 5458 | try { |
| 5459 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5460 | .getApplicationByType(appType).getAid(); |
| 5461 | } catch (Exception e) { |
| 5462 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5463 | } |
| 5464 | return aid; |
| 5465 | } finally { |
| 5466 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5467 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5468 | } |
| 5469 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5470 | /** |
| 5471 | * Return the Electronic Serial Number. |
| 5472 | * |
| 5473 | * @param subId the subscription ID that this request applies to. |
| 5474 | * @return ESN or null if error. |
| 5475 | */ |
| 5476 | @Override |
| 5477 | public String getEsn(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5478 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5479 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5480 | |
| 5481 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5482 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5483 | if (phone == null) { |
| 5484 | return null; |
| 5485 | } |
| 5486 | String esn = null; |
| 5487 | try { |
| 5488 | esn = phone.getEsn(); |
| 5489 | } catch (Exception e) { |
| 5490 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5491 | } |
| 5492 | return esn; |
| 5493 | } finally { |
| 5494 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5495 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5496 | } |
| 5497 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5498 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5499 | * Return the Preferred Roaming List Version. |
| 5500 | * |
| 5501 | * @param subId the subscription ID that this request applies to. |
| 5502 | * @return PRLVersion or null if error. |
| 5503 | */ |
| 5504 | @Override |
| 5505 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5506 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5507 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5508 | |
| 5509 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5510 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5511 | if (phone == null) { |
| 5512 | return null; |
| 5513 | } |
| 5514 | String cdmaPrlVersion = null; |
| 5515 | try { |
| 5516 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 5517 | } catch (Exception e) { |
| 5518 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 5519 | } |
| 5520 | return cdmaPrlVersion; |
| 5521 | } finally { |
| 5522 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5523 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5524 | } |
| 5525 | |
| 5526 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5527 | * Get snapshot of Telephony histograms |
| 5528 | * @return List of Telephony histograms |
| 5529 | * @hide |
| 5530 | */ |
| 5531 | @Override |
| 5532 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5533 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5534 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5535 | |
| 5536 | final long identity = Binder.clearCallingIdentity(); |
| 5537 | try { |
| 5538 | return RIL.getTelephonyRILTimingHistograms(); |
| 5539 | } finally { |
| 5540 | Binder.restoreCallingIdentity(identity); |
| 5541 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5542 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5543 | |
| 5544 | /** |
| 5545 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5546 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 5547 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5548 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5549 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5550 | * @return Integer with the result of the operation, as defined in {@link TelephonyManager}. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5551 | */ |
| 5552 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5553 | @TelephonyManager.SetCarrierRestrictionResult |
| 5554 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5555 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5556 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5557 | |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5558 | if (carrierRestrictionRules == null) { |
| 5559 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5560 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5561 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5562 | final long identity = Binder.clearCallingIdentity(); |
| 5563 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5564 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5565 | workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5566 | } finally { |
| 5567 | Binder.restoreCallingIdentity(identity); |
| 5568 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5569 | } |
| 5570 | |
| 5571 | /** |
| 5572 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5573 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 5574 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5575 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5576 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5577 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5578 | */ |
| 5579 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5580 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5581 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5582 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5583 | |
| 5584 | final long identity = Binder.clearCallingIdentity(); |
| 5585 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5586 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 5587 | if (response instanceof CarrierRestrictionRules) { |
| 5588 | return (CarrierRestrictionRules) response; |
| 5589 | } |
| 5590 | // Response is an Exception of some kind, |
| 5591 | // which is signalled to the user as a NULL retval |
| 5592 | return null; |
| 5593 | } catch (Exception e) { |
| 5594 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 5595 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5596 | } finally { |
| 5597 | Binder.restoreCallingIdentity(identity); |
| 5598 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5599 | } |
| 5600 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5601 | /** |
| 5602 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 5603 | * @param subId the subscription ID that this action applies to. |
| 5604 | * @param enabled control enable or disable metered apns. |
| 5605 | * {@hide} |
| 5606 | */ |
| 5607 | @Override |
| 5608 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 5609 | enforceModifyPermission(); |
| 5610 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5611 | |
| 5612 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5613 | if (phone == null) { |
| 5614 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 5615 | return; |
| 5616 | } |
| 5617 | try { |
| 5618 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 5619 | } catch (Exception e) { |
| 5620 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5621 | } finally { |
| 5622 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5623 | } |
| 5624 | } |
| 5625 | |
| 5626 | /** |
| 5627 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 5628 | * @param subId the subscription ID that this action applies to. |
| 5629 | * @param enabled control enable or disable radio. |
| 5630 | * {@hide} |
| 5631 | */ |
| 5632 | @Override |
| 5633 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 5634 | enforceModifyPermission(); |
| 5635 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5636 | |
| 5637 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5638 | if (phone == null) { |
| 5639 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 5640 | return; |
| 5641 | } |
| 5642 | try { |
| 5643 | phone.carrierActionSetRadioEnabled(enabled); |
| 5644 | } catch (Exception e) { |
| 5645 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5646 | } finally { |
| 5647 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5648 | } |
| 5649 | } |
| 5650 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5651 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5652 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 5653 | * network status based on which carrier apps could apply actions accordingly, |
| 5654 | * enable/disable default url handler for example. |
| 5655 | * |
| 5656 | * @param subId the subscription ID that this action applies to. |
| 5657 | * @param report control start/stop reporting the default network status. |
| 5658 | * {@hide} |
| 5659 | */ |
| 5660 | @Override |
| 5661 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 5662 | enforceModifyPermission(); |
| 5663 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5664 | |
| 5665 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5666 | if (phone == null) { |
| 5667 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 5668 | return; |
| 5669 | } |
| 5670 | try { |
| 5671 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 5672 | } catch (Exception e) { |
| 5673 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5674 | } finally { |
| 5675 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5676 | } |
| 5677 | } |
| 5678 | |
| 5679 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5680 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 5681 | * bug report is being generated. |
| 5682 | */ |
| 5683 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 5684 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5685 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 5686 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 5687 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 5688 | + Binder.getCallingPid() |
| 5689 | + ", uid=" + Binder.getCallingUid() |
| 5690 | + "without permission " |
| 5691 | + android.Manifest.permission.DUMP); |
| 5692 | return; |
| 5693 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5694 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5695 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5696 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5697 | @Override |
| 5698 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 5699 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 5700 | throws RemoteException { |
| 5701 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 5702 | } |
| 5703 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5704 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5705 | * Get aggregated video call data usage since boot. |
| 5706 | * |
| 5707 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 5708 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5709 | * {@hide} |
| 5710 | */ |
| 5711 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5712 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5713 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 5714 | null); |
| 5715 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5716 | final long identity = Binder.clearCallingIdentity(); |
| 5717 | try { |
| 5718 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 5719 | // records the delta with the corresponding network identity. |
| 5720 | // We just return the total video call data usage snapshot since boot. |
| 5721 | Phone phone = getPhone(subId); |
| 5722 | if (phone != null) { |
| 5723 | return phone.getVtDataUsage(perUidStats); |
| 5724 | } |
| 5725 | return null; |
| 5726 | } finally { |
| 5727 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5728 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5729 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5730 | |
| 5731 | /** |
| 5732 | * Policy control of data connection. Usually used when data limit is passed. |
| 5733 | * @param enabled True if enabling the data, otherwise disabling. |
| 5734 | * @param subId Subscription index |
| 5735 | * {@hide} |
| 5736 | */ |
| 5737 | @Override |
| 5738 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 5739 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5740 | |
| 5741 | final long identity = Binder.clearCallingIdentity(); |
| 5742 | try { |
| 5743 | Phone phone = getPhone(subId); |
| 5744 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5745 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5746 | } |
| 5747 | } finally { |
| 5748 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5749 | } |
| 5750 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5751 | |
| 5752 | /** |
| 5753 | * Get Client request stats |
| 5754 | * @return List of Client Request Stats |
| 5755 | * @hide |
| 5756 | */ |
| 5757 | @Override |
| 5758 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5759 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5760 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5761 | return null; |
| 5762 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5763 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5764 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5765 | final long identity = Binder.clearCallingIdentity(); |
| 5766 | try { |
| 5767 | if (phone != null) { |
| 5768 | return phone.getClientRequestStats(); |
| 5769 | } |
| 5770 | |
| 5771 | return null; |
| 5772 | } finally { |
| 5773 | Binder.restoreCallingIdentity(identity); |
| 5774 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5775 | } |
| 5776 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5777 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5778 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5779 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5780 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5781 | |
| 5782 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5783 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5784 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5785 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5786 | * @param state State of SIM (power down, power up, pass through) |
| 5787 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 5788 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 5789 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5790 | * |
| 5791 | **/ |
| 5792 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5793 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5794 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5795 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5796 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5797 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5798 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5799 | final long identity = Binder.clearCallingIdentity(); |
| 5800 | try { |
| 5801 | if (phone != null) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5802 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5803 | } |
| 5804 | } finally { |
| 5805 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5806 | } |
| 5807 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5808 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5809 | private boolean isUssdApiAllowed(int subId) { |
| 5810 | CarrierConfigManager configManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5811 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5812 | if (configManager == null) { |
| 5813 | return false; |
| 5814 | } |
| 5815 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 5816 | if (pb == null) { |
| 5817 | return false; |
| 5818 | } |
| 5819 | return pb.getBoolean( |
| 5820 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 5821 | } |
| 5822 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5823 | /** |
| 5824 | * Check if phone is in emergency callback mode |
| 5825 | * @return true if phone is in emergency callback mode |
| 5826 | * @param subId sub id |
| 5827 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 5828 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5829 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5830 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5831 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5832 | |
| 5833 | final long identity = Binder.clearCallingIdentity(); |
| 5834 | try { |
| 5835 | if (phone != null) { |
| 5836 | return phone.isInEcm(); |
| 5837 | } else { |
| 5838 | return false; |
| 5839 | } |
| 5840 | } finally { |
| 5841 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5842 | } |
| 5843 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5844 | |
| 5845 | /** |
| 5846 | * Get the current signal strength information for the given subscription. |
| 5847 | * Because this information is not updated when the device is in a low power state |
| 5848 | * it should not be relied-upon to be current. |
| 5849 | * @param subId Subscription index |
| 5850 | * @return the most recent cached signal strength info from the modem |
| 5851 | */ |
| 5852 | @Override |
| 5853 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5854 | final long identity = Binder.clearCallingIdentity(); |
| 5855 | try { |
| 5856 | Phone p = getPhone(subId); |
| 5857 | if (p == null) { |
| 5858 | return null; |
| 5859 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5860 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5861 | return p.getSignalStrength(); |
| 5862 | } finally { |
| 5863 | Binder.restoreCallingIdentity(identity); |
| 5864 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5865 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5866 | |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5867 | /** |
chen xu | 907e5a2 | 2018-10-11 13:21:04 -0700 | [diff] [blame] | 5868 | * Get the current modem radio state for the given slot. |
| 5869 | * @param slotIndex slot index. |
| 5870 | * @param callingPackage the name of the package making the call. |
| 5871 | * @return the current radio power state from the modem |
| 5872 | */ |
| 5873 | @Override |
| 5874 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 5875 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5876 | if (phone != null) { |
| 5877 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5878 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 5879 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5880 | } |
| 5881 | |
| 5882 | final long identity = Binder.clearCallingIdentity(); |
| 5883 | try { |
| 5884 | return phone.getRadioPowerState(); |
| 5885 | } finally { |
| 5886 | Binder.restoreCallingIdentity(identity); |
| 5887 | } |
| 5888 | } |
| 5889 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 5890 | } |
| 5891 | |
| 5892 | /** |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5893 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 5894 | * |
| 5895 | * <p>Requires one of the following permissions: |
| 5896 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 5897 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 5898 | * privileges. |
| 5899 | * |
| 5900 | * @param subId subscription id |
| 5901 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 5902 | * {@code false}. |
| 5903 | */ |
| 5904 | @Override |
| 5905 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5906 | boolean isEnabled = false; |
| 5907 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5908 | try { |
| 5909 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5910 | null /* message */); |
| 5911 | Phone phone = getPhone(subId); |
| 5912 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5913 | } catch (Exception e) { |
| 5914 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 5915 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5916 | } finally { |
| 5917 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5918 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5919 | return isEnabled; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5920 | } |
| 5921 | |
| 5922 | |
| 5923 | /** |
| 5924 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 5925 | * |
| 5926 | * <p> Requires permission: |
| 5927 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 5928 | * privileges. |
| 5929 | * |
| 5930 | * @param subId subscription id |
| 5931 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 5932 | */ |
| 5933 | @Override |
| 5934 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5935 | final long identity = Binder.clearCallingIdentity(); |
| 5936 | try { |
| 5937 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5938 | mApp, subId, "setDataRoamingEnabled"); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5939 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5940 | Phone phone = getPhone(subId); |
| 5941 | if (phone != null) { |
| 5942 | phone.setDataRoamingEnabled(isEnabled); |
| 5943 | } |
| 5944 | } finally { |
| 5945 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5946 | } |
| 5947 | } |
| 5948 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5949 | @Override |
Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 5950 | public boolean isManualNetworkSelectionAllowed(int subId) { |
| 5951 | boolean isAllowed = true; |
| 5952 | final long identity = Binder.clearCallingIdentity(); |
| 5953 | try { |
| 5954 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 5955 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 5956 | Phone phone = getPhone(subId); |
| 5957 | if (phone != null) { |
| 5958 | isAllowed = phone.isCspPlmnEnabled(); |
| 5959 | } |
| 5960 | } finally { |
| 5961 | Binder.restoreCallingIdentity(identity); |
| 5962 | } |
| 5963 | return isAllowed; |
| 5964 | } |
| 5965 | |
| 5966 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 5967 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
| 5968 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 5969 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5970 | throw new SecurityException("Caller does not have carrier privileges on any UICC."); |
| 5971 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 5972 | |
| 5973 | final long identity = Binder.clearCallingIdentity(); |
| 5974 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 5975 | UiccController uiccController = UiccController.getInstance(); |
| 5976 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
| 5977 | |
| 5978 | ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0); |
| 5979 | if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 5980 | // Remove private info if the caller doesn't have access |
| 5981 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 5982 | for (UiccCardInfo cardInfo : cardInfos) { |
| 5983 | UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex()); |
| 5984 | UiccProfile profile = card.getUiccProfile(); |
| 5985 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 5986 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5987 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 5988 | } else { |
| 5989 | filteredInfos.add(cardInfo); |
| 5990 | } |
| 5991 | } |
| 5992 | return filteredInfos; |
| 5993 | } |
| 5994 | return cardInfos; |
| 5995 | } catch (PackageManager.NameNotFoundException e) { |
| 5996 | // This should not happen since we pass the package info in from TelephonyManager |
| 5997 | throw new SecurityException("Invalid calling package."); |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 5998 | } finally { |
| 5999 | Binder.restoreCallingIdentity(identity); |
| 6000 | } |
| 6001 | } |
| 6002 | |
| 6003 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6004 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6005 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6006 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6007 | final long identity = Binder.clearCallingIdentity(); |
| 6008 | try { |
| 6009 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6010 | if (slots == null) { |
| 6011 | Rlog.i(LOG_TAG, "slots is null."); |
| 6012 | return null; |
| 6013 | } |
| 6014 | |
| 6015 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6016 | for (int i = 0; i < slots.length; i++) { |
| 6017 | UiccSlot slot = slots[i]; |
| 6018 | if (slot == null) { |
| 6019 | continue; |
| 6020 | } |
| 6021 | |
| 6022 | String cardId; |
| 6023 | UiccCard card = slot.getUiccCard(); |
| 6024 | if (card != null) { |
| 6025 | cardId = card.getCardId(); |
| 6026 | } else { |
| 6027 | cardId = slot.getIccId(); |
| 6028 | } |
| 6029 | |
| 6030 | int cardState = 0; |
| 6031 | switch (slot.getCardState()) { |
| 6032 | case CARDSTATE_ABSENT: |
| 6033 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6034 | break; |
| 6035 | case CARDSTATE_PRESENT: |
| 6036 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6037 | break; |
| 6038 | case CARDSTATE_ERROR: |
| 6039 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6040 | break; |
| 6041 | case CARDSTATE_RESTRICTED: |
| 6042 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6043 | break; |
| 6044 | default: |
| 6045 | break; |
| 6046 | |
| 6047 | } |
| 6048 | |
| 6049 | infos[i] = new UiccSlotInfo( |
| 6050 | slot.isActive(), |
| 6051 | slot.isEuicc(), |
| 6052 | cardId, |
| 6053 | cardState, |
| 6054 | slot.getPhoneId(), |
| 6055 | slot.isExtendedApduSupported()); |
| 6056 | } |
| 6057 | return infos; |
| 6058 | } finally { |
| 6059 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6060 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6061 | } |
| 6062 | |
| 6063 | @Override |
| 6064 | public boolean switchSlots(int[] physicalSlots) { |
| 6065 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6066 | |
| 6067 | final long identity = Binder.clearCallingIdentity(); |
| 6068 | try { |
| 6069 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6070 | } finally { |
| 6071 | Binder.restoreCallingIdentity(identity); |
| 6072 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6073 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6074 | |
| 6075 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6076 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6077 | final long identity = Binder.clearCallingIdentity(); |
| 6078 | try { |
| 6079 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6080 | } finally { |
| 6081 | Binder.restoreCallingIdentity(identity); |
| 6082 | } |
| 6083 | } |
| 6084 | |
| 6085 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6086 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6087 | enforceModifyPermission(); |
| 6088 | final Phone phone = getPhone(subId); |
| 6089 | if (phone == null) { |
| 6090 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6091 | return; |
| 6092 | } |
| 6093 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6094 | final long identity = Binder.clearCallingIdentity(); |
| 6095 | try { |
| 6096 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6097 | } finally { |
| 6098 | Binder.restoreCallingIdentity(identity); |
| 6099 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6100 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6101 | |
| 6102 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6103 | * A test API to reload the UICC profile. |
| 6104 | * |
| 6105 | * <p>Requires that the calling app has permission |
| 6106 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6107 | * @hide |
| 6108 | */ |
| 6109 | @Override |
| 6110 | public void refreshUiccProfile(int subId) { |
| 6111 | enforceModifyPermission(); |
| 6112 | |
| 6113 | final long identity = Binder.clearCallingIdentity(); |
| 6114 | try { |
| 6115 | Phone phone = getPhone(subId); |
| 6116 | if (phone == null) { |
| 6117 | return; |
| 6118 | } |
| 6119 | UiccCard uiccCard = phone.getUiccCard(); |
| 6120 | if (uiccCard == null) { |
| 6121 | return; |
| 6122 | } |
| 6123 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6124 | if (uiccProfile == null) { |
| 6125 | return; |
| 6126 | } |
| 6127 | uiccProfile.refresh(); |
| 6128 | } finally { |
| 6129 | Binder.restoreCallingIdentity(identity); |
| 6130 | } |
| 6131 | } |
| 6132 | |
| 6133 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6134 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6135 | */ |
| 6136 | private boolean getDefaultDataEnabled() { |
| 6137 | return "true".equalsIgnoreCase( |
| 6138 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6139 | } |
| 6140 | |
| 6141 | /** |
| 6142 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6143 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6144 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6145 | */ |
| 6146 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6147 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6148 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6149 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6150 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6151 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6152 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 6153 | return isDataRoamingEnabled; |
| 6154 | } |
| 6155 | |
| 6156 | /** |
| 6157 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 6158 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 6159 | */ |
| 6160 | private int getDefaultNetworkType(int subId) { |
| 6161 | return Integer.parseInt( |
| 6162 | TelephonyManager.getTelephonyProperty( |
| 6163 | mSubscriptionController.getPhoneId(subId), |
| 6164 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 6165 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 6166 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6167 | |
| 6168 | @Override |
| 6169 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
| 6170 | gid1, String gid2, String plmn, String spn) { |
| 6171 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6172 | |
| 6173 | final long identity = Binder.clearCallingIdentity(); |
| 6174 | try { |
| 6175 | final Phone phone = getPhone(subId); |
| 6176 | if (phone == null) { |
| 6177 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 6178 | return; |
| 6179 | } |
| 6180 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn); |
| 6181 | } finally { |
| 6182 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6183 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6184 | } |
| 6185 | |
| 6186 | @Override |
| 6187 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6188 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6189 | |
| 6190 | final long identity = Binder.clearCallingIdentity(); |
| 6191 | try { |
| 6192 | final Phone phone = getPhone(subId); |
| 6193 | if (phone == null) { |
| 6194 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 6195 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 6196 | } |
| 6197 | return phone.getCarrierIdListVersion(); |
| 6198 | } finally { |
| 6199 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6200 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6201 | } |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6202 | |
| 6203 | @Override |
| 6204 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 6205 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6206 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 6207 | return -1; |
| 6208 | } |
| 6209 | |
| 6210 | final long identity = Binder.clearCallingIdentity(); |
| 6211 | try { |
| 6212 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 6213 | } finally { |
| 6214 | Binder.restoreCallingIdentity(identity); |
| 6215 | } |
| 6216 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6217 | |
| 6218 | @Override |
| 6219 | public int getCdmaRoamingMode(int subId) { |
| 6220 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6221 | mApp, subId, "getCdmaRoamingMode"); |
| 6222 | |
| 6223 | final long identity = Binder.clearCallingIdentity(); |
| 6224 | try { |
| 6225 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 6226 | } finally { |
| 6227 | Binder.restoreCallingIdentity(identity); |
| 6228 | } |
| 6229 | } |
| 6230 | |
| 6231 | @Override |
| 6232 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 6233 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6234 | mApp, subId, "setCdmaRoamingMode"); |
| 6235 | |
| 6236 | final long identity = Binder.clearCallingIdentity(); |
| 6237 | try { |
| 6238 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 6239 | } finally { |
| 6240 | Binder.restoreCallingIdentity(identity); |
| 6241 | } |
| 6242 | } |
| 6243 | |
| 6244 | @Override |
| 6245 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 6246 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6247 | mApp, subId, "setCdmaSubscriptionMode"); |
| 6248 | |
| 6249 | final long identity = Binder.clearCallingIdentity(); |
| 6250 | try { |
| 6251 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 6252 | } finally { |
| 6253 | Binder.restoreCallingIdentity(identity); |
| 6254 | } |
| 6255 | } |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6256 | |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 6257 | private void ensureUserRunning(int userId) { |
| 6258 | if (!mUserManager.isUserRunning(userId)) { |
| 6259 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 6260 | } |
| 6261 | } |
| 6262 | |
| 6263 | /** |
| 6264 | * Returns a list of SMS apps on a given user. |
| 6265 | * |
| 6266 | * Only the shell user (UID 2000 or 0) can call it. |
| 6267 | * Target user must be running. |
| 6268 | */ |
| 6269 | @Override |
| 6270 | public String[] getSmsApps(int userId) { |
| 6271 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 6272 | ensureUserRunning(userId); |
| 6273 | |
| 6274 | final Collection<SmsApplicationData> apps = |
| 6275 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 6276 | |
| 6277 | String[] ret = new String[apps.size()]; |
| 6278 | int i = 0; |
| 6279 | for (SmsApplicationData app : apps) { |
| 6280 | ret[i++] = app.mPackageName; |
| 6281 | } |
| 6282 | return ret; |
| 6283 | } |
| 6284 | |
| 6285 | /** |
| 6286 | * Returns the default SMS app package name on a given user. |
| 6287 | * |
| 6288 | * Only the shell user (UID 2000 or 0) can call it. |
| 6289 | * Target user must be running. |
| 6290 | */ |
| 6291 | @Override |
| 6292 | public String getDefaultSmsApp(int userId) { |
| 6293 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 6294 | ensureUserRunning(userId); |
| 6295 | |
| 6296 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 6297 | /* updateIfNeeded= */ true, userId); |
| 6298 | return cn == null ? null : cn.getPackageName(); |
| 6299 | } |
| 6300 | |
| 6301 | /** |
| 6302 | * Set a package as the default SMS app on a given user. |
| 6303 | * |
| 6304 | * Only the shell user (UID 2000 or 0) can call it. |
| 6305 | * Target user must be running. |
| 6306 | */ |
| 6307 | @Override |
| 6308 | public void setDefaultSmsApp(int userId, String packageName) { |
| 6309 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6310 | ensureUserRunning(userId); |
| 6311 | |
| 6312 | boolean found = false; |
| 6313 | for (String pkg : getSmsApps(userId)) { |
| 6314 | if (TextUtils.equals(packageName, pkg)) { |
| 6315 | found = true; |
| 6316 | break; |
| 6317 | } |
| 6318 | } |
| 6319 | if (!found) { |
| 6320 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6321 | } |
| 6322 | |
| 6323 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6324 | } |
| 6325 | |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6326 | @Override |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6327 | public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList( |
| 6328 | String callingPackage) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6329 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6330 | mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) { |
| 6331 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6332 | } |
| 6333 | final long identity = Binder.clearCallingIdentity(); |
| 6334 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6335 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6336 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6337 | if (phone.getEmergencyNumberTracker() != null |
| 6338 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6339 | emergencyNumberListInternal.put( |
| 6340 | phone.getSubId(), |
| 6341 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6342 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6343 | } |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6344 | return emergencyNumberListInternal; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6345 | } finally { |
| 6346 | Binder.restoreCallingIdentity(identity); |
| 6347 | } |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6348 | } |
| 6349 | |
| 6350 | @Override |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6351 | public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) { |
| 6352 | final Phone defaultPhone = getDefaultPhone(); |
| 6353 | if (!exactMatch) { |
| 6354 | TelephonyPermissions |
| 6355 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6356 | mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)"); |
| 6357 | } |
| 6358 | final long identity = Binder.clearCallingIdentity(); |
| 6359 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6360 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6361 | if (phone.getEmergencyNumberTracker() != null |
| 6362 | && phone.getEmergencyNumberTracker() != null) { |
| 6363 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 6364 | number, exactMatch)) { |
| 6365 | return true; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6366 | } |
| 6367 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6368 | } |
| 6369 | return false; |
| 6370 | } finally { |
| 6371 | Binder.restoreCallingIdentity(identity); |
| 6372 | } |
| 6373 | } |
| 6374 | |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6375 | /** |
| 6376 | * Update emergency number list for test mode. |
| 6377 | */ |
| 6378 | @Override |
| 6379 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 6380 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6381 | "updateEmergencyNumberListTestMode"); |
| 6382 | |
| 6383 | final long identity = Binder.clearCallingIdentity(); |
| 6384 | try { |
| 6385 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6386 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6387 | if (tracker != null) { |
| 6388 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 6389 | } |
| 6390 | } |
| 6391 | } finally { |
| 6392 | Binder.restoreCallingIdentity(identity); |
| 6393 | } |
| 6394 | } |
| 6395 | |
| 6396 | /** |
| 6397 | * Get the full emergency number list for test mode. |
| 6398 | */ |
| 6399 | @Override |
| 6400 | public List<String> getEmergencyNumberListTestMode() { |
| 6401 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6402 | "getEmergencyNumberListTestMode"); |
| 6403 | |
| 6404 | final long identity = Binder.clearCallingIdentity(); |
| 6405 | try { |
| 6406 | Set<String> emergencyNumbers = new HashSet<>(); |
| 6407 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6408 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6409 | if (tracker != null) { |
| 6410 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 6411 | emergencyNumbers.add(num.getNumber()); |
| 6412 | } |
| 6413 | } |
| 6414 | } |
| 6415 | return new ArrayList<>(emergencyNumbers); |
| 6416 | } finally { |
| 6417 | Binder.restoreCallingIdentity(identity); |
| 6418 | } |
| 6419 | } |
| 6420 | |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6421 | @Override |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6422 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6423 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6424 | Phone phone = getPhone(subId); |
| 6425 | if (phone == null) { |
| 6426 | return null; |
| 6427 | } |
| 6428 | final long identity = Binder.clearCallingIdentity(); |
| 6429 | try { |
| 6430 | UiccProfile profile = UiccController.getInstance() |
| 6431 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6432 | if (profile != null) { |
| 6433 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6434 | } |
| 6435 | } finally { |
| 6436 | Binder.restoreCallingIdentity(identity); |
| 6437 | } |
| 6438 | return null; |
| 6439 | } |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6440 | |
| 6441 | /** |
| 6442 | * Enable or disable a modem stack. |
| 6443 | */ |
| 6444 | @Override |
| 6445 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 6446 | enforceModifyPermission(); |
| 6447 | |
| 6448 | final long identity = Binder.clearCallingIdentity(); |
| 6449 | try { |
| 6450 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6451 | if (phone == null) { |
| 6452 | return false; |
| 6453 | } else { |
| 6454 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 6455 | } |
| 6456 | } finally { |
| 6457 | Binder.restoreCallingIdentity(identity); |
| 6458 | } |
| 6459 | } |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6460 | |
| 6461 | @Override |
| 6462 | public void setMultisimCarrierRestriction(boolean isMultisimCarrierRestricted) { |
| 6463 | enforceModifyPermission(); |
| 6464 | |
| 6465 | final long identity = Binder.clearCallingIdentity(); |
| 6466 | try { |
| 6467 | mTelephonySharedPreferences.edit() |
| 6468 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultisimCarrierRestricted) |
| 6469 | .commit(); |
| 6470 | } finally { |
| 6471 | Binder.restoreCallingIdentity(identity); |
| 6472 | } |
| 6473 | } |
| 6474 | |
| 6475 | @Override |
| 6476 | public boolean isMultisimCarrierRestricted() { |
| 6477 | enforceReadPrivilegedPermission("isMultisimCarrierRestricted"); |
| 6478 | |
| 6479 | final long identity = Binder.clearCallingIdentity(); |
| 6480 | try { |
| 6481 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 6482 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 6483 | if (numPhysicalSlots < 2) { |
| 6484 | loge("isMultisimCarrierRestricted: requires at least 2 cards"); |
| 6485 | return true; |
| 6486 | } |
| 6487 | |
| 6488 | // Default value is false. Multi SIM is allowed unless explicitly restricted. |
| 6489 | return mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false); |
| 6490 | } finally { |
| 6491 | Binder.restoreCallingIdentity(identity); |
| 6492 | } |
| 6493 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6494 | |
| 6495 | /** |
| 6496 | * Switch configs to enable multi-sim or switch back to single-sim |
| 6497 | * @param numOfSims number of active sims we want to switch to |
| 6498 | */ |
| 6499 | @Override |
| 6500 | public void switchMultiSimConfig(int numOfSims) { |
| 6501 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6502 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 6503 | final long identity = Binder.clearCallingIdentity(); |
| 6504 | try { |
| 6505 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 6506 | } finally { |
| 6507 | Binder.restoreCallingIdentity(identity); |
| 6508 | } |
| 6509 | } |
| 6510 | |
| 6511 | /** |
| 6512 | * Get how many sims have been activated on the phone |
| 6513 | */ |
| 6514 | @Override |
| 6515 | public int getNumOfActiveSims() { |
| 6516 | final long identity = Binder.clearCallingIdentity(); |
| 6517 | try { |
| 6518 | return mPhoneConfigurationManager.getNumOfActiveSims(); |
| 6519 | } finally { |
| 6520 | Binder.restoreCallingIdentity(identity); |
| 6521 | } |
| 6522 | } |
Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6523 | |
| 6524 | /** |
| 6525 | * Get whether reboot is required or not after making changes to modem configurations. |
Nazanin Bakhshi | 4a68f5f | 2019-02-08 14:31:19 -0800 | [diff] [blame] | 6526 | * Return value defaults to true |
Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6527 | */ |
| 6528 | @Override |
| 6529 | public boolean isRebootRequiredForModemConfigChange() { |
| 6530 | enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange"); |
| 6531 | final long identity = Binder.clearCallingIdentity(); |
| 6532 | try { |
| 6533 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 6534 | } finally { |
| 6535 | Binder.restoreCallingIdentity(identity); |
| 6536 | } |
| 6537 | } |
| 6538 | |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 6539 | private void updateModemStateMetrics() { |
| 6540 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 6541 | // TODO: check the state for each modem if the api is ready. |
| 6542 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 6543 | } |
| 6544 | |
Pengquan Meng | 3aceaec | 2019-01-23 11:16:29 -0800 | [diff] [blame^] | 6545 | @Override |
| 6546 | public int[] getSlotsMapping() { |
| 6547 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 6548 | |
| 6549 | final long identity = Binder.clearCallingIdentity(); |
| 6550 | try { |
| 6551 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 6552 | // All logical slots should have a mapping to a physical slot. |
| 6553 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 6554 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 6555 | for (int i = 0; i < slotInfos.length; i++) { |
| 6556 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 6557 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 6558 | } |
| 6559 | } |
| 6560 | return logicalSlotsMapping; |
| 6561 | } finally { |
| 6562 | Binder.restoreCallingIdentity(identity); |
| 6563 | } |
| 6564 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6565 | } |