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 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame^] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 22 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 23 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 24 | import android.Manifest.permission; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 25 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 26 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 27 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 28 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 29 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 30 | import android.content.Context; |
| 31 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 32 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 33 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 34 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 35 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 36 | import android.content.pm.PackageManager; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 37 | import android.net.NetworkStats; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.net.Uri; |
| 39 | import android.os.AsyncResult; |
| 40 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 41 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
| 43 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.Messenger; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 48 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 49 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 50 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 51 | import android.os.ServiceManager; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 52 | import android.os.ServiceSpecificException; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 53 | import android.os.ShellCallback; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 54 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 56 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 57 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 58 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 59 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 60 | import android.provider.Telephony; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 61 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 62 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 63 | import android.telecom.TelecomManager; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 64 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 65 | import android.telephony.CarrierRestrictionRules; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 66 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 67 | import android.telephony.CellInfoGsm; |
| 68 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 69 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 70 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 71 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 72 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 73 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 74 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 75 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 76 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 77 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 78 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 79 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 80 | import android.telephony.RadioAccessSpecifier; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 81 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 82 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 83 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 84 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 85 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 86 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 87 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 88 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 89 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 90 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 91 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 92 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 93 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 94 | import android.telephony.data.ApnSetting; |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 95 | import android.telephony.data.ApnSetting.ApnType; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 96 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 97 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 98 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 99 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 100 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 101 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 102 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 103 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 104 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 105 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 107 | import android.telephony.ims.feature.MmTelFeature; |
| 108 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 109 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 110 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 111 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 112 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 113 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 114 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 115 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 116 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 117 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 118 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 119 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 120 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 121 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 122 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 125 | import com.android.internal.telephony.HalVersion; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 127 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 129 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 131 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.ServiceStateTracker; |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.SmsApplication; |
| 144 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 147 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame^] | 153 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 154 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.uicc.IccIoResult; |
| 157 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 160 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 165 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 166 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 167 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 168 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 169 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 170 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 171 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 172 | import java.io.FileDescriptor; |
| 173 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 174 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 175 | import java.util.Arrays; |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 176 | import java.util.Collection; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 177 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 178 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 179 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 180 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 181 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 182 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 183 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 184 | |
| 185 | /** |
| 186 | * Implementation of the ITelephony interface. |
| 187 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 188 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 189 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 190 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 191 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 192 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 193 | |
| 194 | // Message codes used with mMainThreadHandler |
| 195 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 196 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 197 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 198 | private static final int CMD_OPEN_CHANNEL = 9; |
| 199 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 200 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 201 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 202 | private static final int CMD_NV_READ_ITEM = 13; |
| 203 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 204 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 205 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 206 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 207 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 208 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 209 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 210 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 211 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 212 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 213 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 214 | private static final int CMD_SEND_ENVELOPE = 25; |
| 215 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 216 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 217 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 218 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 219 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 220 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 221 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 222 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 223 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 224 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 225 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 226 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 227 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 228 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 229 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 230 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 231 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 232 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 233 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 234 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 235 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 236 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 237 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 238 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 239 | private static final int CMD_SWITCH_SLOTS = 50; |
| 240 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 241 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 242 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 243 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 244 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 245 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 246 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 247 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 248 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 249 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 250 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 251 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 252 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 253 | private static final int CMD_MODEM_REBOOT = 64; |
| 254 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 255 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 256 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 257 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 258 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 259 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 260 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 261 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 262 | // Parameters of select command. |
| 263 | private static final int SELECT_COMMAND = 0xA4; |
| 264 | private static final int SELECT_P1 = 0x04; |
| 265 | private static final int SELECT_P2 = 0; |
| 266 | private static final int SELECT_P3 = 0x10; |
| 267 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 268 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 269 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 270 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 271 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 272 | /** The singleton instance. */ |
| 273 | private static PhoneInterfaceManager sInstance; |
| 274 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 275 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 276 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 277 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 278 | private AppOpsManager mAppOps; |
| 279 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 280 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 281 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 282 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 283 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 284 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 285 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 286 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 287 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 288 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 289 | // String to store multi SIM allowed |
| 290 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 291 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 292 | // The AID of ISD-R. |
| 293 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 294 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 295 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 296 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 297 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 298 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 299 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 300 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 301 | * A request object to use for transmitting data to an ICC. |
| 302 | */ |
| 303 | private static final class IccAPDUArgument { |
| 304 | public int channel, cla, command, p1, p2, p3; |
| 305 | public String data; |
| 306 | |
| 307 | public IccAPDUArgument(int channel, int cla, int command, |
| 308 | int p1, int p2, int p3, String data) { |
| 309 | this.channel = channel; |
| 310 | this.cla = cla; |
| 311 | this.command = command; |
| 312 | this.p1 = p1; |
| 313 | this.p2 = p2; |
| 314 | this.p3 = p3; |
| 315 | this.data = data; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 320 | * A request object to use for transmitting data to an ICC. |
| 321 | */ |
| 322 | private static final class ManualNetworkSelectionArgument { |
| 323 | public OperatorInfo operatorInfo; |
| 324 | public boolean persistSelection; |
| 325 | |
| 326 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 327 | this.operatorInfo = operatorInfo; |
| 328 | this.persistSelection = persistSelection; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 333 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 334 | * request after sending. The main thread will notify the request when it is complete. |
| 335 | */ |
| 336 | private static final class MainThreadRequest { |
| 337 | /** The argument to use for the request */ |
| 338 | public Object argument; |
| 339 | /** The result of the request that is run on the main thread */ |
| 340 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 341 | // The subscriber id that this request applies to. Defaults to |
| 342 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 343 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 344 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 345 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 346 | public Phone phone; |
| 347 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 348 | public WorkSource workSource; |
| 349 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 350 | public MainThreadRequest(Object argument) { |
| 351 | this.argument = argument; |
| 352 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 353 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 354 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 355 | this.argument = argument; |
| 356 | if (phone != null) { |
| 357 | this.phone = phone; |
| 358 | } |
| 359 | this.workSource = workSource; |
| 360 | } |
| 361 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 362 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 363 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 364 | if (subId != null) { |
| 365 | this.subId = subId; |
| 366 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 367 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 368 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 371 | private static final class IncomingThirdPartyCallArgs { |
| 372 | public final ComponentName component; |
| 373 | public final String callId; |
| 374 | public final String callerDisplayName; |
| 375 | |
| 376 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 377 | String callerDisplayName) { |
| 378 | this.component = component; |
| 379 | this.callId = callId; |
| 380 | this.callerDisplayName = callerDisplayName; |
| 381 | } |
| 382 | } |
| 383 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 384 | /** |
| 385 | * A handler that processes messages on the main thread in the phone process. Since many |
| 386 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 387 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 388 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 389 | * on, which will be notified when the operation completes and will contain the result of the |
| 390 | * request. |
| 391 | * |
| 392 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 393 | * note that request.result must be set to something non-null for the calling thread to |
| 394 | * unblock. |
| 395 | */ |
| 396 | private final class MainThreadHandler extends Handler { |
| 397 | @Override |
| 398 | public void handleMessage(Message msg) { |
| 399 | MainThreadRequest request; |
| 400 | Message onCompleted; |
| 401 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 402 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 403 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 404 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 405 | |
| 406 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 407 | case CMD_HANDLE_USSD_REQUEST: { |
| 408 | request = (MainThreadRequest) msg.obj; |
| 409 | final Phone phone = getPhoneFromRequest(request); |
| 410 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 411 | String ussdRequest = ussdObject.first; |
| 412 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 413 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 414 | if (!isUssdApiAllowed(request.subId)) { |
| 415 | // Carrier does not support use of this API, return failure. |
| 416 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 417 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 418 | Bundle returnData = new Bundle(); |
| 419 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 420 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 421 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 422 | request.result = true; |
| 423 | notifyRequester(request); |
| 424 | return; |
| 425 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 426 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 427 | try { |
| 428 | request.result = phone != null |
| 429 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 430 | } catch (CallStateException cse) { |
| 431 | request.result = false; |
| 432 | } |
| 433 | // Wake up the requesting thread |
| 434 | notifyRequester(request); |
| 435 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 438 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 439 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 440 | final Phone phone = getPhoneFromRequest(request); |
| 441 | request.result = phone != null ? |
| 442 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 443 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 444 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 445 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 446 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 447 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 448 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 449 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 450 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 451 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 452 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 453 | if (uiccCard == null) { |
| 454 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 455 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 456 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 457 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 458 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 459 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 460 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 461 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 462 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 463 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 464 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 465 | break; |
| 466 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 467 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 468 | ar = (AsyncResult) msg.obj; |
| 469 | request = (MainThreadRequest) ar.userObj; |
| 470 | if (ar.exception == null && ar.result != null) { |
| 471 | request.result = ar.result; |
| 472 | } else { |
| 473 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 474 | if (ar.result == null) { |
| 475 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 476 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 477 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 478 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 479 | } else { |
| 480 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 481 | } |
| 482 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 483 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 484 | break; |
| 485 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 486 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 487 | request = (MainThreadRequest) msg.obj; |
| 488 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 489 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 490 | if (uiccCard == null) { |
| 491 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 492 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 493 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 494 | } else { |
| 495 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 496 | request); |
| 497 | uiccCard.iccTransmitApduBasicChannel( |
| 498 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 499 | iccArgument.p3, iccArgument.data, onCompleted); |
| 500 | } |
| 501 | break; |
| 502 | |
| 503 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 504 | ar = (AsyncResult) msg.obj; |
| 505 | request = (MainThreadRequest) ar.userObj; |
| 506 | if (ar.exception == null && ar.result != null) { |
| 507 | request.result = ar.result; |
| 508 | } else { |
| 509 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 510 | if (ar.result == null) { |
| 511 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 512 | } else if (ar.exception instanceof CommandException) { |
| 513 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 514 | ar.exception); |
| 515 | } else { |
| 516 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 517 | } |
| 518 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 519 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 520 | break; |
| 521 | |
| 522 | case CMD_EXCHANGE_SIM_IO: |
| 523 | request = (MainThreadRequest) msg.obj; |
| 524 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 525 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 526 | if (uiccCard == null) { |
| 527 | loge("iccExchangeSimIO: No UICC"); |
| 528 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 529 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 530 | } else { |
| 531 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 532 | request); |
| 533 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 534 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 535 | iccArgument.data, onCompleted); |
| 536 | } |
| 537 | break; |
| 538 | |
| 539 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 540 | ar = (AsyncResult) msg.obj; |
| 541 | request = (MainThreadRequest) ar.userObj; |
| 542 | if (ar.exception == null && ar.result != null) { |
| 543 | request.result = ar.result; |
| 544 | } else { |
| 545 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 546 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 547 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 548 | break; |
| 549 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 550 | case CMD_SEND_ENVELOPE: |
| 551 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 552 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 553 | if (uiccCard == null) { |
| 554 | loge("sendEnvelopeWithStatus: No UICC"); |
| 555 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 556 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 557 | } else { |
| 558 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 559 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 560 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 561 | break; |
| 562 | |
| 563 | case EVENT_SEND_ENVELOPE_DONE: |
| 564 | ar = (AsyncResult) msg.obj; |
| 565 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 566 | if (ar.exception == null && ar.result != null) { |
| 567 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 568 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 569 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 570 | if (ar.result == null) { |
| 571 | loge("sendEnvelopeWithStatus: Empty response"); |
| 572 | } else if (ar.exception instanceof CommandException) { |
| 573 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 574 | ar.exception); |
| 575 | } else { |
| 576 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 577 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 578 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 579 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 580 | break; |
| 581 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 582 | case CMD_OPEN_CHANNEL: |
| 583 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 584 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 585 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 586 | if (uiccCard == null) { |
| 587 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 588 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 589 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 590 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 591 | } else { |
| 592 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 593 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 594 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 595 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 596 | break; |
| 597 | |
| 598 | case EVENT_OPEN_CHANNEL_DONE: |
| 599 | ar = (AsyncResult) msg.obj; |
| 600 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 601 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 602 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 603 | int[] result = (int[]) ar.result; |
| 604 | int channelId = result[0]; |
| 605 | byte[] selectResponse = null; |
| 606 | if (result.length > 1) { |
| 607 | selectResponse = new byte[result.length - 1]; |
| 608 | for (int i = 1; i < result.length; ++i) { |
| 609 | selectResponse[i - 1] = (byte) result[i]; |
| 610 | } |
| 611 | } |
| 612 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 613 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 614 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 615 | if (ar.result == null) { |
| 616 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 617 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 618 | if (ar.exception != null) { |
| 619 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 620 | } |
| 621 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 622 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 623 | if (ar.exception instanceof CommandException) { |
| 624 | CommandException.Error error = |
| 625 | ((CommandException) (ar.exception)).getCommandError(); |
| 626 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 627 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 628 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 629 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 630 | } |
| 631 | } |
| 632 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 633 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 634 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 635 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 636 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 637 | break; |
| 638 | |
| 639 | case CMD_CLOSE_CHANNEL: |
| 640 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 641 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 642 | if (uiccCard == null) { |
| 643 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 644 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 645 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 646 | } else { |
| 647 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 648 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 649 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 650 | break; |
| 651 | |
| 652 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 653 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 654 | break; |
| 655 | |
| 656 | case CMD_NV_READ_ITEM: |
| 657 | request = (MainThreadRequest) msg.obj; |
| 658 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 659 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 660 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 661 | break; |
| 662 | |
| 663 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 664 | ar = (AsyncResult) msg.obj; |
| 665 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 666 | if (ar.exception == null && ar.result != null) { |
| 667 | request.result = ar.result; // String |
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 | request.result = ""; |
| 670 | if (ar.result == null) { |
| 671 | loge("nvReadItem: Empty response"); |
| 672 | } else if (ar.exception instanceof CommandException) { |
| 673 | loge("nvReadItem: CommandException: " + |
| 674 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 675 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 676 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 677 | } |
| 678 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 679 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 680 | break; |
| 681 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 682 | case CMD_NV_WRITE_ITEM: |
| 683 | request = (MainThreadRequest) msg.obj; |
| 684 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 685 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 686 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 687 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 688 | break; |
| 689 | |
| 690 | case EVENT_NV_WRITE_ITEM_DONE: |
| 691 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 692 | break; |
| 693 | |
| 694 | case CMD_NV_WRITE_CDMA_PRL: |
| 695 | request = (MainThreadRequest) msg.obj; |
| 696 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 697 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 698 | break; |
| 699 | |
| 700 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 701 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 702 | break; |
| 703 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 704 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 705 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 706 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 707 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 708 | break; |
| 709 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 710 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 711 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 712 | break; |
| 713 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 714 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 715 | request = (MainThreadRequest) msg.obj; |
| 716 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 717 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 718 | break; |
| 719 | |
| 720 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 721 | ar = (AsyncResult) msg.obj; |
| 722 | request = (MainThreadRequest) ar.userObj; |
| 723 | if (ar.exception == null && ar.result != null) { |
| 724 | request.result = ar.result; // Integer |
| 725 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 726 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 727 | if (ar.result == null) { |
| 728 | loge("getPreferredNetworkType: Empty response"); |
| 729 | } else if (ar.exception instanceof CommandException) { |
| 730 | loge("getPreferredNetworkType: CommandException: " + |
| 731 | ar.exception); |
| 732 | } else { |
| 733 | loge("getPreferredNetworkType: Unknown exception"); |
| 734 | } |
| 735 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 736 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 737 | break; |
| 738 | |
| 739 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 740 | request = (MainThreadRequest) msg.obj; |
| 741 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 742 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 743 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 744 | break; |
| 745 | |
| 746 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 747 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 748 | break; |
| 749 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 750 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 751 | request = (MainThreadRequest)msg.obj; |
| 752 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 753 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 754 | break; |
| 755 | |
| 756 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 757 | ar = (AsyncResult)msg.obj; |
| 758 | request = (MainThreadRequest)ar.userObj; |
| 759 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 760 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 761 | break; |
| 762 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 763 | case CMD_SET_VOICEMAIL_NUMBER: |
| 764 | request = (MainThreadRequest) msg.obj; |
| 765 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 766 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 767 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 768 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 769 | break; |
| 770 | |
| 771 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 772 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 773 | break; |
| 774 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 775 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 776 | request = (MainThreadRequest) msg.obj; |
| 777 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 778 | request); |
| 779 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 780 | break; |
| 781 | |
| 782 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 783 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 784 | break; |
| 785 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 786 | case CMD_PERFORM_NETWORK_SCAN: |
| 787 | request = (MainThreadRequest) msg.obj; |
| 788 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 789 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 790 | break; |
| 791 | |
| 792 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 793 | ar = (AsyncResult) msg.obj; |
| 794 | request = (MainThreadRequest) ar.userObj; |
| 795 | CellNetworkScanResult cellScanResult; |
| 796 | if (ar.exception == null && ar.result != null) { |
| 797 | cellScanResult = new CellNetworkScanResult( |
| 798 | CellNetworkScanResult.STATUS_SUCCESS, |
| 799 | (List<OperatorInfo>) ar.result); |
| 800 | } else { |
| 801 | if (ar.result == null) { |
| 802 | loge("getCellNetworkScanResults: Empty response"); |
| 803 | } |
| 804 | if (ar.exception != null) { |
| 805 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 806 | } |
| 807 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 808 | if (ar.exception instanceof CommandException) { |
| 809 | CommandException.Error error = |
| 810 | ((CommandException) (ar.exception)).getCommandError(); |
| 811 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 812 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 813 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 814 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 815 | } |
| 816 | } |
| 817 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 818 | } |
| 819 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 820 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 821 | break; |
| 822 | |
| 823 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 824 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 825 | ManualNetworkSelectionArgument selArg = |
| 826 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 827 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 828 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 829 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 830 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 831 | break; |
| 832 | |
| 833 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 834 | ar = (AsyncResult) msg.obj; |
| 835 | request = (MainThreadRequest) ar.userObj; |
| 836 | if (ar.exception == null) { |
| 837 | request.result = true; |
| 838 | } else { |
| 839 | request.result = false; |
| 840 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 841 | } |
| 842 | notifyRequester(request); |
| 843 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 844 | break; |
| 845 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 846 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 847 | request = (MainThreadRequest) msg.obj; |
| 848 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 849 | if (defaultPhone != null) { |
| 850 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 851 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 852 | break; |
| 853 | |
| 854 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 855 | ar = (AsyncResult) msg.obj; |
| 856 | request = (MainThreadRequest) ar.userObj; |
| 857 | if (ar.exception == null && ar.result != null) { |
| 858 | request.result = ar.result; |
| 859 | } else { |
| 860 | if (ar.result == null) { |
| 861 | loge("queryModemActivityInfo: Empty response"); |
| 862 | } else if (ar.exception instanceof CommandException) { |
| 863 | loge("queryModemActivityInfo: CommandException: " + |
| 864 | ar.exception); |
| 865 | } else { |
| 866 | loge("queryModemActivityInfo: Unknown exception"); |
| 867 | } |
| 868 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 869 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 870 | if (request.result == null) { |
| 871 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 872 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 873 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 874 | break; |
| 875 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 876 | case CMD_SET_ALLOWED_CARRIERS: |
| 877 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 878 | CarrierRestrictionRules argument = |
| 879 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 880 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 881 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 882 | break; |
| 883 | |
| 884 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 885 | ar = (AsyncResult) msg.obj; |
| 886 | request = (MainThreadRequest) ar.userObj; |
| 887 | if (ar.exception == null && ar.result != null) { |
| 888 | request.result = ar.result; |
| 889 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 890 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 891 | if (ar.exception instanceof CommandException) { |
| 892 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 893 | CommandException.Error error = |
| 894 | ((CommandException) (ar.exception)).getCommandError(); |
| 895 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 896 | request.result = |
| 897 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 898 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 899 | } else { |
| 900 | loge("setAllowedCarriers: Unknown exception"); |
| 901 | } |
| 902 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 903 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 904 | break; |
| 905 | |
| 906 | case CMD_GET_ALLOWED_CARRIERS: |
| 907 | request = (MainThreadRequest) msg.obj; |
| 908 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 909 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 910 | break; |
| 911 | |
| 912 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 913 | ar = (AsyncResult) msg.obj; |
| 914 | request = (MainThreadRequest) ar.userObj; |
| 915 | if (ar.exception == null && ar.result != null) { |
| 916 | request.result = ar.result; |
| 917 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 918 | request.result = new IllegalStateException( |
| 919 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 920 | if (ar.result == null) { |
| 921 | loge("getAllowedCarriers: Empty response"); |
| 922 | } else if (ar.exception instanceof CommandException) { |
| 923 | loge("getAllowedCarriers: CommandException: " + |
| 924 | ar.exception); |
| 925 | } else { |
| 926 | loge("getAllowedCarriers: Unknown exception"); |
| 927 | } |
| 928 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 929 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 930 | break; |
| 931 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 932 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 933 | ar = (AsyncResult) msg.obj; |
| 934 | request = (MainThreadRequest) ar.userObj; |
| 935 | if (ar.exception == null && ar.result != null) { |
| 936 | request.result = ar.result; |
| 937 | } else { |
| 938 | request.result = new IllegalArgumentException( |
| 939 | "Failed to retrieve Forbidden Plmns"); |
| 940 | if (ar.result == null) { |
| 941 | loge("getForbiddenPlmns: Empty response"); |
| 942 | } else { |
| 943 | loge("getForbiddenPlmns: Unknown exception"); |
| 944 | } |
| 945 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 946 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 947 | break; |
| 948 | |
| 949 | case CMD_GET_FORBIDDEN_PLMNS: |
| 950 | request = (MainThreadRequest) msg.obj; |
| 951 | uiccCard = getUiccCardFromRequest(request); |
| 952 | if (uiccCard == null) { |
| 953 | loge("getForbiddenPlmns() UiccCard is null"); |
| 954 | request.result = new IllegalArgumentException( |
| 955 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 956 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 957 | break; |
| 958 | } |
| 959 | Integer appType = (Integer) request.argument; |
| 960 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 961 | if (uiccApp == null) { |
| 962 | loge("getForbiddenPlmns() no app with specified type -- " |
| 963 | + appType); |
| 964 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 965 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 966 | break; |
| 967 | } else { |
| 968 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 969 | + " specified type -- " + appType); |
| 970 | } |
| 971 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 972 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 973 | onCompleted); |
| 974 | break; |
| 975 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 976 | case CMD_SWITCH_SLOTS: |
| 977 | request = (MainThreadRequest) msg.obj; |
| 978 | int[] physicalSlots = (int[]) request.argument; |
| 979 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 980 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 981 | break; |
| 982 | |
| 983 | case EVENT_SWITCH_SLOTS_DONE: |
| 984 | ar = (AsyncResult) msg.obj; |
| 985 | request = (MainThreadRequest) ar.userObj; |
| 986 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 987 | notifyRequester(request); |
| 988 | break; |
| 989 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 990 | request = (MainThreadRequest) msg.obj; |
| 991 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 992 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 993 | break; |
| 994 | |
| 995 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 996 | ar = (AsyncResult) msg.obj; |
| 997 | request = (MainThreadRequest) ar.userObj; |
| 998 | if (ar.exception != null) { |
| 999 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1000 | } else { |
| 1001 | int mode = ((int[]) ar.result)[0]; |
| 1002 | if (mode == 0) { |
| 1003 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1004 | } else { |
| 1005 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1006 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1007 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1008 | notifyRequester(request); |
| 1009 | break; |
| 1010 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1011 | request = (MainThreadRequest) msg.obj; |
| 1012 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1013 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1014 | break; |
| 1015 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1016 | ar = (AsyncResult) msg.obj; |
| 1017 | request = (MainThreadRequest) ar.userObj; |
| 1018 | if (ar.exception != null) { |
| 1019 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1020 | } else { |
| 1021 | request.result = ((int[]) ar.result)[0]; |
| 1022 | } |
| 1023 | notifyRequester(request); |
| 1024 | break; |
| 1025 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1026 | request = (MainThreadRequest) msg.obj; |
| 1027 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1028 | int mode = (int) request.argument; |
| 1029 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1030 | break; |
| 1031 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1032 | ar = (AsyncResult) msg.obj; |
| 1033 | request = (MainThreadRequest) ar.userObj; |
| 1034 | request.result = ar.exception == null; |
| 1035 | notifyRequester(request); |
| 1036 | break; |
| 1037 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1038 | request = (MainThreadRequest) msg.obj; |
| 1039 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1040 | int subscriptionMode = (int) request.argument; |
| 1041 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1042 | break; |
| 1043 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1044 | ar = (AsyncResult) msg.obj; |
| 1045 | request = (MainThreadRequest) ar.userObj; |
| 1046 | request.result = ar.exception == null; |
| 1047 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1048 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1049 | case CMD_GET_ALL_CELL_INFO: |
| 1050 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1051 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1052 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1053 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1054 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1055 | ar = (AsyncResult) msg.obj; |
| 1056 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1057 | // If a timeout occurs, the response will be null |
| 1058 | request.result = (ar.exception == null && ar.result != null) |
| 1059 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1060 | synchronized (request) { |
| 1061 | request.notifyAll(); |
| 1062 | } |
| 1063 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1064 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1065 | request = (MainThreadRequest) msg.obj; |
| 1066 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1067 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1068 | break; |
| 1069 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1070 | ar = (AsyncResult) msg.obj; |
| 1071 | request = (MainThreadRequest) ar.userObj; |
| 1072 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1073 | try { |
| 1074 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1075 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1076 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1077 | new android.os.ParcelableException(ar.exception)); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1078 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1079 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1080 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1081 | } else { |
| 1082 | // use the result as returned |
| 1083 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1084 | } |
| 1085 | } catch (RemoteException re) { |
| 1086 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1087 | } |
| 1088 | break; |
| 1089 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1090 | request = (MainThreadRequest) msg.obj; |
| 1091 | WorkSource ws = (WorkSource) request.argument; |
| 1092 | Phone phone = getPhoneFromRequest(request); |
| 1093 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1094 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1095 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1096 | ar = (AsyncResult) msg.obj; |
| 1097 | request = (MainThreadRequest) ar.userObj; |
| 1098 | if (ar.exception == null) { |
| 1099 | request.result = ar.result; |
| 1100 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1101 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1102 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1103 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1104 | } |
| 1105 | |
| 1106 | synchronized (request) { |
| 1107 | request.notifyAll(); |
| 1108 | } |
| 1109 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1110 | case CMD_MODEM_REBOOT: |
| 1111 | request = (MainThreadRequest) msg.obj; |
| 1112 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1113 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1114 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1115 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1116 | handleNullReturnEvent(msg, "rebootModem"); |
| 1117 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1118 | case CMD_REQUEST_ENABLE_MODEM: |
| 1119 | request = (MainThreadRequest) msg.obj; |
| 1120 | boolean enable = (boolean) request.argument; |
| 1121 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1122 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1123 | PhoneConfigurationManager.getInstance() |
| 1124 | .enablePhone(request.phone, enable, onCompleted); |
| 1125 | break; |
| 1126 | case EVENT_ENABLE_MODEM_DONE: |
| 1127 | ar = (AsyncResult) msg.obj; |
| 1128 | request = (MainThreadRequest) ar.userObj; |
| 1129 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1130 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1131 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1132 | if ((boolean) request.result) { |
| 1133 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1134 | updateModemStateMetrics(); |
| 1135 | } else { |
| 1136 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1137 | + ar.exception); |
| 1138 | } |
| 1139 | notifyRequester(request); |
| 1140 | break; |
| 1141 | case CMD_GET_MODEM_STATUS: |
| 1142 | request = (MainThreadRequest) msg.obj; |
| 1143 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1144 | PhoneConfigurationManager.getInstance() |
| 1145 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1146 | break; |
| 1147 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1148 | ar = (AsyncResult) msg.obj; |
| 1149 | request = (MainThreadRequest) ar.userObj; |
| 1150 | int id = request.phone.getPhoneId(); |
| 1151 | if (ar.exception == null && ar.result != null) { |
| 1152 | request.result = ar.result; |
| 1153 | //update the cache as modem status has changed |
| 1154 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1155 | (boolean) request.result); |
| 1156 | } else { |
| 1157 | // Return true if modem status cannot be retrieved. For most cases, |
| 1158 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1159 | // and disable modem are not supported. Modem is always on. |
| 1160 | // TODO: this should be fixed in R to support a third |
| 1161 | // status UNKNOWN b/131631629 |
| 1162 | request.result = true; |
| 1163 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1164 | + ar.exception); |
| 1165 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1166 | notifyRequester(request); |
| 1167 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1168 | default: |
| 1169 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1170 | break; |
| 1171 | } |
| 1172 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1173 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1174 | private void notifyRequester(MainThreadRequest request) { |
| 1175 | synchronized (request) { |
| 1176 | request.notifyAll(); |
| 1177 | } |
| 1178 | } |
| 1179 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1180 | private void handleNullReturnEvent(Message msg, String command) { |
| 1181 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1182 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1183 | if (ar.exception == null) { |
| 1184 | request.result = true; |
| 1185 | } else { |
| 1186 | request.result = false; |
| 1187 | if (ar.exception instanceof CommandException) { |
| 1188 | loge(command + ": CommandException: " + ar.exception); |
| 1189 | } else { |
| 1190 | loge(command + ": Unknown exception"); |
| 1191 | } |
| 1192 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1193 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1194 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | /** |
| 1198 | * Posts the specified command to be executed on the main thread, |
| 1199 | * waits for the request to complete, and returns the result. |
| 1200 | * @see #sendRequestAsync |
| 1201 | */ |
| 1202 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1203 | return sendRequest( |
| 1204 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | /** |
| 1208 | * Posts the specified command to be executed on the main thread, |
| 1209 | * waits for the request to complete, and returns the result. |
| 1210 | * @see #sendRequestAsync |
| 1211 | */ |
| 1212 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1213 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1214 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | /** |
| 1218 | * Posts the specified command to be executed on the main thread, |
| 1219 | * waits for the request to complete, and returns the result. |
| 1220 | * @see #sendRequestAsync |
| 1221 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1222 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1223 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | /** |
| 1227 | * Posts the specified command to be executed on the main thread, |
| 1228 | * waits for the request to complete, and returns the result. |
| 1229 | * @see #sendRequestAsync |
| 1230 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1231 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1232 | return sendRequest(command, argument, subId, null, workSource); |
| 1233 | } |
| 1234 | |
| 1235 | /** |
| 1236 | * Posts the specified command to be executed on the main thread, |
| 1237 | * waits for the request to complete, and returns the result. |
| 1238 | * @see #sendRequestAsync |
| 1239 | */ |
| 1240 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1241 | return sendRequest( |
| 1242 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1243 | } |
| 1244 | |
| 1245 | /** |
| 1246 | * Posts the specified command to be executed on the main thread, |
| 1247 | * waits for the request to complete, and returns the result. |
| 1248 | * @see #sendRequestAsync |
| 1249 | */ |
| 1250 | private Object sendRequest( |
| 1251 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1252 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1253 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1254 | } |
| 1255 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1256 | MainThreadRequest request = null; |
| 1257 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1258 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1259 | } else if (phone != null) { |
| 1260 | request = new MainThreadRequest(argument, phone, workSource); |
| 1261 | } else { |
| 1262 | request = new MainThreadRequest(argument, subId, workSource); |
| 1263 | } |
| 1264 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1265 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1266 | msg.sendToTarget(); |
| 1267 | |
| 1268 | // Wait for the request to complete |
| 1269 | synchronized (request) { |
| 1270 | while (request.result == null) { |
| 1271 | try { |
| 1272 | request.wait(); |
| 1273 | } catch (InterruptedException e) { |
| 1274 | // Do nothing, go back and wait until the request is complete |
| 1275 | } |
| 1276 | } |
| 1277 | } |
| 1278 | return request.result; |
| 1279 | } |
| 1280 | |
| 1281 | /** |
| 1282 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1283 | * Posts the specified command to be executed on the main thread, and |
| 1284 | * returns immediately. |
| 1285 | * @see #sendRequest |
| 1286 | */ |
| 1287 | private void sendRequestAsync(int command) { |
| 1288 | mMainThreadHandler.sendEmptyMessage(command); |
| 1289 | } |
| 1290 | |
| 1291 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1292 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1293 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1294 | */ |
| 1295 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1296 | sendRequestAsync(command, argument, null, null); |
| 1297 | } |
| 1298 | |
| 1299 | /** |
| 1300 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1301 | * @see {@link #sendRequest(int,Object)} |
| 1302 | */ |
| 1303 | private void sendRequestAsync( |
| 1304 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1305 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1306 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1307 | msg.sendToTarget(); |
| 1308 | } |
| 1309 | |
| 1310 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1311 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1312 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1313 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1314 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1315 | synchronized (PhoneInterfaceManager.class) { |
| 1316 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1317 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1318 | } else { |
| 1319 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1320 | } |
| 1321 | return sInstance; |
| 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1326 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1327 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1328 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1329 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1330 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1331 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1332 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1333 | mTelephonySharedPreferences = |
| 1334 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1335 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1336 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1337 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1338 | publish(); |
| 1339 | } |
| 1340 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1341 | private Phone getDefaultPhone() { |
| 1342 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1343 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1344 | } |
| 1345 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1346 | private void publish() { |
| 1347 | if (DBG) log("publish: " + this); |
| 1348 | |
| 1349 | ServiceManager.addService("phone", this); |
| 1350 | } |
| 1351 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1352 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1353 | if (request.phone != null) { |
| 1354 | return request.phone; |
| 1355 | } else { |
| 1356 | return getPhoneFromSubId(request.subId); |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | private Phone getPhoneFromSubId(int subId) { |
| 1361 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1362 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1363 | } |
| 1364 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1365 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1366 | Phone phone = getPhoneFromRequest(request); |
| 1367 | return phone == null ? null : |
| 1368 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1369 | } |
| 1370 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1371 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1372 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1373 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1374 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1375 | |
| 1376 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1377 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1378 | } |
| 1379 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1380 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1381 | if (DBG) log("dial: " + number); |
| 1382 | // No permission check needed here: This is just a wrapper around the |
| 1383 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1384 | // the UI before it does anything. |
| 1385 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1386 | final long identity = Binder.clearCallingIdentity(); |
| 1387 | try { |
| 1388 | String url = createTelUrl(number); |
| 1389 | if (url == null) { |
| 1390 | return; |
| 1391 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1392 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1393 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1394 | PhoneConstants.State state = mCM.getState(subId); |
| 1395 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1396 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1397 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1398 | mApp.startActivity(intent); |
| 1399 | } |
| 1400 | } finally { |
| 1401 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1402 | } |
| 1403 | } |
| 1404 | |
| 1405 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1406 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1409 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1410 | if (DBG) log("call: " + number); |
| 1411 | |
| 1412 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1413 | // need to do a permission check since we're calling startActivity() |
| 1414 | // from the context of the phone app. |
| 1415 | enforceCallPermission(); |
| 1416 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1417 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1418 | != AppOpsManager.MODE_ALLOWED) { |
| 1419 | return; |
| 1420 | } |
| 1421 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1422 | final long identity = Binder.clearCallingIdentity(); |
| 1423 | try { |
| 1424 | String url = createTelUrl(number); |
| 1425 | if (url == null) { |
| 1426 | return; |
| 1427 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1428 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1429 | boolean isValid = false; |
| 1430 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1431 | if (slist != null) { |
| 1432 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1433 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1434 | isValid = true; |
| 1435 | break; |
| 1436 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1437 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1438 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1439 | if (!isValid) { |
| 1440 | return; |
| 1441 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1442 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1443 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1444 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1445 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1446 | mApp.startActivity(intent); |
| 1447 | } finally { |
| 1448 | Binder.restoreCallingIdentity(identity); |
| 1449 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1450 | } |
| 1451 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1452 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1453 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1454 | } |
| 1455 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1456 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1457 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1458 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1459 | } |
| 1460 | |
| 1461 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1462 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1463 | } |
| 1464 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1465 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1466 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1467 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1468 | } |
| 1469 | |
| 1470 | /** {@hide} */ |
| 1471 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1472 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1473 | } |
| 1474 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1475 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1476 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1477 | |
| 1478 | final long identity = Binder.clearCallingIdentity(); |
| 1479 | try { |
| 1480 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1481 | checkSimPin.start(); |
| 1482 | return checkSimPin.unlockSim(null, pin); |
| 1483 | } finally { |
| 1484 | Binder.restoreCallingIdentity(identity); |
| 1485 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1486 | } |
| 1487 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1488 | /** {@hide} */ |
| 1489 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1490 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1493 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1494 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1495 | |
| 1496 | final long identity = Binder.clearCallingIdentity(); |
| 1497 | try { |
| 1498 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1499 | checkSimPuk.start(); |
| 1500 | return checkSimPuk.unlockSim(puk, pin); |
| 1501 | } finally { |
| 1502 | Binder.restoreCallingIdentity(identity); |
| 1503 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1507 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1508 | * a synchronous one. |
| 1509 | */ |
| 1510 | private static class UnlockSim extends Thread { |
| 1511 | |
| 1512 | private final IccCard mSimCard; |
| 1513 | |
| 1514 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1515 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1516 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1517 | |
| 1518 | // For replies from SimCard interface |
| 1519 | private Handler mHandler; |
| 1520 | |
| 1521 | // For async handler to identify request type |
| 1522 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1523 | |
| 1524 | public UnlockSim(IccCard simCard) { |
| 1525 | mSimCard = simCard; |
| 1526 | } |
| 1527 | |
| 1528 | @Override |
| 1529 | public void run() { |
| 1530 | Looper.prepare(); |
| 1531 | synchronized (UnlockSim.this) { |
| 1532 | mHandler = new Handler() { |
| 1533 | @Override |
| 1534 | public void handleMessage(Message msg) { |
| 1535 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1536 | switch (msg.what) { |
| 1537 | case SUPPLY_PIN_COMPLETE: |
| 1538 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1539 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1540 | mRetryCount = msg.arg1; |
| 1541 | if (ar.exception != null) { |
| 1542 | if (ar.exception instanceof CommandException && |
| 1543 | ((CommandException)(ar.exception)).getCommandError() |
| 1544 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1545 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1546 | } else { |
| 1547 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1548 | } |
| 1549 | } else { |
| 1550 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1551 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1552 | mDone = true; |
| 1553 | UnlockSim.this.notifyAll(); |
| 1554 | } |
| 1555 | break; |
| 1556 | } |
| 1557 | } |
| 1558 | }; |
| 1559 | UnlockSim.this.notifyAll(); |
| 1560 | } |
| 1561 | Looper.loop(); |
| 1562 | } |
| 1563 | |
| 1564 | /* |
| 1565 | * Use PIN or PUK to unlock SIM card |
| 1566 | * |
| 1567 | * If PUK is null, unlock SIM card with PIN |
| 1568 | * |
| 1569 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1570 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1571 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1572 | |
| 1573 | while (mHandler == null) { |
| 1574 | try { |
| 1575 | wait(); |
| 1576 | } catch (InterruptedException e) { |
| 1577 | Thread.currentThread().interrupt(); |
| 1578 | } |
| 1579 | } |
| 1580 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1581 | |
| 1582 | if (puk == null) { |
| 1583 | mSimCard.supplyPin(pin, callback); |
| 1584 | } else { |
| 1585 | mSimCard.supplyPuk(puk, pin, callback); |
| 1586 | } |
| 1587 | |
| 1588 | while (!mDone) { |
| 1589 | try { |
| 1590 | Log.d(LOG_TAG, "wait for done"); |
| 1591 | wait(); |
| 1592 | } catch (InterruptedException e) { |
| 1593 | // Restore the interrupted status |
| 1594 | Thread.currentThread().interrupt(); |
| 1595 | } |
| 1596 | } |
| 1597 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1598 | int[] resultArray = new int[2]; |
| 1599 | resultArray[0] = mResult; |
| 1600 | resultArray[1] = mRetryCount; |
| 1601 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1606 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1607 | |
| 1608 | } |
| 1609 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1610 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1611 | // No permission check needed here: this call is harmless, and it's |
| 1612 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1613 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1614 | final long identity = Binder.clearCallingIdentity(); |
| 1615 | try { |
| 1616 | final Phone phone = getPhone(subId); |
| 1617 | if (phone != null) { |
| 1618 | phone.updateServiceLocation(); |
| 1619 | } |
| 1620 | } finally { |
| 1621 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1622 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1623 | } |
| 1624 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1625 | @Override |
| 1626 | public boolean isRadioOn(String callingPackage) { |
| 1627 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1628 | } |
| 1629 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1630 | @Override |
| 1631 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1632 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1633 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1634 | return false; |
| 1635 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1636 | |
| 1637 | final long identity = Binder.clearCallingIdentity(); |
| 1638 | try { |
| 1639 | return isRadioOnForSubscriber(subId); |
| 1640 | } finally { |
| 1641 | Binder.restoreCallingIdentity(identity); |
| 1642 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1646 | final long identity = Binder.clearCallingIdentity(); |
| 1647 | try { |
| 1648 | final Phone phone = getPhone(subId); |
| 1649 | if (phone != null) { |
| 1650 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1651 | } else { |
| 1652 | return false; |
| 1653 | } |
| 1654 | } finally { |
| 1655 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1656 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1660 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1661 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1662 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1663 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1664 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1665 | |
| 1666 | final long identity = Binder.clearCallingIdentity(); |
| 1667 | try { |
| 1668 | final Phone phone = getPhone(subId); |
| 1669 | if (phone != null) { |
| 1670 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1671 | } |
| 1672 | } finally { |
| 1673 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1674 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1675 | } |
| 1676 | |
| 1677 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1678 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1679 | } |
| 1680 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1681 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1682 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1683 | |
| 1684 | final long identity = Binder.clearCallingIdentity(); |
| 1685 | try { |
| 1686 | final Phone phone = getPhone(subId); |
| 1687 | if (phone == null) { |
| 1688 | return false; |
| 1689 | } |
| 1690 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1691 | toggleRadioOnOffForSubscriber(subId); |
| 1692 | } |
| 1693 | return true; |
| 1694 | } finally { |
| 1695 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1696 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1697 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1698 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1699 | public boolean needMobileRadioShutdown() { |
| 1700 | /* |
| 1701 | * If any of the Radios are available, it will need to be |
| 1702 | * shutdown. So return true if any Radio is available. |
| 1703 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1704 | final long identity = Binder.clearCallingIdentity(); |
| 1705 | try { |
| 1706 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1707 | Phone phone = PhoneFactory.getPhone(i); |
| 1708 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1709 | } |
| 1710 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1711 | return false; |
| 1712 | } finally { |
| 1713 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1714 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1715 | } |
| 1716 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1717 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1718 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1719 | enforceModifyPermission(); |
| 1720 | |
| 1721 | final long identity = Binder.clearCallingIdentity(); |
| 1722 | try { |
| 1723 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1724 | logv("Shutting down Phone " + i); |
| 1725 | shutdownRadioUsingPhoneId(i); |
| 1726 | } |
| 1727 | } finally { |
| 1728 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1729 | } |
| 1730 | } |
| 1731 | |
| 1732 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1733 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1734 | if (phone != null && phone.isRadioAvailable()) { |
| 1735 | phone.shutdownRadio(); |
| 1736 | } |
| 1737 | } |
| 1738 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1739 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1740 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1741 | |
| 1742 | final long identity = Binder.clearCallingIdentity(); |
| 1743 | try { |
| 1744 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1745 | if (defaultPhone != null) { |
| 1746 | defaultPhone.setRadioPower(turnOn); |
| 1747 | return true; |
| 1748 | } else { |
| 1749 | loge("There's no default phone."); |
| 1750 | return false; |
| 1751 | } |
| 1752 | } finally { |
| 1753 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1754 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1755 | } |
| 1756 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1757 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1758 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1759 | |
| 1760 | final long identity = Binder.clearCallingIdentity(); |
| 1761 | try { |
| 1762 | final Phone phone = getPhone(subId); |
| 1763 | if (phone != null) { |
| 1764 | phone.setRadioPower(turnOn); |
| 1765 | return true; |
| 1766 | } else { |
| 1767 | return false; |
| 1768 | } |
| 1769 | } finally { |
| 1770 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1771 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1772 | } |
| 1773 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1774 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1775 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1776 | public boolean enableDataConnectivity() { |
| 1777 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1778 | |
| 1779 | final long identity = Binder.clearCallingIdentity(); |
| 1780 | try { |
| 1781 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1782 | final Phone phone = getPhone(subId); |
| 1783 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1784 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1785 | return true; |
| 1786 | } else { |
| 1787 | return false; |
| 1788 | } |
| 1789 | } finally { |
| 1790 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1791 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1792 | } |
| 1793 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1794 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1795 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1796 | public boolean disableDataConnectivity() { |
| 1797 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1798 | |
| 1799 | final long identity = Binder.clearCallingIdentity(); |
| 1800 | try { |
| 1801 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1802 | final Phone phone = getPhone(subId); |
| 1803 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1804 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1805 | return true; |
| 1806 | } else { |
| 1807 | return false; |
| 1808 | } |
| 1809 | } finally { |
| 1810 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1811 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1814 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1815 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1816 | final long identity = Binder.clearCallingIdentity(); |
| 1817 | try { |
| 1818 | final Phone phone = getPhone(subId); |
| 1819 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1820 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1821 | } else { |
| 1822 | return false; |
| 1823 | } |
| 1824 | } finally { |
| 1825 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1826 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1830 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1831 | } |
| 1832 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1833 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1834 | enforceCallPermission(); |
| 1835 | |
| 1836 | final long identity = Binder.clearCallingIdentity(); |
| 1837 | try { |
| 1838 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1839 | return; |
| 1840 | } |
| 1841 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1842 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1843 | } finally { |
| 1844 | Binder.restoreCallingIdentity(identity); |
| 1845 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1846 | }; |
| 1847 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1848 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1849 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1850 | |
| 1851 | final long identity = Binder.clearCallingIdentity(); |
| 1852 | try { |
| 1853 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1854 | return false; |
| 1855 | } |
| 1856 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1857 | } finally { |
| 1858 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1859 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1860 | } |
| 1861 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1862 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1863 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1864 | } |
| 1865 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1866 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1867 | final long identity = Binder.clearCallingIdentity(); |
| 1868 | try { |
| 1869 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1870 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1871 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1872 | } finally { |
| 1873 | Binder.restoreCallingIdentity(identity); |
| 1874 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1875 | } |
| 1876 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1877 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 1878 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1879 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1880 | } |
| 1881 | |
| 1882 | @Override |
| 1883 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1884 | final long identity = Binder.clearCallingIdentity(); |
| 1885 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1886 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1887 | if (phone != null) { |
| 1888 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1889 | } else { |
| 1890 | return PhoneConstantConversions.convertDataState( |
| 1891 | PhoneConstants.DataState.DISCONNECTED); |
| 1892 | } |
| 1893 | } finally { |
| 1894 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1895 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1896 | } |
| 1897 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1898 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 1899 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1900 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1901 | } |
| 1902 | |
| 1903 | @Override |
| 1904 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1905 | final long identity = Binder.clearCallingIdentity(); |
| 1906 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1907 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1908 | if (phone != null) { |
| 1909 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1910 | } else { |
| 1911 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1912 | } |
| 1913 | } finally { |
| 1914 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1915 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1919 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1920 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1921 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1922 | |
| 1923 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 1924 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 1925 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 1926 | .setCallingPackage(callingPackage) |
| 1927 | .setCallingPid(Binder.getCallingPid()) |
| 1928 | .setCallingUid(Binder.getCallingUid()) |
| 1929 | .setMethod("getCellLocation") |
| 1930 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 1931 | .build()); |
| 1932 | switch (locationResult) { |
| 1933 | case DENIED_HARD: |
| 1934 | throw new SecurityException("Not allowed to access cell location"); |
| 1935 | case DENIED_SOFT: |
| 1936 | return new Bundle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1937 | } |
| 1938 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1939 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1940 | final long identity = Binder.clearCallingIdentity(); |
| 1941 | try { |
| 1942 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1943 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1944 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1945 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1946 | cl.fillInNotifierBundle(data); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1947 | return data; |
| 1948 | } finally { |
| 1949 | Binder.restoreCallingIdentity(identity); |
| 1950 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1951 | } |
| 1952 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1953 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1954 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1955 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1956 | // registered cell info, so return a NULL country instead. |
| 1957 | final long identity = Binder.clearCallingIdentity(); |
| 1958 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1959 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1960 | // Get default phone in this case. |
| 1961 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1962 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1963 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1964 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1965 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1966 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1967 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1968 | return ""; |
| 1969 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1970 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1971 | if (phone != null) { |
| 1972 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | 1c069d0 | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 1973 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1974 | if (sst != null) { |
| 1975 | LocaleTracker lt = sst.getLocaleTracker(); |
| 1976 | if (lt != null) { |
sqian | 1c069d0 | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 1977 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 1978 | return lt.getCurrentCountry(); |
| 1979 | } else if (emergencyNumberTracker != null) { |
| 1980 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 1981 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1982 | } |
| 1983 | } |
| 1984 | } |
| 1985 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1986 | } finally { |
| 1987 | Binder.restoreCallingIdentity(identity); |
| 1988 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1989 | } |
| 1990 | |
| 1991 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1992 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1993 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1994 | } |
| 1995 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1996 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1997 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1998 | mApp.enforceCallingOrSelfPermission( |
| 1999 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2000 | |
| 2001 | final long identity = Binder.clearCallingIdentity(); |
| 2002 | try { |
| 2003 | final Phone phone = getPhone(subId); |
| 2004 | if (phone != null) { |
| 2005 | phone.enableLocationUpdates(); |
| 2006 | } |
| 2007 | } finally { |
| 2008 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2009 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | @Override |
| 2013 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2014 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2015 | } |
| 2016 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2017 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2018 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2019 | mApp.enforceCallingOrSelfPermission( |
| 2020 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2021 | |
| 2022 | final long identity = Binder.clearCallingIdentity(); |
| 2023 | try { |
| 2024 | final Phone phone = getPhone(subId); |
| 2025 | if (phone != null) { |
| 2026 | phone.disableLocationUpdates(); |
| 2027 | } |
| 2028 | } finally { |
| 2029 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2030 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2031 | } |
| 2032 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2033 | /** |
| 2034 | * Returns the target SDK version number for a given package name. |
| 2035 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2036 | * This call MUST be invoked before clearing the calling UID. |
| 2037 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2038 | * @return target SDK if the package is found or INT_MAX. |
| 2039 | */ |
| 2040 | private int getTargetSdk(String packageName) { |
| 2041 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2042 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
| 2043 | packageName, 0, UserHandle.getUserId(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2044 | if (ai != null) return ai.targetSdkVersion; |
| 2045 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2046 | loge("Failed to get package info for pkg=" |
| 2047 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2048 | } |
| 2049 | return Integer.MAX_VALUE; |
| 2050 | } |
| 2051 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2052 | @Override |
| 2053 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2054 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 2055 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2056 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2057 | throw new SecurityException( |
| 2058 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2059 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2060 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2061 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2062 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2063 | return null; |
| 2064 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2065 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2066 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2067 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2068 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 2069 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2070 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2071 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2072 | for (CellInfo ci : info) { |
| 2073 | if (ci instanceof CellInfoGsm) { |
| 2074 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2075 | } else if (ci instanceof CellInfoWcdma) { |
| 2076 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2077 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2078 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2079 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2080 | } |
| 2081 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2082 | private List<CellInfo> getCachedCellInfo() { |
| 2083 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2084 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2085 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2086 | if (info != null) cellInfos.addAll(info); |
| 2087 | } |
| 2088 | return cellInfos; |
| 2089 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2090 | |
| 2091 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2092 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2093 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2094 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2095 | |
| 2096 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2097 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2098 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2099 | .setCallingPackage(callingPackage) |
| 2100 | .setCallingPid(Binder.getCallingPid()) |
| 2101 | .setCallingUid(Binder.getCallingUid()) |
| 2102 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2103 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2104 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2105 | .build()); |
| 2106 | switch (locationResult) { |
| 2107 | case DENIED_HARD: |
| 2108 | throw new SecurityException("Not allowed to access cell info"); |
| 2109 | case DENIED_SOFT: |
| 2110 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2111 | } |
| 2112 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2113 | final int targetSdk = getTargetSdk(callingPackage); |
| 2114 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2115 | return getCachedCellInfo(); |
| 2116 | } |
| 2117 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2118 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2119 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2120 | final long identity = Binder.clearCallingIdentity(); |
| 2121 | try { |
| 2122 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2123 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2124 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2125 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2126 | if (info != null) cellInfos.addAll(info); |
| 2127 | } |
| 2128 | return cellInfos; |
| 2129 | } finally { |
| 2130 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2131 | } |
| 2132 | } |
| 2133 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2134 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2135 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2136 | requestCellInfoUpdateInternal( |
| 2137 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2138 | } |
| 2139 | |
| 2140 | @Override |
| 2141 | public void requestCellInfoUpdateWithWorkSource( |
| 2142 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2143 | enforceModifyPermission(); |
| 2144 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2145 | } |
| 2146 | |
| 2147 | private void requestCellInfoUpdateInternal( |
| 2148 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2149 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2150 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2151 | |
| 2152 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2153 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2154 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2155 | .setCallingPackage(callingPackage) |
| 2156 | .setCallingPid(Binder.getCallingPid()) |
| 2157 | .setCallingUid(Binder.getCallingUid()) |
| 2158 | .setMethod("requestCellInfoUpdate") |
| 2159 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2160 | .build()); |
| 2161 | switch (locationResult) { |
| 2162 | case DENIED_HARD: |
| 2163 | throw new SecurityException("Not allowed to access cell info"); |
| 2164 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2165 | try { |
| 2166 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2167 | } catch (RemoteException re) { |
| 2168 | // Drop without consequences |
| 2169 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2170 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2171 | } |
| 2172 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2173 | |
| 2174 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2175 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2176 | |
| 2177 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2178 | } |
| 2179 | |
| 2180 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2181 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2182 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2183 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2184 | |
| 2185 | final long identity = Binder.clearCallingIdentity(); |
| 2186 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2187 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2188 | } finally { |
| 2189 | Binder.restoreCallingIdentity(identity); |
| 2190 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2191 | } |
| 2192 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2193 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2194 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2195 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2196 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2197 | return null; |
| 2198 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2199 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2200 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2201 | callingPackage, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2202 | return null; |
| 2203 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2204 | |
| 2205 | final long identity = Binder.clearCallingIdentity(); |
| 2206 | try { |
| 2207 | return phone.getImei(); |
| 2208 | } finally { |
| 2209 | Binder.restoreCallingIdentity(identity); |
| 2210 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2211 | } |
| 2212 | |
| 2213 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2214 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2215 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2216 | String tac = null; |
| 2217 | if (phone != null) { |
| 2218 | String imei = phone.getImei(); |
| 2219 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2220 | } |
| 2221 | return tac; |
| 2222 | } |
| 2223 | |
| 2224 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2225 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2226 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2227 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2228 | return null; |
| 2229 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2230 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2231 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2232 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2233 | callingPackage, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2234 | return null; |
| 2235 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2236 | |
| 2237 | final long identity = Binder.clearCallingIdentity(); |
| 2238 | try { |
| 2239 | return phone.getMeid(); |
| 2240 | } finally { |
| 2241 | Binder.restoreCallingIdentity(identity); |
| 2242 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2243 | } |
| 2244 | |
| 2245 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2246 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2247 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2248 | String manufacturerCode = null; |
| 2249 | if (phone != null) { |
| 2250 | String meid = phone.getMeid(); |
| 2251 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2252 | } |
| 2253 | return manufacturerCode; |
| 2254 | } |
| 2255 | |
| 2256 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2257 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2258 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2259 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2260 | return null; |
| 2261 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2262 | int subId = phone.getSubId(); |
| 2263 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2264 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2265 | return null; |
| 2266 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2267 | |
| 2268 | final long identity = Binder.clearCallingIdentity(); |
| 2269 | try { |
| 2270 | return phone.getDeviceSvn(); |
| 2271 | } finally { |
| 2272 | Binder.restoreCallingIdentity(identity); |
| 2273 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2274 | } |
| 2275 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2276 | @Override |
| 2277 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2278 | final long identity = Binder.clearCallingIdentity(); |
| 2279 | try { |
| 2280 | final Phone phone = getPhone(subId); |
| 2281 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2282 | } finally { |
| 2283 | Binder.restoreCallingIdentity(identity); |
| 2284 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | @Override |
| 2288 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2289 | final long identity = Binder.clearCallingIdentity(); |
| 2290 | try { |
| 2291 | final Phone phone = getPhone(subId); |
| 2292 | return phone == null ? null : phone.getCarrierName(); |
| 2293 | } finally { |
| 2294 | Binder.restoreCallingIdentity(identity); |
| 2295 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2296 | } |
| 2297 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2298 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2299 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2300 | final long identity = Binder.clearCallingIdentity(); |
| 2301 | try { |
| 2302 | final Phone phone = getPhone(subId); |
| 2303 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2304 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2305 | } finally { |
| 2306 | Binder.restoreCallingIdentity(identity); |
| 2307 | } |
| 2308 | } |
| 2309 | |
| 2310 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2311 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2312 | final long identity = Binder.clearCallingIdentity(); |
| 2313 | try { |
| 2314 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2315 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2316 | } finally { |
| 2317 | Binder.restoreCallingIdentity(identity); |
| 2318 | } |
| 2319 | } |
| 2320 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2321 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2322 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2323 | if (!isSubscriptionMccMnc) { |
| 2324 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2325 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2326 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2327 | if (phone == null) { |
| 2328 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2329 | } |
| 2330 | final long identity = Binder.clearCallingIdentity(); |
| 2331 | try { |
| 2332 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2333 | } finally { |
| 2334 | Binder.restoreCallingIdentity(identity); |
| 2335 | } |
| 2336 | } |
| 2337 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2338 | // |
| 2339 | // Internal helper methods. |
| 2340 | // |
| 2341 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2342 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2343 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2344 | * |
| 2345 | * @throws SecurityException if the caller does not have the required permission |
| 2346 | */ |
| 2347 | private void enforceModifyPermission() { |
| 2348 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2349 | } |
| 2350 | |
| 2351 | /** |
| 2352 | * Make sure the caller has the CALL_PHONE permission. |
| 2353 | * |
| 2354 | * @throws SecurityException if the caller does not have the required permission |
| 2355 | */ |
| 2356 | private void enforceCallPermission() { |
| 2357 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2358 | } |
| 2359 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2360 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2361 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2362 | "ConnectivityService"); |
| 2363 | } |
| 2364 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2365 | private String createTelUrl(String number) { |
| 2366 | if (TextUtils.isEmpty(number)) { |
| 2367 | return null; |
| 2368 | } |
| 2369 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2370 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2371 | } |
| 2372 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2373 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2374 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2375 | } |
| 2376 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2377 | private static void logv(String msg) { |
| 2378 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2379 | } |
| 2380 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2381 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2382 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2383 | } |
| 2384 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2385 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2386 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2387 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2388 | } |
| 2389 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2390 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2391 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2392 | final long identity = Binder.clearCallingIdentity(); |
| 2393 | try { |
| 2394 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2395 | if (phone == null) { |
| 2396 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2397 | } else { |
| 2398 | return phone.getPhoneType(); |
| 2399 | } |
| 2400 | } finally { |
| 2401 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2402 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | /** |
| 2406 | * Returns the CDMA ERI icon index to display |
| 2407 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2408 | @Override |
| 2409 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2410 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2411 | } |
| 2412 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2413 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2414 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2415 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2416 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2417 | return -1; |
| 2418 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2419 | |
| 2420 | final long identity = Binder.clearCallingIdentity(); |
| 2421 | try { |
| 2422 | final Phone phone = getPhone(subId); |
| 2423 | if (phone != null) { |
| 2424 | return phone.getCdmaEriIconIndex(); |
| 2425 | } else { |
| 2426 | return -1; |
| 2427 | } |
| 2428 | } finally { |
| 2429 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2430 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | /** |
| 2434 | * Returns the CDMA ERI icon mode, |
| 2435 | * 0 - ON |
| 2436 | * 1 - FLASHING |
| 2437 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2438 | @Override |
| 2439 | public int getCdmaEriIconMode(String callingPackage) { |
| 2440 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2441 | } |
| 2442 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2443 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2444 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2445 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2446 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2447 | return -1; |
| 2448 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2449 | |
| 2450 | final long identity = Binder.clearCallingIdentity(); |
| 2451 | try { |
| 2452 | final Phone phone = getPhone(subId); |
| 2453 | if (phone != null) { |
| 2454 | return phone.getCdmaEriIconMode(); |
| 2455 | } else { |
| 2456 | return -1; |
| 2457 | } |
| 2458 | } finally { |
| 2459 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2460 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2461 | } |
| 2462 | |
| 2463 | /** |
| 2464 | * Returns the CDMA ERI text, |
| 2465 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2466 | @Override |
| 2467 | public String getCdmaEriText(String callingPackage) { |
| 2468 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2469 | } |
| 2470 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2471 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2472 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2473 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2474 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2475 | return null; |
| 2476 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2477 | |
| 2478 | final long identity = Binder.clearCallingIdentity(); |
| 2479 | try { |
| 2480 | final Phone phone = getPhone(subId); |
| 2481 | if (phone != null) { |
| 2482 | return phone.getCdmaEriText(); |
| 2483 | } else { |
| 2484 | return null; |
| 2485 | } |
| 2486 | } finally { |
| 2487 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2488 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2492 | * Returns the CDMA MDN. |
| 2493 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2494 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2495 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2496 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2497 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2498 | |
| 2499 | final long identity = Binder.clearCallingIdentity(); |
| 2500 | try { |
| 2501 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2502 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2503 | return phone.getLine1Number(); |
| 2504 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2505 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2506 | return null; |
| 2507 | } |
| 2508 | } finally { |
| 2509 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2510 | } |
| 2511 | } |
| 2512 | |
| 2513 | /** |
| 2514 | * Returns the CDMA MIN. |
| 2515 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2516 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2517 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2518 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2519 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2520 | |
| 2521 | final long identity = Binder.clearCallingIdentity(); |
| 2522 | try { |
| 2523 | final Phone phone = getPhone(subId); |
| 2524 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2525 | return phone.getCdmaMin(); |
| 2526 | } else { |
| 2527 | return null; |
| 2528 | } |
| 2529 | } finally { |
| 2530 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2531 | } |
| 2532 | } |
| 2533 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2534 | @Override |
| 2535 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2536 | INumberVerificationCallback callback, String callingPackage) { |
| 2537 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2538 | != PERMISSION_GRANTED) { |
| 2539 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2540 | } |
| 2541 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2542 | |
| 2543 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2544 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2545 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2546 | } |
| 2547 | |
| 2548 | if (range == null) { |
| 2549 | throw new NullPointerException("Range must be non-null"); |
| 2550 | } |
| 2551 | |
| 2552 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2553 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2554 | |
| 2555 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2556 | } |
| 2557 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2558 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2559 | * Returns true if CDMA provisioning needs to run. |
| 2560 | */ |
| 2561 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2562 | final long identity = Binder.clearCallingIdentity(); |
| 2563 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2564 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2565 | } finally { |
| 2566 | Binder.restoreCallingIdentity(identity); |
| 2567 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2568 | } |
| 2569 | |
| 2570 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2571 | * Sets the voice mail number of a given subId. |
| 2572 | */ |
| 2573 | @Override |
| 2574 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2575 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2576 | |
| 2577 | final long identity = Binder.clearCallingIdentity(); |
| 2578 | try { |
| 2579 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2580 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2581 | return success; |
| 2582 | } finally { |
| 2583 | Binder.restoreCallingIdentity(identity); |
| 2584 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2585 | } |
| 2586 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2587 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2588 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2589 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2590 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2591 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2592 | throw new SecurityException("caller must be system dialer"); |
| 2593 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2594 | |
| 2595 | final long identity = Binder.clearCallingIdentity(); |
| 2596 | try { |
| 2597 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2598 | if (phoneAccountHandle == null) { |
| 2599 | return null; |
| 2600 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2601 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2602 | } finally { |
| 2603 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2604 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2605 | } |
| 2606 | |
| 2607 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2608 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2609 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2610 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2611 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2612 | return null; |
| 2613 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2614 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2615 | final long identity = Binder.clearCallingIdentity(); |
| 2616 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2617 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2618 | } finally { |
| 2619 | Binder.restoreCallingIdentity(identity); |
| 2620 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2621 | } |
| 2622 | |
| 2623 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2624 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2625 | VisualVoicemailSmsFilterSettings settings) { |
| 2626 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2627 | |
| 2628 | final long identity = Binder.clearCallingIdentity(); |
| 2629 | try { |
| 2630 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2631 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2632 | } finally { |
| 2633 | Binder.restoreCallingIdentity(identity); |
| 2634 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2638 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2639 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2640 | |
| 2641 | final long identity = Binder.clearCallingIdentity(); |
| 2642 | try { |
| 2643 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2644 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2645 | } finally { |
| 2646 | Binder.restoreCallingIdentity(identity); |
| 2647 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2648 | } |
| 2649 | |
| 2650 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2651 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2652 | String callingPackage, int subId) { |
| 2653 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2654 | |
| 2655 | final long identity = Binder.clearCallingIdentity(); |
| 2656 | try { |
| 2657 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2658 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2659 | } finally { |
| 2660 | Binder.restoreCallingIdentity(identity); |
| 2661 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2662 | } |
| 2663 | |
| 2664 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2665 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2666 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2667 | |
| 2668 | final long identity = Binder.clearCallingIdentity(); |
| 2669 | try { |
| 2670 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2671 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2672 | } finally { |
| 2673 | Binder.restoreCallingIdentity(identity); |
| 2674 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2675 | } |
| 2676 | |
| 2677 | @Override |
| 2678 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2679 | String number, int port, String text, PendingIntent sentIntent) { |
| 2680 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2681 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2682 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2683 | SmsController smsController = PhoneFactory.getSmsController(); |
| 2684 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 2685 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2686 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2687 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2688 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2689 | * Sets the voice activation state of a given subId. |
| 2690 | */ |
| 2691 | @Override |
| 2692 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2693 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2694 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2695 | |
| 2696 | final long identity = Binder.clearCallingIdentity(); |
| 2697 | try { |
| 2698 | final Phone phone = getPhone(subId); |
| 2699 | if (phone != null) { |
| 2700 | phone.setVoiceActivationState(activationState); |
| 2701 | } else { |
| 2702 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2703 | } |
| 2704 | } finally { |
| 2705 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2706 | } |
| 2707 | } |
| 2708 | |
| 2709 | /** |
| 2710 | * Sets the data activation state of a given subId. |
| 2711 | */ |
| 2712 | @Override |
| 2713 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2714 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2715 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2716 | |
| 2717 | final long identity = Binder.clearCallingIdentity(); |
| 2718 | try { |
| 2719 | final Phone phone = getPhone(subId); |
| 2720 | if (phone != null) { |
| 2721 | phone.setDataActivationState(activationState); |
| 2722 | } else { |
| 2723 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2724 | } |
| 2725 | } finally { |
| 2726 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2727 | } |
| 2728 | } |
| 2729 | |
| 2730 | /** |
| 2731 | * Returns the voice activation state of a given subId. |
| 2732 | */ |
| 2733 | @Override |
| 2734 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2735 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2736 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2737 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2738 | final long identity = Binder.clearCallingIdentity(); |
| 2739 | try { |
| 2740 | if (phone != null) { |
| 2741 | return phone.getVoiceActivationState(); |
| 2742 | } else { |
| 2743 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2744 | } |
| 2745 | } finally { |
| 2746 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2747 | } |
| 2748 | } |
| 2749 | |
| 2750 | /** |
| 2751 | * Returns the data activation state of a given subId. |
| 2752 | */ |
| 2753 | @Override |
| 2754 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2755 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2756 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2757 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2758 | final long identity = Binder.clearCallingIdentity(); |
| 2759 | try { |
| 2760 | if (phone != null) { |
| 2761 | return phone.getDataActivationState(); |
| 2762 | } else { |
| 2763 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2764 | } |
| 2765 | } finally { |
| 2766 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2767 | } |
| 2768 | } |
| 2769 | |
| 2770 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2771 | * Returns the unread count of voicemails for a subId |
| 2772 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2773 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2774 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2775 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2776 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2777 | return 0; |
| 2778 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2779 | final long identity = Binder.clearCallingIdentity(); |
| 2780 | try { |
| 2781 | final Phone phone = getPhone(subId); |
| 2782 | if (phone != null) { |
| 2783 | return phone.getVoiceMessageCount(); |
| 2784 | } else { |
| 2785 | return 0; |
| 2786 | } |
| 2787 | } finally { |
| 2788 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2789 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2790 | } |
| 2791 | |
| 2792 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2793 | * returns true, if the device is in a state where both voice and data |
| 2794 | * are supported simultaneously. This can change based on location or network condition. |
| 2795 | */ |
| 2796 | @Override |
| 2797 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2798 | final long identity = Binder.clearCallingIdentity(); |
| 2799 | try { |
| 2800 | final Phone phone = getPhone(subId); |
| 2801 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2802 | } finally { |
| 2803 | Binder.restoreCallingIdentity(identity); |
| 2804 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2805 | } |
| 2806 | |
| 2807 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2808 | * Send the dialer code if called from the current default dialer or the caller has |
| 2809 | * carrier privilege. |
| 2810 | * @param inputCode The dialer code to send |
| 2811 | */ |
| 2812 | @Override |
| 2813 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2814 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2815 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2816 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2817 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2818 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2819 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2820 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2821 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2822 | |
| 2823 | final long identity = Binder.clearCallingIdentity(); |
| 2824 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2825 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2826 | } finally { |
| 2827 | Binder.restoreCallingIdentity(identity); |
| 2828 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2829 | } |
| 2830 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2831 | @Override |
| 2832 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2833 | if (!isActiveSubscription(subId)) { |
| 2834 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2835 | } |
| 2836 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2837 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2838 | } |
| 2839 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2840 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2841 | public boolean isInEmergencySmsMode() { |
| 2842 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 2843 | final long identity = Binder.clearCallingIdentity(); |
| 2844 | try { |
| 2845 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2846 | if (phone.isInEmergencySmsMode()) { |
| 2847 | return true; |
| 2848 | } |
| 2849 | } |
| 2850 | } finally { |
| 2851 | Binder.restoreCallingIdentity(identity); |
| 2852 | } |
| 2853 | return false; |
| 2854 | } |
| 2855 | |
| 2856 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2857 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2858 | throws RemoteException { |
| 2859 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2860 | final long token = Binder.clearCallingIdentity(); |
| 2861 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2862 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2863 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2864 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2865 | } catch (ImsException e) { |
| 2866 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2867 | } finally { |
| 2868 | Binder.restoreCallingIdentity(token); |
| 2869 | } |
| 2870 | } |
| 2871 | |
| 2872 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2873 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2874 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2875 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2876 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2877 | } |
| 2878 | Binder.withCleanCallingIdentity(() -> { |
| 2879 | try { |
| 2880 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2881 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2882 | .removeRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2883 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2884 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2885 | + "is inactive, ignoring unregister."); |
| 2886 | // If the subscription is no longer active, just return, since the callback |
| 2887 | // will already have been removed internally. |
| 2888 | } |
| 2889 | }); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2890 | } |
| 2891 | |
| 2892 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2893 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2894 | throws RemoteException { |
| 2895 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2896 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2897 | final long token = Binder.clearCallingIdentity(); |
| 2898 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2899 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2900 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2901 | } catch (ImsException e) { |
| 2902 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2903 | } finally { |
| 2904 | Binder.restoreCallingIdentity(token); |
| 2905 | } |
| 2906 | } |
| 2907 | |
| 2908 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2909 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2910 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2911 | |
| 2912 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2913 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2914 | } |
| 2915 | Binder.withCleanCallingIdentity(() -> { |
| 2916 | try { |
| 2917 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2918 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2919 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2920 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2921 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2922 | + "is inactive, ignoring unregister."); |
| 2923 | // If the subscription is no longer active, just return, since the callback |
| 2924 | // will already have been removed internally. |
| 2925 | } |
| 2926 | }); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2927 | } |
| 2928 | |
| 2929 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2930 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2931 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2932 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2933 | final long token = Binder.clearCallingIdentity(); |
| 2934 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2935 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2936 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2937 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2938 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2939 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2940 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2941 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 2942 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2943 | } finally { |
| 2944 | Binder.restoreCallingIdentity(token); |
| 2945 | } |
| 2946 | } |
| 2947 | |
| 2948 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2949 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2950 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2951 | final long token = Binder.clearCallingIdentity(); |
| 2952 | try { |
| 2953 | Phone phone = getPhone(subId); |
| 2954 | if (phone == null) return false; |
| 2955 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2956 | } finally { |
| 2957 | Binder.restoreCallingIdentity(token); |
| 2958 | } |
| 2959 | } |
| 2960 | |
| 2961 | @Override |
| 2962 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2963 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2964 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2965 | final long token = Binder.clearCallingIdentity(); |
| 2966 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2967 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2968 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2969 | } catch (ImsException e) { |
| 2970 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2971 | } finally { |
| 2972 | Binder.restoreCallingIdentity(token); |
| 2973 | } |
| 2974 | } |
| 2975 | |
| 2976 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2977 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2978 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2979 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2980 | final long identity = Binder.clearCallingIdentity(); |
| 2981 | try { |
| 2982 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2983 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2984 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2985 | } catch (ImsException e) { |
| 2986 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2987 | } finally { |
| 2988 | Binder.restoreCallingIdentity(identity); |
| 2989 | } |
| 2990 | } |
| 2991 | |
| 2992 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2993 | public boolean isVtSettingEnabled(int subId) { |
| 2994 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2995 | final long identity = Binder.clearCallingIdentity(); |
| 2996 | try { |
| 2997 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2998 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2999 | } catch (ImsException e) { |
| 3000 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3001 | } finally { |
| 3002 | Binder.restoreCallingIdentity(identity); |
| 3003 | } |
| 3004 | } |
| 3005 | |
| 3006 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3007 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3008 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3009 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3010 | final long identity = Binder.clearCallingIdentity(); |
| 3011 | try { |
| 3012 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3013 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3014 | } catch (ImsException e) { |
| 3015 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3016 | } finally { |
| 3017 | Binder.restoreCallingIdentity(identity); |
| 3018 | } |
| 3019 | } |
| 3020 | |
| 3021 | @Override |
| 3022 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 3023 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 3024 | final long identity = Binder.clearCallingIdentity(); |
| 3025 | try { |
| 3026 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3027 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3028 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3029 | } catch (ImsException e) { |
| 3030 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3031 | } finally { |
| 3032 | Binder.restoreCallingIdentity(identity); |
| 3033 | } |
| 3034 | } |
| 3035 | |
| 3036 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3037 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3038 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3039 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3040 | final long identity = Binder.clearCallingIdentity(); |
| 3041 | try { |
| 3042 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3043 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3044 | } catch (ImsException e) { |
| 3045 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3046 | } finally { |
| 3047 | Binder.restoreCallingIdentity(identity); |
| 3048 | } |
| 3049 | } |
| 3050 | |
| 3051 | @Override |
| 3052 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 3053 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3054 | final long identity = Binder.clearCallingIdentity(); |
| 3055 | try { |
| 3056 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3057 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3058 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3059 | } catch (ImsException e) { |
| 3060 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3061 | } finally { |
| 3062 | Binder.restoreCallingIdentity(identity); |
| 3063 | } |
| 3064 | } |
| 3065 | |
| 3066 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3067 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3068 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3069 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3070 | final long identity = Binder.clearCallingIdentity(); |
| 3071 | try { |
| 3072 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3073 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3074 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3075 | } catch (ImsException e) { |
| 3076 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3077 | } finally { |
| 3078 | Binder.restoreCallingIdentity(identity); |
| 3079 | } |
| 3080 | } |
| 3081 | |
| 3082 | @Override |
| 3083 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3084 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3085 | "setVoWiFiNonPersistent"); |
| 3086 | final long identity = Binder.clearCallingIdentity(); |
| 3087 | try { |
| 3088 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3089 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3090 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3091 | } catch (ImsException e) { |
| 3092 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3093 | } finally { |
| 3094 | Binder.restoreCallingIdentity(identity); |
| 3095 | } |
| 3096 | } |
| 3097 | |
| 3098 | @Override |
| 3099 | public int getVoWiFiModeSetting(int subId) { |
| 3100 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3101 | final long identity = Binder.clearCallingIdentity(); |
| 3102 | try { |
| 3103 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3104 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3105 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3106 | } catch (ImsException e) { |
| 3107 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3108 | } finally { |
| 3109 | Binder.restoreCallingIdentity(identity); |
| 3110 | } |
| 3111 | } |
| 3112 | |
| 3113 | @Override |
| 3114 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3115 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3116 | "setVoWiFiModeSetting"); |
| 3117 | final long identity = Binder.clearCallingIdentity(); |
| 3118 | try { |
| 3119 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3120 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3121 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3122 | } catch (ImsException e) { |
| 3123 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3124 | } finally { |
| 3125 | Binder.restoreCallingIdentity(identity); |
| 3126 | } |
| 3127 | } |
| 3128 | |
| 3129 | @Override |
| 3130 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3131 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3132 | final long identity = Binder.clearCallingIdentity(); |
| 3133 | try { |
| 3134 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3135 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3136 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3137 | } catch (ImsException e) { |
| 3138 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3139 | } finally { |
| 3140 | Binder.restoreCallingIdentity(identity); |
| 3141 | } |
| 3142 | } |
| 3143 | |
| 3144 | @Override |
| 3145 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3146 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3147 | "setVoWiFiRoamingModeSetting"); |
| 3148 | final long identity = Binder.clearCallingIdentity(); |
| 3149 | try { |
| 3150 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3151 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3152 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3153 | } catch (ImsException e) { |
| 3154 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3155 | } finally { |
| 3156 | Binder.restoreCallingIdentity(identity); |
| 3157 | } |
| 3158 | } |
| 3159 | |
| 3160 | @Override |
| 3161 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3162 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3163 | "setRttCapabilityEnabled"); |
| 3164 | final long identity = Binder.clearCallingIdentity(); |
| 3165 | try { |
| 3166 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3167 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3168 | } catch (ImsException e) { |
| 3169 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3170 | } finally { |
| 3171 | Binder.restoreCallingIdentity(identity); |
| 3172 | } |
| 3173 | } |
| 3174 | |
| 3175 | @Override |
| 3176 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3177 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3178 | final long identity = Binder.clearCallingIdentity(); |
| 3179 | try { |
| 3180 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3181 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3182 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3183 | } catch (ImsException e) { |
| 3184 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3185 | } finally { |
| 3186 | Binder.restoreCallingIdentity(identity); |
| 3187 | } |
| 3188 | } |
| 3189 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3190 | @Override |
| 3191 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3192 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3193 | final long identity = Binder.clearCallingIdentity(); |
| 3194 | try { |
| 3195 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3196 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3197 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3198 | } catch (ImsException e) { |
| 3199 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3200 | } finally { |
| 3201 | Binder.restoreCallingIdentity(identity); |
| 3202 | } |
| 3203 | } |
| 3204 | |
| 3205 | @Override |
| 3206 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3207 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3208 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3209 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3210 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3211 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3212 | try { |
| 3213 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3214 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3215 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3216 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3217 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3218 | + "is inactive, ignoring unregister."); |
| 3219 | // If the subscription is no longer active, just return, since the callback will already |
| 3220 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3221 | } finally { |
| 3222 | Binder.restoreCallingIdentity(identity); |
| 3223 | } |
| 3224 | } |
| 3225 | |
| 3226 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3227 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3228 | boolean isProvisioned) { |
| 3229 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3230 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3231 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3232 | } |
| 3233 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3234 | "setProvisioningStatusForCapability"); |
| 3235 | final long identity = Binder.clearCallingIdentity(); |
| 3236 | try { |
| 3237 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3238 | Phone phone = getPhone(subId); |
| 3239 | if (phone == null) { |
| 3240 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3241 | + subId); |
| 3242 | return; |
| 3243 | } |
| 3244 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3245 | return; |
| 3246 | } |
| 3247 | |
| 3248 | // this capability requires provisioning, route to the correct API. |
| 3249 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3250 | switch (capability) { |
| 3251 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3252 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3253 | ims.setVolteProvisioned(isProvisioned); |
| 3254 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3255 | ims.setWfcProvisioned(isProvisioned); |
| 3256 | } |
| 3257 | break; |
| 3258 | } |
| 3259 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3260 | // There is currently no difference in VT provisioning type. |
| 3261 | ims.setVtProvisioned(isProvisioned); |
| 3262 | break; |
| 3263 | } |
| 3264 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3265 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3266 | // change the capability of the feature instead if needed. |
| 3267 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3268 | == isProvisioned) { |
| 3269 | // No change in provisioning. |
| 3270 | return; |
| 3271 | } |
| 3272 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3273 | try { |
| 3274 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3275 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3276 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3277 | + ", Exception" + e.getMessage()); |
| 3278 | } |
| 3279 | break; |
| 3280 | } |
| 3281 | default: { |
| 3282 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3283 | + capability + "', which does not require provisioning."); |
| 3284 | } |
| 3285 | } |
| 3286 | |
| 3287 | } finally { |
| 3288 | Binder.restoreCallingIdentity(identity); |
| 3289 | } |
| 3290 | } |
| 3291 | |
| 3292 | @Override |
| 3293 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3294 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3295 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3296 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3297 | } |
| 3298 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3299 | final long identity = Binder.clearCallingIdentity(); |
| 3300 | try { |
| 3301 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3302 | Phone phone = getPhone(subId); |
| 3303 | if (phone == null) { |
| 3304 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3305 | + subId); |
| 3306 | // We will fail with "true" as the provisioning status because this is the default |
| 3307 | // if we do not require provisioning. |
| 3308 | return true; |
| 3309 | } |
| 3310 | |
| 3311 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3312 | return true; |
| 3313 | } |
| 3314 | |
| 3315 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3316 | switch (capability) { |
| 3317 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3318 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3319 | return ims.isVolteProvisionedOnDevice(); |
| 3320 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3321 | return ims.isWfcProvisionedOnDevice(); |
| 3322 | } |
| 3323 | // This should never happen, since we are checking tech above to make sure it |
| 3324 | // is either LTE or IWLAN. |
| 3325 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3326 | + "capability."); |
| 3327 | } |
| 3328 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3329 | // There is currently no difference in VT provisioning type. |
| 3330 | return ims.isVtProvisionedOnDevice(); |
| 3331 | } |
| 3332 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3333 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3334 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3335 | } |
| 3336 | default: { |
| 3337 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3338 | + capability + "', which does not require provisioning."); |
| 3339 | } |
| 3340 | } |
| 3341 | |
| 3342 | } finally { |
| 3343 | Binder.restoreCallingIdentity(identity); |
| 3344 | } |
| 3345 | } |
| 3346 | |
| 3347 | @Override |
| 3348 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3349 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3350 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3351 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3352 | } |
| 3353 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3354 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3355 | return (provisionedBits & capability) > 0; |
| 3356 | } |
| 3357 | |
| 3358 | @Override |
| 3359 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3360 | boolean isProvisioned) { |
| 3361 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3362 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3363 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3364 | } |
| 3365 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3366 | "setProvisioningStatusForCapability"); |
| 3367 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3368 | // If the current provisioning status for capability already matches isProvisioned, |
| 3369 | // do nothing. |
| 3370 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3371 | return; |
| 3372 | } |
| 3373 | if (isProvisioned) { |
| 3374 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3375 | } else { |
| 3376 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3377 | } |
| 3378 | } |
| 3379 | |
| 3380 | /** |
| 3381 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3382 | * technology. The bitfield should mirror the bitfield defined by |
| 3383 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3384 | */ |
| 3385 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3386 | String key = getMmTelProvisioningKey(subId, tech); |
| 3387 | // Default is no capabilities are provisioned. |
| 3388 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3389 | } |
| 3390 | |
| 3391 | /** |
| 3392 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3393 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3394 | * technology specified. |
| 3395 | * |
| 3396 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3397 | */ |
| 3398 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3399 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3400 | String key = getMmTelProvisioningKey(subId, tech); |
| 3401 | editor.putInt(key, newField); |
| 3402 | editor.commit(); |
| 3403 | } |
| 3404 | |
| 3405 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3406 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3407 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3408 | } |
| 3409 | |
| 3410 | /** |
| 3411 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3412 | * carrier associated with the subscription id. |
| 3413 | */ |
| 3414 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3415 | int capability) { |
| 3416 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3417 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3418 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 3419 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3420 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3421 | false); |
| 3422 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3423 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3424 | |
| 3425 | // First check to make sure that the capability requires provisioning. |
| 3426 | switch (capability) { |
| 3427 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3428 | // intentional fallthrough |
| 3429 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3430 | if (requireVoiceVtProvisioning) { |
| 3431 | // Voice and Video requires provisioning |
| 3432 | return true; |
| 3433 | } |
| 3434 | break; |
| 3435 | } |
| 3436 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3437 | if (requireUtProvisioning) { |
| 3438 | // UT requires provisioning |
| 3439 | return true; |
| 3440 | } |
| 3441 | break; |
| 3442 | } |
| 3443 | } |
| 3444 | return false; |
| 3445 | } |
| 3446 | |
| 3447 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3448 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3449 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3450 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3451 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3452 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3453 | final long identity = Binder.clearCallingIdentity(); |
| 3454 | try { |
| 3455 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3456 | int slotId = getSlotIndex(subId); |
| 3457 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3458 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3459 | + subId + "' for key:" + key); |
| 3460 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3461 | } |
| 3462 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3463 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3464 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3465 | + subId + "' for key:" + key); |
| 3466 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3467 | } finally { |
| 3468 | Binder.restoreCallingIdentity(identity); |
| 3469 | } |
| 3470 | } |
| 3471 | |
| 3472 | @Override |
| 3473 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3474 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3475 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3476 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3477 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3478 | final long identity = Binder.clearCallingIdentity(); |
| 3479 | try { |
| 3480 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3481 | int slotId = getSlotIndex(subId); |
| 3482 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3483 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3484 | + subId + "' for key:" + key); |
| 3485 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3486 | } |
| 3487 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3488 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3489 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3490 | + subId + "' for key:" + key); |
| 3491 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3492 | } finally { |
| 3493 | Binder.restoreCallingIdentity(identity); |
| 3494 | } |
| 3495 | } |
| 3496 | |
| 3497 | @Override |
| 3498 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3499 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3500 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3501 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3502 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3503 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3504 | final long identity = Binder.clearCallingIdentity(); |
| 3505 | try { |
| 3506 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3507 | int slotId = getSlotIndex(subId); |
| 3508 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3509 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3510 | + subId + "' for key:" + key); |
| 3511 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3512 | } |
| 3513 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3514 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3515 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3516 | + "' for key:" + key); |
| 3517 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3518 | } finally { |
| 3519 | Binder.restoreCallingIdentity(identity); |
| 3520 | } |
| 3521 | } |
| 3522 | |
| 3523 | @Override |
| 3524 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3525 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3526 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3527 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3528 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3529 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3530 | final long identity = Binder.clearCallingIdentity(); |
| 3531 | try { |
| 3532 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3533 | int slotId = getSlotIndex(subId); |
| 3534 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3535 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3536 | + subId + "' for key:" + key); |
| 3537 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3538 | } |
| 3539 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3540 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3541 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3542 | + "' for key:" + key); |
| 3543 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3544 | } finally { |
| 3545 | Binder.restoreCallingIdentity(identity); |
| 3546 | } |
| 3547 | } |
| 3548 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3549 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3550 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3551 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3552 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 3553 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3554 | } |
| 3555 | return slotId; |
| 3556 | } |
| 3557 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3558 | private int getSlotIndex(int subId) { |
| 3559 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3560 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3561 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3562 | } |
| 3563 | return slotId; |
| 3564 | } |
| 3565 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3566 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3567 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3568 | */ |
| 3569 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3570 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 3571 | final int targetSdk = getTargetSdk(callingPackage); |
| 3572 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
| 3573 | return getDataNetworkTypeForSubscriber(subId, callingPackage); |
| 3574 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3575 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
| 3576 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3577 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3578 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3579 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3580 | final long identity = Binder.clearCallingIdentity(); |
| 3581 | try { |
| 3582 | final Phone phone = getPhone(subId); |
| 3583 | if (phone != null) { |
| 3584 | return phone.getServiceState().getDataNetworkType(); |
| 3585 | } else { |
| 3586 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3587 | } |
| 3588 | } finally { |
| 3589 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3590 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3591 | } |
| 3592 | |
| 3593 | /** |
| 3594 | * Returns the data network type |
| 3595 | */ |
| 3596 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3597 | public int getDataNetworkType(String callingPackage) { |
| 3598 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3599 | } |
| 3600 | |
| 3601 | /** |
| 3602 | * Returns the data network type for a subId |
| 3603 | */ |
| 3604 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3605 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3606 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3607 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3608 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3609 | } |
| 3610 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3611 | final long identity = Binder.clearCallingIdentity(); |
| 3612 | try { |
| 3613 | final Phone phone = getPhone(subId); |
| 3614 | if (phone != null) { |
| 3615 | return phone.getServiceState().getDataNetworkType(); |
| 3616 | } else { |
| 3617 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3618 | } |
| 3619 | } finally { |
| 3620 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3621 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3622 | } |
| 3623 | |
| 3624 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3625 | * Returns the Voice network type for a subId |
| 3626 | */ |
| 3627 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3628 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3629 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3630 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3631 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3632 | } |
| 3633 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3634 | final long identity = Binder.clearCallingIdentity(); |
| 3635 | try { |
| 3636 | final Phone phone = getPhone(subId); |
| 3637 | if (phone != null) { |
| 3638 | return phone.getServiceState().getVoiceNetworkType(); |
| 3639 | } else { |
| 3640 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3641 | } |
| 3642 | } finally { |
| 3643 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3644 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3645 | } |
| 3646 | |
| 3647 | /** |
| 3648 | * @return true if a ICC card is present |
| 3649 | */ |
| 3650 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3651 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3652 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3653 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3654 | } |
| 3655 | |
| 3656 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3657 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3658 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3659 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3660 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3661 | final long identity = Binder.clearCallingIdentity(); |
| 3662 | try { |
| 3663 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3664 | if (phone != null) { |
| 3665 | return phone.getIccCard().hasIccCard(); |
| 3666 | } else { |
| 3667 | return false; |
| 3668 | } |
| 3669 | } finally { |
| 3670 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3671 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3672 | } |
| 3673 | |
| 3674 | /** |
| 3675 | * Return if the current radio is LTE on CDMA. This |
| 3676 | * is a tri-state return value as for a period of time |
| 3677 | * the mode may be unknown. |
| 3678 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3679 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3680 | * @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] | 3681 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3682 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3683 | @Override |
| 3684 | public int getLteOnCdmaMode(String callingPackage) { |
| 3685 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3686 | } |
| 3687 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3688 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3689 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3690 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3691 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3692 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3693 | } |
| 3694 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3695 | final long identity = Binder.clearCallingIdentity(); |
| 3696 | try { |
| 3697 | final Phone phone = getPhone(subId); |
| 3698 | if (phone == null) { |
| 3699 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3700 | } else { |
| 3701 | return phone.getLteOnCdmaMode(); |
| 3702 | } |
| 3703 | } finally { |
| 3704 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3705 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3706 | } |
| 3707 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3708 | /** |
| 3709 | * {@hide} |
| 3710 | * Returns Default subId, 0 in the case of single standby. |
| 3711 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3712 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3713 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3714 | } |
| 3715 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3716 | private int getSlotForDefaultSubscription() { |
| 3717 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3718 | } |
| 3719 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3720 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3721 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3722 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3723 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3724 | private boolean isActiveSubscription(int subId) { |
| 3725 | return mSubscriptionController.isActiveSubId(subId); |
| 3726 | } |
| 3727 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3728 | /** |
| 3729 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3730 | */ |
| 3731 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3732 | final long identity = Binder.clearCallingIdentity(); |
| 3733 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3734 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3735 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3736 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3737 | } finally { |
| 3738 | Binder.restoreCallingIdentity(identity); |
| 3739 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3740 | } |
| 3741 | |
| 3742 | /** |
| 3743 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3744 | */ |
| 3745 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3746 | final long identity = Binder.clearCallingIdentity(); |
| 3747 | try { |
| 3748 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3749 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3750 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3751 | } finally { |
| 3752 | Binder.restoreCallingIdentity(identity); |
| 3753 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3754 | } |
| 3755 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3756 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3757 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3758 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3759 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3760 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3761 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 3762 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 3763 | if (phoneId == -1) { |
| 3764 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 3765 | + " does not correspond to an active phone"); |
| 3766 | } |
| 3767 | return PhoneFactory.getPhone(phoneId); |
| 3768 | } |
| 3769 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3770 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3771 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3772 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3773 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3774 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3775 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3776 | if (DBG) { |
| 3777 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3778 | } |
| 3779 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 3780 | p2); |
| 3781 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3782 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3783 | |
| 3784 | @Override |
| 3785 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 3786 | int slotIndex, String callingPackage, String aid, int p2) { |
| 3787 | enforceModifyPermission(); |
| 3788 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3789 | if (DBG) { |
| 3790 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 3791 | } |
| 3792 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3793 | callingPackage, aid, p2); |
| 3794 | } |
| 3795 | |
| 3796 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 3797 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3798 | final long identity = Binder.clearCallingIdentity(); |
| 3799 | try { |
| 3800 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3801 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3802 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3803 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3804 | if (bestComponent == null |
| 3805 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3806 | loge("The calling package is not allowed to access ISD-R."); |
| 3807 | throw new SecurityException( |
| 3808 | "The calling package is not allowed to access ISD-R."); |
| 3809 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3810 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3811 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3812 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3813 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 3814 | null /* workSource */); |
| 3815 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3816 | return response; |
| 3817 | } finally { |
| 3818 | Binder.restoreCallingIdentity(identity); |
| 3819 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3820 | } |
| 3821 | |
| 3822 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3823 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3824 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3825 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3826 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3827 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 3828 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3829 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3830 | @Override |
| 3831 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 3832 | enforceModifyPermission(); |
| 3833 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 3834 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3835 | channel); |
| 3836 | } |
| 3837 | |
| 3838 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3839 | final long identity = Binder.clearCallingIdentity(); |
| 3840 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3841 | if (channel < 0) { |
| 3842 | return false; |
| 3843 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3844 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 3845 | null /* workSource */); |
| 3846 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3847 | return success; |
| 3848 | } finally { |
| 3849 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3850 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3851 | } |
| 3852 | |
| 3853 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3854 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3855 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3856 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3857 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3858 | if (DBG) { |
| 3859 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3860 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3861 | + p3 + " data=" + data); |
| 3862 | } |
| 3863 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 3864 | command, p1, p2, p3, data); |
| 3865 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3866 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3867 | @Override |
| 3868 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 3869 | int command, int p1, int p2, int p3, String data) { |
| 3870 | enforceModifyPermission(); |
| 3871 | if (DBG) { |
| 3872 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 3873 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3874 | + p3 + " data=" + data); |
| 3875 | } |
| 3876 | return iccTransmitApduLogicalChannelWithPermission( |
| 3877 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 3878 | data); |
| 3879 | } |
| 3880 | |
| 3881 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 3882 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3883 | final long identity = Binder.clearCallingIdentity(); |
| 3884 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 3885 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3886 | return ""; |
| 3887 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3888 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3889 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3890 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 3891 | null /* workSource */); |
| 3892 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3893 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3894 | // Append the returned status code to the end of the response payload. |
| 3895 | String s = Integer.toHexString( |
| 3896 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3897 | if (response.payload != null) { |
| 3898 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3899 | } |
| 3900 | return s; |
| 3901 | } finally { |
| 3902 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3903 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3904 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3905 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3906 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3907 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3908 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3909 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3910 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3911 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3912 | if (DBG) { |
| 3913 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3914 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3915 | } |
| 3916 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 3917 | cla, command, p1, p2, p3, data); |
| 3918 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3919 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3920 | @Override |
| 3921 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 3922 | int command, int p1, int p2, int p3, String data) { |
| 3923 | enforceModifyPermission(); |
| 3924 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3925 | if (DBG) { |
| 3926 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 3927 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 3928 | + " data=" + data); |
| 3929 | } |
| 3930 | |
| 3931 | return iccTransmitApduBasicChannelWithPermission( |
| 3932 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 3933 | p2, p3, data); |
| 3934 | } |
| 3935 | |
| 3936 | // open APDU basic channel assuming the caller has sufficient permissions |
| 3937 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 3938 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3939 | final long identity = Binder.clearCallingIdentity(); |
| 3940 | try { |
| 3941 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3942 | && TextUtils.equals(ISDR_AID, data)) { |
| 3943 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3944 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3945 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3946 | if (bestComponent == null |
| 3947 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3948 | loge("The calling package is not allowed to select ISD-R."); |
| 3949 | throw new SecurityException( |
| 3950 | "The calling package is not allowed to select ISD-R."); |
| 3951 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3952 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3953 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3954 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3955 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 3956 | null /* workSource */); |
| 3957 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3958 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3959 | // Append the returned status code to the end of the response payload. |
| 3960 | String s = Integer.toHexString( |
| 3961 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3962 | if (response.payload != null) { |
| 3963 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3964 | } |
| 3965 | return s; |
| 3966 | } finally { |
| 3967 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3968 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3969 | } |
| 3970 | |
| 3971 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3972 | 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] | 3973 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3974 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3975 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3976 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3977 | final long identity = Binder.clearCallingIdentity(); |
| 3978 | try { |
| 3979 | if (DBG) { |
| 3980 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3981 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3982 | } |
| 3983 | |
| 3984 | IccIoResult response = |
| 3985 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3986 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3987 | subId); |
| 3988 | |
| 3989 | if (DBG) { |
| 3990 | log("Exchange SIM_IO [R]" + response); |
| 3991 | } |
| 3992 | |
| 3993 | byte[] result = null; |
| 3994 | int length = 2; |
| 3995 | if (response.payload != null) { |
| 3996 | length = 2 + response.payload.length; |
| 3997 | result = new byte[length]; |
| 3998 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3999 | } else { |
| 4000 | result = new byte[length]; |
| 4001 | } |
| 4002 | |
| 4003 | result[length - 1] = (byte) response.sw2; |
| 4004 | result[length - 2] = (byte) response.sw1; |
| 4005 | return result; |
| 4006 | } finally { |
| 4007 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4008 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4009 | } |
| 4010 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4011 | /** |
| 4012 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4013 | * on a particular subscription |
| 4014 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4015 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 4016 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4017 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 4018 | return null; |
| 4019 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4020 | |
| 4021 | final long identity = Binder.clearCallingIdentity(); |
| 4022 | try { |
| 4023 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4024 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4025 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4026 | return null; |
| 4027 | } |
| 4028 | Object response = sendRequest( |
| 4029 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4030 | if (response instanceof String[]) { |
| 4031 | return (String[]) response; |
| 4032 | } |
| 4033 | // Response is an Exception of some kind, |
| 4034 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4035 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4036 | } finally { |
| 4037 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4038 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4039 | } |
| 4040 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4041 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4042 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4043 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4044 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4045 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4046 | final long identity = Binder.clearCallingIdentity(); |
| 4047 | try { |
| 4048 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4049 | if (response.payload == null) { |
| 4050 | return ""; |
| 4051 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4052 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4053 | // Append the returned status code to the end of the response payload. |
| 4054 | String s = Integer.toHexString( |
| 4055 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4056 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4057 | return s; |
| 4058 | } finally { |
| 4059 | Binder.restoreCallingIdentity(identity); |
| 4060 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4061 | } |
| 4062 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4063 | /** |
| 4064 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4065 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4066 | * |
| 4067 | * @param itemID the ID of the item to read |
| 4068 | * @return the NV item as a String, or null on error. |
| 4069 | */ |
| 4070 | @Override |
| 4071 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4072 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4073 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4074 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4075 | |
| 4076 | final long identity = Binder.clearCallingIdentity(); |
| 4077 | try { |
| 4078 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4079 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4080 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4081 | return value; |
| 4082 | } finally { |
| 4083 | Binder.restoreCallingIdentity(identity); |
| 4084 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4085 | } |
| 4086 | |
| 4087 | /** |
| 4088 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4089 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4090 | * |
| 4091 | * @param itemID the ID of the item to read |
| 4092 | * @param itemValue the value to write, as a String |
| 4093 | * @return true on success; false on any failure |
| 4094 | */ |
| 4095 | @Override |
| 4096 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4097 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4098 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4099 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4100 | |
| 4101 | final long identity = Binder.clearCallingIdentity(); |
| 4102 | try { |
| 4103 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4104 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4105 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4106 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4107 | return success; |
| 4108 | } finally { |
| 4109 | Binder.restoreCallingIdentity(identity); |
| 4110 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4111 | } |
| 4112 | |
| 4113 | /** |
| 4114 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4115 | * Used for device configuration by some CDMA operators. |
| 4116 | * |
| 4117 | * @param preferredRoamingList byte array containing the new PRL |
| 4118 | * @return true on success; false on any failure |
| 4119 | */ |
| 4120 | @Override |
| 4121 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4122 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4123 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4124 | |
| 4125 | final long identity = Binder.clearCallingIdentity(); |
| 4126 | try { |
| 4127 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4128 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4129 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4130 | return success; |
| 4131 | } finally { |
| 4132 | Binder.restoreCallingIdentity(identity); |
| 4133 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4134 | } |
| 4135 | |
| 4136 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4137 | * 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] | 4138 | * Used for device configuration by some CDMA operators. |
| 4139 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4140 | * @param slotIndex - device slot. |
| 4141 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4142 | * @return true on success; false on any failure |
| 4143 | */ |
| 4144 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4145 | public boolean resetModemConfig(int slotIndex) { |
| 4146 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4147 | if (phone != null) { |
| 4148 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4149 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4150 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4151 | final long identity = Binder.clearCallingIdentity(); |
| 4152 | try { |
| 4153 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4154 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4155 | return success; |
| 4156 | } finally { |
| 4157 | Binder.restoreCallingIdentity(identity); |
| 4158 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4159 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4160 | return false; |
| 4161 | } |
| 4162 | |
| 4163 | /** |
| 4164 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4165 | * |
| 4166 | * @param slotIndex - device slot. |
| 4167 | * |
| 4168 | * @return true on success; false on any failure |
| 4169 | */ |
| 4170 | @Override |
| 4171 | public boolean rebootModem(int slotIndex) { |
| 4172 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4173 | if (phone != null) { |
| 4174 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4175 | mApp, phone.getSubId(), "rebootModem"); |
| 4176 | |
| 4177 | final long identity = Binder.clearCallingIdentity(); |
| 4178 | try { |
| 4179 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4180 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4181 | return success; |
| 4182 | } finally { |
| 4183 | Binder.restoreCallingIdentity(identity); |
| 4184 | } |
| 4185 | } |
| 4186 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4187 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4188 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4189 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4190 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4191 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4192 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4193 | return new String[0]; |
| 4194 | } |
| 4195 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4196 | final long identity = Binder.clearCallingIdentity(); |
| 4197 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4198 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4199 | } finally { |
| 4200 | Binder.restoreCallingIdentity(identity); |
| 4201 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4202 | } |
| 4203 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4204 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4205 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4206 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4207 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4208 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4209 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4210 | |
| 4211 | final long identity = Binder.clearCallingIdentity(); |
| 4212 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4213 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4214 | if (resolver == null) { |
| 4215 | // may happen if the device does not support IMS. |
| 4216 | return; |
| 4217 | } |
| 4218 | resolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4219 | } finally { |
| 4220 | Binder.restoreCallingIdentity(identity); |
| 4221 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4222 | } |
| 4223 | |
| 4224 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4225 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4226 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4227 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4228 | public void disableIms(int slotId) { |
| 4229 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4230 | |
| 4231 | final long identity = Binder.clearCallingIdentity(); |
| 4232 | try { |
Brad Ebinger | 9c0eb50 | 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; |
| 4237 | } |
| 4238 | resolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4239 | } finally { |
| 4240 | Binder.restoreCallingIdentity(identity); |
| 4241 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4242 | } |
| 4243 | |
| 4244 | /** |
| 4245 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4246 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4247 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4248 | */ |
| 4249 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4250 | IImsServiceFeatureCallback callback) { |
| 4251 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4252 | |
| 4253 | final long identity = Binder.clearCallingIdentity(); |
| 4254 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4255 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4256 | if (resolver == null) { |
| 4257 | // may happen if the device does not support IMS. |
| 4258 | return null; |
| 4259 | } |
| 4260 | return resolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4261 | } finally { |
| 4262 | Binder.restoreCallingIdentity(identity); |
| 4263 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4264 | } |
| 4265 | |
| 4266 | /** |
| 4267 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4268 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4269 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4270 | * listener for feature updates. |
| 4271 | */ |
| 4272 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4273 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4274 | |
| 4275 | final long identity = Binder.clearCallingIdentity(); |
| 4276 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4277 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4278 | if (resolver == null) { |
| 4279 | // may happen if the device does not support IMS. |
| 4280 | return null; |
| 4281 | } |
| 4282 | return resolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4283 | } finally { |
| 4284 | Binder.restoreCallingIdentity(identity); |
| 4285 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4286 | } |
| 4287 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4288 | /** |
| 4289 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4290 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4291 | */ |
| 4292 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4293 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4294 | |
| 4295 | final long identity = Binder.clearCallingIdentity(); |
| 4296 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4297 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4298 | if (resolver == null) { |
| 4299 | // may happen if the device does not support IMS. |
| 4300 | return null; |
| 4301 | } |
| 4302 | return resolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4303 | } finally { |
| 4304 | Binder.restoreCallingIdentity(identity); |
| 4305 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4306 | } |
| 4307 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4308 | /** |
| 4309 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4310 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4311 | */ |
| 4312 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4313 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4314 | |
| 4315 | final long identity = Binder.clearCallingIdentity(); |
| 4316 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4317 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4318 | if (resolver == null) { |
| 4319 | // may happen if the device does not support IMS. |
| 4320 | return null; |
| 4321 | } |
| 4322 | return resolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4323 | } finally { |
| 4324 | Binder.restoreCallingIdentity(identity); |
| 4325 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4326 | } |
| 4327 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4328 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4329 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4330 | * |
| 4331 | * @param slotId the slot ID that the ImsService should bind for. |
| 4332 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4333 | * ImsService is the device default ImsService. |
| 4334 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4335 | * to. |
| 4336 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4337 | * @hide |
| 4338 | */ |
| 4339 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4340 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4341 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4342 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4343 | "setImsService"); |
| 4344 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4345 | final long identity = Binder.clearCallingIdentity(); |
| 4346 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4347 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4348 | if (resolver == null) { |
| 4349 | // may happen if the device does not support IMS. |
| 4350 | return false; |
| 4351 | } |
| 4352 | return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService, |
| 4353 | packageName); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4354 | } finally { |
| 4355 | Binder.restoreCallingIdentity(identity); |
| 4356 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4357 | } |
| 4358 | |
| 4359 | /** |
| 4360 | * Return the ImsService configuration. |
| 4361 | * |
| 4362 | * @param slotId The slot that the ImsService is associated with. |
| 4363 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4364 | * the device default. |
| 4365 | * @return the package name of the ImsService configuration. |
| 4366 | */ |
| 4367 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4368 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4369 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4370 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4371 | "getImsService"); |
| 4372 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4373 | final long identity = Binder.clearCallingIdentity(); |
| 4374 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4375 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4376 | if (resolver == null) { |
| 4377 | // may happen if the device does not support IMS. |
| 4378 | return ""; |
| 4379 | } |
| 4380 | return resolver.getImsServiceConfiguration(slotId, isCarrierImsService); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4381 | } finally { |
| 4382 | Binder.restoreCallingIdentity(identity); |
| 4383 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4384 | } |
| 4385 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4386 | public void setImsRegistrationState(boolean registered) { |
| 4387 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4388 | |
| 4389 | final long identity = Binder.clearCallingIdentity(); |
| 4390 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4391 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4392 | } finally { |
| 4393 | Binder.restoreCallingIdentity(identity); |
| 4394 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4395 | } |
| 4396 | |
| 4397 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4398 | * Set the network selection mode to automatic. |
| 4399 | * |
| 4400 | */ |
| 4401 | @Override |
| 4402 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4403 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4404 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4405 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4406 | if (!isActiveSubscription(subId)) { |
| 4407 | return; |
| 4408 | } |
| 4409 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4410 | final long identity = Binder.clearCallingIdentity(); |
| 4411 | try { |
| 4412 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4413 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4414 | } finally { |
| 4415 | Binder.restoreCallingIdentity(identity); |
| 4416 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4417 | } |
| 4418 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4419 | /** |
| 4420 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4421 | * |
| 4422 | * @param subId the id of the subscription. |
| 4423 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4424 | * the operator to attach to. |
| 4425 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4426 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4427 | * normal network selection next time. |
| 4428 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4429 | */ |
| 4430 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4431 | public boolean setNetworkSelectionModeManual( |
| 4432 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4433 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4434 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4435 | |
| 4436 | if (!isActiveSubscription(subId)) { |
| 4437 | return false; |
| 4438 | } |
| 4439 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4440 | final long identity = Binder.clearCallingIdentity(); |
| 4441 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4442 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4443 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4444 | if (DBG) { |
| 4445 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4446 | + " operator: " + operatorInfo); |
| 4447 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4448 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4449 | } finally { |
| 4450 | Binder.restoreCallingIdentity(identity); |
| 4451 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4452 | } |
| 4453 | |
| 4454 | /** |
| 4455 | * Scans for available networks. |
| 4456 | */ |
| 4457 | @Override |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4458 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4459 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4460 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4461 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4462 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4463 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4464 | .setCallingPackage(callingPackage) |
| 4465 | .setCallingPid(Binder.getCallingPid()) |
| 4466 | .setCallingUid(Binder.getCallingUid()) |
| 4467 | .setMethod("getCellNetworkScanResults") |
| 4468 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4469 | .build()); |
| 4470 | switch (locationResult) { |
| 4471 | case DENIED_HARD: |
| 4472 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4473 | case DENIED_SOFT: |
| 4474 | return null; |
| 4475 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4476 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4477 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4478 | try { |
| 4479 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4480 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4481 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4482 | } finally { |
| 4483 | Binder.restoreCallingIdentity(identity); |
| 4484 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4485 | } |
| 4486 | |
| 4487 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4488 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4489 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4490 | * @param subId id of the subscription |
| 4491 | * @param request contains the radio access networks with bands/channels to scan |
| 4492 | * @param messenger callback messenger for scan results or errors |
| 4493 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4494 | * @return the id of the requested scan which can be used to stop the scan. |
| 4495 | */ |
| 4496 | @Override |
| 4497 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4498 | IBinder binder, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4499 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4500 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4501 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4502 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4503 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4504 | .setCallingPackage(callingPackage) |
| 4505 | .setCallingPid(Binder.getCallingPid()) |
| 4506 | .setCallingUid(Binder.getCallingUid()) |
| 4507 | .setMethod("requestNetworkScan") |
| 4508 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4509 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4510 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4511 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4512 | if (e != null) { |
| 4513 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 4514 | throw e; |
| 4515 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 4516 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4517 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 4518 | } |
| 4519 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4520 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4521 | int callingUid = Binder.getCallingUid(); |
| 4522 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4523 | final long identity = Binder.clearCallingIdentity(); |
| 4524 | try { |
| 4525 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4526 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4527 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4528 | } finally { |
| 4529 | Binder.restoreCallingIdentity(identity); |
| 4530 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4531 | } |
| 4532 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4533 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4534 | NetworkScanRequest request, int subId) { |
| 4535 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 4536 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 4537 | boolean hasNetworkScanPermission = |
| 4538 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 4539 | == PERMISSION_GRANTED; |
| 4540 | |
| 4541 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 4542 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 4543 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4544 | } |
| 4545 | |
| 4546 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 4547 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4548 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 4549 | return new SecurityException("Specific channels must not be" |
| 4550 | + " scanned without location access."); |
| 4551 | } |
| 4552 | } |
| 4553 | } |
| 4554 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4555 | return null; |
| 4556 | } |
| 4557 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4558 | /** |
| 4559 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4560 | * |
| 4561 | * @param subId id of the subscription |
| 4562 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4563 | */ |
| 4564 | @Override |
| 4565 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4566 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4567 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4568 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4569 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4570 | final long identity = Binder.clearCallingIdentity(); |
| 4571 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4572 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4573 | } finally { |
| 4574 | Binder.restoreCallingIdentity(identity); |
| 4575 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4576 | } |
| 4577 | |
| 4578 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4579 | * Get the calculated preferred network type. |
| 4580 | * Used for debugging incorrect network type. |
| 4581 | * |
| 4582 | * @return the preferred network type, defined in RILConstants.java. |
| 4583 | */ |
| 4584 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4585 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4586 | final Phone defaultPhone = getDefaultPhone(); |
| 4587 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4588 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4589 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4590 | } |
| 4591 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4592 | final long identity = Binder.clearCallingIdentity(); |
| 4593 | try { |
| 4594 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4595 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4596 | } finally { |
| 4597 | Binder.restoreCallingIdentity(identity); |
| 4598 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4599 | } |
| 4600 | |
| 4601 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4602 | * Get the preferred network type. |
| 4603 | * Used for device configuration by some CDMA operators. |
| 4604 | * |
| 4605 | * @return the preferred network type, defined in RILConstants.java. |
| 4606 | */ |
| 4607 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4608 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4609 | TelephonyPermissions |
| 4610 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4611 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4612 | |
| 4613 | final long identity = Binder.clearCallingIdentity(); |
| 4614 | try { |
| 4615 | if (DBG) log("getPreferredNetworkType"); |
| 4616 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4617 | int networkType = (result != null ? result[0] : -1); |
| 4618 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4619 | return networkType; |
| 4620 | } finally { |
| 4621 | Binder.restoreCallingIdentity(identity); |
| 4622 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4623 | } |
| 4624 | |
| 4625 | /** |
| 4626 | * Set the preferred network type. |
| 4627 | * Used for device configuration by some CDMA operators. |
| 4628 | * |
| 4629 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4630 | * @return true on success; false on any failure. |
| 4631 | */ |
| 4632 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4633 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4634 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4635 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4636 | |
| 4637 | final long identity = Binder.clearCallingIdentity(); |
| 4638 | try { |
| 4639 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4640 | Boolean success = (Boolean) sendRequest( |
| 4641 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4642 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4643 | if (success) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4644 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4645 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4646 | } |
| 4647 | return success; |
| 4648 | } finally { |
| 4649 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4650 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4651 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4652 | |
| 4653 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4654 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4655 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4656 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4657 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4658 | * @hide |
| 4659 | */ |
| 4660 | @Override |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4661 | public boolean getTetherApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4662 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4663 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4664 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4665 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4666 | if (phone != null) { |
| 4667 | return phone.hasMatchedTetherApnSetting(); |
| 4668 | } else { |
| 4669 | return false; |
| 4670 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4671 | } finally { |
| 4672 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4673 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4674 | } |
| 4675 | |
| 4676 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4677 | * Set mobile data enabled |
| 4678 | * Used by the user through settings etc to turn on/off mobile data |
| 4679 | * |
| 4680 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4681 | */ |
| 4682 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4683 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4684 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4685 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4686 | |
| 4687 | final long identity = Binder.clearCallingIdentity(); |
| 4688 | try { |
| 4689 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4690 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4691 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4692 | if (phone != null) { |
| 4693 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4694 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4695 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4696 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4697 | } |
| 4698 | } finally { |
| 4699 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4700 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4701 | } |
| 4702 | |
| 4703 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4704 | * Get the user enabled state of Mobile Data. |
| 4705 | * |
| 4706 | * TODO: remove and use isUserDataEnabled. |
| 4707 | * This can't be removed now because some vendor codes |
| 4708 | * calls through ITelephony directly while they should |
| 4709 | * use TelephonyManager. |
| 4710 | * |
| 4711 | * @return true on enabled |
| 4712 | */ |
| 4713 | @Override |
| 4714 | public boolean getDataEnabled(int subId) { |
| 4715 | return isUserDataEnabled(subId); |
| 4716 | } |
| 4717 | |
| 4718 | /** |
| 4719 | * Get whether mobile data is enabled per user setting. |
| 4720 | * |
| 4721 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4722 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4723 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4724 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4725 | * |
| 4726 | * @return {@code true} if data is enabled else {@code false} |
| 4727 | */ |
| 4728 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4729 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4730 | try { |
| 4731 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4732 | null); |
| 4733 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4734 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4735 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4736 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4737 | |
| 4738 | final long identity = Binder.clearCallingIdentity(); |
| 4739 | try { |
| 4740 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4741 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4742 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4743 | if (phone != null) { |
| 4744 | boolean retVal = phone.isUserDataEnabled(); |
| 4745 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4746 | return retVal; |
| 4747 | } else { |
| 4748 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4749 | return false; |
| 4750 | } |
| 4751 | } finally { |
| 4752 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4753 | } |
| 4754 | } |
| 4755 | |
| 4756 | /** |
| 4757 | * Get whether mobile data is enabled. |
| 4758 | * |
| 4759 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4760 | * whether mobile data is actually enabled. |
| 4761 | * |
| 4762 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4763 | * |
| 4764 | * @return {@code true} if data is enabled else {@code false} |
| 4765 | */ |
| 4766 | @Override |
| 4767 | public boolean isDataEnabled(int subId) { |
| 4768 | try { |
| 4769 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4770 | null); |
| 4771 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4772 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4773 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4774 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4775 | |
| 4776 | final long identity = Binder.clearCallingIdentity(); |
| 4777 | try { |
| 4778 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4779 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4780 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4781 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4782 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4783 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4784 | return retVal; |
| 4785 | } else { |
| 4786 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4787 | return false; |
| 4788 | } |
| 4789 | } finally { |
| 4790 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4791 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4792 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4793 | |
| 4794 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4795 | public int getCarrierPrivilegeStatus(int subId) { |
| 4796 | final Phone phone = getPhone(subId); |
| 4797 | if (phone == null) { |
| 4798 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4799 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4800 | } |
| 4801 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4802 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4803 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4804 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4805 | } |
| 4806 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4807 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4808 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4809 | |
| 4810 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4811 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4812 | final Phone phone = getPhone(subId); |
| 4813 | if (phone == null) { |
| 4814 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4815 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4816 | } |
| 4817 | UiccProfile profile = |
| 4818 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4819 | if (profile == null) { |
| 4820 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4821 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4822 | } |
| 4823 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 4824 | } |
| 4825 | |
| 4826 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4827 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 4828 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4829 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4830 | } |
| 4831 | |
| 4832 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 4833 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4834 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4835 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4836 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4837 | } |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4838 | |
| 4839 | return card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4840 | } |
| 4841 | |
| 4842 | @Override |
| 4843 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4844 | if (TextUtils.isEmpty(pkgName)) |
| 4845 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4846 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4847 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4848 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4849 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4850 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4851 | continue; |
| 4852 | } |
| 4853 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4854 | result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4855 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4856 | break; |
| 4857 | } |
| 4858 | } |
| 4859 | |
| 4860 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4861 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4862 | |
| 4863 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4864 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4865 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4866 | loge("phoneId " + phoneId + " is not valid."); |
| 4867 | return null; |
| 4868 | } |
| 4869 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4870 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4871 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4872 | return null ; |
| 4873 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4874 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4875 | } |
| 4876 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4877 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4878 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4879 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4880 | List<String> privilegedPackages = new ArrayList<>(); |
| 4881 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4882 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 4883 | // has UICC in that slot. |
| 4884 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4885 | if (card.hasCarrierPrivilegeRules()) { |
| 4886 | if (packages == null) { |
| 4887 | // Only check packages in user 0 for now |
| 4888 | packages = pm.getInstalledPackagesAsUser( |
| 4889 | PackageManager.MATCH_DISABLED_COMPONENTS |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4890 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4891 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4892 | } |
| 4893 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4894 | PackageInfo pkgInfo = packages.get(p); |
| 4895 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4896 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4897 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4898 | privilegedPackages.add(pkgInfo.packageName); |
| 4899 | } |
| 4900 | } |
| 4901 | } |
| 4902 | } |
| 4903 | return privilegedPackages; |
| 4904 | } |
| 4905 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4906 | @Override |
| 4907 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
| 4908 | List<String> privilegedPackages = new ArrayList<>(); |
| 4909 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4910 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 4911 | } |
| 4912 | return privilegedPackages; |
| 4913 | } |
| 4914 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4915 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4916 | final Phone phone = getPhone(subId); |
| 4917 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4918 | if (card == null) { |
| 4919 | loge("getIccId: No UICC"); |
| 4920 | return null; |
| 4921 | } |
| 4922 | String iccId = card.getIccId(); |
| 4923 | if (TextUtils.isEmpty(iccId)) { |
| 4924 | loge("getIccId: ICC ID is null or empty."); |
| 4925 | return null; |
| 4926 | } |
| 4927 | return iccId; |
| 4928 | } |
| 4929 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4930 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4931 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4932 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4933 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4934 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4935 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4936 | final long identity = Binder.clearCallingIdentity(); |
| 4937 | try { |
| 4938 | final String iccId = getIccId(subId); |
| 4939 | final Phone phone = getPhone(subId); |
| 4940 | if (phone == null) { |
| 4941 | return false; |
| 4942 | } |
| 4943 | final String subscriberId = phone.getSubscriberId(); |
| 4944 | |
| 4945 | if (DBG_MERGE) { |
| 4946 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4947 | + subscriberId + " to " + number); |
| 4948 | } |
| 4949 | |
| 4950 | if (TextUtils.isEmpty(iccId)) { |
| 4951 | return false; |
| 4952 | } |
| 4953 | |
| 4954 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4955 | |
| 4956 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4957 | if (alphaTag == null) { |
| 4958 | editor.remove(alphaTagPrefKey); |
| 4959 | } else { |
| 4960 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4961 | } |
| 4962 | |
| 4963 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4964 | // track all merged IMSIs based on line number |
| 4965 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4966 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4967 | if (number == null) { |
| 4968 | editor.remove(numberPrefKey); |
| 4969 | editor.remove(subscriberPrefKey); |
| 4970 | } else { |
| 4971 | editor.putString(numberPrefKey, number); |
| 4972 | editor.putString(subscriberPrefKey, subscriberId); |
| 4973 | } |
| 4974 | |
| 4975 | editor.commit(); |
| 4976 | return true; |
| 4977 | } finally { |
| 4978 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4979 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4980 | } |
| 4981 | |
| 4982 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4983 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4984 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4985 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4986 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4987 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4988 | return null; |
| 4989 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4990 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4991 | final long identity = Binder.clearCallingIdentity(); |
| 4992 | try { |
| 4993 | String iccId = getIccId(subId); |
| 4994 | if (iccId != null) { |
| 4995 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4996 | if (DBG_MERGE) { |
| 4997 | log("getLine1NumberForDisplay returning " |
| 4998 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 4999 | } |
| 5000 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5001 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5002 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5003 | return null; |
| 5004 | } finally { |
| 5005 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5006 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5007 | } |
| 5008 | |
| 5009 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5010 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5011 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5012 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5013 | return null; |
| 5014 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5015 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5016 | final long identity = Binder.clearCallingIdentity(); |
| 5017 | try { |
| 5018 | String iccId = getIccId(subId); |
| 5019 | if (iccId != null) { |
| 5020 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5021 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5022 | } |
| 5023 | return null; |
| 5024 | } finally { |
| 5025 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5026 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5027 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5028 | |
| 5029 | @Override |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5030 | public String[] getMergedSubscriberIds(int subId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5031 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5032 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5033 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5034 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 5035 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5036 | return null; |
| 5037 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5038 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5039 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 5040 | // the process, where TelephonyManager was instantiated. |
| 5041 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5042 | final long identity = Binder.clearCallingIdentity(); |
| 5043 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5044 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5045 | final TelephonyManager tele = TelephonyManager.from(context); |
| 5046 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5047 | |
| 5048 | // Figure out what subscribers are currently active |
| 5049 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5050 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5051 | // Only consider subs which match the current subId |
| 5052 | // This logic can be simplified. See b/131189269 for progress. |
| 5053 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5054 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 5055 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5056 | |
| 5057 | // First pass, find a number override for an active subscriber |
| 5058 | String mergeNumber = null; |
| 5059 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 5060 | for (String key : prefs.keySet()) { |
| 5061 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 5062 | final String subscriberId = (String) prefs.get(key); |
| 5063 | if (activeSubscriberIds.contains(subscriberId)) { |
| 5064 | final String iccId = key.substring( |
| 5065 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 5066 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5067 | mergeNumber = (String) prefs.get(numberKey); |
| 5068 | if (DBG_MERGE) { |
| 5069 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 5070 | + " for active subscriber " + subscriberId); |
| 5071 | } |
| 5072 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 5073 | break; |
| 5074 | } |
| 5075 | } |
| 5076 | } |
| 5077 | } |
| 5078 | |
| 5079 | // Shortcut when no active merged subscribers |
| 5080 | if (TextUtils.isEmpty(mergeNumber)) { |
| 5081 | return null; |
| 5082 | } |
| 5083 | |
| 5084 | // Second pass, find all subscribers under that line override |
| 5085 | final ArraySet<String> result = new ArraySet<>(); |
| 5086 | for (String key : prefs.keySet()) { |
| 5087 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5088 | final String number = (String) prefs.get(key); |
| 5089 | if (mergeNumber.equals(number)) { |
| 5090 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5091 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5092 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5093 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5094 | result.add(subscriberId); |
| 5095 | } |
| 5096 | } |
| 5097 | } |
| 5098 | } |
| 5099 | |
| 5100 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5101 | Arrays.sort(resultArray); |
| 5102 | if (DBG_MERGE) { |
| 5103 | Slog.d(LOG_TAG, |
| 5104 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5105 | } |
| 5106 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5107 | } finally { |
| 5108 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5109 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5110 | } |
| 5111 | |
| 5112 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5113 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5114 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5115 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5116 | |
| 5117 | final long identity = Binder.clearCallingIdentity(); |
| 5118 | try { |
| 5119 | final Phone phone = getPhone(subId); |
| 5120 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5121 | } finally { |
| 5122 | Binder.restoreCallingIdentity(identity); |
| 5123 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5124 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5125 | |
| 5126 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5127 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5128 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5129 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5130 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5131 | |
| 5132 | final long identity = Binder.clearCallingIdentity(); |
| 5133 | try { |
| 5134 | final Phone phone = getPhone(subId); |
| 5135 | if (phone == null) { |
| 5136 | return false; |
| 5137 | } |
| 5138 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5139 | cdmaNonRoamingList); |
| 5140 | } finally { |
| 5141 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5142 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5143 | } |
| 5144 | |
| 5145 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5146 | @Deprecated |
| 5147 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5148 | enforceModifyPermission(); |
| 5149 | |
| 5150 | int returnValue = 0; |
| 5151 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5152 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5153 | if(result.exception == null) { |
| 5154 | if (result.result != null) { |
| 5155 | byte[] responseData = (byte[])(result.result); |
| 5156 | if(responseData.length > oemResp.length) { |
| 5157 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5158 | responseData.length + "bytes. Buffer Size is " + |
| 5159 | oemResp.length + "bytes."); |
| 5160 | } |
| 5161 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5162 | returnValue = responseData.length; |
| 5163 | } |
| 5164 | } else { |
| 5165 | CommandException ex = (CommandException) result.exception; |
| 5166 | returnValue = ex.getCommandError().ordinal(); |
| 5167 | if(returnValue > 0) returnValue *= -1; |
| 5168 | } |
| 5169 | } catch (RuntimeException e) { |
| 5170 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5171 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5172 | if(returnValue > 0) returnValue *= -1; |
| 5173 | } |
| 5174 | |
| 5175 | return returnValue; |
| 5176 | } |
| 5177 | |
| 5178 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5179 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5180 | try { |
| 5181 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5182 | } catch (RuntimeException e) { |
| 5183 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5184 | } |
| 5185 | } |
| 5186 | |
| 5187 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5188 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5189 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5190 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5191 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5192 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5193 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5194 | final long identity = Binder.clearCallingIdentity(); |
| 5195 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5196 | TelephonyPermissions |
| 5197 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5198 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5199 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5200 | } finally { |
| 5201 | Binder.restoreCallingIdentity(identity); |
| 5202 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5203 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5204 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5205 | |
| 5206 | @Override |
| 5207 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5208 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5209 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5210 | |
| 5211 | final long identity = Binder.clearCallingIdentity(); |
| 5212 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5213 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5214 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5215 | } finally { |
| 5216 | Binder.restoreCallingIdentity(identity); |
| 5217 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5218 | } |
| 5219 | |
| 5220 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5221 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5222 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5223 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5224 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5225 | return false; |
| 5226 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5227 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5228 | final long identity = Binder.clearCallingIdentity(); |
| 5229 | try { |
| 5230 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5231 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5232 | // In the long run, we may instead need to check if there exists a connection service |
| 5233 | // which can support video calling. |
| 5234 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5235 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5236 | return imsManager.isVtEnabledByPlatform() |
| 5237 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5238 | && imsManager.isVtEnabledByUser(); |
| 5239 | } finally { |
| 5240 | Binder.restoreCallingIdentity(identity); |
| 5241 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5242 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5243 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5244 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5245 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 5246 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5247 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5248 | return false; |
| 5249 | } |
| 5250 | |
| 5251 | final long identity = Binder.clearCallingIdentity(); |
| 5252 | try { |
| 5253 | CarrierConfigManager configManager = |
| 5254 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5255 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5256 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5257 | } finally { |
| 5258 | Binder.restoreCallingIdentity(identity); |
| 5259 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5260 | } |
| 5261 | |
| 5262 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5263 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 5264 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5265 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5266 | return false; |
| 5267 | } |
| 5268 | |
| 5269 | final long identity = Binder.clearCallingIdentity(); |
| 5270 | try { |
| 5271 | CarrierConfigManager configManager = |
| 5272 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5273 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5274 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5275 | } finally { |
| 5276 | Binder.restoreCallingIdentity(identity); |
| 5277 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5278 | } |
| 5279 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5280 | @Override |
| 5281 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5282 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5283 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5284 | } |
| 5285 | |
| 5286 | @Override |
| 5287 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5288 | final long identity = Binder.clearCallingIdentity(); |
| 5289 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5290 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5291 | } finally { |
| 5292 | Binder.restoreCallingIdentity(identity); |
| 5293 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5294 | } |
| 5295 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5296 | /** |
| 5297 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5298 | * support for the feature and device firmware support. |
| 5299 | * |
| 5300 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5301 | */ |
| 5302 | @Override |
| 5303 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5304 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5305 | final Phone phone = getPhone(subscriptionId); |
| 5306 | if (phone == null) { |
| 5307 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5308 | return false; |
| 5309 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5310 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5311 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5312 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5313 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5314 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5315 | return isCarrierSupported && isDeviceSupported; |
| 5316 | } finally { |
| 5317 | Binder.restoreCallingIdentity(identity); |
| 5318 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5319 | } |
| 5320 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5321 | /** |
| 5322 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier |
| 5323 | * both also support RTT. |
| 5324 | */ |
| 5325 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5326 | final long identity = Binder.clearCallingIdentity(); |
| 5327 | try { |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5328 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5329 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5330 | } finally { |
| 5331 | Binder.restoreCallingIdentity(identity); |
| 5332 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5333 | } |
| 5334 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5335 | /** |
| 5336 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5337 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5338 | * |
| 5339 | * <p>Requires Permission: |
| 5340 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5341 | */ |
| 5342 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5343 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5344 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5345 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5346 | return null; |
| 5347 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5348 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 5349 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 5350 | callingPackage, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5351 | return null; |
| 5352 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5353 | |
| 5354 | final long identity = Binder.clearCallingIdentity(); |
| 5355 | try { |
| 5356 | return phone.getDeviceId(); |
| 5357 | } finally { |
| 5358 | Binder.restoreCallingIdentity(identity); |
| 5359 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5360 | } |
| 5361 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5362 | /** |
| 5363 | * {@hide} |
| 5364 | * Returns the IMS Registration Status on a particular subid |
| 5365 | * |
| 5366 | * @param subId |
| 5367 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5368 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5369 | Phone phone = getPhone(subId); |
| 5370 | if (phone != null) { |
| 5371 | return phone.isImsRegistered(); |
| 5372 | } else { |
| 5373 | return false; |
| 5374 | } |
| 5375 | } |
| 5376 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5377 | @Override |
| 5378 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5379 | final long identity = Binder.clearCallingIdentity(); |
| 5380 | try { |
| 5381 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5382 | } finally { |
| 5383 | Binder.restoreCallingIdentity(identity); |
| 5384 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5385 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5386 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5387 | @Override |
| 5388 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 5389 | final long identity = Binder.clearCallingIdentity(); |
| 5390 | try { |
| 5391 | Phone phone = getPhone(subscriptionId); |
| 5392 | if (phone == null) { |
| 5393 | return null; |
| 5394 | } |
| 5395 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 5396 | } finally { |
| 5397 | Binder.restoreCallingIdentity(identity); |
| 5398 | } |
| 5399 | } |
| 5400 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5401 | /** |
| 5402 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5403 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5404 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5405 | final long identity = Binder.clearCallingIdentity(); |
| 5406 | try { |
| 5407 | Phone phone = getPhone(subId); |
| 5408 | if (phone != null) { |
| 5409 | return phone.isWifiCallingEnabled(); |
| 5410 | } else { |
| 5411 | return false; |
| 5412 | } |
| 5413 | } finally { |
| 5414 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5415 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5416 | } |
| 5417 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5418 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5419 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5420 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5421 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5422 | final long identity = Binder.clearCallingIdentity(); |
| 5423 | try { |
| 5424 | Phone phone = getPhone(subId); |
| 5425 | if (phone != null) { |
| 5426 | return phone.isVideoEnabled(); |
| 5427 | } else { |
| 5428 | return false; |
| 5429 | } |
| 5430 | } finally { |
| 5431 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5432 | } |
| 5433 | } |
| 5434 | |
| 5435 | /** |
| 5436 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5437 | * defined in {@link ImsRegistrationImplBase}. |
| 5438 | */ |
| 5439 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5440 | final long identity = Binder.clearCallingIdentity(); |
| 5441 | try { |
| 5442 | Phone phone = getPhone(subId); |
| 5443 | if (phone != null) { |
| 5444 | return phone.getImsRegistrationTech(); |
| 5445 | } else { |
| 5446 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5447 | } |
| 5448 | } finally { |
| 5449 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5450 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5451 | } |
| 5452 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5453 | @Override |
| 5454 | public void factoryReset(int subId) { |
| 5455 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5456 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5457 | return; |
| 5458 | } |
| 5459 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5460 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5461 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5462 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5463 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5464 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5465 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5466 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5467 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5468 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5469 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5470 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5471 | // There has been issues when Sms raw table somehow stores orphan |
| 5472 | // fragments. They lead to garbled message when new fragments come |
| 5473 | // in and combined with those stale ones. In case this happens again, |
| 5474 | // user can reset all network settings which will clean up this table. |
| 5475 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5476 | } finally { |
| 5477 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5478 | } |
| 5479 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5480 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5481 | private void cleanUpSmsRawTable(Context context) { |
| 5482 | ContentResolver resolver = context.getContentResolver(); |
| 5483 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 5484 | resolver.delete(uri, null, null); |
| 5485 | } |
| 5486 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5487 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5488 | public String getSimLocaleForSubscriber(int subId) { |
| 5489 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5490 | final Phone phone = getPhone(subId); |
| 5491 | if (phone == null) { |
| 5492 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 5493 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5494 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5495 | final long identity = Binder.clearCallingIdentity(); |
| 5496 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5497 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5498 | phone.getContext().getOpPackageName()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 5499 | if (info == null) { |
| 5500 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 5501 | return null; |
| 5502 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5503 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5504 | // preferences (EF-PL and EF-LI)... |
| 5505 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5506 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5507 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5508 | if (localeFromDefaultSim != null) { |
| 5509 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5510 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5511 | + localeFromDefaultSim); |
| 5512 | return localeFromDefaultSim.toLanguageTag(); |
| 5513 | } else { |
| 5514 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5515 | } |
| 5516 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5517 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5518 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5519 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5520 | // the SIM and carrier preferences does not include a country we add the country |
| 5521 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5522 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5523 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5524 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5525 | return mccLocale.toLanguageTag(); |
| 5526 | } |
| 5527 | |
| 5528 | if (DBG) log("No locale found - returning null"); |
| 5529 | return null; |
| 5530 | } finally { |
| 5531 | Binder.restoreCallingIdentity(identity); |
| 5532 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5533 | } |
| 5534 | |
| 5535 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5536 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5537 | } |
| 5538 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5539 | /** |
| 5540 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5541 | */ |
| 5542 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5543 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5544 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5545 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5546 | private final ModemActivityInfo mLastModemActivityInfo = |
| 5547 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 5548 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5549 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5550 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5551 | * representing the state of the modem. |
| 5552 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5553 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5554 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5555 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5556 | */ |
| 5557 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5558 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5559 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5560 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5561 | |
| 5562 | final long identity = Binder.clearCallingIdentity(); |
| 5563 | try { |
| 5564 | ModemActivityInfo ret = null; |
| 5565 | synchronized (mLastModemActivityInfo) { |
| 5566 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5567 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5568 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5569 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5570 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 5571 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5572 | mergedTxTimeMs[i] = info.getTxTimeMillis()[i] |
| 5573 | + mLastModemActivityInfo.getTxTimeMillis()[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5574 | } |
| 5575 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5576 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 5577 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5578 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5579 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 5580 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 5581 | mLastModemActivityInfo.setRxTimeMillis( |
| 5582 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 5583 | mLastModemActivityInfo.setEnergyUsed( |
| 5584 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5585 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5586 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5587 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5588 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 5589 | mLastModemActivityInfo.getTxTimeMillis(), |
| 5590 | mLastModemActivityInfo.getRxTimeMillis(), |
| 5591 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5592 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5593 | Bundle bundle = new Bundle(); |
| 5594 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 5595 | result.send(0, bundle); |
| 5596 | } finally { |
| 5597 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5598 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5599 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5600 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5601 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 5602 | // less than total activity duration. |
| 5603 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 5604 | if (info == null) { |
| 5605 | return false; |
| 5606 | } |
| 5607 | int activityDurationMs = |
| 5608 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 5609 | int totalTxTimeMs = 0; |
| 5610 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 5611 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 5612 | } |
| 5613 | return (info.isValid() |
| 5614 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 5615 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 5616 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 5617 | && (totalTxTimeMs <= activityDurationMs)); |
| 5618 | } |
| 5619 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5620 | /** |
| 5621 | * {@hide} |
| 5622 | * Returns the service state information on specified subscription. |
| 5623 | */ |
| 5624 | @Override |
| 5625 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5626 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5627 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5628 | return null; |
| 5629 | } |
| 5630 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5631 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 5632 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5633 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5634 | .setCallingPackage(callingPackage) |
| 5635 | .setCallingPid(Binder.getCallingPid()) |
| 5636 | .setCallingUid(Binder.getCallingUid()) |
| 5637 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5638 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5639 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5640 | .build()); |
| 5641 | |
| 5642 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 5643 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5644 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5645 | .setCallingPackage(callingPackage) |
| 5646 | .setCallingPid(Binder.getCallingPid()) |
| 5647 | .setCallingUid(Binder.getCallingUid()) |
| 5648 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5649 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5650 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5651 | .build()); |
| 5652 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 5653 | boolean hasFinePermission = |
| 5654 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5655 | boolean hasCoarsePermission = |
| 5656 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5657 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5658 | final long identity = Binder.clearCallingIdentity(); |
| 5659 | try { |
| 5660 | final Phone phone = getPhone(subId); |
| 5661 | if (phone == null) { |
| 5662 | return null; |
| 5663 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5664 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5665 | ServiceState ss = phone.getServiceState(); |
| 5666 | |
| 5667 | // Scrub out the location info in ServiceState depending on what level of access |
| 5668 | // the caller has. |
| 5669 | if (hasFinePermission) return ss; |
| 5670 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 5671 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5672 | } finally { |
| 5673 | Binder.restoreCallingIdentity(identity); |
| 5674 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5675 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5676 | |
| 5677 | /** |
| 5678 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5679 | * |
| 5680 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5681 | * voicemail ringtone. |
| 5682 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5683 | * PhoneAccount. |
| 5684 | */ |
| 5685 | @Override |
| 5686 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 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 | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5691 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 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 | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5694 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5695 | } finally { |
| 5696 | Binder.restoreCallingIdentity(identity); |
| 5697 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5698 | } |
| 5699 | |
| 5700 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5701 | * Sets the per-account voicemail ringtone. |
| 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 ringtone. |
| 5708 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5709 | * PhoneAccount. |
| 5710 | */ |
| 5711 | @Override |
| 5712 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5713 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 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 | f782e56 | 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 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5721 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5722 | |
| 5723 | final long identity = Binder.clearCallingIdentity(); |
| 5724 | try { |
| 5725 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5726 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5727 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5728 | } |
| 5729 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 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 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5736 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5737 | * |
| 5738 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5739 | * voicemail vibration setting. |
| 5740 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5741 | */ |
| 5742 | @Override |
| 5743 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5744 | final long identity = Binder.clearCallingIdentity(); |
| 5745 | try { |
| 5746 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5747 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5748 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5749 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5750 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5751 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5752 | } finally { |
| 5753 | Binder.restoreCallingIdentity(identity); |
| 5754 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5755 | } |
| 5756 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5757 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5758 | * Sets the per-account voicemail vibration. |
| 5759 | * |
| 5760 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5761 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5762 | * |
| 5763 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5764 | * voicemail vibration setting. |
| 5765 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5766 | * specific PhoneAccount. |
| 5767 | */ |
| 5768 | @Override |
| 5769 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5770 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5771 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5772 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5773 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5774 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5775 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5776 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5777 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5778 | } |
| 5779 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5780 | final long identity = Binder.clearCallingIdentity(); |
| 5781 | try { |
| 5782 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5783 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5784 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5785 | } |
| 5786 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5787 | } finally { |
| 5788 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5789 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5790 | } |
| 5791 | |
| 5792 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5793 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5794 | * |
| 5795 | * @throws SecurityException if the caller does not have the required permission |
| 5796 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5797 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5798 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5799 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5800 | } |
| 5801 | |
| 5802 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5803 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5804 | * permission. |
| 5805 | * |
| 5806 | * @throws SecurityException if the caller does not have the required permission |
| 5807 | */ |
| 5808 | private void enforceSendSmsPermission() { |
| 5809 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5810 | } |
| 5811 | |
| 5812 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5813 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5814 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5815 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5816 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5817 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5818 | final long identity = Binder.clearCallingIdentity(); |
| 5819 | try { |
| 5820 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5821 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5822 | if (componentName == null) { |
| 5823 | throw new SecurityException( |
| 5824 | "Caller not current active visual voicemail package[null]"); |
| 5825 | } |
| 5826 | String vvmPackage = componentName.getPackageName(); |
| 5827 | if (!callingPackage.equals(vvmPackage)) { |
| 5828 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5829 | + vvmPackage + "]"); |
| 5830 | } |
| 5831 | } finally { |
| 5832 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5833 | } |
| 5834 | } |
| 5835 | |
| 5836 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5837 | * Return the application ID for the app type. |
| 5838 | * |
| 5839 | * @param subId the subscription ID that this request applies to. |
| 5840 | * @param appType the uicc app type. |
| 5841 | * @return Application ID for specificied app type, or null if no uicc. |
| 5842 | */ |
| 5843 | @Override |
| 5844 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5845 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5846 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5847 | |
| 5848 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5849 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5850 | if (phone == null) { |
| 5851 | return null; |
| 5852 | } |
| 5853 | String aid = null; |
| 5854 | try { |
| 5855 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5856 | .getApplicationByType(appType).getAid(); |
| 5857 | } catch (Exception e) { |
| 5858 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5859 | } |
| 5860 | return aid; |
| 5861 | } finally { |
| 5862 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5863 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5864 | } |
| 5865 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5866 | /** |
| 5867 | * Return the Electronic Serial Number. |
| 5868 | * |
| 5869 | * @param subId the subscription ID that this request applies to. |
| 5870 | * @return ESN or null if error. |
| 5871 | */ |
| 5872 | @Override |
| 5873 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5874 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5875 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5876 | |
| 5877 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5878 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5879 | if (phone == null) { |
| 5880 | return null; |
| 5881 | } |
| 5882 | String esn = null; |
| 5883 | try { |
| 5884 | esn = phone.getEsn(); |
| 5885 | } catch (Exception e) { |
| 5886 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5887 | } |
| 5888 | return esn; |
| 5889 | } finally { |
| 5890 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5891 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5892 | } |
| 5893 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5894 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5895 | * Return the Preferred Roaming List Version. |
| 5896 | * |
| 5897 | * @param subId the subscription ID that this request applies to. |
| 5898 | * @return PRLVersion or null if error. |
| 5899 | */ |
| 5900 | @Override |
| 5901 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5902 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5903 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5904 | |
| 5905 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5906 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5907 | if (phone == null) { |
| 5908 | return null; |
| 5909 | } |
| 5910 | String cdmaPrlVersion = null; |
| 5911 | try { |
| 5912 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 5913 | } catch (Exception e) { |
| 5914 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 5915 | } |
| 5916 | return cdmaPrlVersion; |
| 5917 | } finally { |
| 5918 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5919 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5920 | } |
| 5921 | |
| 5922 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5923 | * Get snapshot of Telephony histograms |
| 5924 | * @return List of Telephony histograms |
| 5925 | * @hide |
| 5926 | */ |
| 5927 | @Override |
| 5928 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5929 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5930 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5931 | |
| 5932 | final long identity = Binder.clearCallingIdentity(); |
| 5933 | try { |
| 5934 | return RIL.getTelephonyRILTimingHistograms(); |
| 5935 | } finally { |
| 5936 | Binder.restoreCallingIdentity(identity); |
| 5937 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5938 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5939 | |
| 5940 | /** |
| 5941 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5942 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 5943 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5944 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5945 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5946 | * @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] | 5947 | */ |
| 5948 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5949 | @TelephonyManager.SetCarrierRestrictionResult |
| 5950 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5951 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5952 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5953 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5954 | if (carrierRestrictionRules == null) { |
| 5955 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5956 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5957 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5958 | final long identity = Binder.clearCallingIdentity(); |
| 5959 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5960 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5961 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5962 | } finally { |
| 5963 | Binder.restoreCallingIdentity(identity); |
| 5964 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5965 | } |
| 5966 | |
| 5967 | /** |
| 5968 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5969 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 5970 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5971 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5972 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5973 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5974 | */ |
| 5975 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5976 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5977 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5978 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5979 | |
| 5980 | final long identity = Binder.clearCallingIdentity(); |
| 5981 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5982 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 5983 | if (response instanceof CarrierRestrictionRules) { |
| 5984 | return (CarrierRestrictionRules) response; |
| 5985 | } |
| 5986 | // Response is an Exception of some kind, |
| 5987 | // which is signalled to the user as a NULL retval |
| 5988 | return null; |
| 5989 | } catch (Exception e) { |
| 5990 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 5991 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5992 | } finally { |
| 5993 | Binder.restoreCallingIdentity(identity); |
| 5994 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5995 | } |
| 5996 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5997 | /** |
| 5998 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 5999 | * @param subId the subscription ID that this action applies to. |
| 6000 | * @param enabled control enable or disable metered apns. |
| 6001 | * {@hide} |
| 6002 | */ |
| 6003 | @Override |
| 6004 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 6005 | enforceModifyPermission(); |
| 6006 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6007 | |
| 6008 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6009 | if (phone == null) { |
| 6010 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 6011 | return; |
| 6012 | } |
| 6013 | try { |
| 6014 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 6015 | } catch (Exception e) { |
| 6016 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6017 | } finally { |
| 6018 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6019 | } |
| 6020 | } |
| 6021 | |
| 6022 | /** |
| 6023 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 6024 | * @param subId the subscription ID that this action applies to. |
| 6025 | * @param enabled control enable or disable radio. |
| 6026 | * {@hide} |
| 6027 | */ |
| 6028 | @Override |
| 6029 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 6030 | enforceModifyPermission(); |
| 6031 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6032 | |
| 6033 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6034 | if (phone == null) { |
| 6035 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 6036 | return; |
| 6037 | } |
| 6038 | try { |
| 6039 | phone.carrierActionSetRadioEnabled(enabled); |
| 6040 | } catch (Exception e) { |
| 6041 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6042 | } finally { |
| 6043 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6044 | } |
| 6045 | } |
| 6046 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6047 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6048 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 6049 | * network status based on which carrier apps could apply actions accordingly, |
| 6050 | * enable/disable default url handler for example. |
| 6051 | * |
| 6052 | * @param subId the subscription ID that this action applies to. |
| 6053 | * @param report control start/stop reporting the default network status. |
| 6054 | * {@hide} |
| 6055 | */ |
| 6056 | @Override |
| 6057 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 6058 | enforceModifyPermission(); |
| 6059 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6060 | |
| 6061 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6062 | if (phone == null) { |
| 6063 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 6064 | return; |
| 6065 | } |
| 6066 | try { |
| 6067 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 6068 | } catch (Exception e) { |
| 6069 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6070 | } finally { |
| 6071 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6072 | } |
| 6073 | } |
| 6074 | |
| 6075 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 6076 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 6077 | * @param subId the subscription ID that this action applies to. |
| 6078 | * {@hide} |
| 6079 | */ |
| 6080 | @Override |
| 6081 | public void carrierActionResetAll(int subId) { |
| 6082 | enforceModifyPermission(); |
| 6083 | final Phone phone = getPhone(subId); |
| 6084 | if (phone == null) { |
| 6085 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 6086 | return; |
| 6087 | } |
| 6088 | try { |
| 6089 | phone.carrierActionResetAll(); |
| 6090 | } catch (Exception e) { |
| 6091 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 6092 | } |
| 6093 | } |
| 6094 | |
| 6095 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6096 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 6097 | * bug report is being generated. |
| 6098 | */ |
| 6099 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 6100 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6101 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6102 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 6103 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 6104 | + Binder.getCallingPid() |
| 6105 | + ", uid=" + Binder.getCallingUid() |
| 6106 | + "without permission " |
| 6107 | + android.Manifest.permission.DUMP); |
| 6108 | return; |
| 6109 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6110 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6111 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6112 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6113 | @Override |
| 6114 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 6115 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 6116 | throws RemoteException { |
| 6117 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 6118 | } |
| 6119 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6120 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6121 | * Get aggregated video call data usage since boot. |
| 6122 | * |
| 6123 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6124 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6125 | * {@hide} |
| 6126 | */ |
| 6127 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6128 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6129 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 6130 | null); |
| 6131 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6132 | final long identity = Binder.clearCallingIdentity(); |
| 6133 | try { |
| 6134 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 6135 | // records the delta with the corresponding network identity. |
| 6136 | // We just return the total video call data usage snapshot since boot. |
| 6137 | Phone phone = getPhone(subId); |
| 6138 | if (phone != null) { |
| 6139 | return phone.getVtDataUsage(perUidStats); |
| 6140 | } |
| 6141 | return null; |
| 6142 | } finally { |
| 6143 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6144 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6145 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6146 | |
| 6147 | /** |
| 6148 | * Policy control of data connection. Usually used when data limit is passed. |
| 6149 | * @param enabled True if enabling the data, otherwise disabling. |
| 6150 | * @param subId Subscription index |
| 6151 | * {@hide} |
| 6152 | */ |
| 6153 | @Override |
| 6154 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6155 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6156 | |
| 6157 | final long identity = Binder.clearCallingIdentity(); |
| 6158 | try { |
| 6159 | Phone phone = getPhone(subId); |
| 6160 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6161 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6162 | } |
| 6163 | } finally { |
| 6164 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6165 | } |
| 6166 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6167 | |
| 6168 | /** |
| 6169 | * Get Client request stats |
| 6170 | * @return List of Client Request Stats |
| 6171 | * @hide |
| 6172 | */ |
| 6173 | @Override |
| 6174 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6175 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6176 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6177 | return null; |
| 6178 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6179 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6180 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6181 | final long identity = Binder.clearCallingIdentity(); |
| 6182 | try { |
| 6183 | if (phone != null) { |
| 6184 | return phone.getClientRequestStats(); |
| 6185 | } |
| 6186 | |
| 6187 | return null; |
| 6188 | } finally { |
| 6189 | Binder.restoreCallingIdentity(identity); |
| 6190 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6191 | } |
| 6192 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6193 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6194 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6195 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6196 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6197 | |
| 6198 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6199 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6200 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6201 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6202 | * @param state State of SIM (power down, power up, pass through) |
| 6203 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6204 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6205 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6206 | * |
| 6207 | **/ |
| 6208 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6209 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6210 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6211 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6212 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6213 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6214 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6215 | final long identity = Binder.clearCallingIdentity(); |
| 6216 | try { |
| 6217 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6218 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6219 | } |
| 6220 | } finally { |
| 6221 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6222 | } |
| 6223 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6224 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6225 | private boolean isUssdApiAllowed(int subId) { |
| 6226 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6227 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6228 | if (configManager == null) { |
| 6229 | return false; |
| 6230 | } |
| 6231 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6232 | if (pb == null) { |
| 6233 | return false; |
| 6234 | } |
| 6235 | return pb.getBoolean( |
| 6236 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6237 | } |
| 6238 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6239 | /** |
| 6240 | * Check if phone is in emergency callback mode |
| 6241 | * @return true if phone is in emergency callback mode |
| 6242 | * @param subId sub id |
| 6243 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6244 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6245 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6246 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6247 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6248 | |
| 6249 | final long identity = Binder.clearCallingIdentity(); |
| 6250 | try { |
| 6251 | if (phone != null) { |
| 6252 | return phone.isInEcm(); |
| 6253 | } else { |
| 6254 | return false; |
| 6255 | } |
| 6256 | } finally { |
| 6257 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6258 | } |
| 6259 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6260 | |
| 6261 | /** |
| 6262 | * Get the current signal strength information for the given subscription. |
| 6263 | * Because this information is not updated when the device is in a low power state |
| 6264 | * it should not be relied-upon to be current. |
| 6265 | * @param subId Subscription index |
| 6266 | * @return the most recent cached signal strength info from the modem |
| 6267 | */ |
| 6268 | @Override |
| 6269 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6270 | final long identity = Binder.clearCallingIdentity(); |
| 6271 | try { |
| 6272 | Phone p = getPhone(subId); |
| 6273 | if (p == null) { |
| 6274 | return null; |
| 6275 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6276 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6277 | return p.getSignalStrength(); |
| 6278 | } finally { |
| 6279 | Binder.restoreCallingIdentity(identity); |
| 6280 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6281 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6282 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6283 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6284 | * Get the current modem radio state for the given slot. |
| 6285 | * @param slotIndex slot index. |
| 6286 | * @param callingPackage the name of the package making the call. |
| 6287 | * @return the current radio power state from the modem |
| 6288 | */ |
| 6289 | @Override |
| 6290 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 6291 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6292 | if (phone != null) { |
| 6293 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6294 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 6295 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6296 | } |
| 6297 | |
| 6298 | final long identity = Binder.clearCallingIdentity(); |
| 6299 | try { |
| 6300 | return phone.getRadioPowerState(); |
| 6301 | } finally { |
| 6302 | Binder.restoreCallingIdentity(identity); |
| 6303 | } |
| 6304 | } |
| 6305 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6306 | } |
| 6307 | |
| 6308 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6309 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6310 | * |
| 6311 | * <p>Requires one of the following permissions: |
| 6312 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6313 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6314 | * privileges. |
| 6315 | * |
| 6316 | * @param subId subscription id |
| 6317 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6318 | * {@code false}. |
| 6319 | */ |
| 6320 | @Override |
| 6321 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6322 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6323 | null /* message */); |
| 6324 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6325 | boolean isEnabled = false; |
| 6326 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6327 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6328 | Phone phone = getPhone(subId); |
| 6329 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6330 | } catch (Exception e) { |
| 6331 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6332 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6333 | } finally { |
| 6334 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6335 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6336 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6337 | } |
| 6338 | |
| 6339 | |
| 6340 | /** |
| 6341 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6342 | * |
| 6343 | * <p> Requires permission: |
| 6344 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6345 | * privileges. |
| 6346 | * |
| 6347 | * @param subId subscription id |
| 6348 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6349 | */ |
| 6350 | @Override |
| 6351 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6352 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6353 | mApp, subId, "setDataRoamingEnabled"); |
| 6354 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6355 | final long identity = Binder.clearCallingIdentity(); |
| 6356 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6357 | Phone phone = getPhone(subId); |
| 6358 | if (phone != null) { |
| 6359 | phone.setDataRoamingEnabled(isEnabled); |
| 6360 | } |
| 6361 | } finally { |
| 6362 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6363 | } |
| 6364 | } |
| 6365 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6366 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6367 | public boolean isManualNetworkSelectionAllowed(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6368 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6369 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6370 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6371 | boolean isAllowed = true; |
| 6372 | final long identity = Binder.clearCallingIdentity(); |
| 6373 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6374 | Phone phone = getPhone(subId); |
| 6375 | if (phone != null) { |
| 6376 | isAllowed = phone.isCspPlmnEnabled(); |
| 6377 | } |
| 6378 | } finally { |
| 6379 | Binder.restoreCallingIdentity(identity); |
| 6380 | } |
| 6381 | return isAllowed; |
| 6382 | } |
| 6383 | |
| 6384 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6385 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6386 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6387 | try { |
| 6388 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6389 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6390 | } catch (SecurityException e) { |
| 6391 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6392 | // has carrier privileges on an active UICC |
| 6393 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6394 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6395 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6396 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6397 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6398 | |
| 6399 | final long identity = Binder.clearCallingIdentity(); |
| 6400 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6401 | UiccController uiccController = UiccController.getInstance(); |
| 6402 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6403 | if (hasReadPermission) { |
| 6404 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6405 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6406 | |
| 6407 | // Remove private info if the caller doesn't have access |
| 6408 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6409 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6410 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 6411 | // is available |
| 6412 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 6413 | if (card == null || card.getUiccProfile() == null) { |
| 6414 | // assume no access if the card or profile is unavailable |
| 6415 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6416 | continue; |
| 6417 | } |
| 6418 | UiccProfile profile = card.getUiccProfile(); |
| 6419 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6420 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6421 | filteredInfos.add(cardInfo); |
| 6422 | } else { |
| 6423 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6424 | } |
| 6425 | } |
| 6426 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6427 | } finally { |
| 6428 | Binder.restoreCallingIdentity(identity); |
| 6429 | } |
| 6430 | } |
| 6431 | |
| 6432 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6433 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6434 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6435 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6436 | final long identity = Binder.clearCallingIdentity(); |
| 6437 | try { |
| 6438 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6439 | if (slots == null) { |
| 6440 | Rlog.i(LOG_TAG, "slots is null."); |
| 6441 | return null; |
| 6442 | } |
| 6443 | |
| 6444 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6445 | for (int i = 0; i < slots.length; i++) { |
| 6446 | UiccSlot slot = slots[i]; |
| 6447 | if (slot == null) { |
| 6448 | continue; |
| 6449 | } |
| 6450 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6451 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6452 | UiccCard card = slot.getUiccCard(); |
| 6453 | if (card != null) { |
| 6454 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6455 | } else { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6456 | cardId = slot.getIccId(); |
| 6457 | } |
| 6458 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 6459 | if (cardId != null) { |
| 6460 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 6461 | // if cardId is an EID, it's all digits so this is fine |
| 6462 | cardId = IccUtils.stripTrailingFs(cardId); |
| 6463 | } |
| 6464 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6465 | int cardState = 0; |
| 6466 | switch (slot.getCardState()) { |
| 6467 | case CARDSTATE_ABSENT: |
| 6468 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6469 | break; |
| 6470 | case CARDSTATE_PRESENT: |
| 6471 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6472 | break; |
| 6473 | case CARDSTATE_ERROR: |
| 6474 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6475 | break; |
| 6476 | case CARDSTATE_RESTRICTED: |
| 6477 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6478 | break; |
| 6479 | default: |
| 6480 | break; |
| 6481 | |
| 6482 | } |
| 6483 | |
| 6484 | infos[i] = new UiccSlotInfo( |
| 6485 | slot.isActive(), |
| 6486 | slot.isEuicc(), |
| 6487 | cardId, |
| 6488 | cardState, |
| 6489 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6490 | slot.isExtendedApduSupported(), |
| 6491 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6492 | } |
| 6493 | return infos; |
| 6494 | } finally { |
| 6495 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6496 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6497 | } |
| 6498 | |
| 6499 | @Override |
| 6500 | public boolean switchSlots(int[] physicalSlots) { |
| 6501 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6502 | |
| 6503 | final long identity = Binder.clearCallingIdentity(); |
| 6504 | try { |
| 6505 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6506 | } finally { |
| 6507 | Binder.restoreCallingIdentity(identity); |
| 6508 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6509 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6510 | |
| 6511 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6512 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6513 | final long identity = Binder.clearCallingIdentity(); |
| 6514 | try { |
| 6515 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6516 | } finally { |
| 6517 | Binder.restoreCallingIdentity(identity); |
| 6518 | } |
| 6519 | } |
| 6520 | |
| 6521 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6522 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6523 | enforceModifyPermission(); |
| 6524 | final Phone phone = getPhone(subId); |
| 6525 | if (phone == null) { |
| 6526 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6527 | return; |
| 6528 | } |
| 6529 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6530 | final long identity = Binder.clearCallingIdentity(); |
| 6531 | try { |
| 6532 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6533 | } finally { |
| 6534 | Binder.restoreCallingIdentity(identity); |
| 6535 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6536 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6537 | |
| 6538 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6539 | * A test API to reload the UICC profile. |
| 6540 | * |
| 6541 | * <p>Requires that the calling app has permission |
| 6542 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6543 | * @hide |
| 6544 | */ |
| 6545 | @Override |
| 6546 | public void refreshUiccProfile(int subId) { |
| 6547 | enforceModifyPermission(); |
| 6548 | |
| 6549 | final long identity = Binder.clearCallingIdentity(); |
| 6550 | try { |
| 6551 | Phone phone = getPhone(subId); |
| 6552 | if (phone == null) { |
| 6553 | return; |
| 6554 | } |
| 6555 | UiccCard uiccCard = phone.getUiccCard(); |
| 6556 | if (uiccCard == null) { |
| 6557 | return; |
| 6558 | } |
| 6559 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6560 | if (uiccProfile == null) { |
| 6561 | return; |
| 6562 | } |
| 6563 | uiccProfile.refresh(); |
| 6564 | } finally { |
| 6565 | Binder.restoreCallingIdentity(identity); |
| 6566 | } |
| 6567 | } |
| 6568 | |
| 6569 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6570 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6571 | */ |
| 6572 | private boolean getDefaultDataEnabled() { |
| 6573 | return "true".equalsIgnoreCase( |
| 6574 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6575 | } |
| 6576 | |
| 6577 | /** |
| 6578 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6579 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6580 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6581 | */ |
| 6582 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6583 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6584 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6585 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6586 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6587 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6588 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 6589 | return isDataRoamingEnabled; |
| 6590 | } |
| 6591 | |
| 6592 | /** |
| 6593 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 6594 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 6595 | */ |
| 6596 | private int getDefaultNetworkType(int subId) { |
| 6597 | return Integer.parseInt( |
| 6598 | TelephonyManager.getTelephonyProperty( |
| 6599 | mSubscriptionController.getPhoneId(subId), |
| 6600 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 6601 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 6602 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6603 | |
| 6604 | @Override |
| 6605 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6606 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6607 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6608 | |
| 6609 | final long identity = Binder.clearCallingIdentity(); |
| 6610 | try { |
| 6611 | final Phone phone = getPhone(subId); |
| 6612 | if (phone == null) { |
| 6613 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 6614 | return; |
| 6615 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6616 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 6617 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6618 | } finally { |
| 6619 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6620 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6621 | } |
| 6622 | |
| 6623 | @Override |
| 6624 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6625 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6626 | |
| 6627 | final long identity = Binder.clearCallingIdentity(); |
| 6628 | try { |
| 6629 | final Phone phone = getPhone(subId); |
| 6630 | if (phone == null) { |
| 6631 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 6632 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 6633 | } |
| 6634 | return phone.getCarrierIdListVersion(); |
| 6635 | } finally { |
| 6636 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6637 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6638 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6639 | |
| 6640 | @Override |
| 6641 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 6642 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6643 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 6644 | return -1; |
| 6645 | } |
| 6646 | |
| 6647 | final long identity = Binder.clearCallingIdentity(); |
| 6648 | try { |
| 6649 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 6650 | } finally { |
| 6651 | Binder.restoreCallingIdentity(identity); |
| 6652 | } |
| 6653 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6654 | |
| 6655 | @Override |
| 6656 | public int getCdmaRoamingMode(int subId) { |
| 6657 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6658 | mApp, subId, "getCdmaRoamingMode"); |
| 6659 | |
| 6660 | final long identity = Binder.clearCallingIdentity(); |
| 6661 | try { |
| 6662 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 6663 | } finally { |
| 6664 | Binder.restoreCallingIdentity(identity); |
| 6665 | } |
| 6666 | } |
| 6667 | |
| 6668 | @Override |
| 6669 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 6670 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6671 | mApp, subId, "setCdmaRoamingMode"); |
| 6672 | |
| 6673 | final long identity = Binder.clearCallingIdentity(); |
| 6674 | try { |
| 6675 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 6676 | } finally { |
| 6677 | Binder.restoreCallingIdentity(identity); |
| 6678 | } |
| 6679 | } |
| 6680 | |
| 6681 | @Override |
| 6682 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 6683 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6684 | mApp, subId, "setCdmaSubscriptionMode"); |
| 6685 | |
| 6686 | final long identity = Binder.clearCallingIdentity(); |
| 6687 | try { |
| 6688 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 6689 | } finally { |
| 6690 | Binder.restoreCallingIdentity(identity); |
| 6691 | } |
| 6692 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 6693 | |
| 6694 | private void ensureUserRunning(int userId) { |
| 6695 | if (!mUserManager.isUserRunning(userId)) { |
| 6696 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 6697 | } |
| 6698 | } |
| 6699 | |
| 6700 | /** |
| 6701 | * Returns a list of SMS apps on a given user. |
| 6702 | * |
| 6703 | * Only the shell user (UID 2000 or 0) can call it. |
| 6704 | * Target user must be running. |
| 6705 | */ |
| 6706 | @Override |
| 6707 | public String[] getSmsApps(int userId) { |
| 6708 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 6709 | ensureUserRunning(userId); |
| 6710 | |
| 6711 | final Collection<SmsApplicationData> apps = |
| 6712 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 6713 | |
| 6714 | String[] ret = new String[apps.size()]; |
| 6715 | int i = 0; |
| 6716 | for (SmsApplicationData app : apps) { |
| 6717 | ret[i++] = app.mPackageName; |
| 6718 | } |
| 6719 | return ret; |
| 6720 | } |
| 6721 | |
| 6722 | /** |
| 6723 | * Returns the default SMS app package name on a given user. |
| 6724 | * |
| 6725 | * Only the shell user (UID 2000 or 0) can call it. |
| 6726 | * Target user must be running. |
| 6727 | */ |
| 6728 | @Override |
| 6729 | public String getDefaultSmsApp(int userId) { |
| 6730 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 6731 | ensureUserRunning(userId); |
| 6732 | |
| 6733 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 6734 | /* updateIfNeeded= */ true, userId); |
| 6735 | return cn == null ? null : cn.getPackageName(); |
| 6736 | } |
| 6737 | |
| 6738 | /** |
| 6739 | * Set a package as the default SMS app on a given user. |
| 6740 | * |
| 6741 | * Only the shell user (UID 2000 or 0) can call it. |
| 6742 | * Target user must be running. |
| 6743 | */ |
| 6744 | @Override |
| 6745 | public void setDefaultSmsApp(int userId, String packageName) { |
| 6746 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6747 | ensureUserRunning(userId); |
| 6748 | |
| 6749 | boolean found = false; |
| 6750 | for (String pkg : getSmsApps(userId)) { |
| 6751 | if (TextUtils.equals(packageName, pkg)) { |
| 6752 | found = true; |
| 6753 | break; |
| 6754 | } |
| 6755 | } |
| 6756 | if (!found) { |
| 6757 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6758 | } |
| 6759 | |
| 6760 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6761 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6762 | |
| 6763 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6764 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6765 | String callingPackage) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6766 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6767 | mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6768 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6769 | } |
| 6770 | final long identity = Binder.clearCallingIdentity(); |
| 6771 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6772 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6773 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6774 | if (phone.getEmergencyNumberTracker() != null |
| 6775 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6776 | emergencyNumberListInternal.put( |
| 6777 | phone.getSubId(), |
| 6778 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6779 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6780 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6781 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6782 | } finally { |
| 6783 | Binder.restoreCallingIdentity(identity); |
| 6784 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6785 | } |
| 6786 | |
| 6787 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6788 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6789 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6790 | if (!exactMatch) { |
| 6791 | TelephonyPermissions |
| 6792 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6793 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6794 | } |
| 6795 | final long identity = Binder.clearCallingIdentity(); |
| 6796 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6797 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6798 | if (phone.getEmergencyNumberTracker() != null |
| 6799 | && phone.getEmergencyNumberTracker() != null) { |
| 6800 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 6801 | number, exactMatch)) { |
| 6802 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6803 | } |
| 6804 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6805 | } |
| 6806 | return false; |
| 6807 | } finally { |
| 6808 | Binder.restoreCallingIdentity(identity); |
| 6809 | } |
| 6810 | } |
| 6811 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6812 | /** |
| 6813 | * Update emergency number list for test mode. |
| 6814 | */ |
| 6815 | @Override |
| 6816 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 6817 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6818 | "updateEmergencyNumberListTestMode"); |
| 6819 | |
| 6820 | final long identity = Binder.clearCallingIdentity(); |
| 6821 | try { |
| 6822 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6823 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6824 | if (tracker != null) { |
| 6825 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 6826 | } |
| 6827 | } |
| 6828 | } finally { |
| 6829 | Binder.restoreCallingIdentity(identity); |
| 6830 | } |
| 6831 | } |
| 6832 | |
| 6833 | /** |
| 6834 | * Get the full emergency number list for test mode. |
| 6835 | */ |
| 6836 | @Override |
| 6837 | public List<String> getEmergencyNumberListTestMode() { |
| 6838 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6839 | "getEmergencyNumberListTestMode"); |
| 6840 | |
| 6841 | final long identity = Binder.clearCallingIdentity(); |
| 6842 | try { |
| 6843 | Set<String> emergencyNumbers = new HashSet<>(); |
| 6844 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6845 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6846 | if (tracker != null) { |
| 6847 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 6848 | emergencyNumbers.add(num.getNumber()); |
| 6849 | } |
| 6850 | } |
| 6851 | } |
| 6852 | return new ArrayList<>(emergencyNumbers); |
| 6853 | } finally { |
| 6854 | Binder.restoreCallingIdentity(identity); |
| 6855 | } |
| 6856 | } |
| 6857 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6858 | @Override |
| 6859 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6860 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6861 | Phone phone = getPhone(subId); |
| 6862 | if (phone == null) { |
| 6863 | return null; |
| 6864 | } |
| 6865 | final long identity = Binder.clearCallingIdentity(); |
| 6866 | try { |
| 6867 | UiccProfile profile = UiccController.getInstance() |
| 6868 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6869 | if (profile != null) { |
| 6870 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6871 | } |
| 6872 | } finally { |
| 6873 | Binder.restoreCallingIdentity(identity); |
| 6874 | } |
| 6875 | return null; |
| 6876 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6877 | |
| 6878 | /** |
| 6879 | * Enable or disable a modem stack. |
| 6880 | */ |
| 6881 | @Override |
| 6882 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 6883 | enforceModifyPermission(); |
| 6884 | |
| 6885 | final long identity = Binder.clearCallingIdentity(); |
| 6886 | try { |
| 6887 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6888 | if (phone == null) { |
| 6889 | return false; |
| 6890 | } else { |
| 6891 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 6892 | } |
| 6893 | } finally { |
| 6894 | Binder.restoreCallingIdentity(identity); |
| 6895 | } |
| 6896 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6897 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 6898 | /** |
| 6899 | * Whether a modem stack is enabled or not. |
| 6900 | */ |
| 6901 | @Override |
| 6902 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) { |
| 6903 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6904 | if (phone == null) return false; |
| 6905 | |
| 6906 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6907 | mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) { |
| 6908 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6909 | } |
| 6910 | |
| 6911 | final long identity = Binder.clearCallingIdentity(); |
| 6912 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 6913 | try { |
| 6914 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 6915 | } catch (NoSuchElementException ex) { |
| 6916 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 6917 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 6918 | } finally { |
| 6919 | Binder.restoreCallingIdentity(identity); |
| 6920 | } |
| 6921 | } |
| 6922 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6923 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6924 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6925 | enforceModifyPermission(); |
| 6926 | |
| 6927 | final long identity = Binder.clearCallingIdentity(); |
| 6928 | try { |
| 6929 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6930 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6931 | .commit(); |
| 6932 | } finally { |
| 6933 | Binder.restoreCallingIdentity(identity); |
| 6934 | } |
| 6935 | } |
| 6936 | |
| 6937 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6938 | @TelephonyManager.IsMultiSimSupportedResult |
| 6939 | public int isMultiSimSupported(String callingPackage) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6940 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6941 | getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) { |
| 6942 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6943 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6944 | |
| 6945 | final long identity = Binder.clearCallingIdentity(); |
| 6946 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6947 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6948 | } finally { |
| 6949 | Binder.restoreCallingIdentity(identity); |
| 6950 | } |
| 6951 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6952 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6953 | @TelephonyManager.IsMultiSimSupportedResult |
| 6954 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6955 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 6956 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 6957 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6958 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 6959 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6960 | } |
| 6961 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 6962 | // supported by the modem, indicate that it is restricted. |
| 6963 | PhoneCapability staticCapability = |
| 6964 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 6965 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6966 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 6967 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6968 | } |
| 6969 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6970 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 6971 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6972 | } |
| 6973 | // Check if support of multiple SIMs is restricted by carrier |
| 6974 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6975 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6976 | } |
| 6977 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6978 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6979 | } |
| 6980 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6981 | /** |
| 6982 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6983 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 6984 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 6985 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6986 | * @param numOfSims number of active sims we want to switch to |
| 6987 | */ |
| 6988 | @Override |
| 6989 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6990 | if (numOfSims == 1) { |
| 6991 | enforceModifyPermission(); |
| 6992 | } else { |
| 6993 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6994 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 6995 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6996 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6997 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6998 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6999 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7000 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7001 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 7002 | return; |
| 7003 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7004 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 7005 | } finally { |
| 7006 | Binder.restoreCallingIdentity(identity); |
| 7007 | } |
| 7008 | } |
| 7009 | |
| 7010 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7011 | * Get whether making changes to modem configurations will trigger reboot. |
| 7012 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7013 | */ |
| 7014 | @Override |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7015 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) { |
| 7016 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7017 | mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) { |
| 7018 | return false; |
| 7019 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7020 | final long identity = Binder.clearCallingIdentity(); |
| 7021 | try { |
| 7022 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 7023 | } finally { |
| 7024 | Binder.restoreCallingIdentity(identity); |
| 7025 | } |
| 7026 | } |
| 7027 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 7028 | private void updateModemStateMetrics() { |
| 7029 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 7030 | // TODO: check the state for each modem if the api is ready. |
| 7031 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 7032 | } |
| 7033 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 7034 | @Override |
| 7035 | public int[] getSlotsMapping() { |
| 7036 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 7037 | |
| 7038 | final long identity = Binder.clearCallingIdentity(); |
| 7039 | try { |
| 7040 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 7041 | // All logical slots should have a mapping to a physical slot. |
| 7042 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 7043 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 7044 | for (int i = 0; i < slotInfos.length; i++) { |
| 7045 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 7046 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 7047 | } |
| 7048 | } |
| 7049 | return logicalSlotsMapping; |
| 7050 | } finally { |
| 7051 | Binder.restoreCallingIdentity(identity); |
| 7052 | } |
| 7053 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 7054 | |
| 7055 | /** |
| 7056 | * Get the IRadio HAL Version |
| 7057 | */ |
| 7058 | @Override |
| 7059 | public int getRadioHalVersion() { |
| 7060 | Phone phone = getDefaultPhone(); |
| 7061 | if (phone == null) return -1; |
| 7062 | HalVersion hv = phone.getHalVersion(); |
| 7063 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 7064 | return hv.major * 100 + hv.minor; |
| 7065 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7066 | |
| 7067 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7068 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 7069 | * corresponding network requests on a subId. |
| 7070 | * |
| 7071 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7072 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7073 | * 2) APN is un-metered for this subscription, or |
| 7074 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
| 7075 | * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. |
| 7076 | * |
| 7077 | * @return whether data is allowed for a apn type. |
| 7078 | * |
| 7079 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7080 | */ |
| 7081 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7082 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7083 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7084 | mApp, subId, callingPackage, "isDataEnabledForApn")) { |
| 7085 | throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7086 | } |
| 7087 | |
| 7088 | // Now that all security checks passes, perform the operation as ourselves. |
| 7089 | final long identity = Binder.clearCallingIdentity(); |
| 7090 | try { |
| 7091 | Phone phone = getPhone(subId); |
| 7092 | if (phone == null) return false; |
| 7093 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7094 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7095 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 7096 | } finally { |
| 7097 | Binder.restoreCallingIdentity(identity); |
| 7098 | } |
| 7099 | } |
| 7100 | |
| 7101 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7102 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7103 | enforceReadPrivilegedPermission("isApnMetered"); |
| 7104 | |
| 7105 | // Now that all security checks passes, perform the operation as ourselves. |
| 7106 | final long identity = Binder.clearCallingIdentity(); |
| 7107 | try { |
| 7108 | Phone phone = getPhone(subId); |
| 7109 | if (phone == null) return true; // By default return true. |
| 7110 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7111 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7112 | } finally { |
| 7113 | Binder.restoreCallingIdentity(identity); |
| 7114 | } |
| 7115 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7116 | |
| 7117 | @Override |
| 7118 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
| 7119 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 7120 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 7121 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 7122 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 7123 | } |
| 7124 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 7125 | Intent intent = new Intent(); |
| 7126 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 7127 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 7128 | // Bring up choose default SMS subscription dialog right now |
| 7129 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 7130 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 7131 | mApp.startActivity(intent); |
| 7132 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 7133 | |
| 7134 | @Override |
| 7135 | public String getMmsUAProfUrl(int subId) { |
| 7136 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7137 | final long identity = Binder.clearCallingIdentity(); |
| 7138 | try { |
| 7139 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7140 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 7141 | } finally { |
| 7142 | Binder.restoreCallingIdentity(identity); |
| 7143 | } |
| 7144 | } |
| 7145 | |
| 7146 | @Override |
| 7147 | public String getMmsUserAgent(int subId) { |
| 7148 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7149 | final long identity = Binder.clearCallingIdentity(); |
| 7150 | try { |
| 7151 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7152 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 7153 | } finally { |
| 7154 | Binder.restoreCallingIdentity(identity); |
| 7155 | } |
| 7156 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 7157 | |
| 7158 | @Override |
| 7159 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 7160 | enforceModifyPermission(); |
| 7161 | |
| 7162 | // Now that all security checks passes, perform the operation as ourselves. |
| 7163 | final long identity = Binder.clearCallingIdentity(); |
| 7164 | try { |
| 7165 | Phone phone = getPhone(subId); |
| 7166 | if (phone == null) return false; |
| 7167 | |
| 7168 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 7169 | } finally { |
| 7170 | Binder.restoreCallingIdentity(identity); |
| 7171 | } |
| 7172 | } |
| 7173 | |
| 7174 | @Override |
| 7175 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 7176 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 7177 | |
| 7178 | // Now that all security checks passes, perform the operation as ourselves. |
| 7179 | final long identity = Binder.clearCallingIdentity(); |
| 7180 | try { |
| 7181 | Phone phone = getPhone(subId); |
| 7182 | if (phone == null) return false; |
| 7183 | |
| 7184 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 7185 | } finally { |
| 7186 | Binder.restoreCallingIdentity(identity); |
| 7187 | } |
| 7188 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame^] | 7189 | |
| 7190 | /** |
| 7191 | * Updates whether conference event pacakge handling is enabled. |
| 7192 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 7193 | * otherwise. |
| 7194 | */ |
| 7195 | @Override |
| 7196 | public void setCepEnabled(boolean isCepEnabled) { |
| 7197 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 7198 | |
| 7199 | final long identity = Binder.clearCallingIdentity(); |
| 7200 | try { |
| 7201 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 7202 | for (Phone phone : PhoneFactory.getPhones()) { |
| 7203 | Phone defaultPhone = phone.getImsPhone(); |
| 7204 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7205 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7206 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 7207 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 7208 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 7209 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 7210 | + imsPhone.getMsisdn()); |
| 7211 | } |
| 7212 | } |
| 7213 | } finally { |
| 7214 | Binder.restoreCallingIdentity(identity); |
| 7215 | } |
| 7216 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 7217 | } |