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; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 82 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 83 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 84 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 85 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 86 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 87 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 88 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 89 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 90 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 91 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 92 | import android.telephony.data.ApnSetting; |
Jack Yu | 40306fc | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 93 | import android.telephony.data.ApnSetting.ApnType; |
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; |
Amit Mahajan | 716e76c | 2019-05-13 13:48:32 -0700 | [diff] [blame^] | 142 | import com.android.internal.telephony.SmsController; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 144 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | 460810d | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 146 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.ims.ImsResolver; |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.uicc.IccIoResult; |
| 151 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 157 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 159 | import com.android.internal.util.HexDump; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 160 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 161 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 162 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 163 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 164 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 165 | import java.io.FileDescriptor; |
| 166 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 167 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 168 | import java.util.Arrays; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 169 | import java.util.Collection; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 170 | import java.util.HashMap; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 171 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 172 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 173 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 174 | import java.util.Map; |
Nazanin Bakhshi | 1f78d7d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 175 | import java.util.NoSuchElementException; |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 176 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 177 | |
| 178 | /** |
| 179 | * Implementation of the ITelephony interface. |
| 180 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 181 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 182 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 183 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 184 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 185 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 186 | |
| 187 | // Message codes used with mMainThreadHandler |
| 188 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 189 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 190 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 191 | private static final int CMD_OPEN_CHANNEL = 9; |
| 192 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 193 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 194 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 195 | private static final int CMD_NV_READ_ITEM = 13; |
| 196 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 197 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 198 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 199 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 200 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 201 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 202 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 203 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 204 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 205 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 206 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 207 | private static final int CMD_SEND_ENVELOPE = 25; |
| 208 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 209 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 210 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 211 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 212 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 213 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 214 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 215 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 216 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 217 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 218 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 219 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 220 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 221 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 222 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 223 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 224 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 225 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 226 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 227 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 228 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 229 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 230 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 231 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 232 | private static final int CMD_SWITCH_SLOTS = 50; |
| 233 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 234 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 235 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 236 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 237 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 238 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 239 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 240 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 241 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 242 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 243 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 244 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 245 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 246 | private static final int CMD_MODEM_REBOOT = 64; |
| 247 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 248 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 249 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 250 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 251 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | 1f78d7d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 252 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 253 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 254 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 255 | // Parameters of select command. |
| 256 | private static final int SELECT_COMMAND = 0xA4; |
| 257 | private static final int SELECT_P1 = 0x04; |
| 258 | private static final int SELECT_P2 = 0; |
| 259 | private static final int SELECT_P3 = 0x10; |
| 260 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 261 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 262 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 263 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 264 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 265 | /** The singleton instance. */ |
| 266 | private static PhoneInterfaceManager sInstance; |
| 267 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 268 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 269 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 270 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 271 | private AppOpsManager mAppOps; |
| 272 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 273 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 274 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 275 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 276 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 277 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 278 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 279 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 280 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 281 | |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 282 | // String to store multi SIM allowed |
| 283 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 284 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 285 | // The AID of ISD-R. |
| 286 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 287 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 288 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 289 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 290 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 291 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 292 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 293 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 294 | * A request object to use for transmitting data to an ICC. |
| 295 | */ |
| 296 | private static final class IccAPDUArgument { |
| 297 | public int channel, cla, command, p1, p2, p3; |
| 298 | public String data; |
| 299 | |
| 300 | public IccAPDUArgument(int channel, int cla, int command, |
| 301 | int p1, int p2, int p3, String data) { |
| 302 | this.channel = channel; |
| 303 | this.cla = cla; |
| 304 | this.command = command; |
| 305 | this.p1 = p1; |
| 306 | this.p2 = p2; |
| 307 | this.p3 = p3; |
| 308 | this.data = data; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 313 | * A request object to use for transmitting data to an ICC. |
| 314 | */ |
| 315 | private static final class ManualNetworkSelectionArgument { |
| 316 | public OperatorInfo operatorInfo; |
| 317 | public boolean persistSelection; |
| 318 | |
| 319 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 320 | this.operatorInfo = operatorInfo; |
| 321 | this.persistSelection = persistSelection; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 326 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 327 | * request after sending. The main thread will notify the request when it is complete. |
| 328 | */ |
| 329 | private static final class MainThreadRequest { |
| 330 | /** The argument to use for the request */ |
| 331 | public Object argument; |
| 332 | /** The result of the request that is run on the main thread */ |
| 333 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 334 | // The subscriber id that this request applies to. Defaults to |
| 335 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 336 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 337 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 338 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 339 | public Phone phone; |
| 340 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 341 | public WorkSource workSource; |
| 342 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 343 | public MainThreadRequest(Object argument) { |
| 344 | this.argument = argument; |
| 345 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 346 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 347 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 348 | this.argument = argument; |
| 349 | if (phone != null) { |
| 350 | this.phone = phone; |
| 351 | } |
| 352 | this.workSource = workSource; |
| 353 | } |
| 354 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 355 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 356 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 357 | if (subId != null) { |
| 358 | this.subId = subId; |
| 359 | } |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 360 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 361 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 364 | private static final class IncomingThirdPartyCallArgs { |
| 365 | public final ComponentName component; |
| 366 | public final String callId; |
| 367 | public final String callerDisplayName; |
| 368 | |
| 369 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 370 | String callerDisplayName) { |
| 371 | this.component = component; |
| 372 | this.callId = callId; |
| 373 | this.callerDisplayName = callerDisplayName; |
| 374 | } |
| 375 | } |
| 376 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 377 | /** |
| 378 | * A handler that processes messages on the main thread in the phone process. Since many |
| 379 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 380 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 381 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 382 | * on, which will be notified when the operation completes and will contain the result of the |
| 383 | * request. |
| 384 | * |
| 385 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 386 | * note that request.result must be set to something non-null for the calling thread to |
| 387 | * unblock. |
| 388 | */ |
| 389 | private final class MainThreadHandler extends Handler { |
| 390 | @Override |
| 391 | public void handleMessage(Message msg) { |
| 392 | MainThreadRequest request; |
| 393 | Message onCompleted; |
| 394 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 395 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 396 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 397 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 398 | |
| 399 | switch (msg.what) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 400 | case CMD_HANDLE_USSD_REQUEST: { |
| 401 | request = (MainThreadRequest) msg.obj; |
| 402 | final Phone phone = getPhoneFromRequest(request); |
| 403 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 404 | String ussdRequest = ussdObject.first; |
| 405 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 406 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 407 | if (!isUssdApiAllowed(request.subId)) { |
| 408 | // Carrier does not support use of this API, return failure. |
| 409 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 410 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 411 | Bundle returnData = new Bundle(); |
| 412 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 413 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 414 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 415 | request.result = true; |
| 416 | notifyRequester(request); |
| 417 | return; |
| 418 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 419 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 420 | try { |
| 421 | request.result = phone != null |
| 422 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 423 | } catch (CallStateException cse) { |
| 424 | request.result = false; |
| 425 | } |
| 426 | // Wake up the requesting thread |
| 427 | notifyRequester(request); |
| 428 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 431 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 432 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 433 | final Phone phone = getPhoneFromRequest(request); |
| 434 | request.result = phone != null ? |
| 435 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 436 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 437 | // Wake up the requesting thread |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 438 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 439 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 440 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 441 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 442 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 443 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 444 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 445 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 446 | if (uiccCard == null) { |
| 447 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 448 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 449 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 450 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 451 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 452 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 453 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 454 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 455 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 456 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 457 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 458 | break; |
| 459 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 460 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 461 | ar = (AsyncResult) msg.obj; |
| 462 | request = (MainThreadRequest) ar.userObj; |
| 463 | if (ar.exception == null && ar.result != null) { |
| 464 | request.result = ar.result; |
| 465 | } else { |
| 466 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 467 | if (ar.result == null) { |
| 468 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 469 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 470 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 471 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 472 | } else { |
| 473 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 474 | } |
| 475 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 476 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 477 | break; |
| 478 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 479 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 480 | request = (MainThreadRequest) msg.obj; |
| 481 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 482 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 483 | if (uiccCard == null) { |
| 484 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 485 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 486 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 487 | } else { |
| 488 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 489 | request); |
| 490 | uiccCard.iccTransmitApduBasicChannel( |
| 491 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 492 | iccArgument.p3, iccArgument.data, onCompleted); |
| 493 | } |
| 494 | break; |
| 495 | |
| 496 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 497 | ar = (AsyncResult) msg.obj; |
| 498 | request = (MainThreadRequest) ar.userObj; |
| 499 | if (ar.exception == null && ar.result != null) { |
| 500 | request.result = ar.result; |
| 501 | } else { |
| 502 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 503 | if (ar.result == null) { |
| 504 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 505 | } else if (ar.exception instanceof CommandException) { |
| 506 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 507 | ar.exception); |
| 508 | } else { |
| 509 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 510 | } |
| 511 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 512 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 513 | break; |
| 514 | |
| 515 | case CMD_EXCHANGE_SIM_IO: |
| 516 | request = (MainThreadRequest) msg.obj; |
| 517 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 518 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 519 | if (uiccCard == null) { |
| 520 | loge("iccExchangeSimIO: No UICC"); |
| 521 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 522 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 523 | } else { |
| 524 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 525 | request); |
| 526 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 527 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 528 | iccArgument.data, onCompleted); |
| 529 | } |
| 530 | break; |
| 531 | |
| 532 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 533 | ar = (AsyncResult) msg.obj; |
| 534 | request = (MainThreadRequest) ar.userObj; |
| 535 | if (ar.exception == null && ar.result != null) { |
| 536 | request.result = ar.result; |
| 537 | } else { |
| 538 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 539 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 540 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 541 | break; |
| 542 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 543 | case CMD_SEND_ENVELOPE: |
| 544 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 545 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 546 | if (uiccCard == null) { |
| 547 | loge("sendEnvelopeWithStatus: No UICC"); |
| 548 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 549 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 550 | } else { |
| 551 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 552 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 553 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 554 | break; |
| 555 | |
| 556 | case EVENT_SEND_ENVELOPE_DONE: |
| 557 | ar = (AsyncResult) msg.obj; |
| 558 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 559 | if (ar.exception == null && ar.result != null) { |
| 560 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 561 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 562 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 563 | if (ar.result == null) { |
| 564 | loge("sendEnvelopeWithStatus: Empty response"); |
| 565 | } else if (ar.exception instanceof CommandException) { |
| 566 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 567 | ar.exception); |
| 568 | } else { |
| 569 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 570 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 571 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 572 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 573 | break; |
| 574 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 575 | case CMD_OPEN_CHANNEL: |
| 576 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 577 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 578 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 579 | if (uiccCard == null) { |
| 580 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 581 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 582 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 583 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 584 | } else { |
| 585 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 586 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 587 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 588 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 589 | break; |
| 590 | |
| 591 | case EVENT_OPEN_CHANNEL_DONE: |
| 592 | ar = (AsyncResult) msg.obj; |
| 593 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 594 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 595 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 596 | int[] result = (int[]) ar.result; |
| 597 | int channelId = result[0]; |
| 598 | byte[] selectResponse = null; |
| 599 | if (result.length > 1) { |
| 600 | selectResponse = new byte[result.length - 1]; |
| 601 | for (int i = 1; i < result.length; ++i) { |
| 602 | selectResponse[i - 1] = (byte) result[i]; |
| 603 | } |
| 604 | } |
| 605 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 606 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 607 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 608 | if (ar.result == null) { |
| 609 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 610 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 611 | if (ar.exception != null) { |
| 612 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 613 | } |
| 614 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 615 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 616 | if (ar.exception instanceof CommandException) { |
| 617 | CommandException.Error error = |
| 618 | ((CommandException) (ar.exception)).getCommandError(); |
| 619 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 620 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 621 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 622 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 623 | } |
| 624 | } |
| 625 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 626 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 627 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 628 | request.result = openChannelResp; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 629 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 630 | break; |
| 631 | |
| 632 | case CMD_CLOSE_CHANNEL: |
| 633 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 634 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 635 | if (uiccCard == null) { |
| 636 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 637 | request.result = false; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 638 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 639 | } else { |
| 640 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 641 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 642 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 643 | break; |
| 644 | |
| 645 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 646 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 647 | break; |
| 648 | |
| 649 | case CMD_NV_READ_ITEM: |
| 650 | request = (MainThreadRequest) msg.obj; |
| 651 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 652 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 653 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 654 | break; |
| 655 | |
| 656 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 657 | ar = (AsyncResult) msg.obj; |
| 658 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 659 | if (ar.exception == null && ar.result != null) { |
| 660 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 661 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 662 | request.result = ""; |
| 663 | if (ar.result == null) { |
| 664 | loge("nvReadItem: Empty response"); |
| 665 | } else if (ar.exception instanceof CommandException) { |
| 666 | loge("nvReadItem: CommandException: " + |
| 667 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 668 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 669 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 670 | } |
| 671 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 672 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 673 | break; |
| 674 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 675 | case CMD_NV_WRITE_ITEM: |
| 676 | request = (MainThreadRequest) msg.obj; |
| 677 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 678 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 679 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 680 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 681 | break; |
| 682 | |
| 683 | case EVENT_NV_WRITE_ITEM_DONE: |
| 684 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 685 | break; |
| 686 | |
| 687 | case CMD_NV_WRITE_CDMA_PRL: |
| 688 | request = (MainThreadRequest) msg.obj; |
| 689 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 690 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 691 | break; |
| 692 | |
| 693 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 694 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 695 | break; |
| 696 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 697 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 698 | request = (MainThreadRequest) msg.obj; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 699 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 700 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 701 | break; |
| 702 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 703 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 704 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 705 | break; |
| 706 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 707 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 708 | request = (MainThreadRequest) msg.obj; |
| 709 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 710 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 711 | break; |
| 712 | |
| 713 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 714 | ar = (AsyncResult) msg.obj; |
| 715 | request = (MainThreadRequest) ar.userObj; |
| 716 | if (ar.exception == null && ar.result != null) { |
| 717 | request.result = ar.result; // Integer |
| 718 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 719 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 720 | if (ar.result == null) { |
| 721 | loge("getPreferredNetworkType: Empty response"); |
| 722 | } else if (ar.exception instanceof CommandException) { |
| 723 | loge("getPreferredNetworkType: CommandException: " + |
| 724 | ar.exception); |
| 725 | } else { |
| 726 | loge("getPreferredNetworkType: Unknown exception"); |
| 727 | } |
| 728 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 729 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 730 | break; |
| 731 | |
| 732 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 733 | request = (MainThreadRequest) msg.obj; |
| 734 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 735 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 736 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 737 | break; |
| 738 | |
| 739 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 740 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 741 | break; |
| 742 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 743 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 744 | request = (MainThreadRequest)msg.obj; |
| 745 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 746 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 747 | break; |
| 748 | |
| 749 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 750 | ar = (AsyncResult)msg.obj; |
| 751 | request = (MainThreadRequest)ar.userObj; |
| 752 | request.result = ar; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 753 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 754 | break; |
| 755 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 756 | case CMD_SET_VOICEMAIL_NUMBER: |
| 757 | request = (MainThreadRequest) msg.obj; |
| 758 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 759 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 760 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 761 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 762 | break; |
| 763 | |
| 764 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 765 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 766 | break; |
| 767 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 768 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 769 | request = (MainThreadRequest) msg.obj; |
| 770 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 771 | request); |
| 772 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 773 | break; |
| 774 | |
| 775 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 776 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 777 | break; |
| 778 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 779 | case CMD_PERFORM_NETWORK_SCAN: |
| 780 | request = (MainThreadRequest) msg.obj; |
| 781 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 782 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 783 | break; |
| 784 | |
| 785 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 786 | ar = (AsyncResult) msg.obj; |
| 787 | request = (MainThreadRequest) ar.userObj; |
| 788 | CellNetworkScanResult cellScanResult; |
| 789 | if (ar.exception == null && ar.result != null) { |
| 790 | cellScanResult = new CellNetworkScanResult( |
| 791 | CellNetworkScanResult.STATUS_SUCCESS, |
| 792 | (List<OperatorInfo>) ar.result); |
| 793 | } else { |
| 794 | if (ar.result == null) { |
| 795 | loge("getCellNetworkScanResults: Empty response"); |
| 796 | } |
| 797 | if (ar.exception != null) { |
| 798 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 799 | } |
| 800 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 801 | if (ar.exception instanceof CommandException) { |
| 802 | CommandException.Error error = |
| 803 | ((CommandException) (ar.exception)).getCommandError(); |
| 804 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 805 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 806 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 807 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 808 | } |
| 809 | } |
| 810 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 811 | } |
| 812 | request.result = cellScanResult; |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 813 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 814 | break; |
| 815 | |
| 816 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 817 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 818 | ManualNetworkSelectionArgument selArg = |
| 819 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 820 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 821 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 822 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 823 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 824 | break; |
| 825 | |
| 826 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | dd9ac82 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 827 | ar = (AsyncResult) msg.obj; |
| 828 | request = (MainThreadRequest) ar.userObj; |
| 829 | if (ar.exception == null) { |
| 830 | request.result = true; |
| 831 | } else { |
| 832 | request.result = false; |
| 833 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 834 | } |
| 835 | notifyRequester(request); |
| 836 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 837 | break; |
| 838 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 839 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 840 | request = (MainThreadRequest) msg.obj; |
| 841 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | c56281c | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 842 | if (defaultPhone != null) { |
| 843 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 844 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 845 | break; |
| 846 | |
| 847 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 848 | ar = (AsyncResult) msg.obj; |
| 849 | request = (MainThreadRequest) ar.userObj; |
| 850 | if (ar.exception == null && ar.result != null) { |
| 851 | request.result = ar.result; |
| 852 | } else { |
| 853 | if (ar.result == null) { |
| 854 | loge("queryModemActivityInfo: Empty response"); |
| 855 | } else if (ar.exception instanceof CommandException) { |
| 856 | loge("queryModemActivityInfo: CommandException: " + |
| 857 | ar.exception); |
| 858 | } else { |
| 859 | loge("queryModemActivityInfo: Unknown exception"); |
| 860 | } |
| 861 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 862 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 863 | if (request.result == null) { |
| 864 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 865 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 866 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 867 | break; |
| 868 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 869 | case CMD_SET_ALLOWED_CARRIERS: |
| 870 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 871 | CarrierRestrictionRules argument = |
| 872 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 873 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 874 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 875 | break; |
| 876 | |
| 877 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 878 | ar = (AsyncResult) msg.obj; |
| 879 | request = (MainThreadRequest) ar.userObj; |
| 880 | if (ar.exception == null && ar.result != null) { |
| 881 | request.result = ar.result; |
| 882 | } else { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 883 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 884 | if (ar.exception instanceof CommandException) { |
| 885 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 886 | CommandException.Error error = |
| 887 | ((CommandException) (ar.exception)).getCommandError(); |
| 888 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 889 | request.result = |
| 890 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 891 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 892 | } else { |
| 893 | loge("setAllowedCarriers: Unknown exception"); |
| 894 | } |
| 895 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 896 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 897 | break; |
| 898 | |
| 899 | case CMD_GET_ALLOWED_CARRIERS: |
| 900 | request = (MainThreadRequest) msg.obj; |
| 901 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 902 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 903 | break; |
| 904 | |
| 905 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 906 | ar = (AsyncResult) msg.obj; |
| 907 | request = (MainThreadRequest) ar.userObj; |
| 908 | if (ar.exception == null && ar.result != null) { |
| 909 | request.result = ar.result; |
| 910 | } else { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 911 | request.result = new IllegalStateException( |
| 912 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 913 | if (ar.result == null) { |
| 914 | loge("getAllowedCarriers: Empty response"); |
| 915 | } else if (ar.exception instanceof CommandException) { |
| 916 | loge("getAllowedCarriers: CommandException: " + |
| 917 | ar.exception); |
| 918 | } else { |
| 919 | loge("getAllowedCarriers: Unknown exception"); |
| 920 | } |
| 921 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 922 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 923 | break; |
| 924 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 925 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 926 | ar = (AsyncResult) msg.obj; |
| 927 | request = (MainThreadRequest) ar.userObj; |
| 928 | if (ar.exception == null && ar.result != null) { |
| 929 | request.result = ar.result; |
| 930 | } else { |
| 931 | request.result = new IllegalArgumentException( |
| 932 | "Failed to retrieve Forbidden Plmns"); |
| 933 | if (ar.result == null) { |
| 934 | loge("getForbiddenPlmns: Empty response"); |
| 935 | } else { |
| 936 | loge("getForbiddenPlmns: Unknown exception"); |
| 937 | } |
| 938 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 939 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 940 | break; |
| 941 | |
| 942 | case CMD_GET_FORBIDDEN_PLMNS: |
| 943 | request = (MainThreadRequest) msg.obj; |
| 944 | uiccCard = getUiccCardFromRequest(request); |
| 945 | if (uiccCard == null) { |
| 946 | loge("getForbiddenPlmns() UiccCard is null"); |
| 947 | request.result = new IllegalArgumentException( |
| 948 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 949 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 950 | break; |
| 951 | } |
| 952 | Integer appType = (Integer) request.argument; |
| 953 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 954 | if (uiccApp == null) { |
| 955 | loge("getForbiddenPlmns() no app with specified type -- " |
| 956 | + appType); |
| 957 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 958 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 959 | break; |
| 960 | } else { |
| 961 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 962 | + " specified type -- " + appType); |
| 963 | } |
| 964 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 965 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 966 | onCompleted); |
| 967 | break; |
| 968 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 969 | case CMD_SWITCH_SLOTS: |
| 970 | request = (MainThreadRequest) msg.obj; |
| 971 | int[] physicalSlots = (int[]) request.argument; |
| 972 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 973 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 974 | break; |
| 975 | |
| 976 | case EVENT_SWITCH_SLOTS_DONE: |
| 977 | ar = (AsyncResult) msg.obj; |
| 978 | request = (MainThreadRequest) ar.userObj; |
| 979 | request.result = (ar.exception == null); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 980 | notifyRequester(request); |
| 981 | break; |
| 982 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 983 | request = (MainThreadRequest) msg.obj; |
| 984 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 985 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 986 | break; |
| 987 | |
| 988 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 989 | ar = (AsyncResult) msg.obj; |
| 990 | request = (MainThreadRequest) ar.userObj; |
| 991 | if (ar.exception != null) { |
| 992 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 993 | } else { |
| 994 | int mode = ((int[]) ar.result)[0]; |
| 995 | if (mode == 0) { |
| 996 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 997 | } else { |
| 998 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 999 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1000 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1001 | notifyRequester(request); |
| 1002 | break; |
| 1003 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1004 | request = (MainThreadRequest) msg.obj; |
| 1005 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1006 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1007 | break; |
| 1008 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1009 | ar = (AsyncResult) msg.obj; |
| 1010 | request = (MainThreadRequest) ar.userObj; |
| 1011 | if (ar.exception != null) { |
| 1012 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1013 | } else { |
| 1014 | request.result = ((int[]) ar.result)[0]; |
| 1015 | } |
| 1016 | notifyRequester(request); |
| 1017 | break; |
| 1018 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1019 | request = (MainThreadRequest) msg.obj; |
| 1020 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1021 | int mode = (int) request.argument; |
| 1022 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1023 | break; |
| 1024 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1025 | ar = (AsyncResult) msg.obj; |
| 1026 | request = (MainThreadRequest) ar.userObj; |
| 1027 | request.result = ar.exception == null; |
| 1028 | notifyRequester(request); |
| 1029 | break; |
| 1030 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1031 | request = (MainThreadRequest) msg.obj; |
| 1032 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1033 | int subscriptionMode = (int) request.argument; |
| 1034 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1035 | break; |
| 1036 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1037 | ar = (AsyncResult) msg.obj; |
| 1038 | request = (MainThreadRequest) ar.userObj; |
| 1039 | request.result = ar.exception == null; |
| 1040 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1041 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1042 | case CMD_GET_ALL_CELL_INFO: |
| 1043 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1044 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1045 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1046 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1047 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1048 | ar = (AsyncResult) msg.obj; |
| 1049 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1050 | // If a timeout occurs, the response will be null |
| 1051 | request.result = (ar.exception == null && ar.result != null) |
| 1052 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1053 | synchronized (request) { |
| 1054 | request.notifyAll(); |
| 1055 | } |
| 1056 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1057 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1058 | request = (MainThreadRequest) msg.obj; |
| 1059 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1060 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1061 | break; |
| 1062 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1063 | ar = (AsyncResult) msg.obj; |
| 1064 | request = (MainThreadRequest) ar.userObj; |
| 1065 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1066 | try { |
| 1067 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1068 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1069 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1070 | new android.os.ParcelableException(ar.exception)); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1071 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1072 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1073 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1074 | } else { |
| 1075 | // use the result as returned |
| 1076 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1077 | } |
| 1078 | } catch (RemoteException re) { |
| 1079 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1080 | } |
| 1081 | break; |
| 1082 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1083 | request = (MainThreadRequest) msg.obj; |
| 1084 | WorkSource ws = (WorkSource) request.argument; |
| 1085 | Phone phone = getPhoneFromRequest(request); |
| 1086 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1087 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1088 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1089 | ar = (AsyncResult) msg.obj; |
| 1090 | request = (MainThreadRequest) ar.userObj; |
| 1091 | if (ar.exception == null) { |
| 1092 | request.result = ar.result; |
| 1093 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1094 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1095 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1096 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1097 | } |
| 1098 | |
| 1099 | synchronized (request) { |
| 1100 | request.notifyAll(); |
| 1101 | } |
| 1102 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1103 | case CMD_MODEM_REBOOT: |
| 1104 | request = (MainThreadRequest) msg.obj; |
| 1105 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1106 | defaultPhone.rebootModem(onCompleted); |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1107 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1108 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1109 | handleNullReturnEvent(msg, "rebootModem"); |
| 1110 | break; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1111 | case CMD_REQUEST_ENABLE_MODEM: |
| 1112 | request = (MainThreadRequest) msg.obj; |
| 1113 | boolean enable = (boolean) request.argument; |
| 1114 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 9b37957 | 2019-03-01 17:27:47 -0800 | [diff] [blame] | 1115 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1116 | PhoneConfigurationManager.getInstance() |
| 1117 | .enablePhone(request.phone, enable, onCompleted); |
| 1118 | break; |
| 1119 | case EVENT_ENABLE_MODEM_DONE: |
| 1120 | ar = (AsyncResult) msg.obj; |
| 1121 | request = (MainThreadRequest) ar.userObj; |
| 1122 | request.result = (ar.exception == null); |
Nazanin Bakhshi | 1f78d7d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1123 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 9b37957 | 2019-03-01 17:27:47 -0800 | [diff] [blame] | 1124 | //update the cache as modem status has changed |
Nazanin Bakhshi | 1f78d7d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1125 | if ((boolean) request.result) { |
| 1126 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1127 | updateModemStateMetrics(); |
| 1128 | } else { |
| 1129 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1130 | + ar.exception); |
| 1131 | } |
| 1132 | notifyRequester(request); |
| 1133 | break; |
| 1134 | case CMD_GET_MODEM_STATUS: |
| 1135 | request = (MainThreadRequest) msg.obj; |
| 1136 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1137 | PhoneConfigurationManager.getInstance() |
| 1138 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1139 | break; |
| 1140 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1141 | ar = (AsyncResult) msg.obj; |
| 1142 | request = (MainThreadRequest) ar.userObj; |
| 1143 | int id = request.phone.getPhoneId(); |
| 1144 | if (ar.exception == null && ar.result != null) { |
| 1145 | request.result = ar.result; |
| 1146 | //update the cache as modem status has changed |
| 1147 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1148 | (boolean) request.result); |
| 1149 | } else { |
| 1150 | // Return true if modem status cannot be retrieved. For most cases, |
| 1151 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1152 | // and disable modem are not supported. Modem is always on. |
| 1153 | // TODO: this should be fixed in R to support a third |
| 1154 | // status UNKNOWN b/131631629 |
| 1155 | request.result = true; |
| 1156 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1157 | + ar.exception); |
| 1158 | } |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1159 | notifyRequester(request); |
| 1160 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1161 | default: |
| 1162 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1163 | break; |
| 1164 | } |
| 1165 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1166 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1167 | private void notifyRequester(MainThreadRequest request) { |
| 1168 | synchronized (request) { |
| 1169 | request.notifyAll(); |
| 1170 | } |
| 1171 | } |
| 1172 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1173 | private void handleNullReturnEvent(Message msg, String command) { |
| 1174 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1175 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1176 | if (ar.exception == null) { |
| 1177 | request.result = true; |
| 1178 | } else { |
| 1179 | request.result = false; |
| 1180 | if (ar.exception instanceof CommandException) { |
| 1181 | loge(command + ": CommandException: " + ar.exception); |
| 1182 | } else { |
| 1183 | loge(command + ": Unknown exception"); |
| 1184 | } |
| 1185 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1186 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1187 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
| 1190 | /** |
| 1191 | * Posts the specified command to be executed on the main thread, |
| 1192 | * waits for the request to complete, and returns the result. |
| 1193 | * @see #sendRequestAsync |
| 1194 | */ |
| 1195 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1196 | return sendRequest( |
| 1197 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | /** |
| 1201 | * Posts the specified command to be executed on the main thread, |
| 1202 | * waits for the request to complete, and returns the result. |
| 1203 | * @see #sendRequestAsync |
| 1204 | */ |
| 1205 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1206 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1207 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | /** |
| 1211 | * Posts the specified command to be executed on the main thread, |
| 1212 | * waits for the request to complete, and returns the result. |
| 1213 | * @see #sendRequestAsync |
| 1214 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1215 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1216 | return sendRequest(command, argument, subId, null, null); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | /** |
| 1220 | * Posts the specified command to be executed on the main thread, |
| 1221 | * waits for the request to complete, and returns the result. |
| 1222 | * @see #sendRequestAsync |
| 1223 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1224 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1225 | return sendRequest(command, argument, subId, null, workSource); |
| 1226 | } |
| 1227 | |
| 1228 | /** |
| 1229 | * Posts the specified command to be executed on the main thread, |
| 1230 | * waits for the request to complete, and returns the result. |
| 1231 | * @see #sendRequestAsync |
| 1232 | */ |
| 1233 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1234 | return sendRequest( |
| 1235 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1236 | } |
| 1237 | |
| 1238 | /** |
| 1239 | * Posts the specified command to be executed on the main thread, |
| 1240 | * waits for the request to complete, and returns the result. |
| 1241 | * @see #sendRequestAsync |
| 1242 | */ |
| 1243 | private Object sendRequest( |
| 1244 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1245 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1246 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1247 | } |
| 1248 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1249 | MainThreadRequest request = null; |
| 1250 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1251 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1252 | } else if (phone != null) { |
| 1253 | request = new MainThreadRequest(argument, phone, workSource); |
| 1254 | } else { |
| 1255 | request = new MainThreadRequest(argument, subId, workSource); |
| 1256 | } |
| 1257 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1258 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1259 | msg.sendToTarget(); |
| 1260 | |
| 1261 | // Wait for the request to complete |
| 1262 | synchronized (request) { |
| 1263 | while (request.result == null) { |
| 1264 | try { |
| 1265 | request.wait(); |
| 1266 | } catch (InterruptedException e) { |
| 1267 | // Do nothing, go back and wait until the request is complete |
| 1268 | } |
| 1269 | } |
| 1270 | } |
| 1271 | return request.result; |
| 1272 | } |
| 1273 | |
| 1274 | /** |
| 1275 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1276 | * Posts the specified command to be executed on the main thread, and |
| 1277 | * returns immediately. |
| 1278 | * @see #sendRequest |
| 1279 | */ |
| 1280 | private void sendRequestAsync(int command) { |
| 1281 | mMainThreadHandler.sendEmptyMessage(command); |
| 1282 | } |
| 1283 | |
| 1284 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1285 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1286 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1287 | */ |
| 1288 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1289 | sendRequestAsync(command, argument, null, null); |
| 1290 | } |
| 1291 | |
| 1292 | /** |
| 1293 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1294 | * @see {@link #sendRequest(int,Object)} |
| 1295 | */ |
| 1296 | private void sendRequestAsync( |
| 1297 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1298 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1299 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1300 | msg.sendToTarget(); |
| 1301 | } |
| 1302 | |
| 1303 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1304 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1305 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1306 | */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1307 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1308 | synchronized (PhoneInterfaceManager.class) { |
| 1309 | if (sInstance == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1310 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1311 | } else { |
| 1312 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1313 | } |
| 1314 | return sInstance; |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1319 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1320 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1321 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1322 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1323 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1324 | mMainThreadHandler = new MainThreadHandler(); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1325 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1326 | mTelephonySharedPreferences = |
| 1327 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1328 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1329 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1330 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1331 | publish(); |
| 1332 | } |
| 1333 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1334 | private Phone getDefaultPhone() { |
| 1335 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1336 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1337 | } |
| 1338 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1339 | private void publish() { |
| 1340 | if (DBG) log("publish: " + this); |
| 1341 | |
| 1342 | ServiceManager.addService("phone", this); |
| 1343 | } |
| 1344 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1345 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1346 | if (request.phone != null) { |
| 1347 | return request.phone; |
| 1348 | } else { |
| 1349 | return getPhoneFromSubId(request.subId); |
| 1350 | } |
| 1351 | } |
| 1352 | |
| 1353 | private Phone getPhoneFromSubId(int subId) { |
| 1354 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1355 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1356 | } |
| 1357 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1358 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1359 | Phone phone = getPhoneFromRequest(request); |
| 1360 | return phone == null ? null : |
| 1361 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1362 | } |
| 1363 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1364 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1365 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1366 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1367 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1368 | |
| 1369 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1370 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1371 | } |
| 1372 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1373 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1374 | if (DBG) log("dial: " + number); |
| 1375 | // No permission check needed here: This is just a wrapper around the |
| 1376 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1377 | // the UI before it does anything. |
| 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 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1387 | PhoneConstants.State state = mCM.getState(subId); |
| 1388 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1389 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1390 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1391 | mApp.startActivity(intent); |
| 1392 | } |
| 1393 | } finally { |
| 1394 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1395 | } |
| 1396 | } |
| 1397 | |
| 1398 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1399 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1402 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1403 | if (DBG) log("call: " + number); |
| 1404 | |
| 1405 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1406 | // need to do a permission check since we're calling startActivity() |
| 1407 | // from the context of the phone app. |
| 1408 | enforceCallPermission(); |
| 1409 | |
| 1410 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1411 | != AppOpsManager.MODE_ALLOWED) { |
| 1412 | return; |
| 1413 | } |
| 1414 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1415 | final long identity = Binder.clearCallingIdentity(); |
| 1416 | try { |
| 1417 | String url = createTelUrl(number); |
| 1418 | if (url == null) { |
| 1419 | return; |
| 1420 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1421 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1422 | boolean isValid = false; |
| 1423 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1424 | if (slist != null) { |
| 1425 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1426 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1427 | isValid = true; |
| 1428 | break; |
| 1429 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1430 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1431 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1432 | if (!isValid) { |
| 1433 | return; |
| 1434 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1435 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1436 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1437 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1438 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1439 | mApp.startActivity(intent); |
| 1440 | } finally { |
| 1441 | Binder.restoreCallingIdentity(identity); |
| 1442 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1445 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1446 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1447 | } |
| 1448 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1449 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1450 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1451 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1452 | } |
| 1453 | |
| 1454 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1455 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1456 | } |
| 1457 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1458 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1459 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1460 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1461 | } |
| 1462 | |
| 1463 | /** {@hide} */ |
| 1464 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1465 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1466 | } |
| 1467 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1468 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1469 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1470 | |
| 1471 | final long identity = Binder.clearCallingIdentity(); |
| 1472 | try { |
| 1473 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1474 | checkSimPin.start(); |
| 1475 | return checkSimPin.unlockSim(null, pin); |
| 1476 | } finally { |
| 1477 | Binder.restoreCallingIdentity(identity); |
| 1478 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1479 | } |
| 1480 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1481 | /** {@hide} */ |
| 1482 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1483 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1484 | } |
| 1485 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1486 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1487 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1488 | |
| 1489 | final long identity = Binder.clearCallingIdentity(); |
| 1490 | try { |
| 1491 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1492 | checkSimPuk.start(); |
| 1493 | return checkSimPuk.unlockSim(puk, pin); |
| 1494 | } finally { |
| 1495 | Binder.restoreCallingIdentity(identity); |
| 1496 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1500 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1501 | * a synchronous one. |
| 1502 | */ |
| 1503 | private static class UnlockSim extends Thread { |
| 1504 | |
| 1505 | private final IccCard mSimCard; |
| 1506 | |
| 1507 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1508 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1509 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1510 | |
| 1511 | // For replies from SimCard interface |
| 1512 | private Handler mHandler; |
| 1513 | |
| 1514 | // For async handler to identify request type |
| 1515 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1516 | |
| 1517 | public UnlockSim(IccCard simCard) { |
| 1518 | mSimCard = simCard; |
| 1519 | } |
| 1520 | |
| 1521 | @Override |
| 1522 | public void run() { |
| 1523 | Looper.prepare(); |
| 1524 | synchronized (UnlockSim.this) { |
| 1525 | mHandler = new Handler() { |
| 1526 | @Override |
| 1527 | public void handleMessage(Message msg) { |
| 1528 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1529 | switch (msg.what) { |
| 1530 | case SUPPLY_PIN_COMPLETE: |
| 1531 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1532 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1533 | mRetryCount = msg.arg1; |
| 1534 | if (ar.exception != null) { |
| 1535 | if (ar.exception instanceof CommandException && |
| 1536 | ((CommandException)(ar.exception)).getCommandError() |
| 1537 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1538 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1539 | } else { |
| 1540 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1541 | } |
| 1542 | } else { |
| 1543 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1544 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1545 | mDone = true; |
| 1546 | UnlockSim.this.notifyAll(); |
| 1547 | } |
| 1548 | break; |
| 1549 | } |
| 1550 | } |
| 1551 | }; |
| 1552 | UnlockSim.this.notifyAll(); |
| 1553 | } |
| 1554 | Looper.loop(); |
| 1555 | } |
| 1556 | |
| 1557 | /* |
| 1558 | * Use PIN or PUK to unlock SIM card |
| 1559 | * |
| 1560 | * If PUK is null, unlock SIM card with PIN |
| 1561 | * |
| 1562 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1563 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1564 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1565 | |
| 1566 | while (mHandler == null) { |
| 1567 | try { |
| 1568 | wait(); |
| 1569 | } catch (InterruptedException e) { |
| 1570 | Thread.currentThread().interrupt(); |
| 1571 | } |
| 1572 | } |
| 1573 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1574 | |
| 1575 | if (puk == null) { |
| 1576 | mSimCard.supplyPin(pin, callback); |
| 1577 | } else { |
| 1578 | mSimCard.supplyPuk(puk, pin, callback); |
| 1579 | } |
| 1580 | |
| 1581 | while (!mDone) { |
| 1582 | try { |
| 1583 | Log.d(LOG_TAG, "wait for done"); |
| 1584 | wait(); |
| 1585 | } catch (InterruptedException e) { |
| 1586 | // Restore the interrupted status |
| 1587 | Thread.currentThread().interrupt(); |
| 1588 | } |
| 1589 | } |
| 1590 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1591 | int[] resultArray = new int[2]; |
| 1592 | resultArray[0] = mResult; |
| 1593 | resultArray[1] = mRetryCount; |
| 1594 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1595 | } |
| 1596 | } |
| 1597 | |
| 1598 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1599 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1600 | |
| 1601 | } |
| 1602 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1603 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1604 | // No permission check needed here: this call is harmless, and it's |
| 1605 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1606 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1607 | final long identity = Binder.clearCallingIdentity(); |
| 1608 | try { |
| 1609 | final Phone phone = getPhone(subId); |
| 1610 | if (phone != null) { |
| 1611 | phone.updateServiceLocation(); |
| 1612 | } |
| 1613 | } finally { |
| 1614 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1615 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1616 | } |
| 1617 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1618 | @Override |
| 1619 | public boolean isRadioOn(String callingPackage) { |
| 1620 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1621 | } |
| 1622 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1623 | @Override |
| 1624 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1625 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1626 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1627 | return false; |
| 1628 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1629 | |
| 1630 | final long identity = Binder.clearCallingIdentity(); |
| 1631 | try { |
| 1632 | return isRadioOnForSubscriber(subId); |
| 1633 | } finally { |
| 1634 | Binder.restoreCallingIdentity(identity); |
| 1635 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1639 | final long identity = Binder.clearCallingIdentity(); |
| 1640 | try { |
| 1641 | final Phone phone = getPhone(subId); |
| 1642 | if (phone != null) { |
| 1643 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1644 | } else { |
| 1645 | return false; |
| 1646 | } |
| 1647 | } finally { |
| 1648 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1649 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1653 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
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 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1656 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1657 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1658 | |
| 1659 | final long identity = Binder.clearCallingIdentity(); |
| 1660 | try { |
| 1661 | final Phone phone = getPhone(subId); |
| 1662 | if (phone != null) { |
| 1663 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1664 | } |
| 1665 | } finally { |
| 1666 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1667 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1671 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1672 | } |
| 1673 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1674 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1675 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1676 | |
| 1677 | final long identity = Binder.clearCallingIdentity(); |
| 1678 | try { |
| 1679 | final Phone phone = getPhone(subId); |
| 1680 | if (phone == null) { |
| 1681 | return false; |
| 1682 | } |
| 1683 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1684 | toggleRadioOnOffForSubscriber(subId); |
| 1685 | } |
| 1686 | return true; |
| 1687 | } finally { |
| 1688 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1689 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1690 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1691 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1692 | public boolean needMobileRadioShutdown() { |
| 1693 | /* |
| 1694 | * If any of the Radios are available, it will need to be |
| 1695 | * shutdown. So return true if any Radio is available. |
| 1696 | */ |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1697 | final long identity = Binder.clearCallingIdentity(); |
| 1698 | try { |
| 1699 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1700 | Phone phone = PhoneFactory.getPhone(i); |
| 1701 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1702 | } |
| 1703 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1704 | return false; |
| 1705 | } finally { |
| 1706 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1707 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1708 | } |
| 1709 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1710 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1711 | public void shutdownMobileRadios() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1712 | enforceModifyPermission(); |
| 1713 | |
| 1714 | final long identity = Binder.clearCallingIdentity(); |
| 1715 | try { |
| 1716 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1717 | logv("Shutting down Phone " + i); |
| 1718 | shutdownRadioUsingPhoneId(i); |
| 1719 | } |
| 1720 | } finally { |
| 1721 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1722 | } |
| 1723 | } |
| 1724 | |
| 1725 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1726 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1727 | if (phone != null && phone.isRadioAvailable()) { |
| 1728 | phone.shutdownRadio(); |
| 1729 | } |
| 1730 | } |
| 1731 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1732 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1733 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1734 | |
| 1735 | final long identity = Binder.clearCallingIdentity(); |
| 1736 | try { |
| 1737 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1738 | if (defaultPhone != null) { |
| 1739 | defaultPhone.setRadioPower(turnOn); |
| 1740 | return true; |
| 1741 | } else { |
| 1742 | loge("There's no default phone."); |
| 1743 | return false; |
| 1744 | } |
| 1745 | } finally { |
| 1746 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1747 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1748 | } |
| 1749 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1750 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1751 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1752 | |
| 1753 | final long identity = Binder.clearCallingIdentity(); |
| 1754 | try { |
| 1755 | final Phone phone = getPhone(subId); |
| 1756 | if (phone != null) { |
| 1757 | phone.setRadioPower(turnOn); |
| 1758 | return true; |
| 1759 | } else { |
| 1760 | return false; |
| 1761 | } |
| 1762 | } finally { |
| 1763 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1764 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1767 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1768 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1769 | public boolean enableDataConnectivity() { |
| 1770 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1771 | |
| 1772 | final long identity = Binder.clearCallingIdentity(); |
| 1773 | try { |
| 1774 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1775 | final Phone phone = getPhone(subId); |
| 1776 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1777 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1778 | return true; |
| 1779 | } else { |
| 1780 | return false; |
| 1781 | } |
| 1782 | } finally { |
| 1783 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1784 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1787 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1788 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1789 | public boolean disableDataConnectivity() { |
| 1790 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1791 | |
| 1792 | final long identity = Binder.clearCallingIdentity(); |
| 1793 | try { |
| 1794 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1795 | final Phone phone = getPhone(subId); |
| 1796 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1797 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1798 | return true; |
| 1799 | } else { |
| 1800 | return false; |
| 1801 | } |
| 1802 | } finally { |
| 1803 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1804 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1807 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1808 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1809 | final long identity = Binder.clearCallingIdentity(); |
| 1810 | try { |
| 1811 | final Phone phone = getPhone(subId); |
| 1812 | if (phone != null) { |
Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1813 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1814 | } else { |
| 1815 | return false; |
| 1816 | } |
| 1817 | } finally { |
| 1818 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1819 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1823 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1824 | } |
| 1825 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1826 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1827 | enforceCallPermission(); |
| 1828 | |
| 1829 | final long identity = Binder.clearCallingIdentity(); |
| 1830 | try { |
| 1831 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1832 | return; |
| 1833 | } |
| 1834 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1835 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1836 | } finally { |
| 1837 | Binder.restoreCallingIdentity(identity); |
| 1838 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1839 | }; |
| 1840 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1841 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1842 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1843 | |
| 1844 | final long identity = Binder.clearCallingIdentity(); |
| 1845 | try { |
| 1846 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1847 | return false; |
| 1848 | } |
| 1849 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1850 | } finally { |
| 1851 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1852 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1853 | } |
| 1854 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1855 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1856 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1857 | } |
| 1858 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1859 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1860 | final long identity = Binder.clearCallingIdentity(); |
| 1861 | try { |
| 1862 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1863 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1864 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1865 | } finally { |
| 1866 | Binder.restoreCallingIdentity(identity); |
| 1867 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1868 | } |
| 1869 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1870 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1871 | public int getDataState() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1872 | final long identity = Binder.clearCallingIdentity(); |
| 1873 | try { |
| 1874 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1875 | if (phone != null) { |
| 1876 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1877 | } else { |
| 1878 | return PhoneConstantConversions.convertDataState( |
| 1879 | PhoneConstants.DataState.DISCONNECTED); |
| 1880 | } |
| 1881 | } finally { |
| 1882 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1883 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1884 | } |
| 1885 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1886 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1887 | public int getDataActivity() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1888 | final long identity = Binder.clearCallingIdentity(); |
| 1889 | try { |
| 1890 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1891 | if (phone != null) { |
| 1892 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1893 | } else { |
| 1894 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1895 | } |
| 1896 | } finally { |
| 1897 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1898 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1902 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1903 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1904 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1905 | |
| 1906 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 1907 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 1908 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 1909 | .setCallingPackage(callingPackage) |
| 1910 | .setCallingPid(Binder.getCallingPid()) |
| 1911 | .setCallingUid(Binder.getCallingUid()) |
| 1912 | .setMethod("getCellLocation") |
| 1913 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 1914 | .build()); |
| 1915 | switch (locationResult) { |
| 1916 | case DENIED_HARD: |
| 1917 | throw new SecurityException("Not allowed to access cell location"); |
| 1918 | case DENIED_SOFT: |
| 1919 | return new Bundle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1920 | } |
| 1921 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1922 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1923 | final long identity = Binder.clearCallingIdentity(); |
| 1924 | try { |
| 1925 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1926 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1927 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1928 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1929 | cl.fillInNotifierBundle(data); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1930 | return data; |
| 1931 | } finally { |
| 1932 | Binder.restoreCallingIdentity(identity); |
| 1933 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1934 | } |
| 1935 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1936 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1937 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1938 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1939 | // registered cell info, so return a NULL country instead. |
| 1940 | final long identity = Binder.clearCallingIdentity(); |
| 1941 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1942 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1943 | // Get default phone in this case. |
| 1944 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1945 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1946 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1947 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1948 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1949 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1950 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1951 | return ""; |
| 1952 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1953 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1954 | if (phone != null) { |
| 1955 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 1956 | if (sst != null) { |
| 1957 | LocaleTracker lt = sst.getLocaleTracker(); |
| 1958 | if (lt != null) { |
| 1959 | return lt.getCurrentCountry(); |
| 1960 | } |
| 1961 | } |
| 1962 | } |
| 1963 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1964 | } finally { |
| 1965 | Binder.restoreCallingIdentity(identity); |
| 1966 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1970 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1971 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1972 | } |
| 1973 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1974 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1975 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1976 | mApp.enforceCallingOrSelfPermission( |
| 1977 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1978 | |
| 1979 | final long identity = Binder.clearCallingIdentity(); |
| 1980 | try { |
| 1981 | final Phone phone = getPhone(subId); |
| 1982 | if (phone != null) { |
| 1983 | phone.enableLocationUpdates(); |
| 1984 | } |
| 1985 | } finally { |
| 1986 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1987 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | @Override |
| 1991 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1992 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1993 | } |
| 1994 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1995 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1996 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1997 | mApp.enforceCallingOrSelfPermission( |
| 1998 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1999 | |
| 2000 | final long identity = Binder.clearCallingIdentity(); |
| 2001 | try { |
| 2002 | final Phone phone = getPhone(subId); |
| 2003 | if (phone != null) { |
| 2004 | phone.disableLocationUpdates(); |
| 2005 | } |
| 2006 | } finally { |
| 2007 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2008 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2009 | } |
| 2010 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2011 | /** |
| 2012 | * Returns the target SDK version number for a given package name. |
| 2013 | * |
| 2014 | * @return target SDK if the package is found or INT_MAX. |
| 2015 | */ |
| 2016 | private int getTargetSdk(String packageName) { |
| 2017 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2018 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo( |
| 2019 | packageName, 0); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2020 | if (ai != null) return ai.targetSdkVersion; |
| 2021 | } catch (PackageManager.NameNotFoundException unexpected) { |
| 2022 | } |
| 2023 | return Integer.MAX_VALUE; |
| 2024 | } |
| 2025 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2026 | @Override |
| 2027 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2028 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 2029 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2030 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2031 | throw new SecurityException( |
| 2032 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2033 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2034 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2035 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 2036 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2037 | return null; |
| 2038 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2039 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2040 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2041 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2042 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 2043 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2044 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2045 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2046 | for (CellInfo ci : info) { |
| 2047 | if (ci instanceof CellInfoGsm) { |
| 2048 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2049 | } else if (ci instanceof CellInfoWcdma) { |
| 2050 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2051 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2052 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2053 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2054 | } |
| 2055 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2056 | private List<CellInfo> getCachedCellInfo() { |
| 2057 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2058 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2059 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2060 | if (info != null) cellInfos.addAll(info); |
| 2061 | } |
| 2062 | return cellInfos; |
| 2063 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2064 | |
| 2065 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2066 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2067 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2068 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2069 | |
| 2070 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2071 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2072 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2073 | .setCallingPackage(callingPackage) |
| 2074 | .setCallingPid(Binder.getCallingPid()) |
| 2075 | .setCallingUid(Binder.getCallingUid()) |
| 2076 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2077 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2078 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2079 | .build()); |
| 2080 | switch (locationResult) { |
| 2081 | case DENIED_HARD: |
| 2082 | throw new SecurityException("Not allowed to access cell info"); |
| 2083 | case DENIED_SOFT: |
| 2084 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2085 | } |
| 2086 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2087 | final int targetSdk = getTargetSdk(callingPackage); |
| 2088 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2089 | return getCachedCellInfo(); |
| 2090 | } |
| 2091 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2092 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2093 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2094 | final long identity = Binder.clearCallingIdentity(); |
| 2095 | try { |
| 2096 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2097 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2098 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2099 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2100 | if (info != null) cellInfos.addAll(info); |
| 2101 | } |
| 2102 | return cellInfos; |
| 2103 | } finally { |
| 2104 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2105 | } |
| 2106 | } |
| 2107 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2108 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2109 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2110 | requestCellInfoUpdateInternal( |
| 2111 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2112 | } |
| 2113 | |
| 2114 | @Override |
| 2115 | public void requestCellInfoUpdateWithWorkSource( |
| 2116 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2117 | enforceModifyPermission(); |
| 2118 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2119 | } |
| 2120 | |
| 2121 | private void requestCellInfoUpdateInternal( |
| 2122 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2123 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2124 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2125 | |
| 2126 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2127 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2128 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2129 | .setCallingPackage(callingPackage) |
| 2130 | .setCallingPid(Binder.getCallingPid()) |
| 2131 | .setCallingUid(Binder.getCallingUid()) |
| 2132 | .setMethod("requestCellInfoUpdate") |
| 2133 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2134 | .build()); |
| 2135 | switch (locationResult) { |
| 2136 | case DENIED_HARD: |
| 2137 | throw new SecurityException("Not allowed to access cell info"); |
| 2138 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2139 | try { |
| 2140 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2141 | } catch (RemoteException re) { |
| 2142 | // Drop without consequences |
| 2143 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2144 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2145 | } |
| 2146 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2147 | |
| 2148 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2149 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2150 | |
| 2151 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2152 | } |
| 2153 | |
| 2154 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2155 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2156 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2157 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2158 | |
| 2159 | final long identity = Binder.clearCallingIdentity(); |
| 2160 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2161 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2162 | } finally { |
| 2163 | Binder.restoreCallingIdentity(identity); |
| 2164 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2165 | } |
| 2166 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2167 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2168 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2169 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2170 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2171 | return null; |
| 2172 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2173 | int subId = phone.getSubId(); |
| 2174 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2175 | mApp, subId, callingPackage, "getImeiForSlot")) { |
| 2176 | return null; |
| 2177 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2178 | |
| 2179 | final long identity = Binder.clearCallingIdentity(); |
| 2180 | try { |
| 2181 | return phone.getImei(); |
| 2182 | } finally { |
| 2183 | Binder.restoreCallingIdentity(identity); |
| 2184 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
| 2187 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2188 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2189 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2190 | String tac = null; |
| 2191 | if (phone != null) { |
| 2192 | String imei = phone.getImei(); |
| 2193 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2194 | } |
| 2195 | return tac; |
| 2196 | } |
| 2197 | |
| 2198 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2199 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2200 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2201 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2202 | return null; |
| 2203 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2204 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2205 | int subId = phone.getSubId(); |
| 2206 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2207 | mApp, subId, callingPackage, "getMeidForSlot")) { |
| 2208 | return null; |
| 2209 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2210 | |
| 2211 | final long identity = Binder.clearCallingIdentity(); |
| 2212 | try { |
| 2213 | return phone.getMeid(); |
| 2214 | } finally { |
| 2215 | Binder.restoreCallingIdentity(identity); |
| 2216 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2217 | } |
| 2218 | |
| 2219 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2220 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2221 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2222 | String manufacturerCode = null; |
| 2223 | if (phone != null) { |
| 2224 | String meid = phone.getMeid(); |
| 2225 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2226 | } |
| 2227 | return manufacturerCode; |
| 2228 | } |
| 2229 | |
| 2230 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2231 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2232 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2233 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2234 | return null; |
| 2235 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2236 | int subId = phone.getSubId(); |
| 2237 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2238 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2239 | return null; |
| 2240 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2241 | |
| 2242 | final long identity = Binder.clearCallingIdentity(); |
| 2243 | try { |
| 2244 | return phone.getDeviceSvn(); |
| 2245 | } finally { |
| 2246 | Binder.restoreCallingIdentity(identity); |
| 2247 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2248 | } |
| 2249 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2250 | @Override |
| 2251 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2252 | final long identity = Binder.clearCallingIdentity(); |
| 2253 | try { |
| 2254 | final Phone phone = getPhone(subId); |
| 2255 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2256 | } finally { |
| 2257 | Binder.restoreCallingIdentity(identity); |
| 2258 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | @Override |
| 2262 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2263 | final long identity = Binder.clearCallingIdentity(); |
| 2264 | try { |
| 2265 | final Phone phone = getPhone(subId); |
| 2266 | return phone == null ? null : phone.getCarrierName(); |
| 2267 | } finally { |
| 2268 | Binder.restoreCallingIdentity(identity); |
| 2269 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2270 | } |
| 2271 | |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2272 | @Override |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2273 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2274 | final long identity = Binder.clearCallingIdentity(); |
| 2275 | try { |
| 2276 | final Phone phone = getPhone(subId); |
| 2277 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2278 | : phone.getSpecificCarrierId(); |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2279 | } finally { |
| 2280 | Binder.restoreCallingIdentity(identity); |
| 2281 | } |
| 2282 | } |
| 2283 | |
| 2284 | @Override |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2285 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2286 | final long identity = Binder.clearCallingIdentity(); |
| 2287 | try { |
| 2288 | final Phone phone = getPhone(subId); |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2289 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2290 | } finally { |
| 2291 | Binder.restoreCallingIdentity(identity); |
| 2292 | } |
| 2293 | } |
| 2294 | |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2295 | @Override |
chen xu | 4ca4e69 | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2296 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2297 | if (!isSubscriptionMccMnc) { |
| 2298 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2299 | } |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2300 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2301 | if (phone == null) { |
| 2302 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2303 | } |
| 2304 | final long identity = Binder.clearCallingIdentity(); |
| 2305 | try { |
| 2306 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2307 | } finally { |
| 2308 | Binder.restoreCallingIdentity(identity); |
| 2309 | } |
| 2310 | } |
| 2311 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2312 | // |
| 2313 | // Internal helper methods. |
| 2314 | // |
| 2315 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2316 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2317 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2318 | * |
| 2319 | * @throws SecurityException if the caller does not have the required permission |
| 2320 | */ |
| 2321 | private void enforceModifyPermission() { |
| 2322 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2323 | } |
| 2324 | |
| 2325 | /** |
| 2326 | * Make sure the caller has the CALL_PHONE permission. |
| 2327 | * |
| 2328 | * @throws SecurityException if the caller does not have the required permission |
| 2329 | */ |
| 2330 | private void enforceCallPermission() { |
| 2331 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2332 | } |
| 2333 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2334 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2335 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2336 | "ConnectivityService"); |
| 2337 | } |
| 2338 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2339 | private String createTelUrl(String number) { |
| 2340 | if (TextUtils.isEmpty(number)) { |
| 2341 | return null; |
| 2342 | } |
| 2343 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2344 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2345 | } |
| 2346 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2347 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2348 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2349 | } |
| 2350 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2351 | private static void logv(String msg) { |
| 2352 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2353 | } |
| 2354 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2355 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2356 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2357 | } |
| 2358 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2359 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2360 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2361 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2362 | } |
| 2363 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2364 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2365 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2366 | final long identity = Binder.clearCallingIdentity(); |
| 2367 | try { |
| 2368 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2369 | if (phone == null) { |
| 2370 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2371 | } else { |
| 2372 | return phone.getPhoneType(); |
| 2373 | } |
| 2374 | } finally { |
| 2375 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2376 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2377 | } |
| 2378 | |
| 2379 | /** |
| 2380 | * Returns the CDMA ERI icon index to display |
| 2381 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2382 | @Override |
| 2383 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2384 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2385 | } |
| 2386 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2387 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2388 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2389 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2390 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2391 | return -1; |
| 2392 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2393 | |
| 2394 | final long identity = Binder.clearCallingIdentity(); |
| 2395 | try { |
| 2396 | final Phone phone = getPhone(subId); |
| 2397 | if (phone != null) { |
| 2398 | return phone.getCdmaEriIconIndex(); |
| 2399 | } else { |
| 2400 | return -1; |
| 2401 | } |
| 2402 | } finally { |
| 2403 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2404 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | /** |
| 2408 | * Returns the CDMA ERI icon mode, |
| 2409 | * 0 - ON |
| 2410 | * 1 - FLASHING |
| 2411 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2412 | @Override |
| 2413 | public int getCdmaEriIconMode(String callingPackage) { |
| 2414 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2415 | } |
| 2416 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2417 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2418 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2419 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2420 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2421 | return -1; |
| 2422 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2423 | |
| 2424 | final long identity = Binder.clearCallingIdentity(); |
| 2425 | try { |
| 2426 | final Phone phone = getPhone(subId); |
| 2427 | if (phone != null) { |
| 2428 | return phone.getCdmaEriIconMode(); |
| 2429 | } else { |
| 2430 | return -1; |
| 2431 | } |
| 2432 | } finally { |
| 2433 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2434 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2435 | } |
| 2436 | |
| 2437 | /** |
| 2438 | * Returns the CDMA ERI text, |
| 2439 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2440 | @Override |
| 2441 | public String getCdmaEriText(String callingPackage) { |
| 2442 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2443 | } |
| 2444 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2445 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2446 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2447 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2448 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2449 | return null; |
| 2450 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2451 | |
| 2452 | final long identity = Binder.clearCallingIdentity(); |
| 2453 | try { |
| 2454 | final Phone phone = getPhone(subId); |
| 2455 | if (phone != null) { |
| 2456 | return phone.getCdmaEriText(); |
| 2457 | } else { |
| 2458 | return null; |
| 2459 | } |
| 2460 | } finally { |
| 2461 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2462 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2463 | } |
| 2464 | |
| 2465 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2466 | * Returns the CDMA MDN. |
| 2467 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2468 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2469 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2470 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2471 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2472 | |
| 2473 | final long identity = Binder.clearCallingIdentity(); |
| 2474 | try { |
| 2475 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2476 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2477 | return phone.getLine1Number(); |
| 2478 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2479 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2480 | return null; |
| 2481 | } |
| 2482 | } finally { |
| 2483 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2484 | } |
| 2485 | } |
| 2486 | |
| 2487 | /** |
| 2488 | * Returns the CDMA MIN. |
| 2489 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2490 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2491 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2492 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2493 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2494 | |
| 2495 | final long identity = Binder.clearCallingIdentity(); |
| 2496 | try { |
| 2497 | final Phone phone = getPhone(subId); |
| 2498 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2499 | return phone.getCdmaMin(); |
| 2500 | } else { |
| 2501 | return null; |
| 2502 | } |
| 2503 | } finally { |
| 2504 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2505 | } |
| 2506 | } |
| 2507 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2508 | @Override |
| 2509 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2510 | INumberVerificationCallback callback, String callingPackage) { |
| 2511 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2512 | != PERMISSION_GRANTED) { |
| 2513 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2514 | } |
| 2515 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2516 | |
| 2517 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2518 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2519 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2520 | } |
| 2521 | |
| 2522 | if (range == null) { |
| 2523 | throw new NullPointerException("Range must be non-null"); |
| 2524 | } |
| 2525 | |
| 2526 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2527 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2528 | |
| 2529 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2530 | } |
| 2531 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2532 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2533 | * Returns true if CDMA provisioning needs to run. |
| 2534 | */ |
| 2535 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2536 | final long identity = Binder.clearCallingIdentity(); |
| 2537 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2538 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2539 | } finally { |
| 2540 | Binder.restoreCallingIdentity(identity); |
| 2541 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2545 | * Sets the voice mail number of a given subId. |
| 2546 | */ |
| 2547 | @Override |
| 2548 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2549 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2550 | |
| 2551 | final long identity = Binder.clearCallingIdentity(); |
| 2552 | try { |
| 2553 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2554 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2555 | return success; |
| 2556 | } finally { |
| 2557 | Binder.restoreCallingIdentity(identity); |
| 2558 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2559 | } |
| 2560 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2561 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2562 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2563 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2564 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2565 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2566 | throw new SecurityException("caller must be system dialer"); |
| 2567 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2568 | |
| 2569 | final long identity = Binder.clearCallingIdentity(); |
| 2570 | try { |
| 2571 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2572 | if (phoneAccountHandle == null) { |
| 2573 | return null; |
| 2574 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2575 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2576 | } finally { |
| 2577 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2578 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2579 | } |
| 2580 | |
| 2581 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2582 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2583 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2584 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2585 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2586 | return null; |
| 2587 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2588 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2589 | final long identity = Binder.clearCallingIdentity(); |
| 2590 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2591 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2592 | } finally { |
| 2593 | Binder.restoreCallingIdentity(identity); |
| 2594 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2595 | } |
| 2596 | |
| 2597 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2598 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2599 | VisualVoicemailSmsFilterSettings settings) { |
| 2600 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2601 | |
| 2602 | final long identity = Binder.clearCallingIdentity(); |
| 2603 | try { |
| 2604 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2605 | mApp, callingPackage, subId, settings); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2606 | } finally { |
| 2607 | Binder.restoreCallingIdentity(identity); |
| 2608 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2609 | } |
| 2610 | |
| 2611 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2612 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2613 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2614 | |
| 2615 | final long identity = Binder.clearCallingIdentity(); |
| 2616 | try { |
| 2617 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2618 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2619 | } finally { |
| 2620 | Binder.restoreCallingIdentity(identity); |
| 2621 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2622 | } |
| 2623 | |
| 2624 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2625 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2626 | String callingPackage, int subId) { |
| 2627 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2628 | |
| 2629 | final long identity = Binder.clearCallingIdentity(); |
| 2630 | try { |
| 2631 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2632 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2633 | } finally { |
| 2634 | Binder.restoreCallingIdentity(identity); |
| 2635 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2636 | } |
| 2637 | |
| 2638 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2639 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2640 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2641 | |
| 2642 | final long identity = Binder.clearCallingIdentity(); |
| 2643 | try { |
| 2644 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2645 | mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2646 | } finally { |
| 2647 | Binder.restoreCallingIdentity(identity); |
| 2648 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2649 | } |
| 2650 | |
| 2651 | @Override |
| 2652 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2653 | String number, int port, String text, PendingIntent sentIntent) { |
| 2654 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2655 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2656 | enforceSendSmsPermission(); |
Amit Mahajan | 716e76c | 2019-05-13 13:48:32 -0700 | [diff] [blame^] | 2657 | SmsController smsController = PhoneFactory.getSmsController(); |
| 2658 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 2659 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2660 | } |
Amit Mahajan | 716e76c | 2019-05-13 13:48:32 -0700 | [diff] [blame^] | 2661 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2662 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2663 | * Sets the voice activation state of a given subId. |
| 2664 | */ |
| 2665 | @Override |
| 2666 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2667 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2668 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2669 | |
| 2670 | final long identity = Binder.clearCallingIdentity(); |
| 2671 | try { |
| 2672 | final Phone phone = getPhone(subId); |
| 2673 | if (phone != null) { |
| 2674 | phone.setVoiceActivationState(activationState); |
| 2675 | } else { |
| 2676 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2677 | } |
| 2678 | } finally { |
| 2679 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2680 | } |
| 2681 | } |
| 2682 | |
| 2683 | /** |
| 2684 | * Sets the data activation state of a given subId. |
| 2685 | */ |
| 2686 | @Override |
| 2687 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2688 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2689 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2690 | |
| 2691 | final long identity = Binder.clearCallingIdentity(); |
| 2692 | try { |
| 2693 | final Phone phone = getPhone(subId); |
| 2694 | if (phone != null) { |
| 2695 | phone.setDataActivationState(activationState); |
| 2696 | } else { |
| 2697 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2698 | } |
| 2699 | } finally { |
| 2700 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2701 | } |
| 2702 | } |
| 2703 | |
| 2704 | /** |
| 2705 | * Returns the voice activation state of a given subId. |
| 2706 | */ |
| 2707 | @Override |
| 2708 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2709 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2710 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2711 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2712 | final long identity = Binder.clearCallingIdentity(); |
| 2713 | try { |
| 2714 | if (phone != null) { |
| 2715 | return phone.getVoiceActivationState(); |
| 2716 | } else { |
| 2717 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2718 | } |
| 2719 | } finally { |
| 2720 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2721 | } |
| 2722 | } |
| 2723 | |
| 2724 | /** |
| 2725 | * Returns the data activation state of a given subId. |
| 2726 | */ |
| 2727 | @Override |
| 2728 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2729 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2730 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2731 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2732 | final long identity = Binder.clearCallingIdentity(); |
| 2733 | try { |
| 2734 | if (phone != null) { |
| 2735 | return phone.getDataActivationState(); |
| 2736 | } else { |
| 2737 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2738 | } |
| 2739 | } finally { |
| 2740 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2741 | } |
| 2742 | } |
| 2743 | |
| 2744 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2745 | * Returns the unread count of voicemails for a subId |
| 2746 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2747 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2748 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2749 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2750 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2751 | return 0; |
| 2752 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2753 | final long identity = Binder.clearCallingIdentity(); |
| 2754 | try { |
| 2755 | final Phone phone = getPhone(subId); |
| 2756 | if (phone != null) { |
| 2757 | return phone.getVoiceMessageCount(); |
| 2758 | } else { |
| 2759 | return 0; |
| 2760 | } |
| 2761 | } finally { |
| 2762 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2763 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2764 | } |
| 2765 | |
| 2766 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2767 | * returns true, if the device is in a state where both voice and data |
| 2768 | * are supported simultaneously. This can change based on location or network condition. |
| 2769 | */ |
| 2770 | @Override |
| 2771 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2772 | final long identity = Binder.clearCallingIdentity(); |
| 2773 | try { |
| 2774 | final Phone phone = getPhone(subId); |
| 2775 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2776 | } finally { |
| 2777 | Binder.restoreCallingIdentity(identity); |
| 2778 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2779 | } |
| 2780 | |
| 2781 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2782 | * Send the dialer code if called from the current default dialer or the caller has |
| 2783 | * carrier privilege. |
| 2784 | * @param inputCode The dialer code to send |
| 2785 | */ |
| 2786 | @Override |
| 2787 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2788 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2789 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2790 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2791 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2792 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2793 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2794 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2795 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2796 | |
| 2797 | final long identity = Binder.clearCallingIdentity(); |
| 2798 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2799 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2800 | } finally { |
| 2801 | Binder.restoreCallingIdentity(identity); |
| 2802 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2803 | } |
| 2804 | |
| 2805 | /** |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2806 | * Returns the data network type. |
| 2807 | * Legacy call, permission-free. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2808 | * |
| 2809 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 2810 | */ |
| 2811 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2812 | public int getNetworkType() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2813 | final long identity = Binder.clearCallingIdentity(); |
| 2814 | try { |
| 2815 | final Phone phone = getPhone(getDefaultSubscription()); |
| 2816 | if (phone != null) { |
| 2817 | return phone.getServiceState().getDataNetworkType(); |
| 2818 | } else { |
| 2819 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2820 | } |
| 2821 | } finally { |
| 2822 | Binder.restoreCallingIdentity(identity); |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2823 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2824 | } |
| 2825 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2826 | @Override |
| 2827 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2828 | if (!isActiveSubscription(subId)) { |
| 2829 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2830 | } |
| 2831 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2832 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2833 | } |
| 2834 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2835 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2836 | public boolean isInEmergencySmsMode() { |
| 2837 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 2838 | final long identity = Binder.clearCallingIdentity(); |
| 2839 | try { |
| 2840 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2841 | if (phone.isInEmergencySmsMode()) { |
| 2842 | return true; |
| 2843 | } |
| 2844 | } |
| 2845 | } finally { |
| 2846 | Binder.restoreCallingIdentity(identity); |
| 2847 | } |
| 2848 | return false; |
| 2849 | } |
| 2850 | |
| 2851 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2852 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2853 | throws RemoteException { |
| 2854 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2855 | final long token = Binder.clearCallingIdentity(); |
| 2856 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2857 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2858 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2859 | .addRegistrationCallbackForSubscription(c, subId); |
| 2860 | } finally { |
| 2861 | Binder.restoreCallingIdentity(token); |
| 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2866 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2867 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2868 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2869 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2870 | } |
| 2871 | Binder.withCleanCallingIdentity(() -> { |
| 2872 | try { |
| 2873 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2874 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2875 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2876 | } catch (IllegalArgumentException e) { |
| 2877 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2878 | + "is inactive, ignoring unregister."); |
| 2879 | // If the subscription is no longer active, just return, since the callback |
| 2880 | // will already have been removed internally. |
| 2881 | } |
| 2882 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2883 | } |
| 2884 | |
| 2885 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2886 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2887 | throws RemoteException { |
| 2888 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2889 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2890 | final long token = Binder.clearCallingIdentity(); |
| 2891 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2892 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2893 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2894 | } finally { |
| 2895 | Binder.restoreCallingIdentity(token); |
| 2896 | } |
| 2897 | } |
| 2898 | |
| 2899 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2900 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2901 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2902 | |
| 2903 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2904 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2905 | } |
| 2906 | Binder.withCleanCallingIdentity(() -> { |
| 2907 | try { |
| 2908 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2909 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2910 | .removeCapabilitiesCallbackForSubscription(c, subId); |
| 2911 | } catch (IllegalArgumentException e) { |
| 2912 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2913 | + "is inactive, ignoring unregister."); |
| 2914 | // If the subscription is no longer active, just return, since the callback |
| 2915 | // will already have been removed internally. |
| 2916 | } |
| 2917 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2918 | } |
| 2919 | |
| 2920 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2921 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2922 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2923 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2924 | final long token = Binder.clearCallingIdentity(); |
| 2925 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2926 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2927 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2928 | } catch (ImsException e) { |
| 2929 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2930 | return false; |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2931 | } catch (IllegalArgumentException e) { |
| 2932 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 2933 | return false; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2934 | } finally { |
| 2935 | Binder.restoreCallingIdentity(token); |
| 2936 | } |
| 2937 | } |
| 2938 | |
| 2939 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2940 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2941 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2942 | final long token = Binder.clearCallingIdentity(); |
| 2943 | try { |
| 2944 | Phone phone = getPhone(subId); |
| 2945 | if (phone == null) return false; |
| 2946 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2947 | } finally { |
| 2948 | Binder.restoreCallingIdentity(token); |
| 2949 | } |
| 2950 | } |
| 2951 | |
| 2952 | @Override |
| 2953 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2954 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2955 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2956 | final long token = Binder.clearCallingIdentity(); |
| 2957 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2958 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2959 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2960 | } finally { |
| 2961 | Binder.restoreCallingIdentity(token); |
| 2962 | } |
| 2963 | } |
| 2964 | |
| 2965 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2966 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2967 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2968 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2969 | final long identity = Binder.clearCallingIdentity(); |
| 2970 | try { |
| 2971 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2972 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2973 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 2974 | } finally { |
| 2975 | Binder.restoreCallingIdentity(identity); |
| 2976 | } |
| 2977 | } |
| 2978 | |
| 2979 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2980 | public boolean isVtSettingEnabled(int subId) { |
| 2981 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2982 | final long identity = Binder.clearCallingIdentity(); |
| 2983 | try { |
| 2984 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2985 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2986 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2987 | } finally { |
| 2988 | Binder.restoreCallingIdentity(identity); |
| 2989 | } |
| 2990 | } |
| 2991 | |
| 2992 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2993 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2994 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2995 | "setVtSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2996 | final long identity = Binder.clearCallingIdentity(); |
| 2997 | try { |
| 2998 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2999 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3000 | } finally { |
| 3001 | Binder.restoreCallingIdentity(identity); |
| 3002 | } |
| 3003 | } |
| 3004 | |
| 3005 | @Override |
| 3006 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 3007 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 3008 | final long identity = Binder.clearCallingIdentity(); |
| 3009 | try { |
| 3010 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3011 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3012 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 3013 | } finally { |
| 3014 | Binder.restoreCallingIdentity(identity); |
| 3015 | } |
| 3016 | } |
| 3017 | |
| 3018 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3019 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3020 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3021 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3022 | final long identity = Binder.clearCallingIdentity(); |
| 3023 | try { |
| 3024 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3025 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3026 | } finally { |
| 3027 | Binder.restoreCallingIdentity(identity); |
| 3028 | } |
| 3029 | } |
| 3030 | |
| 3031 | @Override |
| 3032 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 3033 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3034 | final long identity = Binder.clearCallingIdentity(); |
| 3035 | try { |
| 3036 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3037 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3038 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 3039 | } finally { |
| 3040 | Binder.restoreCallingIdentity(identity); |
| 3041 | } |
| 3042 | } |
| 3043 | |
| 3044 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3045 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3046 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3047 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3048 | final long identity = Binder.clearCallingIdentity(); |
| 3049 | try { |
| 3050 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3051 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3052 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 3053 | } finally { |
| 3054 | Binder.restoreCallingIdentity(identity); |
| 3055 | } |
| 3056 | } |
| 3057 | |
| 3058 | @Override |
| 3059 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3060 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3061 | "setVoWiFiNonPersistent"); |
| 3062 | final long identity = Binder.clearCallingIdentity(); |
| 3063 | try { |
| 3064 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3065 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2bc9570 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3066 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3067 | } finally { |
| 3068 | Binder.restoreCallingIdentity(identity); |
| 3069 | } |
| 3070 | } |
| 3071 | |
| 3072 | @Override |
| 3073 | public int getVoWiFiModeSetting(int subId) { |
| 3074 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3075 | final long identity = Binder.clearCallingIdentity(); |
| 3076 | try { |
| 3077 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3078 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3079 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 3080 | } finally { |
| 3081 | Binder.restoreCallingIdentity(identity); |
| 3082 | } |
| 3083 | } |
| 3084 | |
| 3085 | @Override |
| 3086 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3087 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3088 | "setVoWiFiModeSetting"); |
| 3089 | final long identity = Binder.clearCallingIdentity(); |
| 3090 | try { |
| 3091 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3092 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3093 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 3094 | } finally { |
| 3095 | Binder.restoreCallingIdentity(identity); |
| 3096 | } |
| 3097 | } |
| 3098 | |
| 3099 | @Override |
| 3100 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3101 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3102 | final long identity = Binder.clearCallingIdentity(); |
| 3103 | try { |
| 3104 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3105 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3106 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 3107 | } finally { |
| 3108 | Binder.restoreCallingIdentity(identity); |
| 3109 | } |
| 3110 | } |
| 3111 | |
| 3112 | @Override |
| 3113 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3114 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3115 | "setVoWiFiRoamingModeSetting"); |
| 3116 | final long identity = Binder.clearCallingIdentity(); |
| 3117 | try { |
| 3118 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3119 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3120 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 3121 | } finally { |
| 3122 | Binder.restoreCallingIdentity(identity); |
| 3123 | } |
| 3124 | } |
| 3125 | |
| 3126 | @Override |
| 3127 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3128 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3129 | "setRttCapabilityEnabled"); |
| 3130 | final long identity = Binder.clearCallingIdentity(); |
| 3131 | try { |
| 3132 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3133 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3134 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3135 | } finally { |
| 3136 | Binder.restoreCallingIdentity(identity); |
| 3137 | } |
| 3138 | } |
| 3139 | |
| 3140 | @Override |
| 3141 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3142 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3143 | final long identity = Binder.clearCallingIdentity(); |
| 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 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3147 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 3148 | } finally { |
| 3149 | Binder.restoreCallingIdentity(identity); |
| 3150 | } |
| 3151 | } |
| 3152 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3153 | @Override |
| 3154 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3155 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3156 | final long identity = Binder.clearCallingIdentity(); |
| 3157 | try { |
| 3158 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3159 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3160 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3161 | } finally { |
| 3162 | Binder.restoreCallingIdentity(identity); |
| 3163 | } |
| 3164 | } |
| 3165 | |
| 3166 | @Override |
| 3167 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3168 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3169 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3170 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3171 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3172 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3173 | try { |
| 3174 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3175 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3176 | .removeProvisioningCallbackForSubscription(callback, subId); |
| 3177 | } catch (IllegalArgumentException e) { |
| 3178 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3179 | + "is inactive, ignoring unregister."); |
| 3180 | // If the subscription is no longer active, just return, since the callback will already |
| 3181 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3182 | } finally { |
| 3183 | Binder.restoreCallingIdentity(identity); |
| 3184 | } |
| 3185 | } |
| 3186 | |
| 3187 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3188 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3189 | boolean isProvisioned) { |
| 3190 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3191 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3192 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3193 | } |
| 3194 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3195 | "setProvisioningStatusForCapability"); |
| 3196 | final long identity = Binder.clearCallingIdentity(); |
| 3197 | try { |
| 3198 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3199 | Phone phone = getPhone(subId); |
| 3200 | if (phone == null) { |
| 3201 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3202 | + subId); |
| 3203 | return; |
| 3204 | } |
| 3205 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3206 | return; |
| 3207 | } |
| 3208 | |
| 3209 | // this capability requires provisioning, route to the correct API. |
| 3210 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3211 | switch (capability) { |
| 3212 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3213 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3214 | ims.setVolteProvisioned(isProvisioned); |
| 3215 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3216 | ims.setWfcProvisioned(isProvisioned); |
| 3217 | } |
| 3218 | break; |
| 3219 | } |
| 3220 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3221 | // There is currently no difference in VT provisioning type. |
| 3222 | ims.setVtProvisioned(isProvisioned); |
| 3223 | break; |
| 3224 | } |
| 3225 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3226 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3227 | // change the capability of the feature instead if needed. |
| 3228 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3229 | == isProvisioned) { |
| 3230 | // No change in provisioning. |
| 3231 | return; |
| 3232 | } |
| 3233 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3234 | try { |
| 3235 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
| 3236 | } catch (ImsException e) { |
| 3237 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3238 | + ", Exception" + e.getMessage()); |
| 3239 | } |
| 3240 | break; |
| 3241 | } |
| 3242 | default: { |
| 3243 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3244 | + capability + "', which does not require provisioning."); |
| 3245 | } |
| 3246 | } |
| 3247 | |
| 3248 | } finally { |
| 3249 | Binder.restoreCallingIdentity(identity); |
| 3250 | } |
| 3251 | } |
| 3252 | |
| 3253 | @Override |
| 3254 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3255 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3256 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3257 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3258 | } |
| 3259 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3260 | final long identity = Binder.clearCallingIdentity(); |
| 3261 | try { |
| 3262 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3263 | Phone phone = getPhone(subId); |
| 3264 | if (phone == null) { |
| 3265 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3266 | + subId); |
| 3267 | // We will fail with "true" as the provisioning status because this is the default |
| 3268 | // if we do not require provisioning. |
| 3269 | return true; |
| 3270 | } |
| 3271 | |
| 3272 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3273 | return true; |
| 3274 | } |
| 3275 | |
| 3276 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3277 | switch (capability) { |
| 3278 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3279 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3280 | return ims.isVolteProvisionedOnDevice(); |
| 3281 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3282 | return ims.isWfcProvisionedOnDevice(); |
| 3283 | } |
| 3284 | // This should never happen, since we are checking tech above to make sure it |
| 3285 | // is either LTE or IWLAN. |
| 3286 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3287 | + "capability."); |
| 3288 | } |
| 3289 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3290 | // There is currently no difference in VT provisioning type. |
| 3291 | return ims.isVtProvisionedOnDevice(); |
| 3292 | } |
| 3293 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3294 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3295 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3296 | } |
| 3297 | default: { |
| 3298 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3299 | + capability + "', which does not require provisioning."); |
| 3300 | } |
| 3301 | } |
| 3302 | |
| 3303 | } finally { |
| 3304 | Binder.restoreCallingIdentity(identity); |
| 3305 | } |
| 3306 | } |
| 3307 | |
| 3308 | @Override |
| 3309 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3310 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3311 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3312 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3313 | } |
| 3314 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3315 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3316 | return (provisionedBits & capability) > 0; |
| 3317 | } |
| 3318 | |
| 3319 | @Override |
| 3320 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3321 | boolean isProvisioned) { |
| 3322 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3323 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3324 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3325 | } |
| 3326 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3327 | "setProvisioningStatusForCapability"); |
| 3328 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3329 | // If the current provisioning status for capability already matches isProvisioned, |
| 3330 | // do nothing. |
| 3331 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3332 | return; |
| 3333 | } |
| 3334 | if (isProvisioned) { |
| 3335 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3336 | } else { |
| 3337 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3338 | } |
| 3339 | } |
| 3340 | |
| 3341 | /** |
| 3342 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3343 | * technology. The bitfield should mirror the bitfield defined by |
| 3344 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3345 | */ |
| 3346 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3347 | String key = getMmTelProvisioningKey(subId, tech); |
| 3348 | // Default is no capabilities are provisioned. |
| 3349 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3350 | } |
| 3351 | |
| 3352 | /** |
| 3353 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3354 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3355 | * technology specified. |
| 3356 | * |
| 3357 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3358 | */ |
| 3359 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3360 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3361 | String key = getMmTelProvisioningKey(subId, tech); |
| 3362 | editor.putInt(key, newField); |
| 3363 | editor.commit(); |
| 3364 | } |
| 3365 | |
| 3366 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3367 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3368 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3369 | } |
| 3370 | |
| 3371 | /** |
| 3372 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3373 | * carrier associated with the subscription id. |
| 3374 | */ |
| 3375 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3376 | int capability) { |
| 3377 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3378 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3379 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 3380 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3381 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3382 | false); |
| 3383 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3384 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3385 | |
| 3386 | // First check to make sure that the capability requires provisioning. |
| 3387 | switch (capability) { |
| 3388 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3389 | // intentional fallthrough |
| 3390 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3391 | if (requireVoiceVtProvisioning) { |
| 3392 | // Voice and Video requires provisioning |
| 3393 | return true; |
| 3394 | } |
| 3395 | break; |
| 3396 | } |
| 3397 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3398 | if (requireUtProvisioning) { |
| 3399 | // UT requires provisioning |
| 3400 | return true; |
| 3401 | } |
| 3402 | break; |
| 3403 | } |
| 3404 | } |
| 3405 | return false; |
| 3406 | } |
| 3407 | |
| 3408 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3409 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3410 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3411 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3412 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3413 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3414 | final long identity = Binder.clearCallingIdentity(); |
| 3415 | try { |
| 3416 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3417 | int slotId = getSlotIndex(subId); |
| 3418 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3419 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3420 | + subId + "' for key:" + key); |
| 3421 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3422 | } |
| 3423 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3424 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3425 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3426 | + subId + "' for key:" + key); |
| 3427 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3428 | } finally { |
| 3429 | Binder.restoreCallingIdentity(identity); |
| 3430 | } |
| 3431 | } |
| 3432 | |
| 3433 | @Override |
| 3434 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3435 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3436 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3437 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3438 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 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, "getImsProvisioningString: called for an inactive subscription id '" |
| 3445 | + subId + "' for key:" + key); |
| 3446 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3447 | } |
| 3448 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
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, "getImsProvisioningString: ImsService is not available for sub '" |
| 3451 | + subId + "' for key:" + key); |
| 3452 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
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 setImsProvisioningInt(int subId, int key, int 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 | "setImsProvisioningInt"); |
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, "setImsProvisioningInt: 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, "setImsProvisioningInt: 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 | |
| 3484 | @Override |
| 3485 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3486 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3487 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3488 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3489 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3490 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3491 | final long identity = Binder.clearCallingIdentity(); |
| 3492 | try { |
| 3493 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3494 | int slotId = getSlotIndex(subId); |
| 3495 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3496 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3497 | + subId + "' for key:" + key); |
| 3498 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3499 | } |
| 3500 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3501 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3502 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3503 | + "' for key:" + key); |
| 3504 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3505 | } finally { |
| 3506 | Binder.restoreCallingIdentity(identity); |
| 3507 | } |
| 3508 | } |
| 3509 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3510 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 3511 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3512 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3513 | throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3514 | } |
| 3515 | return slotId; |
| 3516 | } |
| 3517 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3518 | private int getSlotIndex(int subId) { |
| 3519 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3520 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3521 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3522 | } |
| 3523 | return slotId; |
| 3524 | } |
| 3525 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3526 | /** |
| 3527 | * Returns the network type for a subId |
| 3528 | */ |
| 3529 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3530 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3531 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3532 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3533 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3534 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3535 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3536 | final long identity = Binder.clearCallingIdentity(); |
| 3537 | try { |
| 3538 | final Phone phone = getPhone(subId); |
| 3539 | if (phone != null) { |
| 3540 | return phone.getServiceState().getDataNetworkType(); |
| 3541 | } else { |
| 3542 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3543 | } |
| 3544 | } finally { |
| 3545 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3546 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3547 | } |
| 3548 | |
| 3549 | /** |
| 3550 | * Returns the data network type |
| 3551 | */ |
| 3552 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3553 | public int getDataNetworkType(String callingPackage) { |
| 3554 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3555 | } |
| 3556 | |
| 3557 | /** |
| 3558 | * Returns the data network type for a subId |
| 3559 | */ |
| 3560 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3561 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3562 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3563 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3564 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3565 | } |
| 3566 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3567 | final long identity = Binder.clearCallingIdentity(); |
| 3568 | try { |
| 3569 | final Phone phone = getPhone(subId); |
| 3570 | if (phone != null) { |
| 3571 | return phone.getServiceState().getDataNetworkType(); |
| 3572 | } else { |
| 3573 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3574 | } |
| 3575 | } finally { |
| 3576 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3577 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3578 | } |
| 3579 | |
| 3580 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3581 | * Returns the Voice network type for a subId |
| 3582 | */ |
| 3583 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3584 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3585 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3586 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3587 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3588 | } |
| 3589 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3590 | final long identity = Binder.clearCallingIdentity(); |
| 3591 | try { |
| 3592 | final Phone phone = getPhone(subId); |
| 3593 | if (phone != null) { |
| 3594 | return phone.getServiceState().getVoiceNetworkType(); |
| 3595 | } else { |
| 3596 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3597 | } |
| 3598 | } finally { |
| 3599 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3600 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3601 | } |
| 3602 | |
| 3603 | /** |
| 3604 | * @return true if a ICC card is present |
| 3605 | */ |
| 3606 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3607 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3608 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3609 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3610 | } |
| 3611 | |
| 3612 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3613 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3614 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3615 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3616 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3617 | final long identity = Binder.clearCallingIdentity(); |
| 3618 | try { |
| 3619 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3620 | if (phone != null) { |
| 3621 | return phone.getIccCard().hasIccCard(); |
| 3622 | } else { |
| 3623 | return false; |
| 3624 | } |
| 3625 | } finally { |
| 3626 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3627 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3628 | } |
| 3629 | |
| 3630 | /** |
| 3631 | * Return if the current radio is LTE on CDMA. This |
| 3632 | * is a tri-state return value as for a period of time |
| 3633 | * the mode may be unknown. |
| 3634 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3635 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3636 | * @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] | 3637 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3638 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3639 | @Override |
| 3640 | public int getLteOnCdmaMode(String callingPackage) { |
| 3641 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3642 | } |
| 3643 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3644 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3645 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3646 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3647 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3648 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3649 | } |
| 3650 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3651 | final long identity = Binder.clearCallingIdentity(); |
| 3652 | try { |
| 3653 | final Phone phone = getPhone(subId); |
| 3654 | if (phone == null) { |
| 3655 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3656 | } else { |
| 3657 | return phone.getLteOnCdmaMode(); |
| 3658 | } |
| 3659 | } finally { |
| 3660 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3661 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3662 | } |
| 3663 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3664 | /** |
| 3665 | * {@hide} |
| 3666 | * Returns Default subId, 0 in the case of single standby. |
| 3667 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3668 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3669 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3670 | } |
| 3671 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3672 | private int getSlotForDefaultSubscription() { |
| 3673 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3674 | } |
| 3675 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3676 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3677 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3678 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3679 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3680 | private boolean isActiveSubscription(int subId) { |
| 3681 | return mSubscriptionController.isActiveSubId(subId); |
| 3682 | } |
| 3683 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3684 | /** |
| 3685 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3686 | */ |
| 3687 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3688 | final long identity = Binder.clearCallingIdentity(); |
| 3689 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3690 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3691 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3692 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3693 | } finally { |
| 3694 | Binder.restoreCallingIdentity(identity); |
| 3695 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3696 | } |
| 3697 | |
| 3698 | /** |
| 3699 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3700 | */ |
| 3701 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3702 | final long identity = Binder.clearCallingIdentity(); |
| 3703 | try { |
| 3704 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3705 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3706 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3707 | } finally { |
| 3708 | Binder.restoreCallingIdentity(identity); |
| 3709 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3710 | } |
| 3711 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3712 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3713 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3714 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3715 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3716 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3717 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 3718 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 3719 | if (phoneId == -1) { |
| 3720 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 3721 | + " does not correspond to an active phone"); |
| 3722 | } |
| 3723 | return PhoneFactory.getPhone(phoneId); |
| 3724 | } |
| 3725 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3726 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3727 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3728 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3729 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3730 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3731 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3732 | if (DBG) { |
| 3733 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3734 | } |
| 3735 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 3736 | p2); |
| 3737 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3738 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3739 | |
| 3740 | @Override |
| 3741 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 3742 | int slotIndex, String callingPackage, String aid, int p2) { |
| 3743 | enforceModifyPermission(); |
| 3744 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3745 | if (DBG) { |
| 3746 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 3747 | } |
| 3748 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3749 | callingPackage, aid, p2); |
| 3750 | } |
| 3751 | |
| 3752 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 3753 | String callingPackage, String aid, int p2) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3754 | final long identity = Binder.clearCallingIdentity(); |
| 3755 | try { |
| 3756 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3757 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3758 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3759 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3760 | if (bestComponent == null |
| 3761 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3762 | loge("The calling package is not allowed to access ISD-R."); |
| 3763 | throw new SecurityException( |
| 3764 | "The calling package is not allowed to access ISD-R."); |
| 3765 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3766 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3767 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3768 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3769 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 3770 | null /* workSource */); |
| 3771 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3772 | return response; |
| 3773 | } finally { |
| 3774 | Binder.restoreCallingIdentity(identity); |
| 3775 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3776 | } |
| 3777 | |
| 3778 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3779 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3780 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3781 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3782 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3783 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 3784 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3785 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3786 | @Override |
| 3787 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 3788 | enforceModifyPermission(); |
| 3789 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 3790 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3791 | channel); |
| 3792 | } |
| 3793 | |
| 3794 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3795 | final long identity = Binder.clearCallingIdentity(); |
| 3796 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3797 | if (channel < 0) { |
| 3798 | return false; |
| 3799 | } |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3800 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 3801 | null /* workSource */); |
| 3802 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3803 | return success; |
| 3804 | } finally { |
| 3805 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3806 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3807 | } |
| 3808 | |
| 3809 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3810 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3811 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3812 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3813 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3814 | if (DBG) { |
| 3815 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3816 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3817 | + p3 + " data=" + data); |
| 3818 | } |
| 3819 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 3820 | command, p1, p2, p3, data); |
| 3821 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3822 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3823 | @Override |
| 3824 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 3825 | int command, int p1, int p2, int p3, String data) { |
| 3826 | enforceModifyPermission(); |
| 3827 | if (DBG) { |
| 3828 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 3829 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3830 | + p3 + " data=" + data); |
| 3831 | } |
| 3832 | return iccTransmitApduLogicalChannelWithPermission( |
| 3833 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 3834 | data); |
| 3835 | } |
| 3836 | |
| 3837 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 3838 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3839 | final long identity = Binder.clearCallingIdentity(); |
| 3840 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3841 | if (channel < 0) { |
| 3842 | return ""; |
| 3843 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3844 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3845 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3846 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 3847 | null /* workSource */); |
| 3848 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3849 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3850 | // Append the returned status code to the end of the response payload. |
| 3851 | String s = Integer.toHexString( |
| 3852 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3853 | if (response.payload != null) { |
| 3854 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3855 | } |
| 3856 | return s; |
| 3857 | } finally { |
| 3858 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3859 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3860 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3861 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3862 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3863 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3864 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3865 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3866 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3867 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3868 | if (DBG) { |
| 3869 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3870 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3871 | } |
| 3872 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 3873 | cla, command, p1, p2, p3, data); |
| 3874 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3875 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3876 | @Override |
| 3877 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 3878 | int command, int p1, int p2, int p3, String data) { |
| 3879 | enforceModifyPermission(); |
| 3880 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3881 | if (DBG) { |
| 3882 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 3883 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 3884 | + " data=" + data); |
| 3885 | } |
| 3886 | |
| 3887 | return iccTransmitApduBasicChannelWithPermission( |
| 3888 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 3889 | p2, p3, data); |
| 3890 | } |
| 3891 | |
| 3892 | // open APDU basic channel assuming the caller has sufficient permissions |
| 3893 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 3894 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3895 | final long identity = Binder.clearCallingIdentity(); |
| 3896 | try { |
| 3897 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3898 | && TextUtils.equals(ISDR_AID, data)) { |
| 3899 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3900 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3901 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3902 | if (bestComponent == null |
| 3903 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3904 | loge("The calling package is not allowed to select ISD-R."); |
| 3905 | throw new SecurityException( |
| 3906 | "The calling package is not allowed to select ISD-R."); |
| 3907 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3908 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3909 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3910 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3911 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 3912 | null /* workSource */); |
| 3913 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3914 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3915 | // Append the returned status code to the end of the response payload. |
| 3916 | String s = Integer.toHexString( |
| 3917 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3918 | if (response.payload != null) { |
| 3919 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3920 | } |
| 3921 | return s; |
| 3922 | } finally { |
| 3923 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3924 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3925 | } |
| 3926 | |
| 3927 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3928 | 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] | 3929 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3930 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3931 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3932 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3933 | final long identity = Binder.clearCallingIdentity(); |
| 3934 | try { |
| 3935 | if (DBG) { |
| 3936 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3937 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3938 | } |
| 3939 | |
| 3940 | IccIoResult response = |
| 3941 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3942 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3943 | subId); |
| 3944 | |
| 3945 | if (DBG) { |
| 3946 | log("Exchange SIM_IO [R]" + response); |
| 3947 | } |
| 3948 | |
| 3949 | byte[] result = null; |
| 3950 | int length = 2; |
| 3951 | if (response.payload != null) { |
| 3952 | length = 2 + response.payload.length; |
| 3953 | result = new byte[length]; |
| 3954 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3955 | } else { |
| 3956 | result = new byte[length]; |
| 3957 | } |
| 3958 | |
| 3959 | result[length - 1] = (byte) response.sw2; |
| 3960 | result[length - 2] = (byte) response.sw1; |
| 3961 | return result; |
| 3962 | } finally { |
| 3963 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3964 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3965 | } |
| 3966 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3967 | /** |
| 3968 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 3969 | * on a particular subscription |
| 3970 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3971 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 3972 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3973 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 3974 | return null; |
| 3975 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3976 | |
| 3977 | final long identity = Binder.clearCallingIdentity(); |
| 3978 | try { |
| 3979 | if (appType != TelephonyManager.APPTYPE_USIM |
| 3980 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 3981 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 3982 | return null; |
| 3983 | } |
| 3984 | Object response = sendRequest( |
| 3985 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 3986 | if (response instanceof String[]) { |
| 3987 | return (String[]) response; |
| 3988 | } |
| 3989 | // Response is an Exception of some kind, |
| 3990 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3991 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3992 | } finally { |
| 3993 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3994 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3995 | } |
| 3996 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3997 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3998 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3999 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4000 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4001 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4002 | final long identity = Binder.clearCallingIdentity(); |
| 4003 | try { |
| 4004 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4005 | if (response.payload == null) { |
| 4006 | return ""; |
| 4007 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4008 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4009 | // Append the returned status code to the end of the response payload. |
| 4010 | String s = Integer.toHexString( |
| 4011 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4012 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4013 | return s; |
| 4014 | } finally { |
| 4015 | Binder.restoreCallingIdentity(identity); |
| 4016 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4017 | } |
| 4018 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4019 | /** |
| 4020 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4021 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4022 | * |
| 4023 | * @param itemID the ID of the item to read |
| 4024 | * @return the NV item as a String, or null on error. |
| 4025 | */ |
| 4026 | @Override |
| 4027 | public String nvReadItem(int itemID) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4028 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4029 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4030 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4031 | |
| 4032 | final long identity = Binder.clearCallingIdentity(); |
| 4033 | try { |
| 4034 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4035 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4036 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4037 | return value; |
| 4038 | } finally { |
| 4039 | Binder.restoreCallingIdentity(identity); |
| 4040 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4041 | } |
| 4042 | |
| 4043 | /** |
| 4044 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4045 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4046 | * |
| 4047 | * @param itemID the ID of the item to read |
| 4048 | * @param itemValue the value to write, as a String |
| 4049 | * @return true on success; false on any failure |
| 4050 | */ |
| 4051 | @Override |
| 4052 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4053 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4054 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4055 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4056 | |
| 4057 | final long identity = Binder.clearCallingIdentity(); |
| 4058 | try { |
| 4059 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4060 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4061 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4062 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4063 | return success; |
| 4064 | } finally { |
| 4065 | Binder.restoreCallingIdentity(identity); |
| 4066 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4067 | } |
| 4068 | |
| 4069 | /** |
| 4070 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4071 | * Used for device configuration by some CDMA operators. |
| 4072 | * |
| 4073 | * @param preferredRoamingList byte array containing the new PRL |
| 4074 | * @return true on success; false on any failure |
| 4075 | */ |
| 4076 | @Override |
| 4077 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4078 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4079 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4080 | |
| 4081 | final long identity = Binder.clearCallingIdentity(); |
| 4082 | try { |
| 4083 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4084 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4085 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4086 | return success; |
| 4087 | } finally { |
| 4088 | Binder.restoreCallingIdentity(identity); |
| 4089 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4090 | } |
| 4091 | |
| 4092 | /** |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4093 | * 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] | 4094 | * Used for device configuration by some CDMA operators. |
| 4095 | * |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4096 | * @param slotIndex - device slot. |
| 4097 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4098 | * @return true on success; false on any failure |
| 4099 | */ |
| 4100 | @Override |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4101 | public boolean resetModemConfig(int slotIndex) { |
| 4102 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4103 | if (phone != null) { |
| 4104 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4105 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4106 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4107 | final long identity = Binder.clearCallingIdentity(); |
| 4108 | try { |
| 4109 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4110 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4111 | return success; |
| 4112 | } finally { |
| 4113 | Binder.restoreCallingIdentity(identity); |
| 4114 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4115 | } |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4116 | return false; |
| 4117 | } |
| 4118 | |
| 4119 | /** |
| 4120 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4121 | * |
| 4122 | * @param slotIndex - device slot. |
| 4123 | * |
| 4124 | * @return true on success; false on any failure |
| 4125 | */ |
| 4126 | @Override |
| 4127 | public boolean rebootModem(int slotIndex) { |
| 4128 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4129 | if (phone != null) { |
| 4130 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4131 | mApp, phone.getSubId(), "rebootModem"); |
| 4132 | |
| 4133 | final long identity = Binder.clearCallingIdentity(); |
| 4134 | try { |
| 4135 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4136 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4137 | return success; |
| 4138 | } finally { |
| 4139 | Binder.restoreCallingIdentity(identity); |
| 4140 | } |
| 4141 | } |
| 4142 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4143 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4144 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4145 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4146 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4147 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4148 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4149 | return new String[0]; |
| 4150 | } |
| 4151 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4152 | final long identity = Binder.clearCallingIdentity(); |
| 4153 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4154 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4155 | } finally { |
| 4156 | Binder.restoreCallingIdentity(identity); |
| 4157 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4158 | } |
| 4159 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4160 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4161 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4162 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4163 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4164 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4165 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4166 | |
| 4167 | final long identity = Binder.clearCallingIdentity(); |
| 4168 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4169 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4170 | if (resolver == null) { |
| 4171 | // may happen if the device does not support IMS. |
| 4172 | return; |
| 4173 | } |
| 4174 | resolver.enableIms(slotId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4175 | } finally { |
| 4176 | Binder.restoreCallingIdentity(identity); |
| 4177 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4178 | } |
| 4179 | |
| 4180 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4181 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4182 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4183 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4184 | public void disableIms(int slotId) { |
| 4185 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4186 | |
| 4187 | final long identity = Binder.clearCallingIdentity(); |
| 4188 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4189 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4190 | if (resolver == null) { |
| 4191 | // may happen if the device does not support IMS. |
| 4192 | return; |
| 4193 | } |
| 4194 | resolver.disableIms(slotId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4195 | } finally { |
| 4196 | Binder.restoreCallingIdentity(identity); |
| 4197 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4198 | } |
| 4199 | |
| 4200 | /** |
| 4201 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4202 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4203 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4204 | */ |
| 4205 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4206 | IImsServiceFeatureCallback callback) { |
| 4207 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4208 | |
| 4209 | final long identity = Binder.clearCallingIdentity(); |
| 4210 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4211 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4212 | if (resolver == null) { |
| 4213 | // may happen if the device does not support IMS. |
| 4214 | return null; |
| 4215 | } |
| 4216 | return resolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4217 | } finally { |
| 4218 | Binder.restoreCallingIdentity(identity); |
| 4219 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4220 | } |
| 4221 | |
| 4222 | /** |
| 4223 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4224 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4225 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4226 | * listener for feature updates. |
| 4227 | */ |
| 4228 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4229 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4230 | |
| 4231 | final long identity = Binder.clearCallingIdentity(); |
| 4232 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4233 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4234 | if (resolver == null) { |
| 4235 | // may happen if the device does not support IMS. |
| 4236 | return null; |
| 4237 | } |
| 4238 | return resolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4239 | } finally { |
| 4240 | Binder.restoreCallingIdentity(identity); |
| 4241 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4242 | } |
| 4243 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4244 | /** |
| 4245 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4246 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4247 | */ |
| 4248 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4249 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4250 | |
| 4251 | final long identity = Binder.clearCallingIdentity(); |
| 4252 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4253 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4254 | if (resolver == null) { |
| 4255 | // may happen if the device does not support IMS. |
| 4256 | return null; |
| 4257 | } |
| 4258 | return resolver.getImsRegistration(slotId, feature); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4259 | } finally { |
| 4260 | Binder.restoreCallingIdentity(identity); |
| 4261 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4262 | } |
| 4263 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4264 | /** |
| 4265 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4266 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4267 | */ |
| 4268 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4269 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4270 | |
| 4271 | final long identity = Binder.clearCallingIdentity(); |
| 4272 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4273 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4274 | if (resolver == null) { |
| 4275 | // may happen if the device does not support IMS. |
| 4276 | return null; |
| 4277 | } |
| 4278 | return resolver.getImsConfig(slotId, feature); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4279 | } finally { |
| 4280 | Binder.restoreCallingIdentity(identity); |
| 4281 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4282 | } |
| 4283 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4284 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4285 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4286 | * |
| 4287 | * @param slotId the slot ID that the ImsService should bind for. |
| 4288 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4289 | * ImsService is the device default ImsService. |
| 4290 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4291 | * to. |
| 4292 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4293 | * @hide |
| 4294 | */ |
| 4295 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4296 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4297 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4298 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4299 | "setImsService"); |
| 4300 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4301 | final long identity = Binder.clearCallingIdentity(); |
| 4302 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4303 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4304 | if (resolver == null) { |
| 4305 | // may happen if the device does not support IMS. |
| 4306 | return false; |
| 4307 | } |
| 4308 | return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService, |
| 4309 | packageName); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4310 | } finally { |
| 4311 | Binder.restoreCallingIdentity(identity); |
| 4312 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4313 | } |
| 4314 | |
| 4315 | /** |
| 4316 | * Return the ImsService configuration. |
| 4317 | * |
| 4318 | * @param slotId The slot that the ImsService is associated with. |
| 4319 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4320 | * the device default. |
| 4321 | * @return the package name of the ImsService configuration. |
| 4322 | */ |
| 4323 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4324 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4325 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4326 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4327 | "getImsService"); |
| 4328 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4329 | final long identity = Binder.clearCallingIdentity(); |
| 4330 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4331 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4332 | if (resolver == null) { |
| 4333 | // may happen if the device does not support IMS. |
| 4334 | return ""; |
| 4335 | } |
| 4336 | return resolver.getImsServiceConfiguration(slotId, isCarrierImsService); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4337 | } finally { |
| 4338 | Binder.restoreCallingIdentity(identity); |
| 4339 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4340 | } |
| 4341 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4342 | public void setImsRegistrationState(boolean registered) { |
| 4343 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4344 | |
| 4345 | final long identity = Binder.clearCallingIdentity(); |
| 4346 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4347 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4348 | } finally { |
| 4349 | Binder.restoreCallingIdentity(identity); |
| 4350 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4351 | } |
| 4352 | |
| 4353 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4354 | * Set the network selection mode to automatic. |
| 4355 | * |
| 4356 | */ |
| 4357 | @Override |
| 4358 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4359 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4360 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4361 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4362 | if (!isActiveSubscription(subId)) { |
| 4363 | return; |
| 4364 | } |
| 4365 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4366 | final long identity = Binder.clearCallingIdentity(); |
| 4367 | try { |
| 4368 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4369 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4370 | } finally { |
| 4371 | Binder.restoreCallingIdentity(identity); |
| 4372 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4373 | } |
| 4374 | |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4375 | /** |
| 4376 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4377 | * |
| 4378 | * @param subId the id of the subscription. |
| 4379 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4380 | * the operator to attach to. |
| 4381 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4382 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4383 | * normal network selection next time. |
| 4384 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4385 | */ |
| 4386 | @Override |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4387 | public boolean setNetworkSelectionModeManual( |
| 4388 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4389 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4390 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4391 | |
| 4392 | if (!isActiveSubscription(subId)) { |
| 4393 | return false; |
| 4394 | } |
| 4395 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4396 | final long identity = Binder.clearCallingIdentity(); |
| 4397 | try { |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4398 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4399 | persistSelection); |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4400 | if (DBG) { |
| 4401 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4402 | + " operator: " + operatorInfo); |
| 4403 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4404 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4405 | } finally { |
| 4406 | Binder.restoreCallingIdentity(identity); |
| 4407 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4408 | } |
| 4409 | |
| 4410 | /** |
| 4411 | * Scans for available networks. |
| 4412 | */ |
| 4413 | @Override |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4414 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4415 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4416 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4417 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4418 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4419 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4420 | .setCallingPackage(callingPackage) |
| 4421 | .setCallingPid(Binder.getCallingPid()) |
| 4422 | .setCallingUid(Binder.getCallingUid()) |
| 4423 | .setMethod("getCellNetworkScanResults") |
| 4424 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4425 | .build()); |
| 4426 | switch (locationResult) { |
| 4427 | case DENIED_HARD: |
| 4428 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4429 | case DENIED_SOFT: |
| 4430 | return null; |
| 4431 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4432 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4433 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4434 | try { |
| 4435 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4436 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4437 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4438 | } finally { |
| 4439 | Binder.restoreCallingIdentity(identity); |
| 4440 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4441 | } |
| 4442 | |
| 4443 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4444 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4445 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4446 | * @param subId id of the subscription |
| 4447 | * @param request contains the radio access networks with bands/channels to scan |
| 4448 | * @param messenger callback messenger for scan results or errors |
| 4449 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4450 | * @return the id of the requested scan which can be used to stop the scan. |
| 4451 | */ |
| 4452 | @Override |
| 4453 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4454 | IBinder binder, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4455 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4456 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4457 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4458 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4459 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4460 | .setCallingPackage(callingPackage) |
| 4461 | .setCallingPid(Binder.getCallingPid()) |
| 4462 | .setCallingUid(Binder.getCallingUid()) |
| 4463 | .setMethod("requestNetworkScan") |
| 4464 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4465 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4466 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
| 4467 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request); |
| 4468 | if (e != null) { |
| 4469 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 4470 | throw e; |
| 4471 | } else { |
Hall Liu | 46dd96a | 2019-04-03 12:50:44 -0700 | [diff] [blame] | 4472 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4473 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 4474 | } |
| 4475 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4476 | } |
Hall Liu | bac7d48 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4477 | int callingUid = Binder.getCallingUid(); |
| 4478 | int callingPid = Binder.getCallingPid(); |
yinxu | 612a819 | 2019-04-18 10:38:27 -0700 | [diff] [blame] | 4479 | final long identity = Binder.clearCallingIdentity(); |
| 4480 | try { |
| 4481 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4482 | request, messenger, binder, getPhone(subId), |
Hall Liu | bac7d48 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4483 | callingUid, callingPid, callingPackage); |
yinxu | 612a819 | 2019-04-18 10:38:27 -0700 | [diff] [blame] | 4484 | } finally { |
| 4485 | Binder.restoreCallingIdentity(identity); |
| 4486 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4487 | } |
| 4488 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4489 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
| 4490 | NetworkScanRequest request) { |
| 4491 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 4492 | != PERMISSION_GRANTED) { |
| 4493 | return new SecurityException("permission.NETWORK_SCAN is needed for network scans" |
| 4494 | + " without location access."); |
| 4495 | } |
| 4496 | |
| 4497 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 4498 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4499 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 4500 | return new SecurityException("Specific channels must not be" |
| 4501 | + " scanned without location access."); |
| 4502 | } |
| 4503 | } |
| 4504 | } |
| 4505 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4506 | return null; |
| 4507 | } |
| 4508 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4509 | /** |
| 4510 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4511 | * |
| 4512 | * @param subId id of the subscription |
| 4513 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4514 | */ |
| 4515 | @Override |
| 4516 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4517 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4518 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4519 | |
Hall Liu | bac7d48 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4520 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4521 | final long identity = Binder.clearCallingIdentity(); |
| 4522 | try { |
Hall Liu | bac7d48 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4523 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4524 | } finally { |
| 4525 | Binder.restoreCallingIdentity(identity); |
| 4526 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4527 | } |
| 4528 | |
| 4529 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4530 | * Get the calculated preferred network type. |
| 4531 | * Used for debugging incorrect network type. |
| 4532 | * |
| 4533 | * @return the preferred network type, defined in RILConstants.java. |
| 4534 | */ |
| 4535 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4536 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4537 | final Phone defaultPhone = getDefaultPhone(); |
| 4538 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4539 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4540 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4541 | } |
| 4542 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4543 | final long identity = Binder.clearCallingIdentity(); |
| 4544 | try { |
| 4545 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4546 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4547 | } finally { |
| 4548 | Binder.restoreCallingIdentity(identity); |
| 4549 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4550 | } |
| 4551 | |
| 4552 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4553 | * Get the preferred network type. |
| 4554 | * Used for device configuration by some CDMA operators. |
| 4555 | * |
| 4556 | * @return the preferred network type, defined in RILConstants.java. |
| 4557 | */ |
| 4558 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4559 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | 4848cd0 | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4560 | TelephonyPermissions |
| 4561 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4562 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4563 | |
| 4564 | final long identity = Binder.clearCallingIdentity(); |
| 4565 | try { |
| 4566 | if (DBG) log("getPreferredNetworkType"); |
| 4567 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4568 | int networkType = (result != null ? result[0] : -1); |
| 4569 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4570 | return networkType; |
| 4571 | } finally { |
| 4572 | Binder.restoreCallingIdentity(identity); |
| 4573 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4574 | } |
| 4575 | |
| 4576 | /** |
| 4577 | * Set the preferred network type. |
| 4578 | * Used for device configuration by some CDMA operators. |
| 4579 | * |
| 4580 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4581 | * @return true on success; false on any failure. |
| 4582 | */ |
| 4583 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4584 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4585 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4586 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4587 | |
| 4588 | final long identity = Binder.clearCallingIdentity(); |
| 4589 | try { |
| 4590 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4591 | Boolean success = (Boolean) sendRequest( |
| 4592 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4593 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4594 | if (success) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4595 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4596 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4597 | } |
| 4598 | return success; |
| 4599 | } finally { |
| 4600 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4601 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4602 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4603 | |
| 4604 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4605 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4606 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4607 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4608 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4609 | * @hide |
| 4610 | */ |
| 4611 | @Override |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4612 | public boolean getTetherApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4613 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4614 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4615 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4616 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4617 | if (phone != null) { |
| 4618 | return phone.hasMatchedTetherApnSetting(); |
| 4619 | } else { |
| 4620 | return false; |
| 4621 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4622 | } finally { |
| 4623 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4624 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4625 | } |
| 4626 | |
| 4627 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4628 | * Set mobile data enabled |
| 4629 | * Used by the user through settings etc to turn on/off mobile data |
| 4630 | * |
| 4631 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4632 | */ |
| 4633 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4634 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4635 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4636 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4637 | |
| 4638 | final long identity = Binder.clearCallingIdentity(); |
| 4639 | try { |
| 4640 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4641 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4642 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4643 | if (phone != null) { |
| 4644 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4645 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4646 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4647 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4648 | } |
| 4649 | } finally { |
| 4650 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4651 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4652 | } |
| 4653 | |
| 4654 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4655 | * Get the user enabled state of Mobile Data. |
| 4656 | * |
| 4657 | * TODO: remove and use isUserDataEnabled. |
| 4658 | * This can't be removed now because some vendor codes |
| 4659 | * calls through ITelephony directly while they should |
| 4660 | * use TelephonyManager. |
| 4661 | * |
| 4662 | * @return true on enabled |
| 4663 | */ |
| 4664 | @Override |
| 4665 | public boolean getDataEnabled(int subId) { |
| 4666 | return isUserDataEnabled(subId); |
| 4667 | } |
| 4668 | |
| 4669 | /** |
| 4670 | * Get whether mobile data is enabled per user setting. |
| 4671 | * |
| 4672 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4673 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4674 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4675 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4676 | * |
| 4677 | * @return {@code true} if data is enabled else {@code false} |
| 4678 | */ |
| 4679 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4680 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4681 | try { |
| 4682 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4683 | null); |
| 4684 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4685 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4686 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4687 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4688 | |
| 4689 | final long identity = Binder.clearCallingIdentity(); |
| 4690 | try { |
| 4691 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4692 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4693 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4694 | if (phone != null) { |
| 4695 | boolean retVal = phone.isUserDataEnabled(); |
| 4696 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4697 | return retVal; |
| 4698 | } else { |
| 4699 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4700 | return false; |
| 4701 | } |
| 4702 | } finally { |
| 4703 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4704 | } |
| 4705 | } |
| 4706 | |
| 4707 | /** |
| 4708 | * Get whether mobile data is enabled. |
| 4709 | * |
| 4710 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4711 | * whether mobile data is actually enabled. |
| 4712 | * |
| 4713 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4714 | * |
| 4715 | * @return {@code true} if data is enabled else {@code false} |
| 4716 | */ |
| 4717 | @Override |
| 4718 | public boolean isDataEnabled(int subId) { |
| 4719 | try { |
| 4720 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4721 | null); |
| 4722 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4723 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4724 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4725 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4726 | |
| 4727 | final long identity = Binder.clearCallingIdentity(); |
| 4728 | try { |
| 4729 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4730 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4731 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4732 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4733 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4734 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4735 | return retVal; |
| 4736 | } else { |
| 4737 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4738 | return false; |
| 4739 | } |
| 4740 | } finally { |
| 4741 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4742 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4743 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4744 | |
| 4745 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4746 | public int getCarrierPrivilegeStatus(int subId) { |
| 4747 | final Phone phone = getPhone(subId); |
| 4748 | if (phone == null) { |
| 4749 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4750 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4751 | } |
| 4752 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4753 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4754 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4755 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4756 | } |
| 4757 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4758 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4759 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4760 | |
| 4761 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4762 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4763 | final Phone phone = getPhone(subId); |
| 4764 | if (phone == null) { |
| 4765 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4766 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4767 | } |
| 4768 | UiccProfile profile = |
| 4769 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4770 | if (profile == null) { |
| 4771 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4772 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4773 | } |
| 4774 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 4775 | } |
| 4776 | |
| 4777 | @Override |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4778 | public int checkCarrierPrivilegesForPackage(String pkgName) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4779 | final Phone defaultPhone = getDefaultPhone(); |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4780 | if (TextUtils.isEmpty(pkgName)) |
| 4781 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4782 | UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4783 | if (card == null) { |
| 4784 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 4785 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4786 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4787 | return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(), |
| 4788 | pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4789 | } |
| 4790 | |
| 4791 | @Override |
| 4792 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4793 | if (TextUtils.isEmpty(pkgName)) |
| 4794 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4795 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4796 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4797 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4798 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4799 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4800 | continue; |
| 4801 | } |
| 4802 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4803 | result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4804 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4805 | break; |
| 4806 | } |
| 4807 | } |
| 4808 | |
| 4809 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4810 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4811 | |
| 4812 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4813 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4814 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4815 | loge("phoneId " + phoneId + " is not valid."); |
| 4816 | return null; |
| 4817 | } |
| 4818 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4819 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4820 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4821 | return null ; |
| 4822 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4823 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4824 | } |
| 4825 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4826 | @Override |
| 4827 | public List<String> getPackagesWithCarrierPrivileges() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4828 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4829 | List<String> privilegedPackages = new ArrayList<>(); |
| 4830 | List<PackageInfo> packages = null; |
| 4831 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4832 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4833 | if (card == null) { |
| 4834 | // No UICC in that slot. |
| 4835 | continue; |
| 4836 | } |
| 4837 | if (card.hasCarrierPrivilegeRules()) { |
| 4838 | if (packages == null) { |
| 4839 | // Only check packages in user 0 for now |
| 4840 | packages = pm.getInstalledPackagesAsUser( |
| 4841 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4842 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4843 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
| 4844 | } |
| 4845 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4846 | PackageInfo pkgInfo = packages.get(p); |
| 4847 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4848 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| 4849 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4850 | privilegedPackages.add(pkgInfo.packageName); |
| 4851 | } |
| 4852 | } |
| 4853 | } |
| 4854 | } |
| 4855 | return privilegedPackages; |
| 4856 | } |
| 4857 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4858 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4859 | final Phone phone = getPhone(subId); |
| 4860 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4861 | if (card == null) { |
| 4862 | loge("getIccId: No UICC"); |
| 4863 | return null; |
| 4864 | } |
| 4865 | String iccId = card.getIccId(); |
| 4866 | if (TextUtils.isEmpty(iccId)) { |
| 4867 | loge("getIccId: ICC ID is null or empty."); |
| 4868 | return null; |
| 4869 | } |
| 4870 | return iccId; |
| 4871 | } |
| 4872 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4873 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4874 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4875 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4876 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4877 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4878 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4879 | final long identity = Binder.clearCallingIdentity(); |
| 4880 | try { |
| 4881 | final String iccId = getIccId(subId); |
| 4882 | final Phone phone = getPhone(subId); |
| 4883 | if (phone == null) { |
| 4884 | return false; |
| 4885 | } |
| 4886 | final String subscriberId = phone.getSubscriberId(); |
| 4887 | |
| 4888 | if (DBG_MERGE) { |
| 4889 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4890 | + subscriberId + " to " + number); |
| 4891 | } |
| 4892 | |
| 4893 | if (TextUtils.isEmpty(iccId)) { |
| 4894 | return false; |
| 4895 | } |
| 4896 | |
| 4897 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4898 | |
| 4899 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4900 | if (alphaTag == null) { |
| 4901 | editor.remove(alphaTagPrefKey); |
| 4902 | } else { |
| 4903 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4904 | } |
| 4905 | |
| 4906 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4907 | // track all merged IMSIs based on line number |
| 4908 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4909 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4910 | if (number == null) { |
| 4911 | editor.remove(numberPrefKey); |
| 4912 | editor.remove(subscriberPrefKey); |
| 4913 | } else { |
| 4914 | editor.putString(numberPrefKey, number); |
| 4915 | editor.putString(subscriberPrefKey, subscriberId); |
| 4916 | } |
| 4917 | |
| 4918 | editor.commit(); |
| 4919 | return true; |
| 4920 | } finally { |
| 4921 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4922 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4923 | } |
| 4924 | |
| 4925 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4926 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4927 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4928 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4929 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4930 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
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 numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4939 | if (DBG_MERGE) { |
| 4940 | log("getLine1NumberForDisplay returning " |
| 4941 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 4942 | } |
| 4943 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4944 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4945 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 4946 | return null; |
| 4947 | } finally { |
| 4948 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4949 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4950 | } |
| 4951 | |
| 4952 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4953 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4954 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4955 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4956 | return null; |
| 4957 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4958 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4959 | final long identity = Binder.clearCallingIdentity(); |
| 4960 | try { |
| 4961 | String iccId = getIccId(subId); |
| 4962 | if (iccId != null) { |
| 4963 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4964 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 4965 | } |
| 4966 | return null; |
| 4967 | } finally { |
| 4968 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4969 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4970 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4971 | |
| 4972 | @Override |
Jordan Liu | 9775d4b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 4973 | public String[] getMergedSubscriberIds(int subId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4974 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 4975 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4976 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4977 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 4978 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4979 | return null; |
| 4980 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4981 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4982 | final long identity = Binder.clearCallingIdentity(); |
| 4983 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4984 | final Context context = mApp; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4985 | final TelephonyManager tele = TelephonyManager.from(context); |
| 4986 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 4987 | |
| 4988 | // Figure out what subscribers are currently active |
| 4989 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
| 4990 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 4991 | // the process, where TelephonyManager was instantiated. |
| 4992 | // Otherwise AppOps check will fail. |
| 4993 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4994 | final int[] subIds = sub.getActiveSubscriptionIdList(); |
Jordan Liu | 9775d4b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 4995 | for (int id : subIds) { |
| 4996 | // Only consider subs which match the current subId |
| 4997 | // This logic can be simplified. See b/131189269 for progress. |
| 4998 | if (subId != id) { |
| 4999 | continue; |
| 5000 | } |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5001 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 5002 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5003 | |
| 5004 | // First pass, find a number override for an active subscriber |
| 5005 | String mergeNumber = null; |
| 5006 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 5007 | for (String key : prefs.keySet()) { |
| 5008 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 5009 | final String subscriberId = (String) prefs.get(key); |
| 5010 | if (activeSubscriberIds.contains(subscriberId)) { |
| 5011 | final String iccId = key.substring( |
| 5012 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 5013 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5014 | mergeNumber = (String) prefs.get(numberKey); |
| 5015 | if (DBG_MERGE) { |
| 5016 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 5017 | + " for active subscriber " + subscriberId); |
| 5018 | } |
| 5019 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 5020 | break; |
| 5021 | } |
| 5022 | } |
| 5023 | } |
| 5024 | } |
| 5025 | |
| 5026 | // Shortcut when no active merged subscribers |
| 5027 | if (TextUtils.isEmpty(mergeNumber)) { |
| 5028 | return null; |
| 5029 | } |
| 5030 | |
| 5031 | // Second pass, find all subscribers under that line override |
| 5032 | final ArraySet<String> result = new ArraySet<>(); |
| 5033 | for (String key : prefs.keySet()) { |
| 5034 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5035 | final String number = (String) prefs.get(key); |
| 5036 | if (mergeNumber.equals(number)) { |
| 5037 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5038 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5039 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5040 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5041 | result.add(subscriberId); |
| 5042 | } |
| 5043 | } |
| 5044 | } |
| 5045 | } |
| 5046 | |
| 5047 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5048 | Arrays.sort(resultArray); |
| 5049 | if (DBG_MERGE) { |
| 5050 | Slog.d(LOG_TAG, |
| 5051 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5052 | } |
| 5053 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5054 | } finally { |
| 5055 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5056 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5057 | } |
| 5058 | |
| 5059 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5060 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5061 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5062 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5063 | |
| 5064 | final long identity = Binder.clearCallingIdentity(); |
| 5065 | try { |
| 5066 | final Phone phone = getPhone(subId); |
| 5067 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5068 | } finally { |
| 5069 | Binder.restoreCallingIdentity(identity); |
| 5070 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5071 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5072 | |
| 5073 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5074 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5075 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5076 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5077 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5078 | |
| 5079 | final long identity = Binder.clearCallingIdentity(); |
| 5080 | try { |
| 5081 | final Phone phone = getPhone(subId); |
| 5082 | if (phone == null) { |
| 5083 | return false; |
| 5084 | } |
| 5085 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5086 | cdmaNonRoamingList); |
| 5087 | } finally { |
| 5088 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5089 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5090 | } |
| 5091 | |
| 5092 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5093 | @Deprecated |
| 5094 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5095 | enforceModifyPermission(); |
| 5096 | |
| 5097 | int returnValue = 0; |
| 5098 | try { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5099 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5100 | if(result.exception == null) { |
| 5101 | if (result.result != null) { |
| 5102 | byte[] responseData = (byte[])(result.result); |
| 5103 | if(responseData.length > oemResp.length) { |
| 5104 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5105 | responseData.length + "bytes. Buffer Size is " + |
| 5106 | oemResp.length + "bytes."); |
| 5107 | } |
| 5108 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5109 | returnValue = responseData.length; |
| 5110 | } |
| 5111 | } else { |
| 5112 | CommandException ex = (CommandException) result.exception; |
| 5113 | returnValue = ex.getCommandError().ordinal(); |
| 5114 | if(returnValue > 0) returnValue *= -1; |
| 5115 | } |
| 5116 | } catch (RuntimeException e) { |
| 5117 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5118 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5119 | if(returnValue > 0) returnValue *= -1; |
| 5120 | } |
| 5121 | |
| 5122 | return returnValue; |
| 5123 | } |
| 5124 | |
| 5125 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5126 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5127 | try { |
| 5128 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5129 | } catch (RuntimeException e) { |
| 5130 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5131 | } |
| 5132 | } |
| 5133 | |
| 5134 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5135 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5136 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5137 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5138 | if (phone == null) { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5139 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5140 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5141 | final long identity = Binder.clearCallingIdentity(); |
| 5142 | try { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5143 | TelephonyPermissions |
| 5144 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5145 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5146 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5147 | } finally { |
| 5148 | Binder.restoreCallingIdentity(identity); |
| 5149 | } |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5150 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5151 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5152 | |
| 5153 | @Override |
| 5154 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5155 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5156 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5157 | |
| 5158 | final long identity = Binder.clearCallingIdentity(); |
| 5159 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5160 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5161 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5162 | } finally { |
| 5163 | Binder.restoreCallingIdentity(identity); |
| 5164 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5165 | } |
| 5166 | |
| 5167 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5168 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5169 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5170 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5171 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5172 | return false; |
| 5173 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5174 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5175 | final long identity = Binder.clearCallingIdentity(); |
| 5176 | try { |
| 5177 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5178 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5179 | // In the long run, we may instead need to check if there exists a connection service |
| 5180 | // which can support video calling. |
| 5181 | ImsManager imsManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5182 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5183 | return imsManager.isVtEnabledByPlatform() |
| 5184 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5185 | && imsManager.isVtEnabledByUser(); |
| 5186 | } finally { |
| 5187 | Binder.restoreCallingIdentity(identity); |
| 5188 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5189 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5190 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5191 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5192 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 5193 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5194 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5195 | return false; |
| 5196 | } |
| 5197 | |
| 5198 | final long identity = Binder.clearCallingIdentity(); |
| 5199 | try { |
| 5200 | CarrierConfigManager configManager = |
| 5201 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5202 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5203 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5204 | } finally { |
| 5205 | Binder.restoreCallingIdentity(identity); |
| 5206 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5207 | } |
| 5208 | |
| 5209 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5210 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 5211 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5212 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5213 | return false; |
| 5214 | } |
| 5215 | |
| 5216 | final long identity = Binder.clearCallingIdentity(); |
| 5217 | try { |
| 5218 | CarrierConfigManager configManager = |
| 5219 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5220 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5221 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5222 | } finally { |
| 5223 | Binder.restoreCallingIdentity(identity); |
| 5224 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5225 | } |
| 5226 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5227 | @Override |
| 5228 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5229 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5230 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5231 | } |
| 5232 | |
| 5233 | @Override |
| 5234 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5235 | final long identity = Binder.clearCallingIdentity(); |
| 5236 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5237 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5238 | } finally { |
| 5239 | Binder.restoreCallingIdentity(identity); |
| 5240 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5241 | } |
| 5242 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5243 | /** |
| 5244 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5245 | * support for the feature and device firmware support. |
| 5246 | * |
| 5247 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5248 | */ |
| 5249 | @Override |
| 5250 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5251 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5252 | final Phone phone = getPhone(subscriptionId); |
| 5253 | if (phone == null) { |
| 5254 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5255 | return false; |
| 5256 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5257 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5258 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5259 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5260 | boolean isDeviceSupported = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5261 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5262 | return isCarrierSupported && isDeviceSupported; |
| 5263 | } finally { |
| 5264 | Binder.restoreCallingIdentity(identity); |
| 5265 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5266 | } |
| 5267 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5268 | /** |
| 5269 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier |
| 5270 | * both also support RTT. |
| 5271 | */ |
| 5272 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5273 | final long identity = Binder.clearCallingIdentity(); |
| 5274 | try { |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5275 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5276 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5277 | } finally { |
| 5278 | Binder.restoreCallingIdentity(identity); |
| 5279 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5280 | } |
| 5281 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5282 | /** |
| 5283 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5284 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5285 | * |
| 5286 | * <p>Requires Permission: |
| 5287 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5288 | */ |
| 5289 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5290 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5291 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5292 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5293 | return null; |
| 5294 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5295 | int subId = phone.getSubId(); |
| 5296 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5297 | mApp, subId, callingPackage, "getDeviceId")) { |
| 5298 | return null; |
| 5299 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5300 | |
| 5301 | final long identity = Binder.clearCallingIdentity(); |
| 5302 | try { |
| 5303 | return phone.getDeviceId(); |
| 5304 | } finally { |
| 5305 | Binder.restoreCallingIdentity(identity); |
| 5306 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5307 | } |
| 5308 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5309 | /** |
| 5310 | * {@hide} |
| 5311 | * Returns the IMS Registration Status on a particular subid |
| 5312 | * |
| 5313 | * @param subId |
| 5314 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5315 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5316 | Phone phone = getPhone(subId); |
| 5317 | if (phone != null) { |
| 5318 | return phone.isImsRegistered(); |
| 5319 | } else { |
| 5320 | return false; |
| 5321 | } |
| 5322 | } |
| 5323 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5324 | @Override |
| 5325 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5326 | final long identity = Binder.clearCallingIdentity(); |
| 5327 | try { |
| 5328 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5329 | } finally { |
| 5330 | Binder.restoreCallingIdentity(identity); |
| 5331 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5332 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5333 | |
Tyler Gunn | 327a972 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5334 | @Override |
| 5335 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 5336 | final long identity = Binder.clearCallingIdentity(); |
| 5337 | try { |
| 5338 | Phone phone = getPhone(subscriptionId); |
| 5339 | if (phone == null) { |
| 5340 | return null; |
| 5341 | } |
| 5342 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 5343 | } finally { |
| 5344 | Binder.restoreCallingIdentity(identity); |
| 5345 | } |
| 5346 | } |
| 5347 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5348 | /** |
| 5349 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5350 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5351 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5352 | final long identity = Binder.clearCallingIdentity(); |
| 5353 | try { |
| 5354 | Phone phone = getPhone(subId); |
| 5355 | if (phone != null) { |
| 5356 | return phone.isWifiCallingEnabled(); |
| 5357 | } else { |
| 5358 | return false; |
| 5359 | } |
| 5360 | } finally { |
| 5361 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5362 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5363 | } |
| 5364 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5365 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5366 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5367 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5368 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5369 | final long identity = Binder.clearCallingIdentity(); |
| 5370 | try { |
| 5371 | Phone phone = getPhone(subId); |
| 5372 | if (phone != null) { |
| 5373 | return phone.isVideoEnabled(); |
| 5374 | } else { |
| 5375 | return false; |
| 5376 | } |
| 5377 | } finally { |
| 5378 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5379 | } |
| 5380 | } |
| 5381 | |
| 5382 | /** |
| 5383 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5384 | * defined in {@link ImsRegistrationImplBase}. |
| 5385 | */ |
| 5386 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5387 | final long identity = Binder.clearCallingIdentity(); |
| 5388 | try { |
| 5389 | Phone phone = getPhone(subId); |
| 5390 | if (phone != null) { |
| 5391 | return phone.getImsRegistrationTech(); |
| 5392 | } else { |
| 5393 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5394 | } |
| 5395 | } finally { |
| 5396 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5397 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5398 | } |
| 5399 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5400 | @Override |
| 5401 | public void factoryReset(int subId) { |
| 5402 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5403 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5404 | return; |
| 5405 | } |
| 5406 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5407 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5408 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5409 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5410 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5411 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5412 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5413 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5414 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5415 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5416 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5417 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5418 | // There has been issues when Sms raw table somehow stores orphan |
| 5419 | // fragments. They lead to garbled message when new fragments come |
| 5420 | // in and combined with those stale ones. In case this happens again, |
| 5421 | // user can reset all network settings which will clean up this table. |
| 5422 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5423 | } finally { |
| 5424 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5425 | } |
| 5426 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5427 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5428 | private void cleanUpSmsRawTable(Context context) { |
| 5429 | ContentResolver resolver = context.getContentResolver(); |
| 5430 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 5431 | resolver.delete(uri, null, null); |
| 5432 | } |
| 5433 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5434 | @Override |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5435 | public String getSimLocaleForSubscriber(int subId) { |
| 5436 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5437 | final Phone phone = getPhone(subId); |
| 5438 | if (phone == null) { |
| 5439 | log("getSimLocaleForSubscriber, invalid subId"); |
Pengquan Meng | 9c29148 | 2019-01-28 16:26:29 -0800 | [diff] [blame] | 5440 | return null; |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5441 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5442 | final long identity = Binder.clearCallingIdentity(); |
| 5443 | try { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5444 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5445 | phone.getContext().getOpPackageName()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5446 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5447 | // preferences (EF-PL and EF-LI)... |
| 5448 | final int mcc = info.getMcc(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5449 | String simLanguage = null; |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5450 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5451 | if (localeFromDefaultSim != null) { |
| 5452 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5453 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5454 | + localeFromDefaultSim); |
| 5455 | return localeFromDefaultSim.toLanguageTag(); |
| 5456 | } else { |
| 5457 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5458 | } |
| 5459 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5460 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5461 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5462 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5463 | // the SIM and carrier preferences does not include a country we add the country |
| 5464 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5465 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5466 | if (mccLocale != null) { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5467 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5468 | return mccLocale.toLanguageTag(); |
| 5469 | } |
| 5470 | |
| 5471 | if (DBG) log("No locale found - returning null"); |
| 5472 | return null; |
| 5473 | } finally { |
| 5474 | Binder.restoreCallingIdentity(identity); |
| 5475 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5476 | } |
| 5477 | |
| 5478 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5479 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5480 | } |
| 5481 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5482 | /** |
| 5483 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5484 | */ |
| 5485 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5486 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5487 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5488 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5489 | private final ModemActivityInfo mLastModemActivityInfo = |
| 5490 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 5491 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5492 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5493 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5494 | * representing the state of the modem. |
| 5495 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5496 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5497 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5498 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5499 | */ |
| 5500 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5501 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5502 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5503 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5504 | |
| 5505 | final long identity = Binder.clearCallingIdentity(); |
| 5506 | try { |
| 5507 | ModemActivityInfo ret = null; |
| 5508 | synchronized (mLastModemActivityInfo) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5509 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5510 | CMD_GET_MODEM_ACTIVITY_INFO, |
| 5511 | null, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5512 | if (isModemActivityInfoValid(info)) { |
| 5513 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 5514 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 5515 | mergedTxTimeMs[i] = |
| 5516 | info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i]; |
| 5517 | } |
| 5518 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 5519 | mLastModemActivityInfo.setSleepTimeMillis( |
| 5520 | info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis()); |
| 5521 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5522 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 5523 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 5524 | mLastModemActivityInfo.setRxTimeMillis( |
| 5525 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 5526 | mLastModemActivityInfo.setEnergyUsed( |
| 5527 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5528 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5529 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5530 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5531 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 5532 | mLastModemActivityInfo.getTxTimeMillis(), |
| 5533 | mLastModemActivityInfo.getRxTimeMillis(), |
| 5534 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5535 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5536 | Bundle bundle = new Bundle(); |
| 5537 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 5538 | result.send(0, bundle); |
| 5539 | } finally { |
| 5540 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5541 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5542 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5543 | |
Siddharth Ray | f5d2955 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5544 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 5545 | // less than total activity duration. |
| 5546 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 5547 | if (info == null) { |
| 5548 | return false; |
| 5549 | } |
| 5550 | int activityDurationMs = |
| 5551 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 5552 | int totalTxTimeMs = 0; |
| 5553 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 5554 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 5555 | } |
| 5556 | return (info.isValid() |
| 5557 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 5558 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 5559 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 5560 | && (totalTxTimeMs <= activityDurationMs)); |
| 5561 | } |
| 5562 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5563 | /** |
| 5564 | * {@hide} |
| 5565 | * Returns the service state information on specified subscription. |
| 5566 | */ |
| 5567 | @Override |
| 5568 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5569 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5570 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5571 | return null; |
| 5572 | } |
| 5573 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5574 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 5575 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5576 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5577 | .setCallingPackage(callingPackage) |
| 5578 | .setCallingPid(Binder.getCallingPid()) |
| 5579 | .setCallingUid(Binder.getCallingUid()) |
| 5580 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | 8b0cba2 | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5581 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5582 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5583 | .build()); |
| 5584 | |
| 5585 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 5586 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5587 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5588 | .setCallingPackage(callingPackage) |
| 5589 | .setCallingPid(Binder.getCallingPid()) |
| 5590 | .setCallingUid(Binder.getCallingUid()) |
| 5591 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | 8b0cba2 | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5592 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5593 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5594 | .build()); |
| 5595 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 5596 | boolean hasFinePermission = |
| 5597 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5598 | boolean hasCoarsePermission = |
| 5599 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5600 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5601 | final long identity = Binder.clearCallingIdentity(); |
| 5602 | try { |
| 5603 | final Phone phone = getPhone(subId); |
| 5604 | if (phone == null) { |
| 5605 | return null; |
| 5606 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5607 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5608 | ServiceState ss = phone.getServiceState(); |
| 5609 | |
| 5610 | // Scrub out the location info in ServiceState depending on what level of access |
| 5611 | // the caller has. |
| 5612 | if (hasFinePermission) return ss; |
| 5613 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 5614 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5615 | } finally { |
| 5616 | Binder.restoreCallingIdentity(identity); |
| 5617 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5618 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5619 | |
| 5620 | /** |
| 5621 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5622 | * |
| 5623 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5624 | * voicemail ringtone. |
| 5625 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5626 | * PhoneAccount. |
| 5627 | */ |
| 5628 | @Override |
| 5629 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5630 | final long identity = Binder.clearCallingIdentity(); |
| 5631 | try { |
| 5632 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5633 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5634 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5635 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5636 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5637 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5638 | } finally { |
| 5639 | Binder.restoreCallingIdentity(identity); |
| 5640 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5641 | } |
| 5642 | |
| 5643 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5644 | * Sets the per-account voicemail ringtone. |
| 5645 | * |
| 5646 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5647 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5648 | * |
| 5649 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5650 | * voicemail ringtone. |
| 5651 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5652 | * PhoneAccount. |
| 5653 | */ |
| 5654 | @Override |
| 5655 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5656 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5657 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5658 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5659 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5660 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5661 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5662 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5663 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5664 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5665 | |
| 5666 | final long identity = Binder.clearCallingIdentity(); |
| 5667 | try { |
| 5668 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5669 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5670 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5671 | } |
| 5672 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5673 | } finally { |
| 5674 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5675 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5676 | } |
| 5677 | |
| 5678 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5679 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5680 | * |
| 5681 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5682 | * voicemail vibration setting. |
| 5683 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5684 | */ |
| 5685 | @Override |
| 5686 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5687 | final long identity = Binder.clearCallingIdentity(); |
| 5688 | try { |
| 5689 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5690 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5691 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5692 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5693 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5694 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5695 | } finally { |
| 5696 | Binder.restoreCallingIdentity(identity); |
| 5697 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5698 | } |
| 5699 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5700 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5701 | * Sets the per-account voicemail vibration. |
| 5702 | * |
| 5703 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5704 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5705 | * |
| 5706 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5707 | * voicemail vibration setting. |
| 5708 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5709 | * specific PhoneAccount. |
| 5710 | */ |
| 5711 | @Override |
| 5712 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5713 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5714 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5715 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5716 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5717 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5718 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5719 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5720 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5721 | } |
| 5722 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5723 | final long identity = Binder.clearCallingIdentity(); |
| 5724 | try { |
| 5725 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5726 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5727 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5728 | } |
| 5729 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5730 | } finally { |
| 5731 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5732 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5733 | } |
| 5734 | |
| 5735 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5736 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5737 | * |
| 5738 | * @throws SecurityException if the caller does not have the required permission |
| 5739 | */ |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5740 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5741 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5742 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5743 | } |
| 5744 | |
| 5745 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5746 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5747 | * permission. |
| 5748 | * |
| 5749 | * @throws SecurityException if the caller does not have the required permission |
| 5750 | */ |
| 5751 | private void enforceSendSmsPermission() { |
| 5752 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5753 | } |
| 5754 | |
| 5755 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5756 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5757 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5758 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5759 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5760 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5761 | final long identity = Binder.clearCallingIdentity(); |
| 5762 | try { |
| 5763 | ComponentName componentName = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5764 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5765 | if (componentName == null) { |
| 5766 | throw new SecurityException( |
| 5767 | "Caller not current active visual voicemail package[null]"); |
| 5768 | } |
| 5769 | String vvmPackage = componentName.getPackageName(); |
| 5770 | if (!callingPackage.equals(vvmPackage)) { |
| 5771 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5772 | + vvmPackage + "]"); |
| 5773 | } |
| 5774 | } finally { |
| 5775 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5776 | } |
| 5777 | } |
| 5778 | |
| 5779 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5780 | * Return the application ID for the app type. |
| 5781 | * |
| 5782 | * @param subId the subscription ID that this request applies to. |
| 5783 | * @param appType the uicc app type. |
| 5784 | * @return Application ID for specificied app type, or null if no uicc. |
| 5785 | */ |
| 5786 | @Override |
| 5787 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5788 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5789 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5790 | |
| 5791 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5792 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5793 | if (phone == null) { |
| 5794 | return null; |
| 5795 | } |
| 5796 | String aid = null; |
| 5797 | try { |
| 5798 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5799 | .getApplicationByType(appType).getAid(); |
| 5800 | } catch (Exception e) { |
| 5801 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5802 | } |
| 5803 | return aid; |
| 5804 | } finally { |
| 5805 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5806 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5807 | } |
| 5808 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5809 | /** |
| 5810 | * Return the Electronic Serial Number. |
| 5811 | * |
| 5812 | * @param subId the subscription ID that this request applies to. |
| 5813 | * @return ESN or null if error. |
| 5814 | */ |
| 5815 | @Override |
| 5816 | public String getEsn(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5817 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5818 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5819 | |
| 5820 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5821 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5822 | if (phone == null) { |
| 5823 | return null; |
| 5824 | } |
| 5825 | String esn = null; |
| 5826 | try { |
| 5827 | esn = phone.getEsn(); |
| 5828 | } catch (Exception e) { |
| 5829 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5830 | } |
| 5831 | return esn; |
| 5832 | } finally { |
| 5833 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5834 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5835 | } |
| 5836 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5837 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5838 | * Return the Preferred Roaming List Version. |
| 5839 | * |
| 5840 | * @param subId the subscription ID that this request applies to. |
| 5841 | * @return PRLVersion or null if error. |
| 5842 | */ |
| 5843 | @Override |
| 5844 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5845 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5846 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5847 | |
| 5848 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5849 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5850 | if (phone == null) { |
| 5851 | return null; |
| 5852 | } |
| 5853 | String cdmaPrlVersion = null; |
| 5854 | try { |
| 5855 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 5856 | } catch (Exception e) { |
| 5857 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 5858 | } |
| 5859 | return cdmaPrlVersion; |
| 5860 | } finally { |
| 5861 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5862 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5863 | } |
| 5864 | |
| 5865 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5866 | * Get snapshot of Telephony histograms |
| 5867 | * @return List of Telephony histograms |
| 5868 | * @hide |
| 5869 | */ |
| 5870 | @Override |
| 5871 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5872 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5873 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5874 | |
| 5875 | final long identity = Binder.clearCallingIdentity(); |
| 5876 | try { |
| 5877 | return RIL.getTelephonyRILTimingHistograms(); |
| 5878 | } finally { |
| 5879 | Binder.restoreCallingIdentity(identity); |
| 5880 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5881 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5882 | |
| 5883 | /** |
| 5884 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5885 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 5886 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5887 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5888 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5889 | * @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] | 5890 | */ |
| 5891 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5892 | @TelephonyManager.SetCarrierRestrictionResult |
| 5893 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5894 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5895 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5896 | |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5897 | if (carrierRestrictionRules == null) { |
| 5898 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5899 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5900 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5901 | final long identity = Binder.clearCallingIdentity(); |
| 5902 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5903 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5904 | workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5905 | } finally { |
| 5906 | Binder.restoreCallingIdentity(identity); |
| 5907 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5908 | } |
| 5909 | |
| 5910 | /** |
| 5911 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5912 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 5913 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5914 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5915 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5916 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5917 | */ |
| 5918 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5919 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5920 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5921 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5922 | |
| 5923 | final long identity = Binder.clearCallingIdentity(); |
| 5924 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5925 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 5926 | if (response instanceof CarrierRestrictionRules) { |
| 5927 | return (CarrierRestrictionRules) response; |
| 5928 | } |
| 5929 | // Response is an Exception of some kind, |
| 5930 | // which is signalled to the user as a NULL retval |
| 5931 | return null; |
| 5932 | } catch (Exception e) { |
| 5933 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 5934 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5935 | } finally { |
| 5936 | Binder.restoreCallingIdentity(identity); |
| 5937 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5938 | } |
| 5939 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5940 | /** |
| 5941 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 5942 | * @param subId the subscription ID that this action applies to. |
| 5943 | * @param enabled control enable or disable metered apns. |
| 5944 | * {@hide} |
| 5945 | */ |
| 5946 | @Override |
| 5947 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 5948 | enforceModifyPermission(); |
| 5949 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5950 | |
| 5951 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5952 | if (phone == null) { |
| 5953 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 5954 | return; |
| 5955 | } |
| 5956 | try { |
| 5957 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 5958 | } catch (Exception e) { |
| 5959 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5960 | } finally { |
| 5961 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5962 | } |
| 5963 | } |
| 5964 | |
| 5965 | /** |
| 5966 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 5967 | * @param subId the subscription ID that this action applies to. |
| 5968 | * @param enabled control enable or disable radio. |
| 5969 | * {@hide} |
| 5970 | */ |
| 5971 | @Override |
| 5972 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 5973 | enforceModifyPermission(); |
| 5974 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5975 | |
| 5976 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5977 | if (phone == null) { |
| 5978 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 5979 | return; |
| 5980 | } |
| 5981 | try { |
| 5982 | phone.carrierActionSetRadioEnabled(enabled); |
| 5983 | } catch (Exception e) { |
| 5984 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5985 | } finally { |
| 5986 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5987 | } |
| 5988 | } |
| 5989 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5990 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5991 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 5992 | * network status based on which carrier apps could apply actions accordingly, |
| 5993 | * enable/disable default url handler for example. |
| 5994 | * |
| 5995 | * @param subId the subscription ID that this action applies to. |
| 5996 | * @param report control start/stop reporting the default network status. |
| 5997 | * {@hide} |
| 5998 | */ |
| 5999 | @Override |
| 6000 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 6001 | enforceModifyPermission(); |
| 6002 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6003 | |
| 6004 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6005 | if (phone == null) { |
| 6006 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 6007 | return; |
| 6008 | } |
| 6009 | try { |
| 6010 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 6011 | } catch (Exception e) { |
| 6012 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6013 | } finally { |
| 6014 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6015 | } |
| 6016 | } |
| 6017 | |
| 6018 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 6019 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 6020 | * @param subId the subscription ID that this action applies to. |
| 6021 | * {@hide} |
| 6022 | */ |
| 6023 | @Override |
| 6024 | public void carrierActionResetAll(int subId) { |
| 6025 | enforceModifyPermission(); |
| 6026 | final Phone phone = getPhone(subId); |
| 6027 | if (phone == null) { |
| 6028 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 6029 | return; |
| 6030 | } |
| 6031 | try { |
| 6032 | phone.carrierActionResetAll(); |
| 6033 | } catch (Exception e) { |
| 6034 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 6035 | } |
| 6036 | } |
| 6037 | |
| 6038 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6039 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 6040 | * bug report is being generated. |
| 6041 | */ |
| 6042 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 6043 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6044 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6045 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 6046 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 6047 | + Binder.getCallingPid() |
| 6048 | + ", uid=" + Binder.getCallingUid() |
| 6049 | + "without permission " |
| 6050 | + android.Manifest.permission.DUMP); |
| 6051 | return; |
| 6052 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6053 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6054 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6055 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6056 | @Override |
| 6057 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 6058 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 6059 | throws RemoteException { |
| 6060 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 6061 | } |
| 6062 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6063 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6064 | * Get aggregated video call data usage since boot. |
| 6065 | * |
| 6066 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6067 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6068 | * {@hide} |
| 6069 | */ |
| 6070 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6071 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6072 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 6073 | null); |
| 6074 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6075 | final long identity = Binder.clearCallingIdentity(); |
| 6076 | try { |
| 6077 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 6078 | // records the delta with the corresponding network identity. |
| 6079 | // We just return the total video call data usage snapshot since boot. |
| 6080 | Phone phone = getPhone(subId); |
| 6081 | if (phone != null) { |
| 6082 | return phone.getVtDataUsage(perUidStats); |
| 6083 | } |
| 6084 | return null; |
| 6085 | } finally { |
| 6086 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6087 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6088 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6089 | |
| 6090 | /** |
| 6091 | * Policy control of data connection. Usually used when data limit is passed. |
| 6092 | * @param enabled True if enabling the data, otherwise disabling. |
| 6093 | * @param subId Subscription index |
| 6094 | * {@hide} |
| 6095 | */ |
| 6096 | @Override |
| 6097 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6098 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6099 | |
| 6100 | final long identity = Binder.clearCallingIdentity(); |
| 6101 | try { |
| 6102 | Phone phone = getPhone(subId); |
| 6103 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6104 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6105 | } |
| 6106 | } finally { |
| 6107 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6108 | } |
| 6109 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6110 | |
| 6111 | /** |
| 6112 | * Get Client request stats |
| 6113 | * @return List of Client Request Stats |
| 6114 | * @hide |
| 6115 | */ |
| 6116 | @Override |
| 6117 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6118 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6119 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6120 | return null; |
| 6121 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6122 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6123 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6124 | final long identity = Binder.clearCallingIdentity(); |
| 6125 | try { |
| 6126 | if (phone != null) { |
| 6127 | return phone.getClientRequestStats(); |
| 6128 | } |
| 6129 | |
| 6130 | return null; |
| 6131 | } finally { |
| 6132 | Binder.restoreCallingIdentity(identity); |
| 6133 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6134 | } |
| 6135 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6136 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6137 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6138 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6139 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6140 | |
| 6141 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6142 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6143 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6144 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6145 | * @param state State of SIM (power down, power up, pass through) |
| 6146 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6147 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6148 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6149 | * |
| 6150 | **/ |
| 6151 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6152 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6153 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6154 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6155 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6156 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6157 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6158 | final long identity = Binder.clearCallingIdentity(); |
| 6159 | try { |
| 6160 | if (phone != null) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6161 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6162 | } |
| 6163 | } finally { |
| 6164 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6165 | } |
| 6166 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6167 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6168 | private boolean isUssdApiAllowed(int subId) { |
| 6169 | CarrierConfigManager configManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6170 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6171 | if (configManager == null) { |
| 6172 | return false; |
| 6173 | } |
| 6174 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6175 | if (pb == null) { |
| 6176 | return false; |
| 6177 | } |
| 6178 | return pb.getBoolean( |
| 6179 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6180 | } |
| 6181 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6182 | /** |
| 6183 | * Check if phone is in emergency callback mode |
| 6184 | * @return true if phone is in emergency callback mode |
| 6185 | * @param subId sub id |
| 6186 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6187 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6188 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6189 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6190 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6191 | |
| 6192 | final long identity = Binder.clearCallingIdentity(); |
| 6193 | try { |
| 6194 | if (phone != null) { |
| 6195 | return phone.isInEcm(); |
| 6196 | } else { |
| 6197 | return false; |
| 6198 | } |
| 6199 | } finally { |
| 6200 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6201 | } |
| 6202 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6203 | |
| 6204 | /** |
| 6205 | * Get the current signal strength information for the given subscription. |
| 6206 | * Because this information is not updated when the device is in a low power state |
| 6207 | * it should not be relied-upon to be current. |
| 6208 | * @param subId Subscription index |
| 6209 | * @return the most recent cached signal strength info from the modem |
| 6210 | */ |
| 6211 | @Override |
| 6212 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6213 | final long identity = Binder.clearCallingIdentity(); |
| 6214 | try { |
| 6215 | Phone p = getPhone(subId); |
| 6216 | if (p == null) { |
| 6217 | return null; |
| 6218 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6219 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6220 | return p.getSignalStrength(); |
| 6221 | } finally { |
| 6222 | Binder.restoreCallingIdentity(identity); |
| 6223 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6224 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6225 | |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6226 | /** |
chen xu | 907e5a2 | 2018-10-11 13:21:04 -0700 | [diff] [blame] | 6227 | * Get the current modem radio state for the given slot. |
| 6228 | * @param slotIndex slot index. |
| 6229 | * @param callingPackage the name of the package making the call. |
| 6230 | * @return the current radio power state from the modem |
| 6231 | */ |
| 6232 | @Override |
| 6233 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 6234 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6235 | if (phone != null) { |
| 6236 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6237 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 6238 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6239 | } |
| 6240 | |
| 6241 | final long identity = Binder.clearCallingIdentity(); |
| 6242 | try { |
| 6243 | return phone.getRadioPowerState(); |
| 6244 | } finally { |
| 6245 | Binder.restoreCallingIdentity(identity); |
| 6246 | } |
| 6247 | } |
| 6248 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6249 | } |
| 6250 | |
| 6251 | /** |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6252 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6253 | * |
| 6254 | * <p>Requires one of the following permissions: |
| 6255 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6256 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6257 | * privileges. |
| 6258 | * |
| 6259 | * @param subId subscription id |
| 6260 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6261 | * {@code false}. |
| 6262 | */ |
| 6263 | @Override |
| 6264 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6265 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6266 | null /* message */); |
| 6267 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6268 | boolean isEnabled = false; |
| 6269 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6270 | try { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6271 | Phone phone = getPhone(subId); |
| 6272 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6273 | } catch (Exception e) { |
| 6274 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6275 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6276 | } finally { |
| 6277 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6278 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6279 | return isEnabled; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6280 | } |
| 6281 | |
| 6282 | |
| 6283 | /** |
| 6284 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6285 | * |
| 6286 | * <p> Requires permission: |
| 6287 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6288 | * privileges. |
| 6289 | * |
| 6290 | * @param subId subscription id |
| 6291 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6292 | */ |
| 6293 | @Override |
| 6294 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6295 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6296 | mApp, subId, "setDataRoamingEnabled"); |
| 6297 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6298 | final long identity = Binder.clearCallingIdentity(); |
| 6299 | try { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6300 | Phone phone = getPhone(subId); |
| 6301 | if (phone != null) { |
| 6302 | phone.setDataRoamingEnabled(isEnabled); |
| 6303 | } |
| 6304 | } finally { |
| 6305 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6306 | } |
| 6307 | } |
| 6308 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6309 | @Override |
Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6310 | public boolean isManualNetworkSelectionAllowed(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6311 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6312 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6313 | |
Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6314 | boolean isAllowed = true; |
| 6315 | final long identity = Binder.clearCallingIdentity(); |
| 6316 | try { |
Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6317 | Phone phone = getPhone(subId); |
| 6318 | if (phone != null) { |
| 6319 | isAllowed = phone.isCspPlmnEnabled(); |
| 6320 | } |
| 6321 | } finally { |
| 6322 | Binder.restoreCallingIdentity(identity); |
| 6323 | } |
| 6324 | return isAllowed; |
| 6325 | } |
| 6326 | |
| 6327 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6328 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 6799795 | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6329 | boolean hasReadPermission = false; |
Jordan Liu | 53fdb78 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6330 | try { |
| 6331 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 6799795 | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6332 | hasReadPermission = true; |
Jordan Liu | 53fdb78 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6333 | } catch (SecurityException e) { |
| 6334 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6335 | // has carrier privileges on an active UICC |
| 6336 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6337 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 6799795 | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6338 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | 53fdb78 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6339 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6340 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6341 | |
| 6342 | final long identity = Binder.clearCallingIdentity(); |
| 6343 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6344 | UiccController uiccController = UiccController.getInstance(); |
| 6345 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 6799795 | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6346 | if (hasReadPermission) { |
| 6347 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6348 | } |
Jordan Liu | 6799795 | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6349 | |
| 6350 | // Remove private info if the caller doesn't have access |
| 6351 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6352 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6353 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 6354 | // is available |
| 6355 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 6356 | if (card == null || card.getUiccProfile() == null) { |
| 6357 | // assume no access if the card or profile is unavailable |
| 6358 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6359 | continue; |
| 6360 | } |
| 6361 | UiccProfile profile = card.getUiccProfile(); |
| 6362 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6363 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6364 | filteredInfos.add(cardInfo); |
| 6365 | } else { |
| 6366 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6367 | } |
| 6368 | } |
| 6369 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6370 | } finally { |
| 6371 | Binder.restoreCallingIdentity(identity); |
| 6372 | } |
| 6373 | } |
| 6374 | |
| 6375 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6376 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6377 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6378 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6379 | final long identity = Binder.clearCallingIdentity(); |
| 6380 | try { |
| 6381 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6382 | if (slots == null) { |
| 6383 | Rlog.i(LOG_TAG, "slots is null."); |
| 6384 | return null; |
| 6385 | } |
| 6386 | |
| 6387 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6388 | for (int i = 0; i < slots.length; i++) { |
| 6389 | UiccSlot slot = slots[i]; |
| 6390 | if (slot == null) { |
| 6391 | continue; |
| 6392 | } |
| 6393 | |
| 6394 | String cardId; |
| 6395 | UiccCard card = slot.getUiccCard(); |
| 6396 | if (card != null) { |
| 6397 | cardId = card.getCardId(); |
| 6398 | } else { |
| 6399 | cardId = slot.getIccId(); |
| 6400 | } |
| 6401 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 6402 | if (cardId != null) { |
| 6403 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 6404 | // if cardId is an EID, it's all digits so this is fine |
| 6405 | cardId = IccUtils.stripTrailingFs(cardId); |
| 6406 | } |
| 6407 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6408 | int cardState = 0; |
| 6409 | switch (slot.getCardState()) { |
| 6410 | case CARDSTATE_ABSENT: |
| 6411 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6412 | break; |
| 6413 | case CARDSTATE_PRESENT: |
| 6414 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6415 | break; |
| 6416 | case CARDSTATE_ERROR: |
| 6417 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6418 | break; |
| 6419 | case CARDSTATE_RESTRICTED: |
| 6420 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6421 | break; |
| 6422 | default: |
| 6423 | break; |
| 6424 | |
| 6425 | } |
| 6426 | |
| 6427 | infos[i] = new UiccSlotInfo( |
| 6428 | slot.isActive(), |
| 6429 | slot.isEuicc(), |
| 6430 | cardId, |
| 6431 | cardState, |
| 6432 | slot.getPhoneId(), |
Jordan Liu | ef65d87 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6433 | slot.isExtendedApduSupported(), |
| 6434 | slot.isRemovable()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6435 | } |
| 6436 | return infos; |
| 6437 | } finally { |
| 6438 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6439 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6440 | } |
| 6441 | |
| 6442 | @Override |
| 6443 | public boolean switchSlots(int[] physicalSlots) { |
| 6444 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6445 | |
| 6446 | final long identity = Binder.clearCallingIdentity(); |
| 6447 | try { |
| 6448 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6449 | } finally { |
| 6450 | Binder.restoreCallingIdentity(identity); |
| 6451 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6452 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6453 | |
| 6454 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6455 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6456 | final long identity = Binder.clearCallingIdentity(); |
| 6457 | try { |
| 6458 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6459 | } finally { |
| 6460 | Binder.restoreCallingIdentity(identity); |
| 6461 | } |
| 6462 | } |
| 6463 | |
| 6464 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6465 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6466 | enforceModifyPermission(); |
| 6467 | final Phone phone = getPhone(subId); |
| 6468 | if (phone == null) { |
| 6469 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6470 | return; |
| 6471 | } |
| 6472 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6473 | final long identity = Binder.clearCallingIdentity(); |
| 6474 | try { |
| 6475 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6476 | } finally { |
| 6477 | Binder.restoreCallingIdentity(identity); |
| 6478 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6479 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6480 | |
| 6481 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6482 | * A test API to reload the UICC profile. |
| 6483 | * |
| 6484 | * <p>Requires that the calling app has permission |
| 6485 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6486 | * @hide |
| 6487 | */ |
| 6488 | @Override |
| 6489 | public void refreshUiccProfile(int subId) { |
| 6490 | enforceModifyPermission(); |
| 6491 | |
| 6492 | final long identity = Binder.clearCallingIdentity(); |
| 6493 | try { |
| 6494 | Phone phone = getPhone(subId); |
| 6495 | if (phone == null) { |
| 6496 | return; |
| 6497 | } |
| 6498 | UiccCard uiccCard = phone.getUiccCard(); |
| 6499 | if (uiccCard == null) { |
| 6500 | return; |
| 6501 | } |
| 6502 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6503 | if (uiccProfile == null) { |
| 6504 | return; |
| 6505 | } |
| 6506 | uiccProfile.refresh(); |
| 6507 | } finally { |
| 6508 | Binder.restoreCallingIdentity(identity); |
| 6509 | } |
| 6510 | } |
| 6511 | |
| 6512 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6513 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6514 | */ |
| 6515 | private boolean getDefaultDataEnabled() { |
| 6516 | return "true".equalsIgnoreCase( |
| 6517 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6518 | } |
| 6519 | |
| 6520 | /** |
| 6521 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6522 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6523 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6524 | */ |
| 6525 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6526 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6527 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6528 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6529 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6530 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6531 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 6532 | return isDataRoamingEnabled; |
| 6533 | } |
| 6534 | |
| 6535 | /** |
| 6536 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 6537 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 6538 | */ |
| 6539 | private int getDefaultNetworkType(int subId) { |
| 6540 | return Integer.parseInt( |
| 6541 | TelephonyManager.getTelephonyProperty( |
| 6542 | mSubscriptionController.getPhoneId(subId), |
| 6543 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 6544 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 6545 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6546 | |
| 6547 | @Override |
| 6548 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
| 6549 | gid1, String gid2, String plmn, String spn) { |
| 6550 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6551 | |
| 6552 | final long identity = Binder.clearCallingIdentity(); |
| 6553 | try { |
| 6554 | final Phone phone = getPhone(subId); |
| 6555 | if (phone == null) { |
| 6556 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 6557 | return; |
| 6558 | } |
| 6559 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn); |
| 6560 | } finally { |
| 6561 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6562 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6563 | } |
| 6564 | |
| 6565 | @Override |
| 6566 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6567 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6568 | |
| 6569 | final long identity = Binder.clearCallingIdentity(); |
| 6570 | try { |
| 6571 | final Phone phone = getPhone(subId); |
| 6572 | if (phone == null) { |
| 6573 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 6574 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 6575 | } |
| 6576 | return phone.getCarrierIdListVersion(); |
| 6577 | } finally { |
| 6578 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6579 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6580 | } |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6581 | |
| 6582 | @Override |
| 6583 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 6584 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6585 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 6586 | return -1; |
| 6587 | } |
| 6588 | |
| 6589 | final long identity = Binder.clearCallingIdentity(); |
| 6590 | try { |
| 6591 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 6592 | } finally { |
| 6593 | Binder.restoreCallingIdentity(identity); |
| 6594 | } |
| 6595 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6596 | |
| 6597 | @Override |
| 6598 | public int getCdmaRoamingMode(int subId) { |
| 6599 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6600 | mApp, subId, "getCdmaRoamingMode"); |
| 6601 | |
| 6602 | final long identity = Binder.clearCallingIdentity(); |
| 6603 | try { |
| 6604 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 6605 | } finally { |
| 6606 | Binder.restoreCallingIdentity(identity); |
| 6607 | } |
| 6608 | } |
| 6609 | |
| 6610 | @Override |
| 6611 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 6612 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6613 | mApp, subId, "setCdmaRoamingMode"); |
| 6614 | |
| 6615 | final long identity = Binder.clearCallingIdentity(); |
| 6616 | try { |
| 6617 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 6618 | } finally { |
| 6619 | Binder.restoreCallingIdentity(identity); |
| 6620 | } |
| 6621 | } |
| 6622 | |
| 6623 | @Override |
| 6624 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 6625 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6626 | mApp, subId, "setCdmaSubscriptionMode"); |
| 6627 | |
| 6628 | final long identity = Binder.clearCallingIdentity(); |
| 6629 | try { |
| 6630 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 6631 | } finally { |
| 6632 | Binder.restoreCallingIdentity(identity); |
| 6633 | } |
| 6634 | } |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6635 | |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 6636 | private void ensureUserRunning(int userId) { |
| 6637 | if (!mUserManager.isUserRunning(userId)) { |
| 6638 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 6639 | } |
| 6640 | } |
| 6641 | |
| 6642 | /** |
| 6643 | * Returns a list of SMS apps on a given user. |
| 6644 | * |
| 6645 | * Only the shell user (UID 2000 or 0) can call it. |
| 6646 | * Target user must be running. |
| 6647 | */ |
| 6648 | @Override |
| 6649 | public String[] getSmsApps(int userId) { |
| 6650 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 6651 | ensureUserRunning(userId); |
| 6652 | |
| 6653 | final Collection<SmsApplicationData> apps = |
| 6654 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 6655 | |
| 6656 | String[] ret = new String[apps.size()]; |
| 6657 | int i = 0; |
| 6658 | for (SmsApplicationData app : apps) { |
| 6659 | ret[i++] = app.mPackageName; |
| 6660 | } |
| 6661 | return ret; |
| 6662 | } |
| 6663 | |
| 6664 | /** |
| 6665 | * Returns the default SMS app package name on a given user. |
| 6666 | * |
| 6667 | * Only the shell user (UID 2000 or 0) can call it. |
| 6668 | * Target user must be running. |
| 6669 | */ |
| 6670 | @Override |
| 6671 | public String getDefaultSmsApp(int userId) { |
| 6672 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 6673 | ensureUserRunning(userId); |
| 6674 | |
| 6675 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 6676 | /* updateIfNeeded= */ true, userId); |
| 6677 | return cn == null ? null : cn.getPackageName(); |
| 6678 | } |
| 6679 | |
| 6680 | /** |
| 6681 | * Set a package as the default SMS app on a given user. |
| 6682 | * |
| 6683 | * Only the shell user (UID 2000 or 0) can call it. |
| 6684 | * Target user must be running. |
| 6685 | */ |
| 6686 | @Override |
| 6687 | public void setDefaultSmsApp(int userId, String packageName) { |
| 6688 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6689 | ensureUserRunning(userId); |
| 6690 | |
| 6691 | boolean found = false; |
| 6692 | for (String pkg : getSmsApps(userId)) { |
| 6693 | if (TextUtils.equals(packageName, pkg)) { |
| 6694 | found = true; |
| 6695 | break; |
| 6696 | } |
| 6697 | } |
| 6698 | if (!found) { |
| 6699 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6700 | } |
| 6701 | |
| 6702 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6703 | } |
| 6704 | |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6705 | @Override |
sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6706 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6707 | String callingPackage) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6708 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6709 | mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6710 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6711 | } |
| 6712 | final long identity = Binder.clearCallingIdentity(); |
| 6713 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6714 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6715 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6716 | if (phone.getEmergencyNumberTracker() != null |
| 6717 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6718 | emergencyNumberListInternal.put( |
| 6719 | phone.getSubId(), |
| 6720 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6721 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6722 | } |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6723 | return emergencyNumberListInternal; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6724 | } finally { |
| 6725 | Binder.restoreCallingIdentity(identity); |
| 6726 | } |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6727 | } |
| 6728 | |
| 6729 | @Override |
sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6730 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6731 | final Phone defaultPhone = getDefaultPhone(); |
| 6732 | if (!exactMatch) { |
| 6733 | TelephonyPermissions |
| 6734 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6735 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6736 | } |
| 6737 | final long identity = Binder.clearCallingIdentity(); |
| 6738 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6739 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6740 | if (phone.getEmergencyNumberTracker() != null |
| 6741 | && phone.getEmergencyNumberTracker() != null) { |
| 6742 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 6743 | number, exactMatch)) { |
| 6744 | return true; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6745 | } |
| 6746 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6747 | } |
| 6748 | return false; |
| 6749 | } finally { |
| 6750 | Binder.restoreCallingIdentity(identity); |
| 6751 | } |
| 6752 | } |
| 6753 | |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6754 | /** |
| 6755 | * Update emergency number list for test mode. |
| 6756 | */ |
| 6757 | @Override |
| 6758 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 6759 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6760 | "updateEmergencyNumberListTestMode"); |
| 6761 | |
| 6762 | final long identity = Binder.clearCallingIdentity(); |
| 6763 | try { |
| 6764 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6765 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6766 | if (tracker != null) { |
| 6767 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 6768 | } |
| 6769 | } |
| 6770 | } finally { |
| 6771 | Binder.restoreCallingIdentity(identity); |
| 6772 | } |
| 6773 | } |
| 6774 | |
| 6775 | /** |
| 6776 | * Get the full emergency number list for test mode. |
| 6777 | */ |
| 6778 | @Override |
| 6779 | public List<String> getEmergencyNumberListTestMode() { |
| 6780 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6781 | "getEmergencyNumberListTestMode"); |
| 6782 | |
| 6783 | final long identity = Binder.clearCallingIdentity(); |
| 6784 | try { |
| 6785 | Set<String> emergencyNumbers = new HashSet<>(); |
| 6786 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6787 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6788 | if (tracker != null) { |
| 6789 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 6790 | emergencyNumbers.add(num.getNumber()); |
| 6791 | } |
| 6792 | } |
| 6793 | } |
| 6794 | return new ArrayList<>(emergencyNumbers); |
| 6795 | } finally { |
| 6796 | Binder.restoreCallingIdentity(identity); |
| 6797 | } |
| 6798 | } |
| 6799 | |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6800 | @Override |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6801 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6802 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6803 | Phone phone = getPhone(subId); |
| 6804 | if (phone == null) { |
| 6805 | return null; |
| 6806 | } |
| 6807 | final long identity = Binder.clearCallingIdentity(); |
| 6808 | try { |
| 6809 | UiccProfile profile = UiccController.getInstance() |
| 6810 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6811 | if (profile != null) { |
| 6812 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6813 | } |
| 6814 | } finally { |
| 6815 | Binder.restoreCallingIdentity(identity); |
| 6816 | } |
| 6817 | return null; |
| 6818 | } |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6819 | |
| 6820 | /** |
| 6821 | * Enable or disable a modem stack. |
| 6822 | */ |
| 6823 | @Override |
| 6824 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 6825 | enforceModifyPermission(); |
| 6826 | |
| 6827 | final long identity = Binder.clearCallingIdentity(); |
| 6828 | try { |
| 6829 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6830 | if (phone == null) { |
| 6831 | return false; |
| 6832 | } else { |
| 6833 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 6834 | } |
| 6835 | } finally { |
| 6836 | Binder.restoreCallingIdentity(identity); |
| 6837 | } |
| 6838 | } |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6839 | |
Malcolm Chen | 33f55e1 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 6840 | /** |
| 6841 | * Whether a modem stack is enabled or not. |
| 6842 | */ |
| 6843 | @Override |
| 6844 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) { |
| 6845 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6846 | if (phone == null) return false; |
| 6847 | |
| 6848 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6849 | mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) { |
| 6850 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6851 | } |
| 6852 | |
| 6853 | final long identity = Binder.clearCallingIdentity(); |
| 6854 | try { |
Nazanin Bakhshi | 1f78d7d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 6855 | try { |
| 6856 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 6857 | } catch (NoSuchElementException ex) { |
| 6858 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 6859 | } |
Malcolm Chen | 33f55e1 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 6860 | } finally { |
| 6861 | Binder.restoreCallingIdentity(identity); |
| 6862 | } |
| 6863 | } |
| 6864 | |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6865 | @Override |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6866 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6867 | enforceModifyPermission(); |
| 6868 | |
| 6869 | final long identity = Binder.clearCallingIdentity(); |
| 6870 | try { |
| 6871 | mTelephonySharedPreferences.edit() |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6872 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6873 | .commit(); |
| 6874 | } finally { |
| 6875 | Binder.restoreCallingIdentity(identity); |
| 6876 | } |
| 6877 | } |
| 6878 | |
| 6879 | @Override |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6880 | @TelephonyManager.IsMultiSimSupportedResult |
| 6881 | public int isMultiSimSupported(String callingPackage) { |
Michele | bcb01bc | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6882 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6883 | getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) { |
| 6884 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | bcb01bc | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6885 | } |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6886 | |
| 6887 | final long identity = Binder.clearCallingIdentity(); |
| 6888 | try { |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6889 | return isMultiSimSupportedInternal(); |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6890 | } finally { |
| 6891 | Binder.restoreCallingIdentity(identity); |
| 6892 | } |
| 6893 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6894 | |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6895 | @TelephonyManager.IsMultiSimSupportedResult |
| 6896 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6897 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 6898 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 6899 | if (numPhysicalSlots < 2) { |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6900 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 6901 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6902 | } |
| 6903 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 6904 | // supported by the modem, indicate that it is restricted. |
| 6905 | PhoneCapability staticCapability = |
| 6906 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 6907 | if (staticCapability == null) { |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6908 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 6909 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6910 | } |
| 6911 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6912 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 6913 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6914 | } |
| 6915 | // Check if support of multiple SIMs is restricted by carrier |
| 6916 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6917 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6918 | } |
| 6919 | |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6920 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6921 | } |
| 6922 | |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6923 | /** |
| 6924 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 814dc22 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6925 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 6926 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 6927 | * or carrier privileges |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6928 | * @param numOfSims number of active sims we want to switch to |
| 6929 | */ |
| 6930 | @Override |
| 6931 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 814dc22 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6932 | if (numOfSims == 1) { |
| 6933 | enforceModifyPermission(); |
| 6934 | } else { |
| 6935 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6936 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 6937 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6938 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6939 | |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6940 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6941 | //only proceed if multi-sim is not restricted |
Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6942 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6943 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 6944 | return; |
| 6945 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6946 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 6947 | } finally { |
| 6948 | Binder.restoreCallingIdentity(identity); |
| 6949 | } |
| 6950 | } |
| 6951 | |
| 6952 | /** |
Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6953 | * 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] | 6954 | * Return value defaults to true |
Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6955 | */ |
| 6956 | @Override |
| 6957 | public boolean isRebootRequiredForModemConfigChange() { |
| 6958 | enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange"); |
| 6959 | final long identity = Binder.clearCallingIdentity(); |
| 6960 | try { |
| 6961 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 6962 | } finally { |
| 6963 | Binder.restoreCallingIdentity(identity); |
| 6964 | } |
| 6965 | } |
| 6966 | |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 6967 | private void updateModemStateMetrics() { |
| 6968 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 6969 | // TODO: check the state for each modem if the api is ready. |
| 6970 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 6971 | } |
| 6972 | |
Pengquan Meng | 3aceaec | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 6973 | @Override |
| 6974 | public int[] getSlotsMapping() { |
| 6975 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 6976 | |
| 6977 | final long identity = Binder.clearCallingIdentity(); |
| 6978 | try { |
| 6979 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 6980 | // All logical slots should have a mapping to a physical slot. |
| 6981 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 6982 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 6983 | for (int i = 0; i < slotInfos.length; i++) { |
| 6984 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 6985 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 6986 | } |
| 6987 | } |
| 6988 | return logicalSlotsMapping; |
| 6989 | } finally { |
| 6990 | Binder.restoreCallingIdentity(identity); |
| 6991 | } |
| 6992 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 6993 | |
| 6994 | /** |
| 6995 | * Get the IRadio HAL Version |
| 6996 | */ |
| 6997 | @Override |
| 6998 | public int getRadioHalVersion() { |
| 6999 | Phone phone = getDefaultPhone(); |
| 7000 | if (phone == null) return -1; |
| 7001 | HalVersion hv = phone.getHalVersion(); |
| 7002 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 7003 | return hv.major * 100 + hv.minor; |
| 7004 | } |
Malcolm Chen | 460810d | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7005 | |
| 7006 | /** |
Malcolm Chen | 2973969 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7007 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 7008 | * corresponding network requests on a subId. |
| 7009 | * |
| 7010 | * Data is enabled if: |
Malcolm Chen | 460810d | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7011 | * 1) user data is turned on, or |
Malcolm Chen | 2973969 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7012 | * 2) APN is un-metered for this subscription, or |
| 7013 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
| 7014 | * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. |
| 7015 | * |
| 7016 | * @return whether data is allowed for a apn type. |
| 7017 | * |
| 7018 | * @hide |
Malcolm Chen | 460810d | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7019 | */ |
| 7020 | @Override |
Malcolm Chen | 2973969 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7021 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Malcolm Chen | 460810d | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7022 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Malcolm Chen | 2973969 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7023 | mApp, subId, callingPackage, "isDataEnabledForApn")) { |
| 7024 | throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn"); |
Malcolm Chen | 460810d | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7025 | } |
| 7026 | |
| 7027 | // Now that all security checks passes, perform the operation as ourselves. |
| 7028 | final long identity = Binder.clearCallingIdentity(); |
| 7029 | try { |
| 7030 | Phone phone = getPhone(subId); |
| 7031 | if (phone == null) return false; |
| 7032 | |
Jack Yu | 40306fc | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7033 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | 2973969 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7034 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 7035 | } finally { |
| 7036 | Binder.restoreCallingIdentity(identity); |
| 7037 | } |
| 7038 | } |
| 7039 | |
| 7040 | @Override |
Jack Yu | 40306fc | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7041 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | 2973969 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7042 | enforceReadPrivilegedPermission("isApnMetered"); |
| 7043 | |
| 7044 | // Now that all security checks passes, perform the operation as ourselves. |
| 7045 | final long identity = Binder.clearCallingIdentity(); |
| 7046 | try { |
| 7047 | Phone phone = getPhone(subId); |
| 7048 | if (phone == null) return true; // By default return true. |
| 7049 | |
Jack Yu | 40306fc | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7050 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | 460810d | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7051 | } finally { |
| 7052 | Binder.restoreCallingIdentity(identity); |
| 7053 | } |
| 7054 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 7055 | } |