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; |
Tyler Gunn | 327a972 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 24 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 25 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 26 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 27 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 28 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 31 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 32 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 33 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 34 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 35 | import android.content.pm.PackageManager; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 36 | import android.net.NetworkStats; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 37 | import android.net.Uri; |
| 38 | import android.os.AsyncResult; |
| 39 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 40 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.os.Bundle; |
| 42 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 43 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.os.Looper; |
| 45 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 46 | import android.os.Messenger; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 47 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 48 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 49 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | import android.os.ServiceManager; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 51 | import android.os.ShellCallback; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 52 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 54 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 55 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 56 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 57 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 58 | import android.provider.Telephony; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 59 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 60 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 61 | import android.telecom.TelecomManager; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 62 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 63 | import android.telephony.CarrierRestrictionRules; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 64 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 65 | import android.telephony.CellInfoGsm; |
| 66 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 67 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 68 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 69 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 70 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 71 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 72 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 73 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 74 | import android.telephony.NetworkScanRequest; |
Michele | bcb01bc | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 75 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 76 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 77 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 78 | import android.telephony.RadioAccessSpecifier; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 79 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 80 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 81 | import android.telephony.SignalStrength; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 82 | import android.telephony.SmsManager; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 83 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 84 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 85 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 86 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 87 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 88 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 89 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 90 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 91 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 92 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 93 | import android.telephony.data.ApnSetting; |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 94 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 95 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 96 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 97 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 98 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 99 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 100 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 101 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 102 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 103 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 104 | import android.telephony.ims.feature.MmTelFeature; |
| 105 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 106 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 107 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 108 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 109 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 110 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 111 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 112 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 113 | import com.android.ims.ImsException; |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 114 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 115 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 116 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 117 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 118 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 119 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 120 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 121 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 122 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 123 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 124 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 126 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 128 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.Phone; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 133 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.ServiceStateTracker; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 140 | import com.android.internal.telephony.SmsApplication; |
| 141 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.TelephonyPermissions; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 144 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 146 | import com.android.internal.telephony.ims.ImsResolver; |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 147 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.uicc.IccIoResult; |
| 149 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 155 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 157 | import com.android.internal.util.HexDump; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 158 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 159 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 160 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 161 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 162 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 163 | import java.io.FileDescriptor; |
| 164 | import java.io.PrintWriter; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 165 | import java.nio.charset.StandardCharsets; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 166 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 167 | import java.util.Arrays; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 168 | import java.util.Collection; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 169 | import java.util.HashMap; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 170 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 171 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 172 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 173 | import java.util.Map; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 174 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 175 | |
| 176 | /** |
| 177 | * Implementation of the ITelephony interface. |
| 178 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 179 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 180 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 181 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 182 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 183 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 184 | |
| 185 | // Message codes used with mMainThreadHandler |
| 186 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 187 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 188 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 189 | private static final int CMD_OPEN_CHANNEL = 9; |
| 190 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 191 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 192 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 193 | private static final int CMD_NV_READ_ITEM = 13; |
| 194 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 195 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 196 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 197 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 198 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 199 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 200 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 201 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 202 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 203 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 204 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 205 | private static final int CMD_SEND_ENVELOPE = 25; |
| 206 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 207 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 208 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 209 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 210 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 211 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 212 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 213 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 214 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 215 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 216 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 217 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 218 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 219 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 220 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 221 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 222 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 223 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 224 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 225 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 226 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 227 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 228 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 229 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 230 | private static final int CMD_SWITCH_SLOTS = 50; |
| 231 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 232 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 233 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 234 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 235 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 236 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 237 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 238 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 239 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 240 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 241 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 242 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 243 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 244 | private static final int CMD_MODEM_REBOOT = 64; |
| 245 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 246 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 247 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 248 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 249 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 250 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 251 | // Parameters of select command. |
| 252 | private static final int SELECT_COMMAND = 0xA4; |
| 253 | private static final int SELECT_P1 = 0x04; |
| 254 | private static final int SELECT_P2 = 0; |
| 255 | private static final int SELECT_P3 = 0x10; |
| 256 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 257 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 258 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 259 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 260 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 261 | /** The singleton instance. */ |
| 262 | private static PhoneInterfaceManager sInstance; |
| 263 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 264 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 265 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 266 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 267 | private AppOpsManager mAppOps; |
| 268 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 269 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 270 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 271 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 272 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 273 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 274 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 275 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 276 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 277 | |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 278 | // String to store multi SIM allowed |
| 279 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 280 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 281 | // The AID of ISD-R. |
| 282 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 283 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 284 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 285 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 286 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 287 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 288 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 289 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 290 | * A request object to use for transmitting data to an ICC. |
| 291 | */ |
| 292 | private static final class IccAPDUArgument { |
| 293 | public int channel, cla, command, p1, p2, p3; |
| 294 | public String data; |
| 295 | |
| 296 | public IccAPDUArgument(int channel, int cla, int command, |
| 297 | int p1, int p2, int p3, String data) { |
| 298 | this.channel = channel; |
| 299 | this.cla = cla; |
| 300 | this.command = command; |
| 301 | this.p1 = p1; |
| 302 | this.p2 = p2; |
| 303 | this.p3 = p3; |
| 304 | this.data = data; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 309 | * A request object to use for transmitting data to an ICC. |
| 310 | */ |
| 311 | private static final class ManualNetworkSelectionArgument { |
| 312 | public OperatorInfo operatorInfo; |
| 313 | public boolean persistSelection; |
| 314 | |
| 315 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 316 | this.operatorInfo = operatorInfo; |
| 317 | this.persistSelection = persistSelection; |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 322 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 323 | * request after sending. The main thread will notify the request when it is complete. |
| 324 | */ |
| 325 | private static final class MainThreadRequest { |
| 326 | /** The argument to use for the request */ |
| 327 | public Object argument; |
| 328 | /** The result of the request that is run on the main thread */ |
| 329 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 330 | // The subscriber id that this request applies to. Defaults to |
| 331 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 332 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 333 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 334 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 335 | public Phone phone; |
| 336 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 337 | public WorkSource workSource; |
| 338 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 339 | public MainThreadRequest(Object argument) { |
| 340 | this.argument = argument; |
| 341 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 342 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 343 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 344 | this.argument = argument; |
| 345 | if (phone != null) { |
| 346 | this.phone = phone; |
| 347 | } |
| 348 | this.workSource = workSource; |
| 349 | } |
| 350 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 351 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 352 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 353 | if (subId != null) { |
| 354 | this.subId = subId; |
| 355 | } |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 356 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 357 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 360 | private static final class IncomingThirdPartyCallArgs { |
| 361 | public final ComponentName component; |
| 362 | public final String callId; |
| 363 | public final String callerDisplayName; |
| 364 | |
| 365 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 366 | String callerDisplayName) { |
| 367 | this.component = component; |
| 368 | this.callId = callId; |
| 369 | this.callerDisplayName = callerDisplayName; |
| 370 | } |
| 371 | } |
| 372 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 373 | /** |
| 374 | * A handler that processes messages on the main thread in the phone process. Since many |
| 375 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 376 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 377 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 378 | * on, which will be notified when the operation completes and will contain the result of the |
| 379 | * request. |
| 380 | * |
| 381 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 382 | * note that request.result must be set to something non-null for the calling thread to |
| 383 | * unblock. |
| 384 | */ |
| 385 | private final class MainThreadHandler extends Handler { |
| 386 | @Override |
| 387 | public void handleMessage(Message msg) { |
| 388 | MainThreadRequest request; |
| 389 | Message onCompleted; |
| 390 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 391 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 392 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 393 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 394 | |
| 395 | switch (msg.what) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 396 | case CMD_HANDLE_USSD_REQUEST: { |
| 397 | request = (MainThreadRequest) msg.obj; |
| 398 | final Phone phone = getPhoneFromRequest(request); |
| 399 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 400 | String ussdRequest = ussdObject.first; |
| 401 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 402 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 403 | if (!isUssdApiAllowed(request.subId)) { |
| 404 | // Carrier does not support use of this API, return failure. |
| 405 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 406 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 407 | Bundle returnData = new Bundle(); |
| 408 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 409 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 410 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 411 | request.result = true; |
| 412 | notifyRequester(request); |
| 413 | return; |
| 414 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 415 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 416 | try { |
| 417 | request.result = phone != null |
| 418 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 419 | } catch (CallStateException cse) { |
| 420 | request.result = false; |
| 421 | } |
| 422 | // Wake up the requesting thread |
| 423 | notifyRequester(request); |
| 424 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 427 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 428 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 429 | final Phone phone = getPhoneFromRequest(request); |
| 430 | request.result = phone != null ? |
| 431 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 432 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 433 | // Wake up the requesting thread |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 434 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 435 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 436 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 437 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 438 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 439 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 440 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 441 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 442 | if (uiccCard == null) { |
| 443 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 444 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 445 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 446 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 447 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 448 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 449 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 450 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 451 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 452 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 453 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 454 | break; |
| 455 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 456 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 457 | ar = (AsyncResult) msg.obj; |
| 458 | request = (MainThreadRequest) ar.userObj; |
| 459 | if (ar.exception == null && ar.result != null) { |
| 460 | request.result = ar.result; |
| 461 | } else { |
| 462 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 463 | if (ar.result == null) { |
| 464 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 465 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 466 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 467 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 468 | } else { |
| 469 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 470 | } |
| 471 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 472 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 473 | break; |
| 474 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 475 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 476 | request = (MainThreadRequest) msg.obj; |
| 477 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 478 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 479 | if (uiccCard == null) { |
| 480 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 481 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 482 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 483 | } else { |
| 484 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 485 | request); |
| 486 | uiccCard.iccTransmitApduBasicChannel( |
| 487 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 488 | iccArgument.p3, iccArgument.data, onCompleted); |
| 489 | } |
| 490 | break; |
| 491 | |
| 492 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 493 | ar = (AsyncResult) msg.obj; |
| 494 | request = (MainThreadRequest) ar.userObj; |
| 495 | if (ar.exception == null && ar.result != null) { |
| 496 | request.result = ar.result; |
| 497 | } else { |
| 498 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 499 | if (ar.result == null) { |
| 500 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 501 | } else if (ar.exception instanceof CommandException) { |
| 502 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 503 | ar.exception); |
| 504 | } else { |
| 505 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 506 | } |
| 507 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 508 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 509 | break; |
| 510 | |
| 511 | case CMD_EXCHANGE_SIM_IO: |
| 512 | request = (MainThreadRequest) msg.obj; |
| 513 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 514 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 515 | if (uiccCard == null) { |
| 516 | loge("iccExchangeSimIO: No UICC"); |
| 517 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 518 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 519 | } else { |
| 520 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 521 | request); |
| 522 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 523 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 524 | iccArgument.data, onCompleted); |
| 525 | } |
| 526 | break; |
| 527 | |
| 528 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 529 | ar = (AsyncResult) msg.obj; |
| 530 | request = (MainThreadRequest) ar.userObj; |
| 531 | if (ar.exception == null && ar.result != null) { |
| 532 | request.result = ar.result; |
| 533 | } else { |
| 534 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 535 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 536 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 537 | break; |
| 538 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 539 | case CMD_SEND_ENVELOPE: |
| 540 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 541 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 542 | if (uiccCard == null) { |
| 543 | loge("sendEnvelopeWithStatus: No UICC"); |
| 544 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 545 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 546 | } else { |
| 547 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 548 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 549 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 550 | break; |
| 551 | |
| 552 | case EVENT_SEND_ENVELOPE_DONE: |
| 553 | ar = (AsyncResult) msg.obj; |
| 554 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 555 | if (ar.exception == null && ar.result != null) { |
| 556 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 557 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 558 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 559 | if (ar.result == null) { |
| 560 | loge("sendEnvelopeWithStatus: Empty response"); |
| 561 | } else if (ar.exception instanceof CommandException) { |
| 562 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 563 | ar.exception); |
| 564 | } else { |
| 565 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 566 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 567 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 568 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 569 | break; |
| 570 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 571 | case CMD_OPEN_CHANNEL: |
| 572 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 573 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 574 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 575 | if (uiccCard == null) { |
| 576 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 577 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 578 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 579 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 580 | } else { |
| 581 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 582 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 583 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 584 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 585 | break; |
| 586 | |
| 587 | case EVENT_OPEN_CHANNEL_DONE: |
| 588 | ar = (AsyncResult) msg.obj; |
| 589 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 590 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 591 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 592 | int[] result = (int[]) ar.result; |
| 593 | int channelId = result[0]; |
| 594 | byte[] selectResponse = null; |
| 595 | if (result.length > 1) { |
| 596 | selectResponse = new byte[result.length - 1]; |
| 597 | for (int i = 1; i < result.length; ++i) { |
| 598 | selectResponse[i - 1] = (byte) result[i]; |
| 599 | } |
| 600 | } |
| 601 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 602 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 603 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 604 | if (ar.result == null) { |
| 605 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 606 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 607 | if (ar.exception != null) { |
| 608 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 609 | } |
| 610 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 611 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 612 | if (ar.exception instanceof CommandException) { |
| 613 | CommandException.Error error = |
| 614 | ((CommandException) (ar.exception)).getCommandError(); |
| 615 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 616 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 617 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 618 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 619 | } |
| 620 | } |
| 621 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 622 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 623 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 624 | request.result = openChannelResp; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 625 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 626 | break; |
| 627 | |
| 628 | case CMD_CLOSE_CHANNEL: |
| 629 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 630 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 631 | if (uiccCard == null) { |
| 632 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 633 | request.result = false; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 634 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 635 | } else { |
| 636 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 637 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 638 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 639 | break; |
| 640 | |
| 641 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 642 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 643 | break; |
| 644 | |
| 645 | case CMD_NV_READ_ITEM: |
| 646 | request = (MainThreadRequest) msg.obj; |
| 647 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 648 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 649 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 650 | break; |
| 651 | |
| 652 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 653 | ar = (AsyncResult) msg.obj; |
| 654 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 655 | if (ar.exception == null && ar.result != null) { |
| 656 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 657 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 658 | request.result = ""; |
| 659 | if (ar.result == null) { |
| 660 | loge("nvReadItem: Empty response"); |
| 661 | } else if (ar.exception instanceof CommandException) { |
| 662 | loge("nvReadItem: CommandException: " + |
| 663 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 664 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 665 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 666 | } |
| 667 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 668 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 669 | break; |
| 670 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 671 | case CMD_NV_WRITE_ITEM: |
| 672 | request = (MainThreadRequest) msg.obj; |
| 673 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 674 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 675 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 676 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 677 | break; |
| 678 | |
| 679 | case EVENT_NV_WRITE_ITEM_DONE: |
| 680 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 681 | break; |
| 682 | |
| 683 | case CMD_NV_WRITE_CDMA_PRL: |
| 684 | request = (MainThreadRequest) msg.obj; |
| 685 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 686 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 687 | break; |
| 688 | |
| 689 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 690 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 691 | break; |
| 692 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 693 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 694 | request = (MainThreadRequest) msg.obj; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 695 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 696 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 697 | break; |
| 698 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 699 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 700 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 701 | break; |
| 702 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 703 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 704 | request = (MainThreadRequest) msg.obj; |
| 705 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 706 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 707 | break; |
| 708 | |
| 709 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 710 | ar = (AsyncResult) msg.obj; |
| 711 | request = (MainThreadRequest) ar.userObj; |
| 712 | if (ar.exception == null && ar.result != null) { |
| 713 | request.result = ar.result; // Integer |
| 714 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 715 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 716 | if (ar.result == null) { |
| 717 | loge("getPreferredNetworkType: Empty response"); |
| 718 | } else if (ar.exception instanceof CommandException) { |
| 719 | loge("getPreferredNetworkType: CommandException: " + |
| 720 | ar.exception); |
| 721 | } else { |
| 722 | loge("getPreferredNetworkType: Unknown exception"); |
| 723 | } |
| 724 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 725 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 726 | break; |
| 727 | |
| 728 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 729 | request = (MainThreadRequest) msg.obj; |
| 730 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 731 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 732 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 733 | break; |
| 734 | |
| 735 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 736 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 737 | break; |
| 738 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 739 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 740 | request = (MainThreadRequest)msg.obj; |
| 741 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 742 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 743 | break; |
| 744 | |
| 745 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 746 | ar = (AsyncResult)msg.obj; |
| 747 | request = (MainThreadRequest)ar.userObj; |
| 748 | request.result = ar; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 749 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 750 | break; |
| 751 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 752 | case CMD_SET_VOICEMAIL_NUMBER: |
| 753 | request = (MainThreadRequest) msg.obj; |
| 754 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 755 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 756 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 757 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 758 | break; |
| 759 | |
| 760 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 761 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 762 | break; |
| 763 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 764 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 765 | request = (MainThreadRequest) msg.obj; |
| 766 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 767 | request); |
| 768 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 769 | break; |
| 770 | |
| 771 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 772 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 773 | break; |
| 774 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 775 | case CMD_PERFORM_NETWORK_SCAN: |
| 776 | request = (MainThreadRequest) msg.obj; |
| 777 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 778 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 779 | break; |
| 780 | |
| 781 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 782 | ar = (AsyncResult) msg.obj; |
| 783 | request = (MainThreadRequest) ar.userObj; |
| 784 | CellNetworkScanResult cellScanResult; |
| 785 | if (ar.exception == null && ar.result != null) { |
| 786 | cellScanResult = new CellNetworkScanResult( |
| 787 | CellNetworkScanResult.STATUS_SUCCESS, |
| 788 | (List<OperatorInfo>) ar.result); |
| 789 | } else { |
| 790 | if (ar.result == null) { |
| 791 | loge("getCellNetworkScanResults: Empty response"); |
| 792 | } |
| 793 | if (ar.exception != null) { |
| 794 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 795 | } |
| 796 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 797 | if (ar.exception instanceof CommandException) { |
| 798 | CommandException.Error error = |
| 799 | ((CommandException) (ar.exception)).getCommandError(); |
| 800 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 801 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 802 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 803 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 804 | } |
| 805 | } |
| 806 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 807 | } |
| 808 | request.result = cellScanResult; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 809 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 810 | break; |
| 811 | |
| 812 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 813 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 814 | ManualNetworkSelectionArgument selArg = |
| 815 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 816 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 817 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 818 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 819 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 820 | break; |
| 821 | |
| 822 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | dd9ac82 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 823 | ar = (AsyncResult) msg.obj; |
| 824 | request = (MainThreadRequest) ar.userObj; |
| 825 | if (ar.exception == null) { |
| 826 | request.result = true; |
| 827 | } else { |
| 828 | request.result = false; |
| 829 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 830 | } |
| 831 | notifyRequester(request); |
| 832 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 833 | break; |
| 834 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 835 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 836 | request = (MainThreadRequest) msg.obj; |
| 837 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | c56281c | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 838 | if (defaultPhone != null) { |
| 839 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 840 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 841 | break; |
| 842 | |
| 843 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 844 | ar = (AsyncResult) msg.obj; |
| 845 | request = (MainThreadRequest) ar.userObj; |
| 846 | if (ar.exception == null && ar.result != null) { |
| 847 | request.result = ar.result; |
| 848 | } else { |
| 849 | if (ar.result == null) { |
| 850 | loge("queryModemActivityInfo: Empty response"); |
| 851 | } else if (ar.exception instanceof CommandException) { |
| 852 | loge("queryModemActivityInfo: CommandException: " + |
| 853 | ar.exception); |
| 854 | } else { |
| 855 | loge("queryModemActivityInfo: Unknown exception"); |
| 856 | } |
| 857 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 858 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 859 | if (request.result == null) { |
| 860 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 861 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 862 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 863 | break; |
| 864 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 865 | case CMD_SET_ALLOWED_CARRIERS: |
| 866 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 867 | CarrierRestrictionRules argument = |
| 868 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 869 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 870 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 871 | break; |
| 872 | |
| 873 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 874 | ar = (AsyncResult) msg.obj; |
| 875 | request = (MainThreadRequest) ar.userObj; |
| 876 | if (ar.exception == null && ar.result != null) { |
| 877 | request.result = ar.result; |
| 878 | } else { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 879 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 880 | if (ar.exception instanceof CommandException) { |
| 881 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 882 | CommandException.Error error = |
| 883 | ((CommandException) (ar.exception)).getCommandError(); |
| 884 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 885 | request.result = |
| 886 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 887 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 888 | } else { |
| 889 | loge("setAllowedCarriers: Unknown exception"); |
| 890 | } |
| 891 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 892 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 893 | break; |
| 894 | |
| 895 | case CMD_GET_ALLOWED_CARRIERS: |
| 896 | request = (MainThreadRequest) msg.obj; |
| 897 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 898 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 899 | break; |
| 900 | |
| 901 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 902 | ar = (AsyncResult) msg.obj; |
| 903 | request = (MainThreadRequest) ar.userObj; |
| 904 | if (ar.exception == null && ar.result != null) { |
| 905 | request.result = ar.result; |
| 906 | } else { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 907 | request.result = new IllegalStateException( |
| 908 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 909 | if (ar.result == null) { |
| 910 | loge("getAllowedCarriers: Empty response"); |
| 911 | } else if (ar.exception instanceof CommandException) { |
| 912 | loge("getAllowedCarriers: CommandException: " + |
| 913 | ar.exception); |
| 914 | } else { |
| 915 | loge("getAllowedCarriers: Unknown exception"); |
| 916 | } |
| 917 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 918 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 919 | break; |
| 920 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 921 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 922 | ar = (AsyncResult) msg.obj; |
| 923 | request = (MainThreadRequest) ar.userObj; |
| 924 | if (ar.exception == null && ar.result != null) { |
| 925 | request.result = ar.result; |
| 926 | } else { |
| 927 | request.result = new IllegalArgumentException( |
| 928 | "Failed to retrieve Forbidden Plmns"); |
| 929 | if (ar.result == null) { |
| 930 | loge("getForbiddenPlmns: Empty response"); |
| 931 | } else { |
| 932 | loge("getForbiddenPlmns: Unknown exception"); |
| 933 | } |
| 934 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 935 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 936 | break; |
| 937 | |
| 938 | case CMD_GET_FORBIDDEN_PLMNS: |
| 939 | request = (MainThreadRequest) msg.obj; |
| 940 | uiccCard = getUiccCardFromRequest(request); |
| 941 | if (uiccCard == null) { |
| 942 | loge("getForbiddenPlmns() UiccCard is null"); |
| 943 | request.result = new IllegalArgumentException( |
| 944 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 945 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 946 | break; |
| 947 | } |
| 948 | Integer appType = (Integer) request.argument; |
| 949 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 950 | if (uiccApp == null) { |
| 951 | loge("getForbiddenPlmns() no app with specified type -- " |
| 952 | + appType); |
| 953 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 954 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 955 | break; |
| 956 | } else { |
| 957 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 958 | + " specified type -- " + appType); |
| 959 | } |
| 960 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 961 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 962 | onCompleted); |
| 963 | break; |
| 964 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 965 | case CMD_SWITCH_SLOTS: |
| 966 | request = (MainThreadRequest) msg.obj; |
| 967 | int[] physicalSlots = (int[]) request.argument; |
| 968 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 969 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 970 | break; |
| 971 | |
| 972 | case EVENT_SWITCH_SLOTS_DONE: |
| 973 | ar = (AsyncResult) msg.obj; |
| 974 | request = (MainThreadRequest) ar.userObj; |
| 975 | request.result = (ar.exception == null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 976 | notifyRequester(request); |
| 977 | break; |
| 978 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 979 | request = (MainThreadRequest) msg.obj; |
| 980 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 981 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 982 | break; |
| 983 | |
| 984 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 985 | ar = (AsyncResult) msg.obj; |
| 986 | request = (MainThreadRequest) ar.userObj; |
| 987 | if (ar.exception != null) { |
| 988 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 989 | } else { |
| 990 | int mode = ((int[]) ar.result)[0]; |
| 991 | if (mode == 0) { |
| 992 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 993 | } else { |
| 994 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 995 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 996 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 997 | notifyRequester(request); |
| 998 | break; |
| 999 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1000 | request = (MainThreadRequest) msg.obj; |
| 1001 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1002 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1003 | break; |
| 1004 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1005 | ar = (AsyncResult) msg.obj; |
| 1006 | request = (MainThreadRequest) ar.userObj; |
| 1007 | if (ar.exception != null) { |
| 1008 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1009 | } else { |
| 1010 | request.result = ((int[]) ar.result)[0]; |
| 1011 | } |
| 1012 | notifyRequester(request); |
| 1013 | break; |
| 1014 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1015 | request = (MainThreadRequest) msg.obj; |
| 1016 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1017 | int mode = (int) request.argument; |
| 1018 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1019 | break; |
| 1020 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1021 | ar = (AsyncResult) msg.obj; |
| 1022 | request = (MainThreadRequest) ar.userObj; |
| 1023 | request.result = ar.exception == null; |
| 1024 | notifyRequester(request); |
| 1025 | break; |
| 1026 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1027 | request = (MainThreadRequest) msg.obj; |
| 1028 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1029 | int subscriptionMode = (int) request.argument; |
| 1030 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1031 | break; |
| 1032 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1033 | ar = (AsyncResult) msg.obj; |
| 1034 | request = (MainThreadRequest) ar.userObj; |
| 1035 | request.result = ar.exception == null; |
| 1036 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1037 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1038 | case CMD_GET_ALL_CELL_INFO: |
| 1039 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1040 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1041 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1042 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1043 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1044 | ar = (AsyncResult) msg.obj; |
| 1045 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1046 | // If a timeout occurs, the response will be null |
| 1047 | request.result = (ar.exception == null && ar.result != null) |
| 1048 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1049 | synchronized (request) { |
| 1050 | request.notifyAll(); |
| 1051 | } |
| 1052 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1053 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1054 | request = (MainThreadRequest) msg.obj; |
| 1055 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1056 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1057 | break; |
| 1058 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1059 | ar = (AsyncResult) msg.obj; |
| 1060 | request = (MainThreadRequest) ar.userObj; |
| 1061 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1062 | try { |
| 1063 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1064 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1065 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1066 | new android.os.ParcelableException(ar.exception)); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1067 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1068 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1069 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1070 | } else { |
| 1071 | // use the result as returned |
| 1072 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1073 | } |
| 1074 | } catch (RemoteException re) { |
| 1075 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1076 | } |
| 1077 | break; |
| 1078 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1079 | request = (MainThreadRequest) msg.obj; |
| 1080 | WorkSource ws = (WorkSource) request.argument; |
| 1081 | Phone phone = getPhoneFromRequest(request); |
| 1082 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1083 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1084 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1085 | ar = (AsyncResult) msg.obj; |
| 1086 | request = (MainThreadRequest) ar.userObj; |
| 1087 | if (ar.exception == null) { |
| 1088 | request.result = ar.result; |
| 1089 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1090 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1091 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1092 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1093 | } |
| 1094 | |
| 1095 | synchronized (request) { |
| 1096 | request.notifyAll(); |
| 1097 | } |
| 1098 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1099 | case CMD_MODEM_REBOOT: |
| 1100 | request = (MainThreadRequest) msg.obj; |
| 1101 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1102 | defaultPhone.rebootModem(onCompleted); |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1103 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1104 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1105 | handleNullReturnEvent(msg, "rebootModem"); |
| 1106 | break; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1107 | case CMD_REQUEST_ENABLE_MODEM: |
| 1108 | request = (MainThreadRequest) msg.obj; |
| 1109 | boolean enable = (boolean) request.argument; |
| 1110 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 9b37957 | 2019-03-01 17:27:47 -0800 | [diff] [blame] | 1111 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1112 | PhoneConfigurationManager.getInstance() |
| 1113 | .enablePhone(request.phone, enable, onCompleted); |
| 1114 | break; |
| 1115 | case EVENT_ENABLE_MODEM_DONE: |
| 1116 | ar = (AsyncResult) msg.obj; |
| 1117 | request = (MainThreadRequest) ar.userObj; |
| 1118 | request.result = (ar.exception == null); |
Nazanin Bakhshi | 9b37957 | 2019-03-01 17:27:47 -0800 | [diff] [blame] | 1119 | //update the cache as modem status has changed |
| 1120 | mPhoneConfigurationManager.addToPhoneStatusCache( |
| 1121 | request.phone.getPhoneId(), msg.arg1 == 1); |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 1122 | updateModemStateMetrics(); |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1123 | notifyRequester(request); |
| 1124 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1125 | default: |
| 1126 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1127 | break; |
| 1128 | } |
| 1129 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1130 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1131 | private void notifyRequester(MainThreadRequest request) { |
| 1132 | synchronized (request) { |
| 1133 | request.notifyAll(); |
| 1134 | } |
| 1135 | } |
| 1136 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1137 | private void handleNullReturnEvent(Message msg, String command) { |
| 1138 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1139 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1140 | if (ar.exception == null) { |
| 1141 | request.result = true; |
| 1142 | } else { |
| 1143 | request.result = false; |
| 1144 | if (ar.exception instanceof CommandException) { |
| 1145 | loge(command + ": CommandException: " + ar.exception); |
| 1146 | } else { |
| 1147 | loge(command + ": Unknown exception"); |
| 1148 | } |
| 1149 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1150 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1151 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | /** |
| 1155 | * Posts the specified command to be executed on the main thread, |
| 1156 | * waits for the request to complete, and returns the result. |
| 1157 | * @see #sendRequestAsync |
| 1158 | */ |
| 1159 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1160 | return sendRequest( |
| 1161 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | /** |
| 1165 | * Posts the specified command to be executed on the main thread, |
| 1166 | * waits for the request to complete, and returns the result. |
| 1167 | * @see #sendRequestAsync |
| 1168 | */ |
| 1169 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1170 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1171 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | /** |
| 1175 | * Posts the specified command to be executed on the main thread, |
| 1176 | * waits for the request to complete, and returns the result. |
| 1177 | * @see #sendRequestAsync |
| 1178 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1179 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1180 | return sendRequest(command, argument, subId, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | /** |
| 1184 | * Posts the specified command to be executed on the main thread, |
| 1185 | * waits for the request to complete, and returns the result. |
| 1186 | * @see #sendRequestAsync |
| 1187 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1188 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1189 | return sendRequest(command, argument, subId, null, workSource); |
| 1190 | } |
| 1191 | |
| 1192 | /** |
| 1193 | * Posts the specified command to be executed on the main thread, |
| 1194 | * waits for the request to complete, and returns the result. |
| 1195 | * @see #sendRequestAsync |
| 1196 | */ |
| 1197 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1198 | return sendRequest( |
| 1199 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1200 | } |
| 1201 | |
| 1202 | /** |
| 1203 | * Posts the specified command to be executed on the main thread, |
| 1204 | * waits for the request to complete, and returns the result. |
| 1205 | * @see #sendRequestAsync |
| 1206 | */ |
| 1207 | private Object sendRequest( |
| 1208 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1209 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1210 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1211 | } |
| 1212 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1213 | MainThreadRequest request = null; |
| 1214 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1215 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1216 | } else if (phone != null) { |
| 1217 | request = new MainThreadRequest(argument, phone, workSource); |
| 1218 | } else { |
| 1219 | request = new MainThreadRequest(argument, subId, workSource); |
| 1220 | } |
| 1221 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1222 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1223 | msg.sendToTarget(); |
| 1224 | |
| 1225 | // Wait for the request to complete |
| 1226 | synchronized (request) { |
| 1227 | while (request.result == null) { |
| 1228 | try { |
| 1229 | request.wait(); |
| 1230 | } catch (InterruptedException e) { |
| 1231 | // Do nothing, go back and wait until the request is complete |
| 1232 | } |
| 1233 | } |
| 1234 | } |
| 1235 | return request.result; |
| 1236 | } |
| 1237 | |
| 1238 | /** |
| 1239 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1240 | * Posts the specified command to be executed on the main thread, and |
| 1241 | * returns immediately. |
| 1242 | * @see #sendRequest |
| 1243 | */ |
| 1244 | private void sendRequestAsync(int command) { |
| 1245 | mMainThreadHandler.sendEmptyMessage(command); |
| 1246 | } |
| 1247 | |
| 1248 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1249 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1250 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1251 | */ |
| 1252 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1253 | sendRequestAsync(command, argument, null, null); |
| 1254 | } |
| 1255 | |
| 1256 | /** |
| 1257 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1258 | * @see {@link #sendRequest(int,Object)} |
| 1259 | */ |
| 1260 | private void sendRequestAsync( |
| 1261 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1262 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1263 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1264 | msg.sendToTarget(); |
| 1265 | } |
| 1266 | |
| 1267 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1268 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1269 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1270 | */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1271 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1272 | synchronized (PhoneInterfaceManager.class) { |
| 1273 | if (sInstance == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1274 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1275 | } else { |
| 1276 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1277 | } |
| 1278 | return sInstance; |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1283 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1284 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1285 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1286 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1287 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1288 | mMainThreadHandler = new MainThreadHandler(); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1289 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1290 | mTelephonySharedPreferences = |
| 1291 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1292 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1293 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1294 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1295 | publish(); |
| 1296 | } |
| 1297 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1298 | private Phone getDefaultPhone() { |
| 1299 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1300 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1301 | } |
| 1302 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1303 | private void publish() { |
| 1304 | if (DBG) log("publish: " + this); |
| 1305 | |
| 1306 | ServiceManager.addService("phone", this); |
| 1307 | } |
| 1308 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1309 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1310 | if (request.phone != null) { |
| 1311 | return request.phone; |
| 1312 | } else { |
| 1313 | return getPhoneFromSubId(request.subId); |
| 1314 | } |
| 1315 | } |
| 1316 | |
| 1317 | private Phone getPhoneFromSubId(int subId) { |
| 1318 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1319 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1320 | } |
| 1321 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1322 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1323 | Phone phone = getPhoneFromRequest(request); |
| 1324 | return phone == null ? null : |
| 1325 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1326 | } |
| 1327 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1328 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1329 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1330 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1331 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1332 | |
| 1333 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1334 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1335 | } |
| 1336 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1337 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1338 | if (DBG) log("dial: " + number); |
| 1339 | // No permission check needed here: This is just a wrapper around the |
| 1340 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1341 | // the UI before it does anything. |
| 1342 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1343 | final long identity = Binder.clearCallingIdentity(); |
| 1344 | try { |
| 1345 | String url = createTelUrl(number); |
| 1346 | if (url == null) { |
| 1347 | return; |
| 1348 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1349 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1350 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1351 | PhoneConstants.State state = mCM.getState(subId); |
| 1352 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1353 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1354 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1355 | mApp.startActivity(intent); |
| 1356 | } |
| 1357 | } finally { |
| 1358 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1363 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1364 | } |
| 1365 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1366 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1367 | if (DBG) log("call: " + number); |
| 1368 | |
| 1369 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1370 | // need to do a permission check since we're calling startActivity() |
| 1371 | // from the context of the phone app. |
| 1372 | enforceCallPermission(); |
| 1373 | |
| 1374 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1375 | != AppOpsManager.MODE_ALLOWED) { |
| 1376 | return; |
| 1377 | } |
| 1378 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1379 | final long identity = Binder.clearCallingIdentity(); |
| 1380 | try { |
| 1381 | String url = createTelUrl(number); |
| 1382 | if (url == null) { |
| 1383 | return; |
| 1384 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1385 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1386 | boolean isValid = false; |
| 1387 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1388 | if (slist != null) { |
| 1389 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1390 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1391 | isValid = true; |
| 1392 | break; |
| 1393 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1394 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1395 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1396 | if (!isValid) { |
| 1397 | return; |
| 1398 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1399 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1400 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1401 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1402 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1403 | mApp.startActivity(intent); |
| 1404 | } finally { |
| 1405 | Binder.restoreCallingIdentity(identity); |
| 1406 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1409 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1410 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1411 | } |
| 1412 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1413 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1414 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1415 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1416 | } |
| 1417 | |
| 1418 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1419 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1422 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1423 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1424 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1425 | } |
| 1426 | |
| 1427 | /** {@hide} */ |
| 1428 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1429 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1430 | } |
| 1431 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1432 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1433 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1434 | |
| 1435 | final long identity = Binder.clearCallingIdentity(); |
| 1436 | try { |
| 1437 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1438 | checkSimPin.start(); |
| 1439 | return checkSimPin.unlockSim(null, pin); |
| 1440 | } finally { |
| 1441 | Binder.restoreCallingIdentity(identity); |
| 1442 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1445 | /** {@hide} */ |
| 1446 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1447 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1448 | } |
| 1449 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1450 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1451 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1452 | |
| 1453 | final long identity = Binder.clearCallingIdentity(); |
| 1454 | try { |
| 1455 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1456 | checkSimPuk.start(); |
| 1457 | return checkSimPuk.unlockSim(puk, pin); |
| 1458 | } finally { |
| 1459 | Binder.restoreCallingIdentity(identity); |
| 1460 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1461 | } |
| 1462 | |
| 1463 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1464 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1465 | * a synchronous one. |
| 1466 | */ |
| 1467 | private static class UnlockSim extends Thread { |
| 1468 | |
| 1469 | private final IccCard mSimCard; |
| 1470 | |
| 1471 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1472 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1473 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1474 | |
| 1475 | // For replies from SimCard interface |
| 1476 | private Handler mHandler; |
| 1477 | |
| 1478 | // For async handler to identify request type |
| 1479 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1480 | |
| 1481 | public UnlockSim(IccCard simCard) { |
| 1482 | mSimCard = simCard; |
| 1483 | } |
| 1484 | |
| 1485 | @Override |
| 1486 | public void run() { |
| 1487 | Looper.prepare(); |
| 1488 | synchronized (UnlockSim.this) { |
| 1489 | mHandler = new Handler() { |
| 1490 | @Override |
| 1491 | public void handleMessage(Message msg) { |
| 1492 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1493 | switch (msg.what) { |
| 1494 | case SUPPLY_PIN_COMPLETE: |
| 1495 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1496 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1497 | mRetryCount = msg.arg1; |
| 1498 | if (ar.exception != null) { |
| 1499 | if (ar.exception instanceof CommandException && |
| 1500 | ((CommandException)(ar.exception)).getCommandError() |
| 1501 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1502 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1503 | } else { |
| 1504 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1505 | } |
| 1506 | } else { |
| 1507 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1508 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1509 | mDone = true; |
| 1510 | UnlockSim.this.notifyAll(); |
| 1511 | } |
| 1512 | break; |
| 1513 | } |
| 1514 | } |
| 1515 | }; |
| 1516 | UnlockSim.this.notifyAll(); |
| 1517 | } |
| 1518 | Looper.loop(); |
| 1519 | } |
| 1520 | |
| 1521 | /* |
| 1522 | * Use PIN or PUK to unlock SIM card |
| 1523 | * |
| 1524 | * If PUK is null, unlock SIM card with PIN |
| 1525 | * |
| 1526 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1527 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1528 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1529 | |
| 1530 | while (mHandler == null) { |
| 1531 | try { |
| 1532 | wait(); |
| 1533 | } catch (InterruptedException e) { |
| 1534 | Thread.currentThread().interrupt(); |
| 1535 | } |
| 1536 | } |
| 1537 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1538 | |
| 1539 | if (puk == null) { |
| 1540 | mSimCard.supplyPin(pin, callback); |
| 1541 | } else { |
| 1542 | mSimCard.supplyPuk(puk, pin, callback); |
| 1543 | } |
| 1544 | |
| 1545 | while (!mDone) { |
| 1546 | try { |
| 1547 | Log.d(LOG_TAG, "wait for done"); |
| 1548 | wait(); |
| 1549 | } catch (InterruptedException e) { |
| 1550 | // Restore the interrupted status |
| 1551 | Thread.currentThread().interrupt(); |
| 1552 | } |
| 1553 | } |
| 1554 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1555 | int[] resultArray = new int[2]; |
| 1556 | resultArray[0] = mResult; |
| 1557 | resultArray[1] = mRetryCount; |
| 1558 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1559 | } |
| 1560 | } |
| 1561 | |
| 1562 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1563 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1564 | |
| 1565 | } |
| 1566 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1567 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1568 | // No permission check needed here: this call is harmless, and it's |
| 1569 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1570 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1571 | final long identity = Binder.clearCallingIdentity(); |
| 1572 | try { |
| 1573 | final Phone phone = getPhone(subId); |
| 1574 | if (phone != null) { |
| 1575 | phone.updateServiceLocation(); |
| 1576 | } |
| 1577 | } finally { |
| 1578 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1579 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1582 | @Override |
| 1583 | public boolean isRadioOn(String callingPackage) { |
| 1584 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1585 | } |
| 1586 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1587 | @Override |
| 1588 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1589 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1590 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1591 | return false; |
| 1592 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1593 | |
| 1594 | final long identity = Binder.clearCallingIdentity(); |
| 1595 | try { |
| 1596 | return isRadioOnForSubscriber(subId); |
| 1597 | } finally { |
| 1598 | Binder.restoreCallingIdentity(identity); |
| 1599 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1603 | final long identity = Binder.clearCallingIdentity(); |
| 1604 | try { |
| 1605 | final Phone phone = getPhone(subId); |
| 1606 | if (phone != null) { |
| 1607 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1608 | } else { |
| 1609 | return false; |
| 1610 | } |
| 1611 | } finally { |
| 1612 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1613 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1617 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1618 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1619 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1620 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1621 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1622 | |
| 1623 | final long identity = Binder.clearCallingIdentity(); |
| 1624 | try { |
| 1625 | final Phone phone = getPhone(subId); |
| 1626 | if (phone != null) { |
| 1627 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1628 | } |
| 1629 | } finally { |
| 1630 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1631 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1632 | } |
| 1633 | |
| 1634 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1635 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1636 | } |
| 1637 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1638 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1639 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1640 | |
| 1641 | final long identity = Binder.clearCallingIdentity(); |
| 1642 | try { |
| 1643 | final Phone phone = getPhone(subId); |
| 1644 | if (phone == null) { |
| 1645 | return false; |
| 1646 | } |
| 1647 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1648 | toggleRadioOnOffForSubscriber(subId); |
| 1649 | } |
| 1650 | return true; |
| 1651 | } finally { |
| 1652 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1653 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1654 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1655 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1656 | public boolean needMobileRadioShutdown() { |
| 1657 | /* |
| 1658 | * If any of the Radios are available, it will need to be |
| 1659 | * shutdown. So return true if any Radio is available. |
| 1660 | */ |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1661 | final long identity = Binder.clearCallingIdentity(); |
| 1662 | try { |
| 1663 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1664 | Phone phone = PhoneFactory.getPhone(i); |
| 1665 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1666 | } |
| 1667 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1668 | return false; |
| 1669 | } finally { |
| 1670 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1671 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1672 | } |
| 1673 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1674 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1675 | public void shutdownMobileRadios() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1676 | enforceModifyPermission(); |
| 1677 | |
| 1678 | final long identity = Binder.clearCallingIdentity(); |
| 1679 | try { |
| 1680 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1681 | logv("Shutting down Phone " + i); |
| 1682 | shutdownRadioUsingPhoneId(i); |
| 1683 | } |
| 1684 | } finally { |
| 1685 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1686 | } |
| 1687 | } |
| 1688 | |
| 1689 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1690 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1691 | if (phone != null && phone.isRadioAvailable()) { |
| 1692 | phone.shutdownRadio(); |
| 1693 | } |
| 1694 | } |
| 1695 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1696 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1697 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1698 | |
| 1699 | final long identity = Binder.clearCallingIdentity(); |
| 1700 | try { |
| 1701 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1702 | if (defaultPhone != null) { |
| 1703 | defaultPhone.setRadioPower(turnOn); |
| 1704 | return true; |
| 1705 | } else { |
| 1706 | loge("There's no default phone."); |
| 1707 | return false; |
| 1708 | } |
| 1709 | } finally { |
| 1710 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1711 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1714 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1715 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1716 | |
| 1717 | final long identity = Binder.clearCallingIdentity(); |
| 1718 | try { |
| 1719 | final Phone phone = getPhone(subId); |
| 1720 | if (phone != null) { |
| 1721 | phone.setRadioPower(turnOn); |
| 1722 | return true; |
| 1723 | } else { |
| 1724 | return false; |
| 1725 | } |
| 1726 | } finally { |
| 1727 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1728 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1729 | } |
| 1730 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1731 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1732 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1733 | public boolean enableDataConnectivity() { |
| 1734 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1735 | |
| 1736 | final long identity = Binder.clearCallingIdentity(); |
| 1737 | try { |
| 1738 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1739 | final Phone phone = getPhone(subId); |
| 1740 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1741 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1742 | return true; |
| 1743 | } else { |
| 1744 | return false; |
| 1745 | } |
| 1746 | } finally { |
| 1747 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1748 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1751 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1752 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1753 | public boolean disableDataConnectivity() { |
| 1754 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1755 | |
| 1756 | final long identity = Binder.clearCallingIdentity(); |
| 1757 | try { |
| 1758 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1759 | final Phone phone = getPhone(subId); |
| 1760 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1761 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1762 | return true; |
| 1763 | } else { |
| 1764 | return false; |
| 1765 | } |
| 1766 | } finally { |
| 1767 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1768 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1769 | } |
| 1770 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1771 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1772 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1773 | final long identity = Binder.clearCallingIdentity(); |
| 1774 | try { |
| 1775 | final Phone phone = getPhone(subId); |
| 1776 | if (phone != null) { |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1777 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1778 | } else { |
| 1779 | return false; |
| 1780 | } |
| 1781 | } finally { |
| 1782 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1783 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1787 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1788 | } |
| 1789 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1790 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1791 | enforceCallPermission(); |
| 1792 | |
| 1793 | final long identity = Binder.clearCallingIdentity(); |
| 1794 | try { |
| 1795 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1796 | return; |
| 1797 | } |
| 1798 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1799 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1800 | } finally { |
| 1801 | Binder.restoreCallingIdentity(identity); |
| 1802 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1803 | }; |
| 1804 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1805 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1806 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1807 | |
| 1808 | final long identity = Binder.clearCallingIdentity(); |
| 1809 | try { |
| 1810 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1811 | return false; |
| 1812 | } |
| 1813 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1814 | } finally { |
| 1815 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1816 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1819 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1820 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1823 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1824 | final long identity = Binder.clearCallingIdentity(); |
| 1825 | try { |
| 1826 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1827 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1828 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1829 | } finally { |
| 1830 | Binder.restoreCallingIdentity(identity); |
| 1831 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1832 | } |
| 1833 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1834 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1835 | public int getDataState() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1836 | final long identity = Binder.clearCallingIdentity(); |
| 1837 | try { |
| 1838 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1839 | if (phone != null) { |
| 1840 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1841 | } else { |
| 1842 | return PhoneConstantConversions.convertDataState( |
| 1843 | PhoneConstants.DataState.DISCONNECTED); |
| 1844 | } |
| 1845 | } finally { |
| 1846 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1847 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1848 | } |
| 1849 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1850 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1851 | public int getDataActivity() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1852 | final long identity = Binder.clearCallingIdentity(); |
| 1853 | try { |
| 1854 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1855 | if (phone != null) { |
| 1856 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1857 | } else { |
| 1858 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1859 | } |
| 1860 | } finally { |
| 1861 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1862 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1866 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1867 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1868 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1869 | |
| 1870 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 1871 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 1872 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 1873 | .setCallingPackage(callingPackage) |
| 1874 | .setCallingPid(Binder.getCallingPid()) |
| 1875 | .setCallingUid(Binder.getCallingUid()) |
| 1876 | .setMethod("getCellLocation") |
| 1877 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 1878 | .build()); |
| 1879 | switch (locationResult) { |
| 1880 | case DENIED_HARD: |
| 1881 | throw new SecurityException("Not allowed to access cell location"); |
| 1882 | case DENIED_SOFT: |
| 1883 | return new Bundle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1884 | } |
| 1885 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1886 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1887 | final long identity = Binder.clearCallingIdentity(); |
| 1888 | try { |
| 1889 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1890 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1891 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1892 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1893 | cl.fillInNotifierBundle(data); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1894 | return data; |
| 1895 | } finally { |
| 1896 | Binder.restoreCallingIdentity(identity); |
| 1897 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1898 | } |
| 1899 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1900 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1901 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1902 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1903 | // registered cell info, so return a NULL country instead. |
| 1904 | final long identity = Binder.clearCallingIdentity(); |
| 1905 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1906 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1907 | // Get default phone in this case. |
| 1908 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1909 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1910 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1911 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1912 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1913 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1914 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1915 | return ""; |
| 1916 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1917 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1918 | if (phone != null) { |
| 1919 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 1920 | if (sst != null) { |
| 1921 | LocaleTracker lt = sst.getLocaleTracker(); |
| 1922 | if (lt != null) { |
| 1923 | return lt.getCurrentCountry(); |
| 1924 | } |
| 1925 | } |
| 1926 | } |
| 1927 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1928 | } finally { |
| 1929 | Binder.restoreCallingIdentity(identity); |
| 1930 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1934 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1935 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1936 | } |
| 1937 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1938 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1939 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1940 | mApp.enforceCallingOrSelfPermission( |
| 1941 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1942 | |
| 1943 | final long identity = Binder.clearCallingIdentity(); |
| 1944 | try { |
| 1945 | final Phone phone = getPhone(subId); |
| 1946 | if (phone != null) { |
| 1947 | phone.enableLocationUpdates(); |
| 1948 | } |
| 1949 | } finally { |
| 1950 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1951 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | @Override |
| 1955 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1956 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1959 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1960 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1961 | mApp.enforceCallingOrSelfPermission( |
| 1962 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1963 | |
| 1964 | final long identity = Binder.clearCallingIdentity(); |
| 1965 | try { |
| 1966 | final Phone phone = getPhone(subId); |
| 1967 | if (phone != null) { |
| 1968 | phone.disableLocationUpdates(); |
| 1969 | } |
| 1970 | } finally { |
| 1971 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1972 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1973 | } |
| 1974 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1975 | /** |
| 1976 | * Returns the target SDK version number for a given package name. |
| 1977 | * |
| 1978 | * @return target SDK if the package is found or INT_MAX. |
| 1979 | */ |
| 1980 | private int getTargetSdk(String packageName) { |
| 1981 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1982 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo( |
| 1983 | packageName, 0); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1984 | if (ai != null) return ai.targetSdkVersion; |
| 1985 | } catch (PackageManager.NameNotFoundException unexpected) { |
| 1986 | } |
| 1987 | return Integer.MAX_VALUE; |
| 1988 | } |
| 1989 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1990 | @Override |
| 1991 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1992 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 1993 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 1994 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 1995 | throw new SecurityException( |
| 1996 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 1997 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 1998 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1999 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 2000 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2001 | return null; |
| 2002 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2003 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2004 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2005 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2006 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 2007 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2008 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2009 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2010 | for (CellInfo ci : info) { |
| 2011 | if (ci instanceof CellInfoGsm) { |
| 2012 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2013 | } else if (ci instanceof CellInfoWcdma) { |
| 2014 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2015 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2016 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2017 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2018 | } |
| 2019 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2020 | private List<CellInfo> getCachedCellInfo() { |
| 2021 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2022 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2023 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2024 | if (info != null) cellInfos.addAll(info); |
| 2025 | } |
| 2026 | return cellInfos; |
| 2027 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2028 | |
| 2029 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2030 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2031 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2032 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2033 | |
| 2034 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2035 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2036 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2037 | .setCallingPackage(callingPackage) |
| 2038 | .setCallingPid(Binder.getCallingPid()) |
| 2039 | .setCallingUid(Binder.getCallingUid()) |
| 2040 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2041 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2042 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2043 | .build()); |
| 2044 | switch (locationResult) { |
| 2045 | case DENIED_HARD: |
| 2046 | throw new SecurityException("Not allowed to access cell info"); |
| 2047 | case DENIED_SOFT: |
| 2048 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2049 | } |
| 2050 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2051 | final int targetSdk = getTargetSdk(callingPackage); |
| 2052 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2053 | return getCachedCellInfo(); |
| 2054 | } |
| 2055 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2056 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2057 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2058 | final long identity = Binder.clearCallingIdentity(); |
| 2059 | try { |
| 2060 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2061 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2062 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2063 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2064 | if (info != null) cellInfos.addAll(info); |
| 2065 | } |
| 2066 | return cellInfos; |
| 2067 | } finally { |
| 2068 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2069 | } |
| 2070 | } |
| 2071 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2072 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2073 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2074 | requestCellInfoUpdateInternal( |
| 2075 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2076 | } |
| 2077 | |
| 2078 | @Override |
| 2079 | public void requestCellInfoUpdateWithWorkSource( |
| 2080 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2081 | enforceModifyPermission(); |
| 2082 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2083 | } |
| 2084 | |
| 2085 | private void requestCellInfoUpdateInternal( |
| 2086 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2087 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2088 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2089 | |
| 2090 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2091 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2092 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2093 | .setCallingPackage(callingPackage) |
| 2094 | .setCallingPid(Binder.getCallingPid()) |
| 2095 | .setCallingUid(Binder.getCallingUid()) |
| 2096 | .setMethod("requestCellInfoUpdate") |
| 2097 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2098 | .build()); |
| 2099 | switch (locationResult) { |
| 2100 | case DENIED_HARD: |
| 2101 | throw new SecurityException("Not allowed to access cell info"); |
| 2102 | case DENIED_SOFT: |
| 2103 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2104 | } |
| 2105 | |
| 2106 | final Phone phone = getPhone(subId); |
| 2107 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2108 | |
| 2109 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2110 | } |
| 2111 | |
| 2112 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2113 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2114 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2115 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2116 | |
| 2117 | final long identity = Binder.clearCallingIdentity(); |
| 2118 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2119 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2120 | } finally { |
| 2121 | Binder.restoreCallingIdentity(identity); |
| 2122 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2123 | } |
| 2124 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2125 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2126 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2127 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2128 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2129 | return null; |
| 2130 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2131 | int subId = phone.getSubId(); |
| 2132 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2133 | mApp, subId, callingPackage, "getImeiForSlot")) { |
| 2134 | return null; |
| 2135 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2136 | |
| 2137 | final long identity = Binder.clearCallingIdentity(); |
| 2138 | try { |
| 2139 | return phone.getImei(); |
| 2140 | } finally { |
| 2141 | Binder.restoreCallingIdentity(identity); |
| 2142 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2146 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2147 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2148 | String tac = null; |
| 2149 | if (phone != null) { |
| 2150 | String imei = phone.getImei(); |
| 2151 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2152 | } |
| 2153 | return tac; |
| 2154 | } |
| 2155 | |
| 2156 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2157 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2158 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2159 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2160 | return null; |
| 2161 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2162 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2163 | int subId = phone.getSubId(); |
| 2164 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2165 | mApp, subId, callingPackage, "getMeidForSlot")) { |
| 2166 | return null; |
| 2167 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2168 | |
| 2169 | final long identity = Binder.clearCallingIdentity(); |
| 2170 | try { |
| 2171 | return phone.getMeid(); |
| 2172 | } finally { |
| 2173 | Binder.restoreCallingIdentity(identity); |
| 2174 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2178 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2179 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2180 | String manufacturerCode = null; |
| 2181 | if (phone != null) { |
| 2182 | String meid = phone.getMeid(); |
| 2183 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2184 | } |
| 2185 | return manufacturerCode; |
| 2186 | } |
| 2187 | |
| 2188 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2189 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2190 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2191 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2192 | return null; |
| 2193 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2194 | int subId = phone.getSubId(); |
| 2195 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2196 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2197 | return null; |
| 2198 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2199 | |
| 2200 | final long identity = Binder.clearCallingIdentity(); |
| 2201 | try { |
| 2202 | return phone.getDeviceSvn(); |
| 2203 | } finally { |
| 2204 | Binder.restoreCallingIdentity(identity); |
| 2205 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2206 | } |
| 2207 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2208 | @Override |
| 2209 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2210 | final long identity = Binder.clearCallingIdentity(); |
| 2211 | try { |
| 2212 | final Phone phone = getPhone(subId); |
| 2213 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2214 | } finally { |
| 2215 | Binder.restoreCallingIdentity(identity); |
| 2216 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2217 | } |
| 2218 | |
| 2219 | @Override |
| 2220 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2221 | final long identity = Binder.clearCallingIdentity(); |
| 2222 | try { |
| 2223 | final Phone phone = getPhone(subId); |
| 2224 | return phone == null ? null : phone.getCarrierName(); |
| 2225 | } finally { |
| 2226 | Binder.restoreCallingIdentity(identity); |
| 2227 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2228 | } |
| 2229 | |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2230 | @Override |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2231 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2232 | final long identity = Binder.clearCallingIdentity(); |
| 2233 | try { |
| 2234 | final Phone phone = getPhone(subId); |
| 2235 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2236 | : phone.getSpecificCarrierId(); |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2237 | } finally { |
| 2238 | Binder.restoreCallingIdentity(identity); |
| 2239 | } |
| 2240 | } |
| 2241 | |
| 2242 | @Override |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2243 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2244 | final long identity = Binder.clearCallingIdentity(); |
| 2245 | try { |
| 2246 | final Phone phone = getPhone(subId); |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2247 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2248 | } finally { |
| 2249 | Binder.restoreCallingIdentity(identity); |
| 2250 | } |
| 2251 | } |
| 2252 | |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2253 | @Override |
chen xu | 4ca4e69 | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2254 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2255 | if (!isSubscriptionMccMnc) { |
| 2256 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2257 | } |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2258 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2259 | if (phone == null) { |
| 2260 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2261 | } |
| 2262 | final long identity = Binder.clearCallingIdentity(); |
| 2263 | try { |
| 2264 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2265 | } finally { |
| 2266 | Binder.restoreCallingIdentity(identity); |
| 2267 | } |
| 2268 | } |
| 2269 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2270 | // |
| 2271 | // Internal helper methods. |
| 2272 | // |
| 2273 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2274 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2275 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2276 | * |
| 2277 | * @throws SecurityException if the caller does not have the required permission |
| 2278 | */ |
| 2279 | private void enforceModifyPermission() { |
| 2280 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2281 | } |
| 2282 | |
| 2283 | /** |
| 2284 | * Make sure the caller has the CALL_PHONE permission. |
| 2285 | * |
| 2286 | * @throws SecurityException if the caller does not have the required permission |
| 2287 | */ |
| 2288 | private void enforceCallPermission() { |
| 2289 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2290 | } |
| 2291 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2292 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2293 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2294 | "ConnectivityService"); |
| 2295 | } |
| 2296 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2297 | private String createTelUrl(String number) { |
| 2298 | if (TextUtils.isEmpty(number)) { |
| 2299 | return null; |
| 2300 | } |
| 2301 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2302 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2303 | } |
| 2304 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2305 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2306 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2307 | } |
| 2308 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2309 | private static void logv(String msg) { |
| 2310 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2311 | } |
| 2312 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2313 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2314 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2315 | } |
| 2316 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2317 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2318 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2319 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2320 | } |
| 2321 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2322 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2323 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2324 | final long identity = Binder.clearCallingIdentity(); |
| 2325 | try { |
| 2326 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2327 | if (phone == null) { |
| 2328 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2329 | } else { |
| 2330 | return phone.getPhoneType(); |
| 2331 | } |
| 2332 | } finally { |
| 2333 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2334 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | /** |
| 2338 | * Returns the CDMA ERI icon index to display |
| 2339 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2340 | @Override |
| 2341 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2342 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2343 | } |
| 2344 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2345 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2346 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2347 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2348 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2349 | return -1; |
| 2350 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2351 | |
| 2352 | final long identity = Binder.clearCallingIdentity(); |
| 2353 | try { |
| 2354 | final Phone phone = getPhone(subId); |
| 2355 | if (phone != null) { |
| 2356 | return phone.getCdmaEriIconIndex(); |
| 2357 | } else { |
| 2358 | return -1; |
| 2359 | } |
| 2360 | } finally { |
| 2361 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2362 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2363 | } |
| 2364 | |
| 2365 | /** |
| 2366 | * Returns the CDMA ERI icon mode, |
| 2367 | * 0 - ON |
| 2368 | * 1 - FLASHING |
| 2369 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2370 | @Override |
| 2371 | public int getCdmaEriIconMode(String callingPackage) { |
| 2372 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2373 | } |
| 2374 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2375 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2376 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2377 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2378 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2379 | return -1; |
| 2380 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2381 | |
| 2382 | final long identity = Binder.clearCallingIdentity(); |
| 2383 | try { |
| 2384 | final Phone phone = getPhone(subId); |
| 2385 | if (phone != null) { |
| 2386 | return phone.getCdmaEriIconMode(); |
| 2387 | } else { |
| 2388 | return -1; |
| 2389 | } |
| 2390 | } finally { |
| 2391 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2392 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2393 | } |
| 2394 | |
| 2395 | /** |
| 2396 | * Returns the CDMA ERI text, |
| 2397 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2398 | @Override |
| 2399 | public String getCdmaEriText(String callingPackage) { |
| 2400 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2401 | } |
| 2402 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2403 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2404 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2405 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2406 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2407 | return null; |
| 2408 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2409 | |
| 2410 | final long identity = Binder.clearCallingIdentity(); |
| 2411 | try { |
| 2412 | final Phone phone = getPhone(subId); |
| 2413 | if (phone != null) { |
| 2414 | return phone.getCdmaEriText(); |
| 2415 | } else { |
| 2416 | return null; |
| 2417 | } |
| 2418 | } finally { |
| 2419 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2420 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2424 | * Returns the CDMA MDN. |
| 2425 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2426 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2427 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2428 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2429 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2430 | |
| 2431 | final long identity = Binder.clearCallingIdentity(); |
| 2432 | try { |
| 2433 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2434 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2435 | return phone.getLine1Number(); |
| 2436 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2437 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2438 | return null; |
| 2439 | } |
| 2440 | } finally { |
| 2441 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2442 | } |
| 2443 | } |
| 2444 | |
| 2445 | /** |
| 2446 | * Returns the CDMA MIN. |
| 2447 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2448 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2449 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2450 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2451 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2452 | |
| 2453 | final long identity = Binder.clearCallingIdentity(); |
| 2454 | try { |
| 2455 | final Phone phone = getPhone(subId); |
| 2456 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2457 | return phone.getCdmaMin(); |
| 2458 | } else { |
| 2459 | return null; |
| 2460 | } |
| 2461 | } finally { |
| 2462 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2463 | } |
| 2464 | } |
| 2465 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2466 | @Override |
| 2467 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2468 | INumberVerificationCallback callback, String callingPackage) { |
| 2469 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2470 | != PERMISSION_GRANTED) { |
| 2471 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2472 | } |
| 2473 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2474 | |
| 2475 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2476 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2477 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2478 | } |
| 2479 | |
| 2480 | if (range == null) { |
| 2481 | throw new NullPointerException("Range must be non-null"); |
| 2482 | } |
| 2483 | |
| 2484 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2485 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2486 | |
| 2487 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2488 | } |
| 2489 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2490 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2491 | * Returns true if CDMA provisioning needs to run. |
| 2492 | */ |
| 2493 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2494 | final long identity = Binder.clearCallingIdentity(); |
| 2495 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2496 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2497 | } finally { |
| 2498 | Binder.restoreCallingIdentity(identity); |
| 2499 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2500 | } |
| 2501 | |
| 2502 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2503 | * Sets the voice mail number of a given subId. |
| 2504 | */ |
| 2505 | @Override |
| 2506 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2507 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2508 | |
| 2509 | final long identity = Binder.clearCallingIdentity(); |
| 2510 | try { |
| 2511 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2512 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2513 | return success; |
| 2514 | } finally { |
| 2515 | Binder.restoreCallingIdentity(identity); |
| 2516 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2517 | } |
| 2518 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2519 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2520 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2521 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2522 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2523 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2524 | throw new SecurityException("caller must be system dialer"); |
| 2525 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2526 | |
| 2527 | final long identity = Binder.clearCallingIdentity(); |
| 2528 | try { |
| 2529 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2530 | if (phoneAccountHandle == null) { |
| 2531 | return null; |
| 2532 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2533 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2534 | } finally { |
| 2535 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2536 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2540 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2541 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2542 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2543 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2544 | return null; |
| 2545 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2546 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2547 | final long identity = Binder.clearCallingIdentity(); |
| 2548 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2549 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2550 | } finally { |
| 2551 | Binder.restoreCallingIdentity(identity); |
| 2552 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2556 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2557 | VisualVoicemailSmsFilterSettings settings) { |
| 2558 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2559 | |
| 2560 | final long identity = Binder.clearCallingIdentity(); |
| 2561 | try { |
| 2562 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2563 | mApp, callingPackage, subId, settings); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2564 | } finally { |
| 2565 | Binder.restoreCallingIdentity(identity); |
| 2566 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2567 | } |
| 2568 | |
| 2569 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2570 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2571 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2572 | |
| 2573 | final long identity = Binder.clearCallingIdentity(); |
| 2574 | try { |
| 2575 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2576 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2577 | } finally { |
| 2578 | Binder.restoreCallingIdentity(identity); |
| 2579 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2580 | } |
| 2581 | |
| 2582 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2583 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2584 | String callingPackage, int subId) { |
| 2585 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2586 | |
| 2587 | final long identity = Binder.clearCallingIdentity(); |
| 2588 | try { |
| 2589 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2590 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2591 | } finally { |
| 2592 | Binder.restoreCallingIdentity(identity); |
| 2593 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2594 | } |
| 2595 | |
| 2596 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2597 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2598 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2599 | |
| 2600 | final long identity = Binder.clearCallingIdentity(); |
| 2601 | try { |
| 2602 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2603 | mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2604 | } finally { |
| 2605 | Binder.restoreCallingIdentity(identity); |
| 2606 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2607 | } |
| 2608 | |
| 2609 | @Override |
| 2610 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2611 | String number, int port, String text, PendingIntent sentIntent) { |
| 2612 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2613 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2614 | enforceSendSmsPermission(); |
| 2615 | // Make the calls as the phone process. |
| 2616 | final long identity = Binder.clearCallingIdentity(); |
| 2617 | try { |
| 2618 | SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); |
| 2619 | if (port == 0) { |
| 2620 | smsManager.sendTextMessageWithSelfPermissions(number, null, text, |
| 2621 | sentIntent, null, false); |
| 2622 | } else { |
| 2623 | byte[] data = text.getBytes(StandardCharsets.UTF_8); |
| 2624 | smsManager.sendDataMessageWithSelfPermissions(number, null, |
| 2625 | (short) port, data, sentIntent, null); |
| 2626 | } |
| 2627 | } finally { |
| 2628 | Binder.restoreCallingIdentity(identity); |
| 2629 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2630 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2631 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2632 | * Sets the voice activation state of a given subId. |
| 2633 | */ |
| 2634 | @Override |
| 2635 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2636 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2637 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2638 | |
| 2639 | final long identity = Binder.clearCallingIdentity(); |
| 2640 | try { |
| 2641 | final Phone phone = getPhone(subId); |
| 2642 | if (phone != null) { |
| 2643 | phone.setVoiceActivationState(activationState); |
| 2644 | } else { |
| 2645 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2646 | } |
| 2647 | } finally { |
| 2648 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2649 | } |
| 2650 | } |
| 2651 | |
| 2652 | /** |
| 2653 | * Sets the data activation state of a given subId. |
| 2654 | */ |
| 2655 | @Override |
| 2656 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2657 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2658 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2659 | |
| 2660 | final long identity = Binder.clearCallingIdentity(); |
| 2661 | try { |
| 2662 | final Phone phone = getPhone(subId); |
| 2663 | if (phone != null) { |
| 2664 | phone.setDataActivationState(activationState); |
| 2665 | } else { |
| 2666 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2667 | } |
| 2668 | } finally { |
| 2669 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2670 | } |
| 2671 | } |
| 2672 | |
| 2673 | /** |
| 2674 | * Returns the voice activation state of a given subId. |
| 2675 | */ |
| 2676 | @Override |
| 2677 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2678 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2679 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2680 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2681 | final long identity = Binder.clearCallingIdentity(); |
| 2682 | try { |
| 2683 | if (phone != null) { |
| 2684 | return phone.getVoiceActivationState(); |
| 2685 | } else { |
| 2686 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2687 | } |
| 2688 | } finally { |
| 2689 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2690 | } |
| 2691 | } |
| 2692 | |
| 2693 | /** |
| 2694 | * Returns the data activation state of a given subId. |
| 2695 | */ |
| 2696 | @Override |
| 2697 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2698 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2699 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2700 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2701 | final long identity = Binder.clearCallingIdentity(); |
| 2702 | try { |
| 2703 | if (phone != null) { |
| 2704 | return phone.getDataActivationState(); |
| 2705 | } else { |
| 2706 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2707 | } |
| 2708 | } finally { |
| 2709 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2710 | } |
| 2711 | } |
| 2712 | |
| 2713 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2714 | * Returns the unread count of voicemails for a subId |
| 2715 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2716 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2717 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2718 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2719 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2720 | return 0; |
| 2721 | } |
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(subId); |
| 2725 | if (phone != null) { |
| 2726 | return phone.getVoiceMessageCount(); |
| 2727 | } else { |
| 2728 | return 0; |
| 2729 | } |
| 2730 | } finally { |
| 2731 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2732 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2736 | * returns true, if the device is in a state where both voice and data |
| 2737 | * are supported simultaneously. This can change based on location or network condition. |
| 2738 | */ |
| 2739 | @Override |
| 2740 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2741 | final long identity = Binder.clearCallingIdentity(); |
| 2742 | try { |
| 2743 | final Phone phone = getPhone(subId); |
| 2744 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2745 | } finally { |
| 2746 | Binder.restoreCallingIdentity(identity); |
| 2747 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2748 | } |
| 2749 | |
| 2750 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2751 | * Send the dialer code if called from the current default dialer or the caller has |
| 2752 | * carrier privilege. |
| 2753 | * @param inputCode The dialer code to send |
| 2754 | */ |
| 2755 | @Override |
| 2756 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2757 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2758 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2759 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2760 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2761 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2762 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2763 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2764 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2765 | |
| 2766 | final long identity = Binder.clearCallingIdentity(); |
| 2767 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2768 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2769 | } finally { |
| 2770 | Binder.restoreCallingIdentity(identity); |
| 2771 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2772 | } |
| 2773 | |
| 2774 | /** |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2775 | * Returns the data network type. |
| 2776 | * Legacy call, permission-free. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2777 | * |
| 2778 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 2779 | */ |
| 2780 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2781 | public int getNetworkType() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2782 | final long identity = Binder.clearCallingIdentity(); |
| 2783 | try { |
| 2784 | final Phone phone = getPhone(getDefaultSubscription()); |
| 2785 | if (phone != null) { |
| 2786 | return phone.getServiceState().getDataNetworkType(); |
| 2787 | } else { |
| 2788 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2789 | } |
| 2790 | } finally { |
| 2791 | Binder.restoreCallingIdentity(identity); |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2792 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2793 | } |
| 2794 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2795 | @Override |
| 2796 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2797 | if (!isActiveSubscription(subId)) { |
| 2798 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2799 | } |
| 2800 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2801 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2802 | } |
| 2803 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2804 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2805 | public boolean isInEmergencySmsMode() { |
| 2806 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 2807 | final long identity = Binder.clearCallingIdentity(); |
| 2808 | try { |
| 2809 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2810 | if (phone.isInEmergencySmsMode()) { |
| 2811 | return true; |
| 2812 | } |
| 2813 | } |
| 2814 | } finally { |
| 2815 | Binder.restoreCallingIdentity(identity); |
| 2816 | } |
| 2817 | return false; |
| 2818 | } |
| 2819 | |
| 2820 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2821 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2822 | throws RemoteException { |
| 2823 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2824 | final long token = Binder.clearCallingIdentity(); |
| 2825 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2826 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2827 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2828 | .addRegistrationCallbackForSubscription(c, subId); |
| 2829 | } finally { |
| 2830 | Binder.restoreCallingIdentity(token); |
| 2831 | } |
| 2832 | } |
| 2833 | |
| 2834 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2835 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2836 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2837 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2838 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2839 | } |
| 2840 | Binder.withCleanCallingIdentity(() -> { |
| 2841 | try { |
| 2842 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2843 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2844 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2845 | } catch (IllegalArgumentException e) { |
| 2846 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2847 | + "is inactive, ignoring unregister."); |
| 2848 | // If the subscription is no longer active, just return, since the callback |
| 2849 | // will already have been removed internally. |
| 2850 | } |
| 2851 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2852 | } |
| 2853 | |
| 2854 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2855 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2856 | throws RemoteException { |
| 2857 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2858 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2859 | final long token = Binder.clearCallingIdentity(); |
| 2860 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2861 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2862 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2863 | } finally { |
| 2864 | Binder.restoreCallingIdentity(token); |
| 2865 | } |
| 2866 | } |
| 2867 | |
| 2868 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2869 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2870 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2871 | |
| 2872 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2873 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2874 | } |
| 2875 | Binder.withCleanCallingIdentity(() -> { |
| 2876 | try { |
| 2877 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2878 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2879 | .removeCapabilitiesCallbackForSubscription(c, subId); |
| 2880 | } catch (IllegalArgumentException e) { |
| 2881 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2882 | + "is inactive, ignoring unregister."); |
| 2883 | // If the subscription is no longer active, just return, since the callback |
| 2884 | // will already have been removed internally. |
| 2885 | } |
| 2886 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2887 | } |
| 2888 | |
| 2889 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2890 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2891 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2892 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2893 | final long token = Binder.clearCallingIdentity(); |
| 2894 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2895 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2896 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2897 | } catch (ImsException e) { |
| 2898 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2899 | return false; |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2900 | } catch (IllegalArgumentException e) { |
| 2901 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 2902 | return false; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2903 | } finally { |
| 2904 | Binder.restoreCallingIdentity(token); |
| 2905 | } |
| 2906 | } |
| 2907 | |
| 2908 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2909 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2910 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2911 | final long token = Binder.clearCallingIdentity(); |
| 2912 | try { |
| 2913 | Phone phone = getPhone(subId); |
| 2914 | if (phone == null) return false; |
| 2915 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2916 | } finally { |
| 2917 | Binder.restoreCallingIdentity(token); |
| 2918 | } |
| 2919 | } |
| 2920 | |
| 2921 | @Override |
| 2922 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2923 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2924 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2925 | final long token = Binder.clearCallingIdentity(); |
| 2926 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2927 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2928 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2929 | } finally { |
| 2930 | Binder.restoreCallingIdentity(token); |
| 2931 | } |
| 2932 | } |
| 2933 | |
| 2934 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2935 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2936 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2937 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2938 | final long identity = Binder.clearCallingIdentity(); |
| 2939 | try { |
| 2940 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2941 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2942 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 2943 | } finally { |
| 2944 | Binder.restoreCallingIdentity(identity); |
| 2945 | } |
| 2946 | } |
| 2947 | |
| 2948 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2949 | public boolean isVtSettingEnabled(int subId) { |
| 2950 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2951 | final long identity = Binder.clearCallingIdentity(); |
| 2952 | try { |
| 2953 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2954 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2955 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2956 | } finally { |
| 2957 | Binder.restoreCallingIdentity(identity); |
| 2958 | } |
| 2959 | } |
| 2960 | |
| 2961 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2962 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2963 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2964 | "setVtSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2965 | final long identity = Binder.clearCallingIdentity(); |
| 2966 | try { |
| 2967 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2968 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2969 | } finally { |
| 2970 | Binder.restoreCallingIdentity(identity); |
| 2971 | } |
| 2972 | } |
| 2973 | |
| 2974 | @Override |
| 2975 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 2976 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 2977 | final long identity = Binder.clearCallingIdentity(); |
| 2978 | try { |
| 2979 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2980 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2981 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 2982 | } finally { |
| 2983 | Binder.restoreCallingIdentity(identity); |
| 2984 | } |
| 2985 | } |
| 2986 | |
| 2987 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2988 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2989 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2990 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2991 | final long identity = Binder.clearCallingIdentity(); |
| 2992 | try { |
| 2993 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2994 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2995 | } finally { |
| 2996 | Binder.restoreCallingIdentity(identity); |
| 2997 | } |
| 2998 | } |
| 2999 | |
| 3000 | @Override |
| 3001 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 3002 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3003 | final long identity = Binder.clearCallingIdentity(); |
| 3004 | try { |
| 3005 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3006 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3007 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 3008 | } finally { |
| 3009 | Binder.restoreCallingIdentity(identity); |
| 3010 | } |
| 3011 | } |
| 3012 | |
| 3013 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3014 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3015 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3016 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3017 | final long identity = Binder.clearCallingIdentity(); |
| 3018 | try { |
| 3019 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3020 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3021 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 3022 | } finally { |
| 3023 | Binder.restoreCallingIdentity(identity); |
| 3024 | } |
| 3025 | } |
| 3026 | |
| 3027 | @Override |
| 3028 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3029 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3030 | "setVoWiFiNonPersistent"); |
| 3031 | final long identity = Binder.clearCallingIdentity(); |
| 3032 | try { |
| 3033 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 3034 | boolean isRoaming = TelephonyManager.from( |
| 3035 | getPhone(subId).getContext()).isNetworkRoaming(subId); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3036 | ImsManager.getInstance(mApp, |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 3037 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3038 | } finally { |
| 3039 | Binder.restoreCallingIdentity(identity); |
| 3040 | } |
| 3041 | } |
| 3042 | |
| 3043 | @Override |
| 3044 | public int getVoWiFiModeSetting(int subId) { |
| 3045 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3046 | final long identity = Binder.clearCallingIdentity(); |
| 3047 | try { |
| 3048 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3049 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3050 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 3051 | } finally { |
| 3052 | Binder.restoreCallingIdentity(identity); |
| 3053 | } |
| 3054 | } |
| 3055 | |
| 3056 | @Override |
| 3057 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3058 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3059 | "setVoWiFiModeSetting"); |
| 3060 | final long identity = Binder.clearCallingIdentity(); |
| 3061 | try { |
| 3062 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3063 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3064 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 3065 | } finally { |
| 3066 | Binder.restoreCallingIdentity(identity); |
| 3067 | } |
| 3068 | } |
| 3069 | |
| 3070 | @Override |
| 3071 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3072 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3073 | final long identity = Binder.clearCallingIdentity(); |
| 3074 | try { |
| 3075 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3076 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3077 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 3078 | } finally { |
| 3079 | Binder.restoreCallingIdentity(identity); |
| 3080 | } |
| 3081 | } |
| 3082 | |
| 3083 | @Override |
| 3084 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3085 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3086 | "setVoWiFiRoamingModeSetting"); |
| 3087 | final long identity = Binder.clearCallingIdentity(); |
| 3088 | try { |
| 3089 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3090 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3091 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 3092 | } finally { |
| 3093 | Binder.restoreCallingIdentity(identity); |
| 3094 | } |
| 3095 | } |
| 3096 | |
| 3097 | @Override |
| 3098 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3099 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3100 | "setRttCapabilityEnabled"); |
| 3101 | final long identity = Binder.clearCallingIdentity(); |
| 3102 | try { |
| 3103 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3104 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3105 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3106 | } finally { |
| 3107 | Binder.restoreCallingIdentity(identity); |
| 3108 | } |
| 3109 | } |
| 3110 | |
| 3111 | @Override |
| 3112 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3113 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3114 | final long identity = Binder.clearCallingIdentity(); |
| 3115 | try { |
| 3116 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3117 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3118 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 3119 | } finally { |
| 3120 | Binder.restoreCallingIdentity(identity); |
| 3121 | } |
| 3122 | } |
| 3123 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3124 | @Override |
| 3125 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3126 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3127 | final long identity = Binder.clearCallingIdentity(); |
| 3128 | try { |
| 3129 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3130 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3131 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3132 | } finally { |
| 3133 | Binder.restoreCallingIdentity(identity); |
| 3134 | } |
| 3135 | } |
| 3136 | |
| 3137 | @Override |
| 3138 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3139 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3140 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3141 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3142 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3143 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3144 | try { |
| 3145 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3146 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3147 | .removeProvisioningCallbackForSubscription(callback, subId); |
| 3148 | } catch (IllegalArgumentException e) { |
| 3149 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3150 | + "is inactive, ignoring unregister."); |
| 3151 | // If the subscription is no longer active, just return, since the callback will already |
| 3152 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3153 | } finally { |
| 3154 | Binder.restoreCallingIdentity(identity); |
| 3155 | } |
| 3156 | } |
| 3157 | |
| 3158 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3159 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3160 | boolean isProvisioned) { |
| 3161 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3162 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3163 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3164 | } |
| 3165 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3166 | "setProvisioningStatusForCapability"); |
| 3167 | final long identity = Binder.clearCallingIdentity(); |
| 3168 | try { |
| 3169 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3170 | Phone phone = getPhone(subId); |
| 3171 | if (phone == null) { |
| 3172 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3173 | + subId); |
| 3174 | return; |
| 3175 | } |
| 3176 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3177 | return; |
| 3178 | } |
| 3179 | |
| 3180 | // this capability requires provisioning, route to the correct API. |
| 3181 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3182 | switch (capability) { |
| 3183 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3184 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3185 | ims.setVolteProvisioned(isProvisioned); |
| 3186 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3187 | ims.setWfcProvisioned(isProvisioned); |
| 3188 | } |
| 3189 | break; |
| 3190 | } |
| 3191 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3192 | // There is currently no difference in VT provisioning type. |
| 3193 | ims.setVtProvisioned(isProvisioned); |
| 3194 | break; |
| 3195 | } |
| 3196 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3197 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3198 | // change the capability of the feature instead if needed. |
| 3199 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3200 | == isProvisioned) { |
| 3201 | // No change in provisioning. |
| 3202 | return; |
| 3203 | } |
| 3204 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3205 | try { |
| 3206 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
| 3207 | } catch (ImsException e) { |
| 3208 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3209 | + ", Exception" + e.getMessage()); |
| 3210 | } |
| 3211 | break; |
| 3212 | } |
| 3213 | default: { |
| 3214 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3215 | + capability + "', which does not require provisioning."); |
| 3216 | } |
| 3217 | } |
| 3218 | |
| 3219 | } finally { |
| 3220 | Binder.restoreCallingIdentity(identity); |
| 3221 | } |
| 3222 | } |
| 3223 | |
| 3224 | @Override |
| 3225 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3226 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3227 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3228 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3229 | } |
| 3230 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3231 | final long identity = Binder.clearCallingIdentity(); |
| 3232 | try { |
| 3233 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3234 | Phone phone = getPhone(subId); |
| 3235 | if (phone == null) { |
| 3236 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3237 | + subId); |
| 3238 | // We will fail with "true" as the provisioning status because this is the default |
| 3239 | // if we do not require provisioning. |
| 3240 | return true; |
| 3241 | } |
| 3242 | |
| 3243 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3244 | return true; |
| 3245 | } |
| 3246 | |
| 3247 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3248 | switch (capability) { |
| 3249 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3250 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3251 | return ims.isVolteProvisionedOnDevice(); |
| 3252 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3253 | return ims.isWfcProvisionedOnDevice(); |
| 3254 | } |
| 3255 | // This should never happen, since we are checking tech above to make sure it |
| 3256 | // is either LTE or IWLAN. |
| 3257 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3258 | + "capability."); |
| 3259 | } |
| 3260 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3261 | // There is currently no difference in VT provisioning type. |
| 3262 | return ims.isVtProvisionedOnDevice(); |
| 3263 | } |
| 3264 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3265 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3266 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3267 | } |
| 3268 | default: { |
| 3269 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3270 | + capability + "', which does not require provisioning."); |
| 3271 | } |
| 3272 | } |
| 3273 | |
| 3274 | } finally { |
| 3275 | Binder.restoreCallingIdentity(identity); |
| 3276 | } |
| 3277 | } |
| 3278 | |
| 3279 | @Override |
| 3280 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3281 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3282 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3283 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3284 | } |
| 3285 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3286 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3287 | return (provisionedBits & capability) > 0; |
| 3288 | } |
| 3289 | |
| 3290 | @Override |
| 3291 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3292 | boolean isProvisioned) { |
| 3293 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3294 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3295 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3296 | } |
| 3297 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3298 | "setProvisioningStatusForCapability"); |
| 3299 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3300 | // If the current provisioning status for capability already matches isProvisioned, |
| 3301 | // do nothing. |
| 3302 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3303 | return; |
| 3304 | } |
| 3305 | if (isProvisioned) { |
| 3306 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3307 | } else { |
| 3308 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3309 | } |
| 3310 | } |
| 3311 | |
| 3312 | /** |
| 3313 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3314 | * technology. The bitfield should mirror the bitfield defined by |
| 3315 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3316 | */ |
| 3317 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3318 | String key = getMmTelProvisioningKey(subId, tech); |
| 3319 | // Default is no capabilities are provisioned. |
| 3320 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3321 | } |
| 3322 | |
| 3323 | /** |
| 3324 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3325 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3326 | * technology specified. |
| 3327 | * |
| 3328 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3329 | */ |
| 3330 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3331 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3332 | String key = getMmTelProvisioningKey(subId, tech); |
| 3333 | editor.putInt(key, newField); |
| 3334 | editor.commit(); |
| 3335 | } |
| 3336 | |
| 3337 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3338 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3339 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3340 | } |
| 3341 | |
| 3342 | /** |
| 3343 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3344 | * carrier associated with the subscription id. |
| 3345 | */ |
| 3346 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3347 | int capability) { |
| 3348 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3349 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3350 | boolean requireUtProvisioning = c.getBoolean( |
| 3351 | // By default, this config is true (even if there is no SIM). We also check to make |
| 3352 | // sure the subscription needs provisioning here, so we do not need to check for |
| 3353 | // the no-SIM case, where we would normally shortcut this to false. |
| 3354 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true) |
| 3355 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3356 | false); |
| 3357 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3358 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3359 | |
| 3360 | // First check to make sure that the capability requires provisioning. |
| 3361 | switch (capability) { |
| 3362 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3363 | // intentional fallthrough |
| 3364 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3365 | if (requireVoiceVtProvisioning) { |
| 3366 | // Voice and Video requires provisioning |
| 3367 | return true; |
| 3368 | } |
| 3369 | break; |
| 3370 | } |
| 3371 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3372 | if (requireUtProvisioning) { |
| 3373 | // UT requires provisioning |
| 3374 | return true; |
| 3375 | } |
| 3376 | break; |
| 3377 | } |
| 3378 | } |
| 3379 | return false; |
| 3380 | } |
| 3381 | |
| 3382 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3383 | public int getImsProvisioningInt(int subId, int key) { |
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 | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3387 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3388 | final long identity = Binder.clearCallingIdentity(); |
| 3389 | try { |
| 3390 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3391 | int slotId = getSlotIndex(subId); |
| 3392 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3393 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3394 | + subId + "' for key:" + key); |
| 3395 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3396 | } |
| 3397 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3398 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3399 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3400 | + subId + "' for key:" + key); |
| 3401 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3402 | } finally { |
| 3403 | Binder.restoreCallingIdentity(identity); |
| 3404 | } |
| 3405 | } |
| 3406 | |
| 3407 | @Override |
| 3408 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3409 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3410 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3411 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3412 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3413 | final long identity = Binder.clearCallingIdentity(); |
| 3414 | try { |
| 3415 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3416 | int slotId = getSlotIndex(subId); |
| 3417 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3418 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3419 | + subId + "' for key:" + key); |
| 3420 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3421 | } |
| 3422 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3423 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3424 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3425 | + subId + "' for key:" + key); |
| 3426 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3427 | } finally { |
| 3428 | Binder.restoreCallingIdentity(identity); |
| 3429 | } |
| 3430 | } |
| 3431 | |
| 3432 | @Override |
| 3433 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3434 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3435 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3436 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3437 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3438 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3439 | final long identity = Binder.clearCallingIdentity(); |
| 3440 | try { |
| 3441 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3442 | int slotId = getSlotIndex(subId); |
| 3443 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3444 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3445 | + subId + "' for key:" + key); |
| 3446 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3447 | } |
| 3448 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3449 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3450 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3451 | + "' for key:" + key); |
| 3452 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3453 | } finally { |
| 3454 | Binder.restoreCallingIdentity(identity); |
| 3455 | } |
| 3456 | } |
| 3457 | |
| 3458 | @Override |
| 3459 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3460 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3461 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3462 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3463 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3464 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3465 | final long identity = Binder.clearCallingIdentity(); |
| 3466 | try { |
| 3467 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3468 | int slotId = getSlotIndex(subId); |
| 3469 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3470 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3471 | + subId + "' for key:" + key); |
| 3472 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3473 | } |
| 3474 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3475 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3476 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3477 | + "' for key:" + key); |
| 3478 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3479 | } finally { |
| 3480 | Binder.restoreCallingIdentity(identity); |
| 3481 | } |
| 3482 | } |
| 3483 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3484 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 3485 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3486 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3487 | throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3488 | } |
| 3489 | return slotId; |
| 3490 | } |
| 3491 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3492 | private int getSlotIndex(int subId) { |
| 3493 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3494 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3495 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3496 | } |
| 3497 | return slotId; |
| 3498 | } |
| 3499 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3500 | /** |
| 3501 | * Returns the network type for a subId |
| 3502 | */ |
| 3503 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3504 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3505 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3506 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3507 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3508 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3509 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3510 | final long identity = Binder.clearCallingIdentity(); |
| 3511 | try { |
| 3512 | final Phone phone = getPhone(subId); |
| 3513 | if (phone != null) { |
| 3514 | return phone.getServiceState().getDataNetworkType(); |
| 3515 | } else { |
| 3516 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3517 | } |
| 3518 | } finally { |
| 3519 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3520 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3521 | } |
| 3522 | |
| 3523 | /** |
| 3524 | * Returns the data network type |
| 3525 | */ |
| 3526 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3527 | public int getDataNetworkType(String callingPackage) { |
| 3528 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3529 | } |
| 3530 | |
| 3531 | /** |
| 3532 | * Returns the data network type for a subId |
| 3533 | */ |
| 3534 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3535 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3536 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3537 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3538 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3539 | } |
| 3540 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3541 | final long identity = Binder.clearCallingIdentity(); |
| 3542 | try { |
| 3543 | final Phone phone = getPhone(subId); |
| 3544 | if (phone != null) { |
| 3545 | return phone.getServiceState().getDataNetworkType(); |
| 3546 | } else { |
| 3547 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3548 | } |
| 3549 | } finally { |
| 3550 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3551 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3552 | } |
| 3553 | |
| 3554 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3555 | * Returns the Voice network type for a subId |
| 3556 | */ |
| 3557 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3558 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3559 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3560 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3561 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3562 | } |
| 3563 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3564 | final long identity = Binder.clearCallingIdentity(); |
| 3565 | try { |
| 3566 | final Phone phone = getPhone(subId); |
| 3567 | if (phone != null) { |
| 3568 | return phone.getServiceState().getVoiceNetworkType(); |
| 3569 | } else { |
| 3570 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3571 | } |
| 3572 | } finally { |
| 3573 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3574 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3575 | } |
| 3576 | |
| 3577 | /** |
| 3578 | * @return true if a ICC card is present |
| 3579 | */ |
| 3580 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3581 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3582 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3583 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3584 | } |
| 3585 | |
| 3586 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3587 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3588 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3589 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3590 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3591 | final long identity = Binder.clearCallingIdentity(); |
| 3592 | try { |
| 3593 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3594 | if (phone != null) { |
| 3595 | return phone.getIccCard().hasIccCard(); |
| 3596 | } else { |
| 3597 | return false; |
| 3598 | } |
| 3599 | } finally { |
| 3600 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3601 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3602 | } |
| 3603 | |
| 3604 | /** |
| 3605 | * Return if the current radio is LTE on CDMA. This |
| 3606 | * is a tri-state return value as for a period of time |
| 3607 | * the mode may be unknown. |
| 3608 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3609 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3610 | * @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] | 3611 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3612 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3613 | @Override |
| 3614 | public int getLteOnCdmaMode(String callingPackage) { |
| 3615 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3616 | } |
| 3617 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3618 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3619 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3620 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3621 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3622 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3623 | } |
| 3624 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3625 | final long identity = Binder.clearCallingIdentity(); |
| 3626 | try { |
| 3627 | final Phone phone = getPhone(subId); |
| 3628 | if (phone == null) { |
| 3629 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3630 | } else { |
| 3631 | return phone.getLteOnCdmaMode(); |
| 3632 | } |
| 3633 | } finally { |
| 3634 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3635 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3636 | } |
| 3637 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3638 | /** |
| 3639 | * {@hide} |
| 3640 | * Returns Default subId, 0 in the case of single standby. |
| 3641 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3642 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3643 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3644 | } |
| 3645 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3646 | private int getSlotForDefaultSubscription() { |
| 3647 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3648 | } |
| 3649 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3650 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3651 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3652 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3653 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3654 | private boolean isActiveSubscription(int subId) { |
| 3655 | return mSubscriptionController.isActiveSubId(subId); |
| 3656 | } |
| 3657 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3658 | /** |
| 3659 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3660 | */ |
| 3661 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3662 | final long identity = Binder.clearCallingIdentity(); |
| 3663 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3664 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3665 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3666 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3667 | } finally { |
| 3668 | Binder.restoreCallingIdentity(identity); |
| 3669 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3670 | } |
| 3671 | |
| 3672 | /** |
| 3673 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3674 | */ |
| 3675 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3676 | final long identity = Binder.clearCallingIdentity(); |
| 3677 | try { |
| 3678 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3679 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3680 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3681 | } finally { |
| 3682 | Binder.restoreCallingIdentity(identity); |
| 3683 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3684 | } |
| 3685 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3686 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3687 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3688 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3689 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3690 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3691 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 3692 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 3693 | if (phoneId == -1) { |
| 3694 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 3695 | + " does not correspond to an active phone"); |
| 3696 | } |
| 3697 | return PhoneFactory.getPhone(phoneId); |
| 3698 | } |
| 3699 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3700 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3701 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3702 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3703 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3704 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3705 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3706 | if (DBG) { |
| 3707 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3708 | } |
| 3709 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 3710 | p2); |
| 3711 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3712 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3713 | |
| 3714 | @Override |
| 3715 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 3716 | int slotIndex, String callingPackage, String aid, int p2) { |
| 3717 | enforceModifyPermission(); |
| 3718 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3719 | if (DBG) { |
| 3720 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 3721 | } |
| 3722 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3723 | callingPackage, aid, p2); |
| 3724 | } |
| 3725 | |
| 3726 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 3727 | String callingPackage, String aid, int p2) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3728 | final long identity = Binder.clearCallingIdentity(); |
| 3729 | try { |
| 3730 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3731 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3732 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3733 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3734 | if (bestComponent == null |
| 3735 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3736 | loge("The calling package is not allowed to access ISD-R."); |
| 3737 | throw new SecurityException( |
| 3738 | "The calling package is not allowed to access ISD-R."); |
| 3739 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3740 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3741 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3742 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3743 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 3744 | null /* workSource */); |
| 3745 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3746 | return response; |
| 3747 | } finally { |
| 3748 | Binder.restoreCallingIdentity(identity); |
| 3749 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3750 | } |
| 3751 | |
| 3752 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3753 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3754 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3755 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3756 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3757 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 3758 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3759 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3760 | @Override |
| 3761 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 3762 | enforceModifyPermission(); |
| 3763 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 3764 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3765 | channel); |
| 3766 | } |
| 3767 | |
| 3768 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3769 | final long identity = Binder.clearCallingIdentity(); |
| 3770 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3771 | if (channel < 0) { |
| 3772 | return false; |
| 3773 | } |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3774 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 3775 | null /* workSource */); |
| 3776 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3777 | return success; |
| 3778 | } finally { |
| 3779 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3780 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3781 | } |
| 3782 | |
| 3783 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3784 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3785 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3786 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3787 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3788 | if (DBG) { |
| 3789 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3790 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3791 | + p3 + " data=" + data); |
| 3792 | } |
| 3793 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 3794 | command, p1, p2, p3, data); |
| 3795 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3796 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3797 | @Override |
| 3798 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 3799 | int command, int p1, int p2, int p3, String data) { |
| 3800 | enforceModifyPermission(); |
| 3801 | if (DBG) { |
| 3802 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 3803 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3804 | + p3 + " data=" + data); |
| 3805 | } |
| 3806 | return iccTransmitApduLogicalChannelWithPermission( |
| 3807 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 3808 | data); |
| 3809 | } |
| 3810 | |
| 3811 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 3812 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3813 | final long identity = Binder.clearCallingIdentity(); |
| 3814 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3815 | if (channel < 0) { |
| 3816 | return ""; |
| 3817 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3818 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3819 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3820 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 3821 | null /* workSource */); |
| 3822 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3823 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3824 | // Append the returned status code to the end of the response payload. |
| 3825 | String s = Integer.toHexString( |
| 3826 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3827 | if (response.payload != null) { |
| 3828 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3829 | } |
| 3830 | return s; |
| 3831 | } finally { |
| 3832 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3833 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3834 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3835 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3836 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3837 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3838 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3839 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3840 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3841 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3842 | if (DBG) { |
| 3843 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3844 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3845 | } |
| 3846 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 3847 | cla, command, p1, p2, p3, data); |
| 3848 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3849 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3850 | @Override |
| 3851 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 3852 | int command, int p1, int p2, int p3, String data) { |
| 3853 | enforceModifyPermission(); |
| 3854 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3855 | if (DBG) { |
| 3856 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 3857 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 3858 | + " data=" + data); |
| 3859 | } |
| 3860 | |
| 3861 | return iccTransmitApduBasicChannelWithPermission( |
| 3862 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 3863 | p2, p3, data); |
| 3864 | } |
| 3865 | |
| 3866 | // open APDU basic channel assuming the caller has sufficient permissions |
| 3867 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 3868 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3869 | final long identity = Binder.clearCallingIdentity(); |
| 3870 | try { |
| 3871 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3872 | && TextUtils.equals(ISDR_AID, data)) { |
| 3873 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3874 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3875 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3876 | if (bestComponent == null |
| 3877 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3878 | loge("The calling package is not allowed to select ISD-R."); |
| 3879 | throw new SecurityException( |
| 3880 | "The calling package is not allowed to select ISD-R."); |
| 3881 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3882 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3883 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3884 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3885 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 3886 | null /* workSource */); |
| 3887 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3888 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3889 | // Append the returned status code to the end of the response payload. |
| 3890 | String s = Integer.toHexString( |
| 3891 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3892 | if (response.payload != null) { |
| 3893 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3894 | } |
| 3895 | return s; |
| 3896 | } finally { |
| 3897 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3898 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3899 | } |
| 3900 | |
| 3901 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3902 | 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] | 3903 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3904 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3905 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3906 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3907 | final long identity = Binder.clearCallingIdentity(); |
| 3908 | try { |
| 3909 | if (DBG) { |
| 3910 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3911 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3912 | } |
| 3913 | |
| 3914 | IccIoResult response = |
| 3915 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3916 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3917 | subId); |
| 3918 | |
| 3919 | if (DBG) { |
| 3920 | log("Exchange SIM_IO [R]" + response); |
| 3921 | } |
| 3922 | |
| 3923 | byte[] result = null; |
| 3924 | int length = 2; |
| 3925 | if (response.payload != null) { |
| 3926 | length = 2 + response.payload.length; |
| 3927 | result = new byte[length]; |
| 3928 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3929 | } else { |
| 3930 | result = new byte[length]; |
| 3931 | } |
| 3932 | |
| 3933 | result[length - 1] = (byte) response.sw2; |
| 3934 | result[length - 2] = (byte) response.sw1; |
| 3935 | return result; |
| 3936 | } finally { |
| 3937 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3938 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3939 | } |
| 3940 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3941 | /** |
| 3942 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 3943 | * on a particular subscription |
| 3944 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3945 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 3946 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3947 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 3948 | return null; |
| 3949 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3950 | |
| 3951 | final long identity = Binder.clearCallingIdentity(); |
| 3952 | try { |
| 3953 | if (appType != TelephonyManager.APPTYPE_USIM |
| 3954 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 3955 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 3956 | return null; |
| 3957 | } |
| 3958 | Object response = sendRequest( |
| 3959 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 3960 | if (response instanceof String[]) { |
| 3961 | return (String[]) response; |
| 3962 | } |
| 3963 | // Response is an Exception of some kind, |
| 3964 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3965 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3966 | } finally { |
| 3967 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3968 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3969 | } |
| 3970 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3971 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3972 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3973 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3974 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3975 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3976 | final long identity = Binder.clearCallingIdentity(); |
| 3977 | try { |
| 3978 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 3979 | if (response.payload == null) { |
| 3980 | return ""; |
| 3981 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3982 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3983 | // Append the returned status code to the end of the response payload. |
| 3984 | String s = Integer.toHexString( |
| 3985 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3986 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3987 | return s; |
| 3988 | } finally { |
| 3989 | Binder.restoreCallingIdentity(identity); |
| 3990 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3991 | } |
| 3992 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3993 | /** |
| 3994 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3995 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3996 | * |
| 3997 | * @param itemID the ID of the item to read |
| 3998 | * @return the NV item as a String, or null on error. |
| 3999 | */ |
| 4000 | @Override |
| 4001 | public String nvReadItem(int itemID) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4002 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4003 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4004 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4005 | |
| 4006 | final long identity = Binder.clearCallingIdentity(); |
| 4007 | try { |
| 4008 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4009 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4010 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4011 | return value; |
| 4012 | } finally { |
| 4013 | Binder.restoreCallingIdentity(identity); |
| 4014 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4015 | } |
| 4016 | |
| 4017 | /** |
| 4018 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4019 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4020 | * |
| 4021 | * @param itemID the ID of the item to read |
| 4022 | * @param itemValue the value to write, as a String |
| 4023 | * @return true on success; false on any failure |
| 4024 | */ |
| 4025 | @Override |
| 4026 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4027 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4028 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4029 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4030 | |
| 4031 | final long identity = Binder.clearCallingIdentity(); |
| 4032 | try { |
| 4033 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4034 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4035 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4036 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4037 | return success; |
| 4038 | } finally { |
| 4039 | Binder.restoreCallingIdentity(identity); |
| 4040 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4041 | } |
| 4042 | |
| 4043 | /** |
| 4044 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4045 | * Used for device configuration by some CDMA operators. |
| 4046 | * |
| 4047 | * @param preferredRoamingList byte array containing the new PRL |
| 4048 | * @return true on success; false on any failure |
| 4049 | */ |
| 4050 | @Override |
| 4051 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4052 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4053 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4054 | |
| 4055 | final long identity = Binder.clearCallingIdentity(); |
| 4056 | try { |
| 4057 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4058 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4059 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4060 | return success; |
| 4061 | } finally { |
| 4062 | Binder.restoreCallingIdentity(identity); |
| 4063 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4064 | } |
| 4065 | |
| 4066 | /** |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4067 | * 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] | 4068 | * Used for device configuration by some CDMA operators. |
| 4069 | * |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4070 | * @param slotIndex - device slot. |
| 4071 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4072 | * @return true on success; false on any failure |
| 4073 | */ |
| 4074 | @Override |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4075 | public boolean resetModemConfig(int slotIndex) { |
| 4076 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4077 | if (phone != null) { |
| 4078 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4079 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4080 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4081 | final long identity = Binder.clearCallingIdentity(); |
| 4082 | try { |
| 4083 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4084 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4085 | return success; |
| 4086 | } finally { |
| 4087 | Binder.restoreCallingIdentity(identity); |
| 4088 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4089 | } |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4090 | return false; |
| 4091 | } |
| 4092 | |
| 4093 | /** |
| 4094 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4095 | * |
| 4096 | * @param slotIndex - device slot. |
| 4097 | * |
| 4098 | * @return true on success; false on any failure |
| 4099 | */ |
| 4100 | @Override |
| 4101 | public boolean rebootModem(int slotIndex) { |
| 4102 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4103 | if (phone != null) { |
| 4104 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4105 | mApp, phone.getSubId(), "rebootModem"); |
| 4106 | |
| 4107 | final long identity = Binder.clearCallingIdentity(); |
| 4108 | try { |
| 4109 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4110 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4111 | return success; |
| 4112 | } finally { |
| 4113 | Binder.restoreCallingIdentity(identity); |
| 4114 | } |
| 4115 | } |
| 4116 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4117 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4118 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4119 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4120 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4121 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4122 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4123 | return new String[0]; |
| 4124 | } |
| 4125 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4126 | final long identity = Binder.clearCallingIdentity(); |
| 4127 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4128 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4129 | } finally { |
| 4130 | Binder.restoreCallingIdentity(identity); |
| 4131 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4132 | } |
| 4133 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4134 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4135 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4136 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4137 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4138 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4139 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4140 | |
| 4141 | final long identity = Binder.clearCallingIdentity(); |
| 4142 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4143 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4144 | if (resolver == null) { |
| 4145 | // may happen if the device does not support IMS. |
| 4146 | return; |
| 4147 | } |
| 4148 | resolver.enableIms(slotId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4149 | } finally { |
| 4150 | Binder.restoreCallingIdentity(identity); |
| 4151 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4152 | } |
| 4153 | |
| 4154 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4155 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4156 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4157 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4158 | public void disableIms(int slotId) { |
| 4159 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4160 | |
| 4161 | final long identity = Binder.clearCallingIdentity(); |
| 4162 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4163 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4164 | if (resolver == null) { |
| 4165 | // may happen if the device does not support IMS. |
| 4166 | return; |
| 4167 | } |
| 4168 | resolver.disableIms(slotId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4169 | } finally { |
| 4170 | Binder.restoreCallingIdentity(identity); |
| 4171 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4172 | } |
| 4173 | |
| 4174 | /** |
| 4175 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4176 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4177 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4178 | */ |
| 4179 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4180 | IImsServiceFeatureCallback callback) { |
| 4181 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4182 | |
| 4183 | final long identity = Binder.clearCallingIdentity(); |
| 4184 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4185 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4186 | if (resolver == null) { |
| 4187 | // may happen if the device does not support IMS. |
| 4188 | return null; |
| 4189 | } |
| 4190 | return resolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4191 | } finally { |
| 4192 | Binder.restoreCallingIdentity(identity); |
| 4193 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4194 | } |
| 4195 | |
| 4196 | /** |
| 4197 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4198 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4199 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4200 | * listener for feature updates. |
| 4201 | */ |
| 4202 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4203 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4204 | |
| 4205 | final long identity = Binder.clearCallingIdentity(); |
| 4206 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4207 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4208 | if (resolver == null) { |
| 4209 | // may happen if the device does not support IMS. |
| 4210 | return null; |
| 4211 | } |
| 4212 | return resolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4213 | } finally { |
| 4214 | Binder.restoreCallingIdentity(identity); |
| 4215 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4216 | } |
| 4217 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4218 | /** |
| 4219 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4220 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4221 | */ |
| 4222 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4223 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4224 | |
| 4225 | final long identity = Binder.clearCallingIdentity(); |
| 4226 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4227 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4228 | if (resolver == null) { |
| 4229 | // may happen if the device does not support IMS. |
| 4230 | return null; |
| 4231 | } |
| 4232 | return resolver.getImsRegistration(slotId, feature); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4233 | } finally { |
| 4234 | Binder.restoreCallingIdentity(identity); |
| 4235 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4236 | } |
| 4237 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4238 | /** |
| 4239 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4240 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4241 | */ |
| 4242 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4243 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4244 | |
| 4245 | final long identity = Binder.clearCallingIdentity(); |
| 4246 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4247 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4248 | if (resolver == null) { |
| 4249 | // may happen if the device does not support IMS. |
| 4250 | return null; |
| 4251 | } |
| 4252 | return resolver.getImsConfig(slotId, feature); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4253 | } finally { |
| 4254 | Binder.restoreCallingIdentity(identity); |
| 4255 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4256 | } |
| 4257 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4258 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4259 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4260 | * |
| 4261 | * @param slotId the slot ID that the ImsService should bind for. |
| 4262 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4263 | * ImsService is the device default ImsService. |
| 4264 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4265 | * to. |
| 4266 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4267 | * @hide |
| 4268 | */ |
| 4269 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4270 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4271 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4272 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4273 | "setImsService"); |
| 4274 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4275 | final long identity = Binder.clearCallingIdentity(); |
| 4276 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4277 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4278 | if (resolver == null) { |
| 4279 | // may happen if the device does not support IMS. |
| 4280 | return false; |
| 4281 | } |
| 4282 | return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService, |
| 4283 | packageName); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4284 | } finally { |
| 4285 | Binder.restoreCallingIdentity(identity); |
| 4286 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4287 | } |
| 4288 | |
| 4289 | /** |
| 4290 | * Return the ImsService configuration. |
| 4291 | * |
| 4292 | * @param slotId The slot that the ImsService is associated with. |
| 4293 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4294 | * the device default. |
| 4295 | * @return the package name of the ImsService configuration. |
| 4296 | */ |
| 4297 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4298 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4299 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4300 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4301 | "getImsService"); |
| 4302 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4303 | final long identity = Binder.clearCallingIdentity(); |
| 4304 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4305 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4306 | if (resolver == null) { |
| 4307 | // may happen if the device does not support IMS. |
| 4308 | return ""; |
| 4309 | } |
| 4310 | return resolver.getImsServiceConfiguration(slotId, isCarrierImsService); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4311 | } finally { |
| 4312 | Binder.restoreCallingIdentity(identity); |
| 4313 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4314 | } |
| 4315 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4316 | public void setImsRegistrationState(boolean registered) { |
| 4317 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4318 | |
| 4319 | final long identity = Binder.clearCallingIdentity(); |
| 4320 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4321 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4322 | } finally { |
| 4323 | Binder.restoreCallingIdentity(identity); |
| 4324 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4325 | } |
| 4326 | |
| 4327 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4328 | * Set the network selection mode to automatic. |
| 4329 | * |
| 4330 | */ |
| 4331 | @Override |
| 4332 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4333 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4334 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4335 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4336 | if (!isActiveSubscription(subId)) { |
| 4337 | return; |
| 4338 | } |
| 4339 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4340 | final long identity = Binder.clearCallingIdentity(); |
| 4341 | try { |
| 4342 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4343 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4344 | } finally { |
| 4345 | Binder.restoreCallingIdentity(identity); |
| 4346 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4347 | } |
| 4348 | |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4349 | /** |
| 4350 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4351 | * |
| 4352 | * @param subId the id of the subscription. |
| 4353 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4354 | * the operator to attach to. |
| 4355 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4356 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4357 | * normal network selection next time. |
| 4358 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4359 | */ |
| 4360 | @Override |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4361 | public boolean setNetworkSelectionModeManual( |
| 4362 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4363 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4364 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4365 | |
| 4366 | if (!isActiveSubscription(subId)) { |
| 4367 | return false; |
| 4368 | } |
| 4369 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4370 | final long identity = Binder.clearCallingIdentity(); |
| 4371 | try { |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4372 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4373 | persistSelection); |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4374 | if (DBG) { |
| 4375 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4376 | + " operator: " + operatorInfo); |
| 4377 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4378 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4379 | } finally { |
| 4380 | Binder.restoreCallingIdentity(identity); |
| 4381 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4382 | } |
| 4383 | |
| 4384 | /** |
| 4385 | * Scans for available networks. |
| 4386 | */ |
| 4387 | @Override |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4388 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4389 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4390 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4391 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4392 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4393 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4394 | .setCallingPackage(callingPackage) |
| 4395 | .setCallingPid(Binder.getCallingPid()) |
| 4396 | .setCallingUid(Binder.getCallingUid()) |
| 4397 | .setMethod("getCellNetworkScanResults") |
| 4398 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4399 | .build()); |
| 4400 | switch (locationResult) { |
| 4401 | case DENIED_HARD: |
| 4402 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4403 | case DENIED_SOFT: |
| 4404 | return null; |
| 4405 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4406 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4407 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4408 | try { |
| 4409 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4410 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4411 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4412 | } finally { |
| 4413 | Binder.restoreCallingIdentity(identity); |
| 4414 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4415 | } |
| 4416 | |
| 4417 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4418 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4419 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4420 | * @param subId id of the subscription |
| 4421 | * @param request contains the radio access networks with bands/channels to scan |
| 4422 | * @param messenger callback messenger for scan results or errors |
| 4423 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4424 | * @return the id of the requested scan which can be used to stop the scan. |
| 4425 | */ |
| 4426 | @Override |
| 4427 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4428 | IBinder binder, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4429 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4430 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4431 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4432 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4433 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4434 | .setCallingPackage(callingPackage) |
| 4435 | .setCallingPid(Binder.getCallingPid()) |
| 4436 | .setCallingUid(Binder.getCallingUid()) |
| 4437 | .setMethod("requestNetworkScan") |
| 4438 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4439 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4440 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
| 4441 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request); |
| 4442 | if (e != null) { |
| 4443 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 4444 | throw e; |
| 4445 | } else { |
Hall Liu | 46dd96a | 2019-04-03 12:50:44 -0700 | [diff] [blame] | 4446 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4447 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 4448 | } |
| 4449 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4450 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4451 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4452 | request, messenger, binder, getPhone(subId), |
| 4453 | callingPackage); |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4454 | } |
| 4455 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4456 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
| 4457 | NetworkScanRequest request) { |
| 4458 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 4459 | != PERMISSION_GRANTED) { |
| 4460 | return new SecurityException("permission.NETWORK_SCAN is needed for network scans" |
| 4461 | + " without location access."); |
| 4462 | } |
| 4463 | |
| 4464 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 4465 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4466 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 4467 | return new SecurityException("Specific channels must not be" |
| 4468 | + " scanned without location access."); |
| 4469 | } |
| 4470 | } |
| 4471 | } |
| 4472 | |
| 4473 | List<String> allowedMccMncs = |
| 4474 | NetworkScanRequestTracker.getAllowedMccMncsForLocationRestrictedScan(mApp); |
| 4475 | for (String mccmnc : request.getPlmns()) { |
| 4476 | if (!allowedMccMncs.contains(mccmnc)) { |
| 4477 | return new SecurityException("Requested mccmnc " + mccmnc + " is not known to the" |
| 4478 | + " device and cannot be scanned for without location access."); |
| 4479 | } |
| 4480 | } |
| 4481 | |
| 4482 | return null; |
| 4483 | } |
| 4484 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4485 | /** |
| 4486 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4487 | * |
| 4488 | * @param subId id of the subscription |
| 4489 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4490 | */ |
| 4491 | @Override |
| 4492 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4493 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4494 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4495 | |
| 4496 | final long identity = Binder.clearCallingIdentity(); |
| 4497 | try { |
| 4498 | mNetworkScanRequestTracker.stopNetworkScan(scanId); |
| 4499 | } finally { |
| 4500 | Binder.restoreCallingIdentity(identity); |
| 4501 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4502 | } |
| 4503 | |
| 4504 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4505 | * Get the calculated preferred network type. |
| 4506 | * Used for debugging incorrect network type. |
| 4507 | * |
| 4508 | * @return the preferred network type, defined in RILConstants.java. |
| 4509 | */ |
| 4510 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4511 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4512 | final Phone defaultPhone = getDefaultPhone(); |
| 4513 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4514 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4515 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4516 | } |
| 4517 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4518 | final long identity = Binder.clearCallingIdentity(); |
| 4519 | try { |
| 4520 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4521 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4522 | } finally { |
| 4523 | Binder.restoreCallingIdentity(identity); |
| 4524 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4525 | } |
| 4526 | |
| 4527 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4528 | * Get the preferred network type. |
| 4529 | * Used for device configuration by some CDMA operators. |
| 4530 | * |
| 4531 | * @return the preferred network type, defined in RILConstants.java. |
| 4532 | */ |
| 4533 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4534 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | 4848cd0 | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4535 | TelephonyPermissions |
| 4536 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4537 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4538 | |
| 4539 | final long identity = Binder.clearCallingIdentity(); |
| 4540 | try { |
| 4541 | if (DBG) log("getPreferredNetworkType"); |
| 4542 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4543 | int networkType = (result != null ? result[0] : -1); |
| 4544 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4545 | return networkType; |
| 4546 | } finally { |
| 4547 | Binder.restoreCallingIdentity(identity); |
| 4548 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4549 | } |
| 4550 | |
| 4551 | /** |
| 4552 | * Set the preferred network type. |
| 4553 | * Used for device configuration by some CDMA operators. |
| 4554 | * |
| 4555 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4556 | * @return true on success; false on any failure. |
| 4557 | */ |
| 4558 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4559 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4560 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4561 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4562 | |
| 4563 | final long identity = Binder.clearCallingIdentity(); |
| 4564 | try { |
| 4565 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4566 | Boolean success = (Boolean) sendRequest( |
| 4567 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4568 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4569 | if (success) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4570 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4571 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4572 | } |
| 4573 | return success; |
| 4574 | } finally { |
| 4575 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4576 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4577 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4578 | |
| 4579 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4580 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4581 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4582 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4583 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4584 | * @hide |
| 4585 | */ |
| 4586 | @Override |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4587 | public boolean getTetherApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4588 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4589 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4590 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4591 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4592 | if (phone != null) { |
| 4593 | return phone.hasMatchedTetherApnSetting(); |
| 4594 | } else { |
| 4595 | return false; |
| 4596 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4597 | } finally { |
| 4598 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4599 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4603 | * Set mobile data enabled |
| 4604 | * Used by the user through settings etc to turn on/off mobile data |
| 4605 | * |
| 4606 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4607 | */ |
| 4608 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4609 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4610 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4611 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4612 | |
| 4613 | final long identity = Binder.clearCallingIdentity(); |
| 4614 | try { |
| 4615 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4616 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4617 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4618 | if (phone != null) { |
| 4619 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4620 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4621 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4622 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4623 | } |
| 4624 | } finally { |
| 4625 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4626 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4627 | } |
| 4628 | |
| 4629 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4630 | * Get the user enabled state of Mobile Data. |
| 4631 | * |
| 4632 | * TODO: remove and use isUserDataEnabled. |
| 4633 | * This can't be removed now because some vendor codes |
| 4634 | * calls through ITelephony directly while they should |
| 4635 | * use TelephonyManager. |
| 4636 | * |
| 4637 | * @return true on enabled |
| 4638 | */ |
| 4639 | @Override |
| 4640 | public boolean getDataEnabled(int subId) { |
| 4641 | return isUserDataEnabled(subId); |
| 4642 | } |
| 4643 | |
| 4644 | /** |
| 4645 | * Get whether mobile data is enabled per user setting. |
| 4646 | * |
| 4647 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4648 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4649 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4650 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4651 | * |
| 4652 | * @return {@code true} if data is enabled else {@code false} |
| 4653 | */ |
| 4654 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4655 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4656 | try { |
| 4657 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4658 | null); |
| 4659 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4660 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4661 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4662 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4663 | |
| 4664 | final long identity = Binder.clearCallingIdentity(); |
| 4665 | try { |
| 4666 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4667 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4668 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4669 | if (phone != null) { |
| 4670 | boolean retVal = phone.isUserDataEnabled(); |
| 4671 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4672 | return retVal; |
| 4673 | } else { |
| 4674 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4675 | return false; |
| 4676 | } |
| 4677 | } finally { |
| 4678 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4679 | } |
| 4680 | } |
| 4681 | |
| 4682 | /** |
| 4683 | * Get whether mobile data is enabled. |
| 4684 | * |
| 4685 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4686 | * whether mobile data is actually enabled. |
| 4687 | * |
| 4688 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4689 | * |
| 4690 | * @return {@code true} if data is enabled else {@code false} |
| 4691 | */ |
| 4692 | @Override |
| 4693 | public boolean isDataEnabled(int subId) { |
| 4694 | try { |
| 4695 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4696 | null); |
| 4697 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4698 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4699 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4700 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4701 | |
| 4702 | final long identity = Binder.clearCallingIdentity(); |
| 4703 | try { |
| 4704 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4705 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4706 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4707 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4708 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4709 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4710 | return retVal; |
| 4711 | } else { |
| 4712 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4713 | return false; |
| 4714 | } |
| 4715 | } finally { |
| 4716 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4717 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4718 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4719 | |
| 4720 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4721 | public int getCarrierPrivilegeStatus(int subId) { |
| 4722 | final Phone phone = getPhone(subId); |
| 4723 | if (phone == null) { |
| 4724 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4725 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4726 | } |
| 4727 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4728 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4729 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4730 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4731 | } |
| 4732 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4733 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4734 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4735 | |
| 4736 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4737 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4738 | final Phone phone = getPhone(subId); |
| 4739 | if (phone == null) { |
| 4740 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4741 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4742 | } |
| 4743 | UiccProfile profile = |
| 4744 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4745 | if (profile == null) { |
| 4746 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4747 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4748 | } |
| 4749 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 4750 | } |
| 4751 | |
| 4752 | @Override |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4753 | public int checkCarrierPrivilegesForPackage(String pkgName) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4754 | final Phone defaultPhone = getDefaultPhone(); |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4755 | if (TextUtils.isEmpty(pkgName)) |
| 4756 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4757 | UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4758 | if (card == null) { |
| 4759 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 4760 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4761 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4762 | return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(), |
| 4763 | pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4764 | } |
| 4765 | |
| 4766 | @Override |
| 4767 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4768 | if (TextUtils.isEmpty(pkgName)) |
| 4769 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4770 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4771 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4772 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4773 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4774 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4775 | continue; |
| 4776 | } |
| 4777 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4778 | result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4779 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4780 | break; |
| 4781 | } |
| 4782 | } |
| 4783 | |
| 4784 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4785 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4786 | |
| 4787 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4788 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4789 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4790 | loge("phoneId " + phoneId + " is not valid."); |
| 4791 | return null; |
| 4792 | } |
| 4793 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4794 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4795 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4796 | return null ; |
| 4797 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4798 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4799 | } |
| 4800 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4801 | @Override |
| 4802 | public List<String> getPackagesWithCarrierPrivileges() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4803 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4804 | List<String> privilegedPackages = new ArrayList<>(); |
| 4805 | List<PackageInfo> packages = null; |
| 4806 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4807 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4808 | if (card == null) { |
| 4809 | // No UICC in that slot. |
| 4810 | continue; |
| 4811 | } |
| 4812 | if (card.hasCarrierPrivilegeRules()) { |
| 4813 | if (packages == null) { |
| 4814 | // Only check packages in user 0 for now |
| 4815 | packages = pm.getInstalledPackagesAsUser( |
| 4816 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4817 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4818 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
| 4819 | } |
| 4820 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4821 | PackageInfo pkgInfo = packages.get(p); |
| 4822 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4823 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| 4824 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4825 | privilegedPackages.add(pkgInfo.packageName); |
| 4826 | } |
| 4827 | } |
| 4828 | } |
| 4829 | } |
| 4830 | return privilegedPackages; |
| 4831 | } |
| 4832 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4833 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4834 | final Phone phone = getPhone(subId); |
| 4835 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4836 | if (card == null) { |
| 4837 | loge("getIccId: No UICC"); |
| 4838 | return null; |
| 4839 | } |
| 4840 | String iccId = card.getIccId(); |
| 4841 | if (TextUtils.isEmpty(iccId)) { |
| 4842 | loge("getIccId: ICC ID is null or empty."); |
| 4843 | return null; |
| 4844 | } |
| 4845 | return iccId; |
| 4846 | } |
| 4847 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4848 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4849 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4850 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4851 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4852 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4853 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4854 | final long identity = Binder.clearCallingIdentity(); |
| 4855 | try { |
| 4856 | final String iccId = getIccId(subId); |
| 4857 | final Phone phone = getPhone(subId); |
| 4858 | if (phone == null) { |
| 4859 | return false; |
| 4860 | } |
| 4861 | final String subscriberId = phone.getSubscriberId(); |
| 4862 | |
| 4863 | if (DBG_MERGE) { |
| 4864 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4865 | + subscriberId + " to " + number); |
| 4866 | } |
| 4867 | |
| 4868 | if (TextUtils.isEmpty(iccId)) { |
| 4869 | return false; |
| 4870 | } |
| 4871 | |
| 4872 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4873 | |
| 4874 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4875 | if (alphaTag == null) { |
| 4876 | editor.remove(alphaTagPrefKey); |
| 4877 | } else { |
| 4878 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4879 | } |
| 4880 | |
| 4881 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4882 | // track all merged IMSIs based on line number |
| 4883 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4884 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4885 | if (number == null) { |
| 4886 | editor.remove(numberPrefKey); |
| 4887 | editor.remove(subscriberPrefKey); |
| 4888 | } else { |
| 4889 | editor.putString(numberPrefKey, number); |
| 4890 | editor.putString(subscriberPrefKey, subscriberId); |
| 4891 | } |
| 4892 | |
| 4893 | editor.commit(); |
| 4894 | return true; |
| 4895 | } finally { |
| 4896 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4897 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4898 | } |
| 4899 | |
| 4900 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4901 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4902 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4903 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4904 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4905 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4906 | return null; |
| 4907 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4908 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4909 | final long identity = Binder.clearCallingIdentity(); |
| 4910 | try { |
| 4911 | String iccId = getIccId(subId); |
| 4912 | if (iccId != null) { |
| 4913 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4914 | if (DBG_MERGE) { |
| 4915 | log("getLine1NumberForDisplay returning " |
| 4916 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 4917 | } |
| 4918 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4919 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4920 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 4921 | return null; |
| 4922 | } finally { |
| 4923 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4924 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4925 | } |
| 4926 | |
| 4927 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4928 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4929 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4930 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4931 | return null; |
| 4932 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4933 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4934 | final long identity = Binder.clearCallingIdentity(); |
| 4935 | try { |
| 4936 | String iccId = getIccId(subId); |
| 4937 | if (iccId != null) { |
| 4938 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4939 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 4940 | } |
| 4941 | return null; |
| 4942 | } finally { |
| 4943 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4944 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4945 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4946 | |
| 4947 | @Override |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4948 | public String[] getMergedSubscriberIds(String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4949 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 4950 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4951 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4952 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 4953 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4954 | return null; |
| 4955 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4956 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4957 | final long identity = Binder.clearCallingIdentity(); |
| 4958 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4959 | final Context context = mApp; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4960 | final TelephonyManager tele = TelephonyManager.from(context); |
| 4961 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 4962 | |
| 4963 | // Figure out what subscribers are currently active |
| 4964 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
| 4965 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 4966 | // the process, where TelephonyManager was instantiated. |
| 4967 | // Otherwise AppOps check will fail. |
| 4968 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4969 | final int[] subIds = sub.getActiveSubscriptionIdList(); |
| 4970 | for (int subId : subIds) { |
| 4971 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 4972 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4973 | |
| 4974 | // First pass, find a number override for an active subscriber |
| 4975 | String mergeNumber = null; |
| 4976 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 4977 | for (String key : prefs.keySet()) { |
| 4978 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 4979 | final String subscriberId = (String) prefs.get(key); |
| 4980 | if (activeSubscriberIds.contains(subscriberId)) { |
| 4981 | final String iccId = key.substring( |
| 4982 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 4983 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4984 | mergeNumber = (String) prefs.get(numberKey); |
| 4985 | if (DBG_MERGE) { |
| 4986 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 4987 | + " for active subscriber " + subscriberId); |
| 4988 | } |
| 4989 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 4990 | break; |
| 4991 | } |
| 4992 | } |
| 4993 | } |
| 4994 | } |
| 4995 | |
| 4996 | // Shortcut when no active merged subscribers |
| 4997 | if (TextUtils.isEmpty(mergeNumber)) { |
| 4998 | return null; |
| 4999 | } |
| 5000 | |
| 5001 | // Second pass, find all subscribers under that line override |
| 5002 | final ArraySet<String> result = new ArraySet<>(); |
| 5003 | for (String key : prefs.keySet()) { |
| 5004 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5005 | final String number = (String) prefs.get(key); |
| 5006 | if (mergeNumber.equals(number)) { |
| 5007 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5008 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5009 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5010 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5011 | result.add(subscriberId); |
| 5012 | } |
| 5013 | } |
| 5014 | } |
| 5015 | } |
| 5016 | |
| 5017 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5018 | Arrays.sort(resultArray); |
| 5019 | if (DBG_MERGE) { |
| 5020 | Slog.d(LOG_TAG, |
| 5021 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5022 | } |
| 5023 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5024 | } finally { |
| 5025 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5026 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5027 | } |
| 5028 | |
| 5029 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5030 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5031 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5032 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5033 | |
| 5034 | final long identity = Binder.clearCallingIdentity(); |
| 5035 | try { |
| 5036 | final Phone phone = getPhone(subId); |
| 5037 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5038 | } finally { |
| 5039 | Binder.restoreCallingIdentity(identity); |
| 5040 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5041 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5042 | |
| 5043 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5044 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5045 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5046 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5047 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5048 | |
| 5049 | final long identity = Binder.clearCallingIdentity(); |
| 5050 | try { |
| 5051 | final Phone phone = getPhone(subId); |
| 5052 | if (phone == null) { |
| 5053 | return false; |
| 5054 | } |
| 5055 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5056 | cdmaNonRoamingList); |
| 5057 | } finally { |
| 5058 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5059 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5060 | } |
| 5061 | |
| 5062 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5063 | @Deprecated |
| 5064 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5065 | enforceModifyPermission(); |
| 5066 | |
| 5067 | int returnValue = 0; |
| 5068 | try { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5069 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5070 | if(result.exception == null) { |
| 5071 | if (result.result != null) { |
| 5072 | byte[] responseData = (byte[])(result.result); |
| 5073 | if(responseData.length > oemResp.length) { |
| 5074 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5075 | responseData.length + "bytes. Buffer Size is " + |
| 5076 | oemResp.length + "bytes."); |
| 5077 | } |
| 5078 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5079 | returnValue = responseData.length; |
| 5080 | } |
| 5081 | } else { |
| 5082 | CommandException ex = (CommandException) result.exception; |
| 5083 | returnValue = ex.getCommandError().ordinal(); |
| 5084 | if(returnValue > 0) returnValue *= -1; |
| 5085 | } |
| 5086 | } catch (RuntimeException e) { |
| 5087 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5088 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5089 | if(returnValue > 0) returnValue *= -1; |
| 5090 | } |
| 5091 | |
| 5092 | return returnValue; |
| 5093 | } |
| 5094 | |
| 5095 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5096 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5097 | try { |
| 5098 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5099 | } catch (RuntimeException e) { |
| 5100 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5101 | } |
| 5102 | } |
| 5103 | |
| 5104 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5105 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5106 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5107 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5108 | if (phone == null) { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5109 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5110 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5111 | final long identity = Binder.clearCallingIdentity(); |
| 5112 | try { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5113 | TelephonyPermissions |
| 5114 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5115 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5116 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5117 | } finally { |
| 5118 | Binder.restoreCallingIdentity(identity); |
| 5119 | } |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5120 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5121 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5122 | |
| 5123 | @Override |
| 5124 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5125 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5126 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5127 | |
| 5128 | final long identity = Binder.clearCallingIdentity(); |
| 5129 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5130 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5131 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5132 | } finally { |
| 5133 | Binder.restoreCallingIdentity(identity); |
| 5134 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5135 | } |
| 5136 | |
| 5137 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5138 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5139 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5140 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5141 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5142 | return false; |
| 5143 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5144 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5145 | final long identity = Binder.clearCallingIdentity(); |
| 5146 | try { |
| 5147 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5148 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5149 | // In the long run, we may instead need to check if there exists a connection service |
| 5150 | // which can support video calling. |
| 5151 | ImsManager imsManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5152 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5153 | return imsManager.isVtEnabledByPlatform() |
| 5154 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5155 | && imsManager.isVtEnabledByUser(); |
| 5156 | } finally { |
| 5157 | Binder.restoreCallingIdentity(identity); |
| 5158 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5159 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5160 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5161 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5162 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 5163 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5164 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5165 | return false; |
| 5166 | } |
| 5167 | |
| 5168 | final long identity = Binder.clearCallingIdentity(); |
| 5169 | try { |
| 5170 | CarrierConfigManager configManager = |
| 5171 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5172 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5173 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5174 | } finally { |
| 5175 | Binder.restoreCallingIdentity(identity); |
| 5176 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5177 | } |
| 5178 | |
| 5179 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5180 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 5181 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5182 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5183 | return false; |
| 5184 | } |
| 5185 | |
| 5186 | final long identity = Binder.clearCallingIdentity(); |
| 5187 | try { |
| 5188 | CarrierConfigManager configManager = |
| 5189 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5190 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5191 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5192 | } finally { |
| 5193 | Binder.restoreCallingIdentity(identity); |
| 5194 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5195 | } |
| 5196 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5197 | @Override |
| 5198 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5199 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5200 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5201 | } |
| 5202 | |
| 5203 | @Override |
| 5204 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5205 | final long identity = Binder.clearCallingIdentity(); |
| 5206 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5207 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5208 | } finally { |
| 5209 | Binder.restoreCallingIdentity(identity); |
| 5210 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5211 | } |
| 5212 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5213 | /** |
| 5214 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5215 | * support for the feature and device firmware support. |
| 5216 | * |
| 5217 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5218 | */ |
| 5219 | @Override |
| 5220 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5221 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5222 | final Phone phone = getPhone(subscriptionId); |
| 5223 | if (phone == null) { |
| 5224 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5225 | return false; |
| 5226 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5227 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5228 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5229 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5230 | boolean isDeviceSupported = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5231 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5232 | return isCarrierSupported && isDeviceSupported; |
| 5233 | } finally { |
| 5234 | Binder.restoreCallingIdentity(identity); |
| 5235 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5236 | } |
| 5237 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5238 | /** |
| 5239 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier |
| 5240 | * both also support RTT. |
| 5241 | */ |
| 5242 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5243 | final long identity = Binder.clearCallingIdentity(); |
| 5244 | try { |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5245 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5246 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5247 | } finally { |
| 5248 | Binder.restoreCallingIdentity(identity); |
| 5249 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5250 | } |
| 5251 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5252 | /** |
| 5253 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5254 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5255 | * |
| 5256 | * <p>Requires Permission: |
| 5257 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5258 | */ |
| 5259 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5260 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5261 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5262 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5263 | return null; |
| 5264 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5265 | int subId = phone.getSubId(); |
| 5266 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5267 | mApp, subId, callingPackage, "getDeviceId")) { |
| 5268 | return null; |
| 5269 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5270 | |
| 5271 | final long identity = Binder.clearCallingIdentity(); |
| 5272 | try { |
| 5273 | return phone.getDeviceId(); |
| 5274 | } finally { |
| 5275 | Binder.restoreCallingIdentity(identity); |
| 5276 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5277 | } |
| 5278 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5279 | /** |
| 5280 | * {@hide} |
| 5281 | * Returns the IMS Registration Status on a particular subid |
| 5282 | * |
| 5283 | * @param subId |
| 5284 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5285 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5286 | Phone phone = getPhone(subId); |
| 5287 | if (phone != null) { |
| 5288 | return phone.isImsRegistered(); |
| 5289 | } else { |
| 5290 | return false; |
| 5291 | } |
| 5292 | } |
| 5293 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5294 | @Override |
| 5295 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5296 | final long identity = Binder.clearCallingIdentity(); |
| 5297 | try { |
| 5298 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5299 | } finally { |
| 5300 | Binder.restoreCallingIdentity(identity); |
| 5301 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5302 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5303 | |
Tyler Gunn | 327a972 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5304 | @Override |
| 5305 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 5306 | final long identity = Binder.clearCallingIdentity(); |
| 5307 | try { |
| 5308 | Phone phone = getPhone(subscriptionId); |
| 5309 | if (phone == null) { |
| 5310 | return null; |
| 5311 | } |
| 5312 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 5313 | } finally { |
| 5314 | Binder.restoreCallingIdentity(identity); |
| 5315 | } |
| 5316 | } |
| 5317 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5318 | /** |
| 5319 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5320 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5321 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5322 | final long identity = Binder.clearCallingIdentity(); |
| 5323 | try { |
| 5324 | Phone phone = getPhone(subId); |
| 5325 | if (phone != null) { |
| 5326 | return phone.isWifiCallingEnabled(); |
| 5327 | } else { |
| 5328 | return false; |
| 5329 | } |
| 5330 | } finally { |
| 5331 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5332 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5333 | } |
| 5334 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5335 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5336 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5337 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5338 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5339 | final long identity = Binder.clearCallingIdentity(); |
| 5340 | try { |
| 5341 | Phone phone = getPhone(subId); |
| 5342 | if (phone != null) { |
| 5343 | return phone.isVideoEnabled(); |
| 5344 | } else { |
| 5345 | return false; |
| 5346 | } |
| 5347 | } finally { |
| 5348 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5349 | } |
| 5350 | } |
| 5351 | |
| 5352 | /** |
| 5353 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5354 | * defined in {@link ImsRegistrationImplBase}. |
| 5355 | */ |
| 5356 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5357 | final long identity = Binder.clearCallingIdentity(); |
| 5358 | try { |
| 5359 | Phone phone = getPhone(subId); |
| 5360 | if (phone != null) { |
| 5361 | return phone.getImsRegistrationTech(); |
| 5362 | } else { |
| 5363 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5364 | } |
| 5365 | } finally { |
| 5366 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5367 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5368 | } |
| 5369 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5370 | @Override |
| 5371 | public void factoryReset(int subId) { |
| 5372 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5373 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5374 | return; |
| 5375 | } |
| 5376 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5377 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5378 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5379 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5380 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5381 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5382 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5383 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5384 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5385 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5386 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5387 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5388 | // There has been issues when Sms raw table somehow stores orphan |
| 5389 | // fragments. They lead to garbled message when new fragments come |
| 5390 | // in and combined with those stale ones. In case this happens again, |
| 5391 | // user can reset all network settings which will clean up this table. |
| 5392 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5393 | } finally { |
| 5394 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5395 | } |
| 5396 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5397 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5398 | private void cleanUpSmsRawTable(Context context) { |
| 5399 | ContentResolver resolver = context.getContentResolver(); |
| 5400 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 5401 | resolver.delete(uri, null, null); |
| 5402 | } |
| 5403 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5404 | @Override |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5405 | public String getSimLocaleForSubscriber(int subId) { |
| 5406 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5407 | final Phone phone = getPhone(subId); |
| 5408 | if (phone == null) { |
| 5409 | log("getSimLocaleForSubscriber, invalid subId"); |
Pengquan Meng | 9c29148 | 2019-01-28 16:26:29 -0800 | [diff] [blame] | 5410 | return null; |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5411 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5412 | final long identity = Binder.clearCallingIdentity(); |
| 5413 | try { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5414 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5415 | phone.getContext().getOpPackageName()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5416 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5417 | // preferences (EF-PL and EF-LI)... |
| 5418 | final int mcc = info.getMcc(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5419 | String simLanguage = null; |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5420 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5421 | if (localeFromDefaultSim != null) { |
| 5422 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5423 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5424 | + localeFromDefaultSim); |
| 5425 | return localeFromDefaultSim.toLanguageTag(); |
| 5426 | } else { |
| 5427 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5428 | } |
| 5429 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5430 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5431 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5432 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5433 | // the SIM and carrier preferences does not include a country we add the country |
| 5434 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5435 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5436 | if (mccLocale != null) { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5437 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5438 | return mccLocale.toLanguageTag(); |
| 5439 | } |
| 5440 | |
| 5441 | if (DBG) log("No locale found - returning null"); |
| 5442 | return null; |
| 5443 | } finally { |
| 5444 | Binder.restoreCallingIdentity(identity); |
| 5445 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5446 | } |
| 5447 | |
| 5448 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5449 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5450 | } |
| 5451 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5452 | /** |
| 5453 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5454 | */ |
| 5455 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5456 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5457 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5458 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5459 | private final ModemActivityInfo mLastModemActivityInfo = |
| 5460 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 5461 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5462 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5463 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5464 | * representing the state of the modem. |
| 5465 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5466 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5467 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5468 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5469 | */ |
| 5470 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5471 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5472 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5473 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5474 | |
| 5475 | final long identity = Binder.clearCallingIdentity(); |
| 5476 | try { |
| 5477 | ModemActivityInfo ret = null; |
| 5478 | synchronized (mLastModemActivityInfo) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5479 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5480 | CMD_GET_MODEM_ACTIVITY_INFO, |
| 5481 | null, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5482 | if (isModemActivityInfoValid(info)) { |
| 5483 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 5484 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 5485 | mergedTxTimeMs[i] = |
| 5486 | info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i]; |
| 5487 | } |
| 5488 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 5489 | mLastModemActivityInfo.setSleepTimeMillis( |
| 5490 | info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis()); |
| 5491 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5492 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 5493 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 5494 | mLastModemActivityInfo.setRxTimeMillis( |
| 5495 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 5496 | mLastModemActivityInfo.setEnergyUsed( |
| 5497 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5498 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5499 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5500 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5501 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 5502 | mLastModemActivityInfo.getTxTimeMillis(), |
| 5503 | mLastModemActivityInfo.getRxTimeMillis(), |
| 5504 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5505 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5506 | Bundle bundle = new Bundle(); |
| 5507 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 5508 | result.send(0, bundle); |
| 5509 | } finally { |
| 5510 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5511 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5512 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5513 | |
Siddharth Ray | f5d2955 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5514 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 5515 | // less than total activity duration. |
| 5516 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 5517 | if (info == null) { |
| 5518 | return false; |
| 5519 | } |
| 5520 | int activityDurationMs = |
| 5521 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 5522 | int totalTxTimeMs = 0; |
| 5523 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 5524 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 5525 | } |
| 5526 | return (info.isValid() |
| 5527 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 5528 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 5529 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 5530 | && (totalTxTimeMs <= activityDurationMs)); |
| 5531 | } |
| 5532 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5533 | /** |
| 5534 | * {@hide} |
| 5535 | * Returns the service state information on specified subscription. |
| 5536 | */ |
| 5537 | @Override |
| 5538 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5539 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5540 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5541 | return null; |
| 5542 | } |
| 5543 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5544 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 5545 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5546 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5547 | .setCallingPackage(callingPackage) |
| 5548 | .setCallingPid(Binder.getCallingPid()) |
| 5549 | .setCallingUid(Binder.getCallingUid()) |
| 5550 | .setMethod("getServiceStateForSubscriber") |
| 5551 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5552 | .build()); |
| 5553 | |
| 5554 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 5555 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5556 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5557 | .setCallingPackage(callingPackage) |
| 5558 | .setCallingPid(Binder.getCallingPid()) |
| 5559 | .setCallingUid(Binder.getCallingUid()) |
| 5560 | .setMethod("getServiceStateForSubscriber") |
| 5561 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5562 | .build()); |
| 5563 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 5564 | boolean hasFinePermission = |
| 5565 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5566 | boolean hasCoarsePermission = |
| 5567 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5568 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5569 | final long identity = Binder.clearCallingIdentity(); |
| 5570 | try { |
| 5571 | final Phone phone = getPhone(subId); |
| 5572 | if (phone == null) { |
| 5573 | return null; |
| 5574 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5575 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5576 | ServiceState ss = phone.getServiceState(); |
| 5577 | |
| 5578 | // Scrub out the location info in ServiceState depending on what level of access |
| 5579 | // the caller has. |
| 5580 | if (hasFinePermission) return ss; |
| 5581 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 5582 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5583 | } finally { |
| 5584 | Binder.restoreCallingIdentity(identity); |
| 5585 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5586 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5587 | |
| 5588 | /** |
| 5589 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5590 | * |
| 5591 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5592 | * voicemail ringtone. |
| 5593 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5594 | * PhoneAccount. |
| 5595 | */ |
| 5596 | @Override |
| 5597 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5598 | final long identity = Binder.clearCallingIdentity(); |
| 5599 | try { |
| 5600 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5601 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5602 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5603 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5604 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5605 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5606 | } finally { |
| 5607 | Binder.restoreCallingIdentity(identity); |
| 5608 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5609 | } |
| 5610 | |
| 5611 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5612 | * Sets the per-account voicemail ringtone. |
| 5613 | * |
| 5614 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5615 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5616 | * |
| 5617 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5618 | * voicemail ringtone. |
| 5619 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5620 | * PhoneAccount. |
| 5621 | */ |
| 5622 | @Override |
| 5623 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5624 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5625 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5626 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5627 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5628 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5629 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5630 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5631 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5632 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5633 | |
| 5634 | final long identity = Binder.clearCallingIdentity(); |
| 5635 | try { |
| 5636 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5637 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5638 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5639 | } |
| 5640 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5641 | } finally { |
| 5642 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5643 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5644 | } |
| 5645 | |
| 5646 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5647 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5648 | * |
| 5649 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5650 | * voicemail vibration setting. |
| 5651 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5652 | */ |
| 5653 | @Override |
| 5654 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5655 | final long identity = Binder.clearCallingIdentity(); |
| 5656 | try { |
| 5657 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5658 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5659 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5660 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5661 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5662 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5663 | } finally { |
| 5664 | Binder.restoreCallingIdentity(identity); |
| 5665 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5666 | } |
| 5667 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5668 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5669 | * Sets the per-account voicemail vibration. |
| 5670 | * |
| 5671 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5672 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5673 | * |
| 5674 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5675 | * voicemail vibration setting. |
| 5676 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5677 | * specific PhoneAccount. |
| 5678 | */ |
| 5679 | @Override |
| 5680 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5681 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5682 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5683 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5684 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5685 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5686 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5687 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5688 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5689 | } |
| 5690 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5691 | final long identity = Binder.clearCallingIdentity(); |
| 5692 | try { |
| 5693 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5694 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5695 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5696 | } |
| 5697 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5698 | } finally { |
| 5699 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5700 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5701 | } |
| 5702 | |
| 5703 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5704 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5705 | * |
| 5706 | * @throws SecurityException if the caller does not have the required permission |
| 5707 | */ |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5708 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5709 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5710 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5711 | } |
| 5712 | |
| 5713 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5714 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5715 | * permission. |
| 5716 | * |
| 5717 | * @throws SecurityException if the caller does not have the required permission |
| 5718 | */ |
| 5719 | private void enforceSendSmsPermission() { |
| 5720 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5721 | } |
| 5722 | |
| 5723 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5724 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5725 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5726 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5727 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5728 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5729 | final long identity = Binder.clearCallingIdentity(); |
| 5730 | try { |
| 5731 | ComponentName componentName = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5732 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5733 | if (componentName == null) { |
| 5734 | throw new SecurityException( |
| 5735 | "Caller not current active visual voicemail package[null]"); |
| 5736 | } |
| 5737 | String vvmPackage = componentName.getPackageName(); |
| 5738 | if (!callingPackage.equals(vvmPackage)) { |
| 5739 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5740 | + vvmPackage + "]"); |
| 5741 | } |
| 5742 | } finally { |
| 5743 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5744 | } |
| 5745 | } |
| 5746 | |
| 5747 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5748 | * Return the application ID for the app type. |
| 5749 | * |
| 5750 | * @param subId the subscription ID that this request applies to. |
| 5751 | * @param appType the uicc app type. |
| 5752 | * @return Application ID for specificied app type, or null if no uicc. |
| 5753 | */ |
| 5754 | @Override |
| 5755 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5756 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5757 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5758 | |
| 5759 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5760 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5761 | if (phone == null) { |
| 5762 | return null; |
| 5763 | } |
| 5764 | String aid = null; |
| 5765 | try { |
| 5766 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5767 | .getApplicationByType(appType).getAid(); |
| 5768 | } catch (Exception e) { |
| 5769 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5770 | } |
| 5771 | return aid; |
| 5772 | } finally { |
| 5773 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5774 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5775 | } |
| 5776 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5777 | /** |
| 5778 | * Return the Electronic Serial Number. |
| 5779 | * |
| 5780 | * @param subId the subscription ID that this request applies to. |
| 5781 | * @return ESN or null if error. |
| 5782 | */ |
| 5783 | @Override |
| 5784 | public String getEsn(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5785 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5786 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5787 | |
| 5788 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5789 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5790 | if (phone == null) { |
| 5791 | return null; |
| 5792 | } |
| 5793 | String esn = null; |
| 5794 | try { |
| 5795 | esn = phone.getEsn(); |
| 5796 | } catch (Exception e) { |
| 5797 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5798 | } |
| 5799 | return esn; |
| 5800 | } finally { |
| 5801 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5802 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5803 | } |
| 5804 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5805 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5806 | * Return the Preferred Roaming List Version. |
| 5807 | * |
| 5808 | * @param subId the subscription ID that this request applies to. |
| 5809 | * @return PRLVersion or null if error. |
| 5810 | */ |
| 5811 | @Override |
| 5812 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5813 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5814 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5815 | |
| 5816 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5817 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5818 | if (phone == null) { |
| 5819 | return null; |
| 5820 | } |
| 5821 | String cdmaPrlVersion = null; |
| 5822 | try { |
| 5823 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 5824 | } catch (Exception e) { |
| 5825 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 5826 | } |
| 5827 | return cdmaPrlVersion; |
| 5828 | } finally { |
| 5829 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5830 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5831 | } |
| 5832 | |
| 5833 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5834 | * Get snapshot of Telephony histograms |
| 5835 | * @return List of Telephony histograms |
| 5836 | * @hide |
| 5837 | */ |
| 5838 | @Override |
| 5839 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5840 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5841 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5842 | |
| 5843 | final long identity = Binder.clearCallingIdentity(); |
| 5844 | try { |
| 5845 | return RIL.getTelephonyRILTimingHistograms(); |
| 5846 | } finally { |
| 5847 | Binder.restoreCallingIdentity(identity); |
| 5848 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5849 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5850 | |
| 5851 | /** |
| 5852 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5853 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 5854 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5855 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5856 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5857 | * @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] | 5858 | */ |
| 5859 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5860 | @TelephonyManager.SetCarrierRestrictionResult |
| 5861 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5862 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5863 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5864 | |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5865 | if (carrierRestrictionRules == null) { |
| 5866 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5867 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5868 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5869 | final long identity = Binder.clearCallingIdentity(); |
| 5870 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5871 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5872 | workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5873 | } finally { |
| 5874 | Binder.restoreCallingIdentity(identity); |
| 5875 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5876 | } |
| 5877 | |
| 5878 | /** |
| 5879 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5880 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 5881 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5882 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5883 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5884 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5885 | */ |
| 5886 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5887 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5888 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5889 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5890 | |
| 5891 | final long identity = Binder.clearCallingIdentity(); |
| 5892 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5893 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 5894 | if (response instanceof CarrierRestrictionRules) { |
| 5895 | return (CarrierRestrictionRules) response; |
| 5896 | } |
| 5897 | // Response is an Exception of some kind, |
| 5898 | // which is signalled to the user as a NULL retval |
| 5899 | return null; |
| 5900 | } catch (Exception e) { |
| 5901 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 5902 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5903 | } finally { |
| 5904 | Binder.restoreCallingIdentity(identity); |
| 5905 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5906 | } |
| 5907 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5908 | /** |
| 5909 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 5910 | * @param subId the subscription ID that this action applies to. |
| 5911 | * @param enabled control enable or disable metered apns. |
| 5912 | * {@hide} |
| 5913 | */ |
| 5914 | @Override |
| 5915 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 5916 | enforceModifyPermission(); |
| 5917 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5918 | |
| 5919 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5920 | if (phone == null) { |
| 5921 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 5922 | return; |
| 5923 | } |
| 5924 | try { |
| 5925 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 5926 | } catch (Exception e) { |
| 5927 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5928 | } finally { |
| 5929 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5930 | } |
| 5931 | } |
| 5932 | |
| 5933 | /** |
| 5934 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 5935 | * @param subId the subscription ID that this action applies to. |
| 5936 | * @param enabled control enable or disable radio. |
| 5937 | * {@hide} |
| 5938 | */ |
| 5939 | @Override |
| 5940 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 5941 | enforceModifyPermission(); |
| 5942 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5943 | |
| 5944 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5945 | if (phone == null) { |
| 5946 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 5947 | return; |
| 5948 | } |
| 5949 | try { |
| 5950 | phone.carrierActionSetRadioEnabled(enabled); |
| 5951 | } catch (Exception e) { |
| 5952 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5953 | } finally { |
| 5954 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5955 | } |
| 5956 | } |
| 5957 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5958 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5959 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 5960 | * network status based on which carrier apps could apply actions accordingly, |
| 5961 | * enable/disable default url handler for example. |
| 5962 | * |
| 5963 | * @param subId the subscription ID that this action applies to. |
| 5964 | * @param report control start/stop reporting the default network status. |
| 5965 | * {@hide} |
| 5966 | */ |
| 5967 | @Override |
| 5968 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 5969 | enforceModifyPermission(); |
| 5970 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5971 | |
| 5972 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5973 | if (phone == null) { |
| 5974 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 5975 | return; |
| 5976 | } |
| 5977 | try { |
| 5978 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 5979 | } catch (Exception e) { |
| 5980 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5981 | } finally { |
| 5982 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5983 | } |
| 5984 | } |
| 5985 | |
| 5986 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5987 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 5988 | * bug report is being generated. |
| 5989 | */ |
| 5990 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 5991 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5992 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 5993 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 5994 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 5995 | + Binder.getCallingPid() |
| 5996 | + ", uid=" + Binder.getCallingUid() |
| 5997 | + "without permission " |
| 5998 | + android.Manifest.permission.DUMP); |
| 5999 | return; |
| 6000 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6001 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6002 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6003 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6004 | @Override |
| 6005 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 6006 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 6007 | throws RemoteException { |
| 6008 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 6009 | } |
| 6010 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6011 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6012 | * Get aggregated video call data usage since boot. |
| 6013 | * |
| 6014 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6015 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6016 | * {@hide} |
| 6017 | */ |
| 6018 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6019 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6020 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 6021 | null); |
| 6022 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6023 | final long identity = Binder.clearCallingIdentity(); |
| 6024 | try { |
| 6025 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 6026 | // records the delta with the corresponding network identity. |
| 6027 | // We just return the total video call data usage snapshot since boot. |
| 6028 | Phone phone = getPhone(subId); |
| 6029 | if (phone != null) { |
| 6030 | return phone.getVtDataUsage(perUidStats); |
| 6031 | } |
| 6032 | return null; |
| 6033 | } finally { |
| 6034 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6035 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6036 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6037 | |
| 6038 | /** |
| 6039 | * Policy control of data connection. Usually used when data limit is passed. |
| 6040 | * @param enabled True if enabling the data, otherwise disabling. |
| 6041 | * @param subId Subscription index |
| 6042 | * {@hide} |
| 6043 | */ |
| 6044 | @Override |
| 6045 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6046 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6047 | |
| 6048 | final long identity = Binder.clearCallingIdentity(); |
| 6049 | try { |
| 6050 | Phone phone = getPhone(subId); |
| 6051 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6052 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6053 | } |
| 6054 | } finally { |
| 6055 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6056 | } |
| 6057 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6058 | |
| 6059 | /** |
| 6060 | * Get Client request stats |
| 6061 | * @return List of Client Request Stats |
| 6062 | * @hide |
| 6063 | */ |
| 6064 | @Override |
| 6065 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6066 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6067 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6068 | return null; |
| 6069 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6070 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6071 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6072 | final long identity = Binder.clearCallingIdentity(); |
| 6073 | try { |
| 6074 | if (phone != null) { |
| 6075 | return phone.getClientRequestStats(); |
| 6076 | } |
| 6077 | |
| 6078 | return null; |
| 6079 | } finally { |
| 6080 | Binder.restoreCallingIdentity(identity); |
| 6081 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6082 | } |
| 6083 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6084 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6085 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6086 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6087 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6088 | |
| 6089 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6090 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6091 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6092 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6093 | * @param state State of SIM (power down, power up, pass through) |
| 6094 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6095 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6096 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6097 | * |
| 6098 | **/ |
| 6099 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6100 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6101 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6102 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6103 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6104 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6105 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6106 | final long identity = Binder.clearCallingIdentity(); |
| 6107 | try { |
| 6108 | if (phone != null) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6109 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6110 | } |
| 6111 | } finally { |
| 6112 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6113 | } |
| 6114 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6115 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6116 | private boolean isUssdApiAllowed(int subId) { |
| 6117 | CarrierConfigManager configManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6118 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6119 | if (configManager == null) { |
| 6120 | return false; |
| 6121 | } |
| 6122 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6123 | if (pb == null) { |
| 6124 | return false; |
| 6125 | } |
| 6126 | return pb.getBoolean( |
| 6127 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6128 | } |
| 6129 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6130 | /** |
| 6131 | * Check if phone is in emergency callback mode |
| 6132 | * @return true if phone is in emergency callback mode |
| 6133 | * @param subId sub id |
| 6134 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6135 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6136 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6137 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6138 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6139 | |
| 6140 | final long identity = Binder.clearCallingIdentity(); |
| 6141 | try { |
| 6142 | if (phone != null) { |
| 6143 | return phone.isInEcm(); |
| 6144 | } else { |
| 6145 | return false; |
| 6146 | } |
| 6147 | } finally { |
| 6148 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6149 | } |
| 6150 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6151 | |
| 6152 | /** |
| 6153 | * Get the current signal strength information for the given subscription. |
| 6154 | * Because this information is not updated when the device is in a low power state |
| 6155 | * it should not be relied-upon to be current. |
| 6156 | * @param subId Subscription index |
| 6157 | * @return the most recent cached signal strength info from the modem |
| 6158 | */ |
| 6159 | @Override |
| 6160 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6161 | final long identity = Binder.clearCallingIdentity(); |
| 6162 | try { |
| 6163 | Phone p = getPhone(subId); |
| 6164 | if (p == null) { |
| 6165 | return null; |
| 6166 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6167 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6168 | return p.getSignalStrength(); |
| 6169 | } finally { |
| 6170 | Binder.restoreCallingIdentity(identity); |
| 6171 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6172 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6173 | |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6174 | /** |
chen xu | 907e5a2 | 2018-10-11 13:21:04 -0700 | [diff] [blame] | 6175 | * Get the current modem radio state for the given slot. |
| 6176 | * @param slotIndex slot index. |
| 6177 | * @param callingPackage the name of the package making the call. |
| 6178 | * @return the current radio power state from the modem |
| 6179 | */ |
| 6180 | @Override |
| 6181 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 6182 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6183 | if (phone != null) { |
| 6184 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6185 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 6186 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6187 | } |
| 6188 | |
| 6189 | final long identity = Binder.clearCallingIdentity(); |
| 6190 | try { |
| 6191 | return phone.getRadioPowerState(); |
| 6192 | } finally { |
| 6193 | Binder.restoreCallingIdentity(identity); |
| 6194 | } |
| 6195 | } |
| 6196 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6197 | } |
| 6198 | |
| 6199 | /** |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6200 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6201 | * |
| 6202 | * <p>Requires one of the following permissions: |
| 6203 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6204 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6205 | * privileges. |
| 6206 | * |
| 6207 | * @param subId subscription id |
| 6208 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6209 | * {@code false}. |
| 6210 | */ |
| 6211 | @Override |
| 6212 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6213 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6214 | null /* message */); |
| 6215 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6216 | boolean isEnabled = false; |
| 6217 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6218 | try { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6219 | Phone phone = getPhone(subId); |
| 6220 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6221 | } catch (Exception e) { |
| 6222 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6223 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6224 | } finally { |
| 6225 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6226 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6227 | return isEnabled; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6228 | } |
| 6229 | |
| 6230 | |
| 6231 | /** |
| 6232 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6233 | * |
| 6234 | * <p> Requires permission: |
| 6235 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6236 | * privileges. |
| 6237 | * |
| 6238 | * @param subId subscription id |
| 6239 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6240 | */ |
| 6241 | @Override |
| 6242 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6243 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6244 | mApp, subId, "setDataRoamingEnabled"); |
| 6245 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6246 | final long identity = Binder.clearCallingIdentity(); |
| 6247 | try { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6248 | Phone phone = getPhone(subId); |
| 6249 | if (phone != null) { |
| 6250 | phone.setDataRoamingEnabled(isEnabled); |
| 6251 | } |
| 6252 | } finally { |
| 6253 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6254 | } |
| 6255 | } |
| 6256 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6257 | @Override |
Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6258 | public boolean isManualNetworkSelectionAllowed(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6259 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6260 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6261 | |
Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6262 | boolean isAllowed = true; |
| 6263 | final long identity = Binder.clearCallingIdentity(); |
| 6264 | try { |
Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6265 | Phone phone = getPhone(subId); |
| 6266 | if (phone != null) { |
| 6267 | isAllowed = phone.isCspPlmnEnabled(); |
| 6268 | } |
| 6269 | } finally { |
| 6270 | Binder.restoreCallingIdentity(identity); |
| 6271 | } |
| 6272 | return isAllowed; |
| 6273 | } |
| 6274 | |
| 6275 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6276 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 53fdb78 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6277 | try { |
| 6278 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
| 6279 | } catch (SecurityException e) { |
| 6280 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6281 | // has carrier privileges on an active UICC |
| 6282 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6283 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6284 | throw new SecurityException("Caller does not have carrier privileges on any UICC"); |
| 6285 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6286 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6287 | |
| 6288 | final long identity = Binder.clearCallingIdentity(); |
| 6289 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6290 | UiccController uiccController = UiccController.getInstance(); |
| 6291 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
| 6292 | |
| 6293 | ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0); |
| 6294 | if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 6295 | // Remove private info if the caller doesn't have access |
| 6296 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6297 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6298 | UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex()); |
| 6299 | UiccProfile profile = card.getUiccProfile(); |
| 6300 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6301 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6302 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6303 | } else { |
| 6304 | filteredInfos.add(cardInfo); |
| 6305 | } |
| 6306 | } |
| 6307 | return filteredInfos; |
| 6308 | } |
| 6309 | return cardInfos; |
| 6310 | } catch (PackageManager.NameNotFoundException e) { |
| 6311 | // This should not happen since we pass the package info in from TelephonyManager |
| 6312 | throw new SecurityException("Invalid calling package."); |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6313 | } finally { |
| 6314 | Binder.restoreCallingIdentity(identity); |
| 6315 | } |
| 6316 | } |
| 6317 | |
| 6318 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6319 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6320 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6321 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6322 | final long identity = Binder.clearCallingIdentity(); |
| 6323 | try { |
| 6324 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6325 | if (slots == null) { |
| 6326 | Rlog.i(LOG_TAG, "slots is null."); |
| 6327 | return null; |
| 6328 | } |
| 6329 | |
| 6330 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6331 | for (int i = 0; i < slots.length; i++) { |
| 6332 | UiccSlot slot = slots[i]; |
| 6333 | if (slot == null) { |
| 6334 | continue; |
| 6335 | } |
| 6336 | |
| 6337 | String cardId; |
| 6338 | UiccCard card = slot.getUiccCard(); |
| 6339 | if (card != null) { |
| 6340 | cardId = card.getCardId(); |
| 6341 | } else { |
| 6342 | cardId = slot.getIccId(); |
| 6343 | } |
| 6344 | |
| 6345 | int cardState = 0; |
| 6346 | switch (slot.getCardState()) { |
| 6347 | case CARDSTATE_ABSENT: |
| 6348 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6349 | break; |
| 6350 | case CARDSTATE_PRESENT: |
| 6351 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6352 | break; |
| 6353 | case CARDSTATE_ERROR: |
| 6354 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6355 | break; |
| 6356 | case CARDSTATE_RESTRICTED: |
| 6357 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6358 | break; |
| 6359 | default: |
| 6360 | break; |
| 6361 | |
| 6362 | } |
| 6363 | |
| 6364 | infos[i] = new UiccSlotInfo( |
| 6365 | slot.isActive(), |
| 6366 | slot.isEuicc(), |
| 6367 | cardId, |
| 6368 | cardState, |
| 6369 | slot.getPhoneId(), |
Jordan Liu | ef65d87 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6370 | slot.isExtendedApduSupported(), |
| 6371 | slot.isRemovable()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6372 | } |
| 6373 | return infos; |
| 6374 | } finally { |
| 6375 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6376 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6377 | } |
| 6378 | |
| 6379 | @Override |
| 6380 | public boolean switchSlots(int[] physicalSlots) { |
| 6381 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6382 | |
| 6383 | final long identity = Binder.clearCallingIdentity(); |
| 6384 | try { |
| 6385 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6386 | } finally { |
| 6387 | Binder.restoreCallingIdentity(identity); |
| 6388 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6389 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6390 | |
| 6391 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6392 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6393 | final long identity = Binder.clearCallingIdentity(); |
| 6394 | try { |
| 6395 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6396 | } finally { |
| 6397 | Binder.restoreCallingIdentity(identity); |
| 6398 | } |
| 6399 | } |
| 6400 | |
| 6401 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6402 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6403 | enforceModifyPermission(); |
| 6404 | final Phone phone = getPhone(subId); |
| 6405 | if (phone == null) { |
| 6406 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6407 | return; |
| 6408 | } |
| 6409 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6410 | final long identity = Binder.clearCallingIdentity(); |
| 6411 | try { |
| 6412 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6413 | } finally { |
| 6414 | Binder.restoreCallingIdentity(identity); |
| 6415 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6416 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6417 | |
| 6418 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6419 | * A test API to reload the UICC profile. |
| 6420 | * |
| 6421 | * <p>Requires that the calling app has permission |
| 6422 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6423 | * @hide |
| 6424 | */ |
| 6425 | @Override |
| 6426 | public void refreshUiccProfile(int subId) { |
| 6427 | enforceModifyPermission(); |
| 6428 | |
| 6429 | final long identity = Binder.clearCallingIdentity(); |
| 6430 | try { |
| 6431 | Phone phone = getPhone(subId); |
| 6432 | if (phone == null) { |
| 6433 | return; |
| 6434 | } |
| 6435 | UiccCard uiccCard = phone.getUiccCard(); |
| 6436 | if (uiccCard == null) { |
| 6437 | return; |
| 6438 | } |
| 6439 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6440 | if (uiccProfile == null) { |
| 6441 | return; |
| 6442 | } |
| 6443 | uiccProfile.refresh(); |
| 6444 | } finally { |
| 6445 | Binder.restoreCallingIdentity(identity); |
| 6446 | } |
| 6447 | } |
| 6448 | |
| 6449 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6450 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6451 | */ |
| 6452 | private boolean getDefaultDataEnabled() { |
| 6453 | return "true".equalsIgnoreCase( |
| 6454 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6455 | } |
| 6456 | |
| 6457 | /** |
| 6458 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6459 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6460 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6461 | */ |
| 6462 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6463 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6464 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6465 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6466 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6467 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6468 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 6469 | return isDataRoamingEnabled; |
| 6470 | } |
| 6471 | |
| 6472 | /** |
| 6473 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 6474 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 6475 | */ |
| 6476 | private int getDefaultNetworkType(int subId) { |
| 6477 | return Integer.parseInt( |
| 6478 | TelephonyManager.getTelephonyProperty( |
| 6479 | mSubscriptionController.getPhoneId(subId), |
| 6480 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 6481 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 6482 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6483 | |
| 6484 | @Override |
| 6485 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
| 6486 | gid1, String gid2, String plmn, String spn) { |
| 6487 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6488 | |
| 6489 | final long identity = Binder.clearCallingIdentity(); |
| 6490 | try { |
| 6491 | final Phone phone = getPhone(subId); |
| 6492 | if (phone == null) { |
| 6493 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 6494 | return; |
| 6495 | } |
| 6496 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn); |
| 6497 | } finally { |
| 6498 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6499 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6500 | } |
| 6501 | |
| 6502 | @Override |
| 6503 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6504 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6505 | |
| 6506 | final long identity = Binder.clearCallingIdentity(); |
| 6507 | try { |
| 6508 | final Phone phone = getPhone(subId); |
| 6509 | if (phone == null) { |
| 6510 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 6511 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 6512 | } |
| 6513 | return phone.getCarrierIdListVersion(); |
| 6514 | } finally { |
| 6515 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6516 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6517 | } |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6518 | |
| 6519 | @Override |
| 6520 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 6521 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6522 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 6523 | return -1; |
| 6524 | } |
| 6525 | |
| 6526 | final long identity = Binder.clearCallingIdentity(); |
| 6527 | try { |
| 6528 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 6529 | } finally { |
| 6530 | Binder.restoreCallingIdentity(identity); |
| 6531 | } |
| 6532 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6533 | |
| 6534 | @Override |
| 6535 | public int getCdmaRoamingMode(int subId) { |
| 6536 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6537 | mApp, subId, "getCdmaRoamingMode"); |
| 6538 | |
| 6539 | final long identity = Binder.clearCallingIdentity(); |
| 6540 | try { |
| 6541 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 6542 | } finally { |
| 6543 | Binder.restoreCallingIdentity(identity); |
| 6544 | } |
| 6545 | } |
| 6546 | |
| 6547 | @Override |
| 6548 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 6549 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6550 | mApp, subId, "setCdmaRoamingMode"); |
| 6551 | |
| 6552 | final long identity = Binder.clearCallingIdentity(); |
| 6553 | try { |
| 6554 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 6555 | } finally { |
| 6556 | Binder.restoreCallingIdentity(identity); |
| 6557 | } |
| 6558 | } |
| 6559 | |
| 6560 | @Override |
| 6561 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 6562 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6563 | mApp, subId, "setCdmaSubscriptionMode"); |
| 6564 | |
| 6565 | final long identity = Binder.clearCallingIdentity(); |
| 6566 | try { |
| 6567 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 6568 | } finally { |
| 6569 | Binder.restoreCallingIdentity(identity); |
| 6570 | } |
| 6571 | } |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6572 | |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 6573 | private void ensureUserRunning(int userId) { |
| 6574 | if (!mUserManager.isUserRunning(userId)) { |
| 6575 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 6576 | } |
| 6577 | } |
| 6578 | |
| 6579 | /** |
| 6580 | * Returns a list of SMS apps on a given user. |
| 6581 | * |
| 6582 | * Only the shell user (UID 2000 or 0) can call it. |
| 6583 | * Target user must be running. |
| 6584 | */ |
| 6585 | @Override |
| 6586 | public String[] getSmsApps(int userId) { |
| 6587 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 6588 | ensureUserRunning(userId); |
| 6589 | |
| 6590 | final Collection<SmsApplicationData> apps = |
| 6591 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 6592 | |
| 6593 | String[] ret = new String[apps.size()]; |
| 6594 | int i = 0; |
| 6595 | for (SmsApplicationData app : apps) { |
| 6596 | ret[i++] = app.mPackageName; |
| 6597 | } |
| 6598 | return ret; |
| 6599 | } |
| 6600 | |
| 6601 | /** |
| 6602 | * Returns the default SMS app package name on a given user. |
| 6603 | * |
| 6604 | * Only the shell user (UID 2000 or 0) can call it. |
| 6605 | * Target user must be running. |
| 6606 | */ |
| 6607 | @Override |
| 6608 | public String getDefaultSmsApp(int userId) { |
| 6609 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 6610 | ensureUserRunning(userId); |
| 6611 | |
| 6612 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 6613 | /* updateIfNeeded= */ true, userId); |
| 6614 | return cn == null ? null : cn.getPackageName(); |
| 6615 | } |
| 6616 | |
| 6617 | /** |
| 6618 | * Set a package as the default SMS app on a given user. |
| 6619 | * |
| 6620 | * Only the shell user (UID 2000 or 0) can call it. |
| 6621 | * Target user must be running. |
| 6622 | */ |
| 6623 | @Override |
| 6624 | public void setDefaultSmsApp(int userId, String packageName) { |
| 6625 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6626 | ensureUserRunning(userId); |
| 6627 | |
| 6628 | boolean found = false; |
| 6629 | for (String pkg : getSmsApps(userId)) { |
| 6630 | if (TextUtils.equals(packageName, pkg)) { |
| 6631 | found = true; |
| 6632 | break; |
| 6633 | } |
| 6634 | } |
| 6635 | if (!found) { |
| 6636 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6637 | } |
| 6638 | |
| 6639 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6640 | } |
| 6641 | |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6642 | @Override |
sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6643 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6644 | String callingPackage) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6645 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6646 | mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6647 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6648 | } |
| 6649 | final long identity = Binder.clearCallingIdentity(); |
| 6650 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6651 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6652 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6653 | if (phone.getEmergencyNumberTracker() != null |
| 6654 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6655 | emergencyNumberListInternal.put( |
| 6656 | phone.getSubId(), |
| 6657 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6658 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6659 | } |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6660 | return emergencyNumberListInternal; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6661 | } finally { |
| 6662 | Binder.restoreCallingIdentity(identity); |
| 6663 | } |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6664 | } |
| 6665 | |
| 6666 | @Override |
sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6667 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6668 | final Phone defaultPhone = getDefaultPhone(); |
| 6669 | if (!exactMatch) { |
| 6670 | TelephonyPermissions |
| 6671 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6672 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6673 | } |
| 6674 | final long identity = Binder.clearCallingIdentity(); |
| 6675 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6676 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6677 | if (phone.getEmergencyNumberTracker() != null |
| 6678 | && phone.getEmergencyNumberTracker() != null) { |
| 6679 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 6680 | number, exactMatch)) { |
| 6681 | return true; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6682 | } |
| 6683 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6684 | } |
| 6685 | return false; |
| 6686 | } finally { |
| 6687 | Binder.restoreCallingIdentity(identity); |
| 6688 | } |
| 6689 | } |
| 6690 | |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6691 | /** |
| 6692 | * Update emergency number list for test mode. |
| 6693 | */ |
| 6694 | @Override |
| 6695 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 6696 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6697 | "updateEmergencyNumberListTestMode"); |
| 6698 | |
| 6699 | final long identity = Binder.clearCallingIdentity(); |
| 6700 | try { |
| 6701 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6702 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6703 | if (tracker != null) { |
| 6704 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 6705 | } |
| 6706 | } |
| 6707 | } finally { |
| 6708 | Binder.restoreCallingIdentity(identity); |
| 6709 | } |
| 6710 | } |
| 6711 | |
| 6712 | /** |
| 6713 | * Get the full emergency number list for test mode. |
| 6714 | */ |
| 6715 | @Override |
| 6716 | public List<String> getEmergencyNumberListTestMode() { |
| 6717 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6718 | "getEmergencyNumberListTestMode"); |
| 6719 | |
| 6720 | final long identity = Binder.clearCallingIdentity(); |
| 6721 | try { |
| 6722 | Set<String> emergencyNumbers = new HashSet<>(); |
| 6723 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6724 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6725 | if (tracker != null) { |
| 6726 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 6727 | emergencyNumbers.add(num.getNumber()); |
| 6728 | } |
| 6729 | } |
| 6730 | } |
| 6731 | return new ArrayList<>(emergencyNumbers); |
| 6732 | } finally { |
| 6733 | Binder.restoreCallingIdentity(identity); |
| 6734 | } |
| 6735 | } |
| 6736 | |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6737 | @Override |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6738 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6739 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6740 | Phone phone = getPhone(subId); |
| 6741 | if (phone == null) { |
| 6742 | return null; |
| 6743 | } |
| 6744 | final long identity = Binder.clearCallingIdentity(); |
| 6745 | try { |
| 6746 | UiccProfile profile = UiccController.getInstance() |
| 6747 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6748 | if (profile != null) { |
| 6749 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6750 | } |
| 6751 | } finally { |
| 6752 | Binder.restoreCallingIdentity(identity); |
| 6753 | } |
| 6754 | return null; |
| 6755 | } |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6756 | |
| 6757 | /** |
| 6758 | * Enable or disable a modem stack. |
| 6759 | */ |
| 6760 | @Override |
| 6761 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 6762 | enforceModifyPermission(); |
| 6763 | |
| 6764 | final long identity = Binder.clearCallingIdentity(); |
| 6765 | try { |
| 6766 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6767 | if (phone == null) { |
| 6768 | return false; |
| 6769 | } else { |
| 6770 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 6771 | } |
| 6772 | } finally { |
| 6773 | Binder.restoreCallingIdentity(identity); |
| 6774 | } |
| 6775 | } |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6776 | |
| 6777 | @Override |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6778 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6779 | enforceModifyPermission(); |
| 6780 | |
| 6781 | final long identity = Binder.clearCallingIdentity(); |
| 6782 | try { |
| 6783 | mTelephonySharedPreferences.edit() |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6784 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6785 | .commit(); |
| 6786 | } finally { |
| 6787 | Binder.restoreCallingIdentity(identity); |
| 6788 | } |
| 6789 | } |
| 6790 | |
| 6791 | @Override |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6792 | @TelephonyManager.IsMultiSimSupportedResult |
| 6793 | public int isMultiSimSupported(String callingPackage) { |
Michele | bcb01bc | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6794 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6795 | getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) { |
| 6796 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | bcb01bc | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6797 | } |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6798 | |
| 6799 | final long identity = Binder.clearCallingIdentity(); |
| 6800 | try { |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6801 | return isMultiSimSupportedInternal(); |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6802 | } finally { |
| 6803 | Binder.restoreCallingIdentity(identity); |
| 6804 | } |
| 6805 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6806 | |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6807 | @TelephonyManager.IsMultiSimSupportedResult |
| 6808 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6809 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 6810 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 6811 | if (numPhysicalSlots < 2) { |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6812 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 6813 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6814 | } |
| 6815 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 6816 | // supported by the modem, indicate that it is restricted. |
| 6817 | PhoneCapability staticCapability = |
| 6818 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 6819 | if (staticCapability == null) { |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6820 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 6821 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6822 | } |
| 6823 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6824 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 6825 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6826 | } |
| 6827 | // Check if support of multiple SIMs is restricted by carrier |
| 6828 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6829 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6830 | } |
| 6831 | |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6832 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6833 | } |
| 6834 | |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6835 | /** |
| 6836 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 814dc22 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6837 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 6838 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 6839 | * or carrier privileges |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6840 | * @param numOfSims number of active sims we want to switch to |
| 6841 | */ |
| 6842 | @Override |
| 6843 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 814dc22 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6844 | if (numOfSims == 1) { |
| 6845 | enforceModifyPermission(); |
| 6846 | } else { |
| 6847 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6848 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 6849 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6850 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6851 | |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6852 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6853 | //only proceed if multi-sim is not restricted |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6854 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6855 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 6856 | return; |
| 6857 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6858 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 6859 | } finally { |
| 6860 | Binder.restoreCallingIdentity(identity); |
| 6861 | } |
| 6862 | } |
| 6863 | |
| 6864 | /** |
Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6865 | * 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] | 6866 | * Return value defaults to true |
Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6867 | */ |
| 6868 | @Override |
| 6869 | public boolean isRebootRequiredForModemConfigChange() { |
| 6870 | enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange"); |
| 6871 | final long identity = Binder.clearCallingIdentity(); |
| 6872 | try { |
| 6873 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 6874 | } finally { |
| 6875 | Binder.restoreCallingIdentity(identity); |
| 6876 | } |
| 6877 | } |
| 6878 | |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 6879 | private void updateModemStateMetrics() { |
| 6880 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 6881 | // TODO: check the state for each modem if the api is ready. |
| 6882 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 6883 | } |
| 6884 | |
Pengquan Meng | 3aceaec | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 6885 | @Override |
| 6886 | public int[] getSlotsMapping() { |
| 6887 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 6888 | |
| 6889 | final long identity = Binder.clearCallingIdentity(); |
| 6890 | try { |
| 6891 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 6892 | // All logical slots should have a mapping to a physical slot. |
| 6893 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 6894 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 6895 | for (int i = 0; i < slotInfos.length; i++) { |
| 6896 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 6897 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 6898 | } |
| 6899 | } |
| 6900 | return logicalSlotsMapping; |
| 6901 | } finally { |
| 6902 | Binder.restoreCallingIdentity(identity); |
| 6903 | } |
| 6904 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 6905 | |
| 6906 | /** |
| 6907 | * Get the IRadio HAL Version |
| 6908 | */ |
| 6909 | @Override |
| 6910 | public int getRadioHalVersion() { |
| 6911 | Phone phone = getDefaultPhone(); |
| 6912 | if (phone == null) return -1; |
| 6913 | HalVersion hv = phone.getHalVersion(); |
| 6914 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 6915 | return hv.major * 100 + hv.minor; |
| 6916 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6917 | } |