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; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 48 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 49 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 50 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 51 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 52 | import android.os.ServiceManager; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 53 | import android.os.ServiceSpecificException; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 54 | import android.os.ShellCallback; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 55 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 56 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 57 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 58 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 59 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 60 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 61 | import android.provider.Telephony; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 62 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 63 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 64 | import android.telecom.TelecomManager; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 65 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 66 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 67 | import android.telephony.CellIdentity; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 68 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 69 | import android.telephony.CellInfoGsm; |
| 70 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 71 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 72 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 73 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 74 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 75 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 76 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 77 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 78 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 79 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 80 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 81 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 82 | import android.telephony.RadioAccessSpecifier; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 83 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 84 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 85 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 86 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 87 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 88 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 89 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 90 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 91 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 92 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 93 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 94 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 95 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 96 | import android.telephony.data.ApnSetting; |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 97 | import android.telephony.data.ApnSetting.ApnType; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 98 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 99 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 100 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 101 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 102 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 103 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 104 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 106 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 107 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 108 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame^] | 109 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 110 | import android.telephony.ims.feature.MmTelFeature; |
| 111 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 112 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 113 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 114 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 115 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 116 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 117 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 118 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 119 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 120 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 121 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 122 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 124 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 128 | import com.android.internal.telephony.HalVersion; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 130 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 134 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 139 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.ServiceStateTracker; |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.SmsApplication; |
| 147 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 157 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 159 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.uicc.IccIoResult; |
| 161 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 169 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 170 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 171 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 172 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 173 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 174 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 175 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 176 | import java.io.FileDescriptor; |
| 177 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 178 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 179 | import java.util.Arrays; |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 180 | import java.util.Collection; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 181 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 182 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 183 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 184 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 185 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 186 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 187 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 188 | |
| 189 | /** |
| 190 | * Implementation of the ITelephony interface. |
| 191 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 192 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 193 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 194 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 195 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 196 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 197 | |
| 198 | // Message codes used with mMainThreadHandler |
| 199 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 200 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 201 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 202 | private static final int CMD_OPEN_CHANNEL = 9; |
| 203 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 204 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 205 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 206 | private static final int CMD_NV_READ_ITEM = 13; |
| 207 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 208 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 209 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 210 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 211 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 212 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 213 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 214 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 215 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 216 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 217 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 218 | private static final int CMD_SEND_ENVELOPE = 25; |
| 219 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 220 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 221 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 222 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 223 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 224 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 225 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 226 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 227 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 228 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 229 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 230 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 231 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 232 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 233 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 234 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 235 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 236 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 237 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 238 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 239 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 240 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 241 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 242 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 243 | private static final int CMD_SWITCH_SLOTS = 50; |
| 244 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 245 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 246 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 247 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 248 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 249 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 250 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 251 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 252 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 253 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 254 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 255 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 256 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 257 | private static final int CMD_MODEM_REBOOT = 64; |
| 258 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 259 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 260 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 261 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 262 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 263 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 264 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 265 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 266 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 267 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 268 | // Parameters of select command. |
| 269 | private static final int SELECT_COMMAND = 0xA4; |
| 270 | private static final int SELECT_P1 = 0x04; |
| 271 | private static final int SELECT_P2 = 0; |
| 272 | private static final int SELECT_P3 = 0x10; |
| 273 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 274 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 275 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 276 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 277 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 278 | /** The singleton instance. */ |
| 279 | private static PhoneInterfaceManager sInstance; |
| 280 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 281 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 282 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 283 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 284 | private AppOpsManager mAppOps; |
| 285 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 286 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 287 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 288 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 289 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 290 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 291 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 292 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 293 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 294 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 295 | // String to store multi SIM allowed |
| 296 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 297 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 298 | // The AID of ISD-R. |
| 299 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 300 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 301 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 302 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 303 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 304 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 305 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 306 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 307 | * A request object to use for transmitting data to an ICC. |
| 308 | */ |
| 309 | private static final class IccAPDUArgument { |
| 310 | public int channel, cla, command, p1, p2, p3; |
| 311 | public String data; |
| 312 | |
| 313 | public IccAPDUArgument(int channel, int cla, int command, |
| 314 | int p1, int p2, int p3, String data) { |
| 315 | this.channel = channel; |
| 316 | this.cla = cla; |
| 317 | this.command = command; |
| 318 | this.p1 = p1; |
| 319 | this.p2 = p2; |
| 320 | this.p3 = p3; |
| 321 | this.data = data; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 326 | * A request object to use for transmitting data to an ICC. |
| 327 | */ |
| 328 | private static final class ManualNetworkSelectionArgument { |
| 329 | public OperatorInfo operatorInfo; |
| 330 | public boolean persistSelection; |
| 331 | |
| 332 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 333 | this.operatorInfo = operatorInfo; |
| 334 | this.persistSelection = persistSelection; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 339 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 340 | * request after sending. The main thread will notify the request when it is complete. |
| 341 | */ |
| 342 | private static final class MainThreadRequest { |
| 343 | /** The argument to use for the request */ |
| 344 | public Object argument; |
| 345 | /** The result of the request that is run on the main thread */ |
| 346 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 347 | // The subscriber id that this request applies to. Defaults to |
| 348 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 349 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 350 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 351 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 352 | public Phone phone; |
| 353 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 354 | public WorkSource workSource; |
| 355 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 356 | public MainThreadRequest(Object argument) { |
| 357 | this.argument = argument; |
| 358 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 359 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 360 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 361 | this.argument = argument; |
| 362 | if (phone != null) { |
| 363 | this.phone = phone; |
| 364 | } |
| 365 | this.workSource = workSource; |
| 366 | } |
| 367 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 368 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 369 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 370 | if (subId != null) { |
| 371 | this.subId = subId; |
| 372 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 373 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 374 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 377 | private static final class IncomingThirdPartyCallArgs { |
| 378 | public final ComponentName component; |
| 379 | public final String callId; |
| 380 | public final String callerDisplayName; |
| 381 | |
| 382 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 383 | String callerDisplayName) { |
| 384 | this.component = component; |
| 385 | this.callId = callId; |
| 386 | this.callerDisplayName = callerDisplayName; |
| 387 | } |
| 388 | } |
| 389 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 390 | /** |
| 391 | * A handler that processes messages on the main thread in the phone process. Since many |
| 392 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 393 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 394 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 395 | * on, which will be notified when the operation completes and will contain the result of the |
| 396 | * request. |
| 397 | * |
| 398 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 399 | * note that request.result must be set to something non-null for the calling thread to |
| 400 | * unblock. |
| 401 | */ |
| 402 | private final class MainThreadHandler extends Handler { |
| 403 | @Override |
| 404 | public void handleMessage(Message msg) { |
| 405 | MainThreadRequest request; |
| 406 | Message onCompleted; |
| 407 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 408 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 409 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 410 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 411 | |
| 412 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 413 | case CMD_HANDLE_USSD_REQUEST: { |
| 414 | request = (MainThreadRequest) msg.obj; |
| 415 | final Phone phone = getPhoneFromRequest(request); |
| 416 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 417 | String ussdRequest = ussdObject.first; |
| 418 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 419 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 420 | if (!isUssdApiAllowed(request.subId)) { |
| 421 | // Carrier does not support use of this API, return failure. |
| 422 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 423 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 424 | Bundle returnData = new Bundle(); |
| 425 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 426 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 427 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 428 | request.result = true; |
| 429 | notifyRequester(request); |
| 430 | return; |
| 431 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 432 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 433 | try { |
| 434 | request.result = phone != null |
| 435 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 436 | } catch (CallStateException cse) { |
| 437 | request.result = false; |
| 438 | } |
| 439 | // Wake up the requesting thread |
| 440 | notifyRequester(request); |
| 441 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 444 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 445 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 446 | final Phone phone = getPhoneFromRequest(request); |
| 447 | request.result = phone != null ? |
| 448 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 449 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 450 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 451 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 452 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 453 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 454 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 455 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 456 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 457 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 458 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 459 | if (uiccCard == null) { |
| 460 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 461 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 462 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 463 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 464 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 465 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 466 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 467 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 468 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 469 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 470 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 471 | break; |
| 472 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 473 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 474 | ar = (AsyncResult) msg.obj; |
| 475 | request = (MainThreadRequest) ar.userObj; |
| 476 | if (ar.exception == null && ar.result != null) { |
| 477 | request.result = ar.result; |
| 478 | } else { |
| 479 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 480 | if (ar.result == null) { |
| 481 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 482 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 483 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 484 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 485 | } else { |
| 486 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 487 | } |
| 488 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 489 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 490 | break; |
| 491 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 492 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 493 | request = (MainThreadRequest) msg.obj; |
| 494 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 495 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 496 | if (uiccCard == null) { |
| 497 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 498 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 499 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 500 | } else { |
| 501 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 502 | request); |
| 503 | uiccCard.iccTransmitApduBasicChannel( |
| 504 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 505 | iccArgument.p3, iccArgument.data, onCompleted); |
| 506 | } |
| 507 | break; |
| 508 | |
| 509 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 510 | ar = (AsyncResult) msg.obj; |
| 511 | request = (MainThreadRequest) ar.userObj; |
| 512 | if (ar.exception == null && ar.result != null) { |
| 513 | request.result = ar.result; |
| 514 | } else { |
| 515 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 516 | if (ar.result == null) { |
| 517 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 518 | } else if (ar.exception instanceof CommandException) { |
| 519 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 520 | ar.exception); |
| 521 | } else { |
| 522 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 523 | } |
| 524 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 525 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 526 | break; |
| 527 | |
| 528 | case CMD_EXCHANGE_SIM_IO: |
| 529 | request = (MainThreadRequest) msg.obj; |
| 530 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 531 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 532 | if (uiccCard == null) { |
| 533 | loge("iccExchangeSimIO: No UICC"); |
| 534 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 535 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 536 | } else { |
| 537 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 538 | request); |
| 539 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 540 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 541 | iccArgument.data, onCompleted); |
| 542 | } |
| 543 | break; |
| 544 | |
| 545 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 546 | ar = (AsyncResult) msg.obj; |
| 547 | request = (MainThreadRequest) ar.userObj; |
| 548 | if (ar.exception == null && ar.result != null) { |
| 549 | request.result = ar.result; |
| 550 | } else { |
| 551 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 552 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 553 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 554 | break; |
| 555 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 556 | case CMD_SEND_ENVELOPE: |
| 557 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 558 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 559 | if (uiccCard == null) { |
| 560 | loge("sendEnvelopeWithStatus: No UICC"); |
| 561 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 562 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 563 | } else { |
| 564 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 565 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 566 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 567 | break; |
| 568 | |
| 569 | case EVENT_SEND_ENVELOPE_DONE: |
| 570 | ar = (AsyncResult) msg.obj; |
| 571 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 572 | if (ar.exception == null && ar.result != null) { |
| 573 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 574 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 575 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 576 | if (ar.result == null) { |
| 577 | loge("sendEnvelopeWithStatus: Empty response"); |
| 578 | } else if (ar.exception instanceof CommandException) { |
| 579 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 580 | ar.exception); |
| 581 | } else { |
| 582 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 583 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 584 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 585 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 586 | break; |
| 587 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 588 | case CMD_OPEN_CHANNEL: |
| 589 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 590 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 591 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 592 | if (uiccCard == null) { |
| 593 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 594 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 595 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 596 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 597 | } else { |
| 598 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 599 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 600 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 601 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 602 | break; |
| 603 | |
| 604 | case EVENT_OPEN_CHANNEL_DONE: |
| 605 | ar = (AsyncResult) msg.obj; |
| 606 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 607 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 608 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 609 | int[] result = (int[]) ar.result; |
| 610 | int channelId = result[0]; |
| 611 | byte[] selectResponse = null; |
| 612 | if (result.length > 1) { |
| 613 | selectResponse = new byte[result.length - 1]; |
| 614 | for (int i = 1; i < result.length; ++i) { |
| 615 | selectResponse[i - 1] = (byte) result[i]; |
| 616 | } |
| 617 | } |
| 618 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 619 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 620 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 621 | if (ar.result == null) { |
| 622 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 623 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 624 | if (ar.exception != null) { |
| 625 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 626 | } |
| 627 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 628 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 629 | if (ar.exception instanceof CommandException) { |
| 630 | CommandException.Error error = |
| 631 | ((CommandException) (ar.exception)).getCommandError(); |
| 632 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 633 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 634 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 635 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 636 | } |
| 637 | } |
| 638 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 639 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 640 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 641 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 642 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 643 | break; |
| 644 | |
| 645 | case CMD_CLOSE_CHANNEL: |
| 646 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 647 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 648 | if (uiccCard == null) { |
| 649 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 650 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 651 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 652 | } else { |
| 653 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 654 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 655 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 656 | break; |
| 657 | |
| 658 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 659 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 660 | break; |
| 661 | |
| 662 | case CMD_NV_READ_ITEM: |
| 663 | request = (MainThreadRequest) msg.obj; |
| 664 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 665 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 666 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 667 | break; |
| 668 | |
| 669 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 670 | ar = (AsyncResult) msg.obj; |
| 671 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 672 | if (ar.exception == null && ar.result != null) { |
| 673 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 674 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 675 | request.result = ""; |
| 676 | if (ar.result == null) { |
| 677 | loge("nvReadItem: Empty response"); |
| 678 | } else if (ar.exception instanceof CommandException) { |
| 679 | loge("nvReadItem: CommandException: " + |
| 680 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 681 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 682 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 683 | } |
| 684 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 685 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 686 | break; |
| 687 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 688 | case CMD_NV_WRITE_ITEM: |
| 689 | request = (MainThreadRequest) msg.obj; |
| 690 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 691 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 692 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 693 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 694 | break; |
| 695 | |
| 696 | case EVENT_NV_WRITE_ITEM_DONE: |
| 697 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 698 | break; |
| 699 | |
| 700 | case CMD_NV_WRITE_CDMA_PRL: |
| 701 | request = (MainThreadRequest) msg.obj; |
| 702 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 703 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 704 | break; |
| 705 | |
| 706 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 707 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 708 | break; |
| 709 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 710 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 711 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 712 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 713 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 714 | break; |
| 715 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 716 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 717 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 718 | break; |
| 719 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 720 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 721 | request = (MainThreadRequest) msg.obj; |
| 722 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 723 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 724 | break; |
| 725 | |
| 726 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 727 | ar = (AsyncResult) msg.obj; |
| 728 | request = (MainThreadRequest) ar.userObj; |
| 729 | if (ar.exception == null && ar.result != null) { |
| 730 | request.result = ar.result; // Integer |
| 731 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 732 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 733 | if (ar.result == null) { |
| 734 | loge("getPreferredNetworkType: Empty response"); |
| 735 | } else if (ar.exception instanceof CommandException) { |
| 736 | loge("getPreferredNetworkType: CommandException: " + |
| 737 | ar.exception); |
| 738 | } else { |
| 739 | loge("getPreferredNetworkType: Unknown exception"); |
| 740 | } |
| 741 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 742 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 743 | break; |
| 744 | |
| 745 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 746 | request = (MainThreadRequest) msg.obj; |
| 747 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 748 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 749 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 750 | break; |
| 751 | |
| 752 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 753 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 754 | break; |
| 755 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 756 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 757 | request = (MainThreadRequest)msg.obj; |
| 758 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 759 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 760 | break; |
| 761 | |
| 762 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 763 | ar = (AsyncResult)msg.obj; |
| 764 | request = (MainThreadRequest)ar.userObj; |
| 765 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 766 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 767 | break; |
| 768 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 769 | case CMD_SET_VOICEMAIL_NUMBER: |
| 770 | request = (MainThreadRequest) msg.obj; |
| 771 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 772 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 773 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 774 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 775 | break; |
| 776 | |
| 777 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 778 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 779 | break; |
| 780 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 781 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 782 | request = (MainThreadRequest) msg.obj; |
| 783 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 784 | request); |
| 785 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 786 | break; |
| 787 | |
| 788 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 789 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 790 | break; |
| 791 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 792 | case CMD_PERFORM_NETWORK_SCAN: |
| 793 | request = (MainThreadRequest) msg.obj; |
| 794 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 795 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 796 | break; |
| 797 | |
| 798 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 799 | ar = (AsyncResult) msg.obj; |
| 800 | request = (MainThreadRequest) ar.userObj; |
| 801 | CellNetworkScanResult cellScanResult; |
| 802 | if (ar.exception == null && ar.result != null) { |
| 803 | cellScanResult = new CellNetworkScanResult( |
| 804 | CellNetworkScanResult.STATUS_SUCCESS, |
| 805 | (List<OperatorInfo>) ar.result); |
| 806 | } else { |
| 807 | if (ar.result == null) { |
| 808 | loge("getCellNetworkScanResults: Empty response"); |
| 809 | } |
| 810 | if (ar.exception != null) { |
| 811 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 812 | } |
| 813 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 814 | if (ar.exception instanceof CommandException) { |
| 815 | CommandException.Error error = |
| 816 | ((CommandException) (ar.exception)).getCommandError(); |
| 817 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 818 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 819 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 820 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 821 | } |
| 822 | } |
| 823 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 824 | } |
| 825 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 826 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 827 | break; |
| 828 | |
| 829 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 830 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 831 | ManualNetworkSelectionArgument selArg = |
| 832 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 833 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 834 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 835 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 836 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 837 | break; |
| 838 | |
| 839 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 840 | ar = (AsyncResult) msg.obj; |
| 841 | request = (MainThreadRequest) ar.userObj; |
| 842 | if (ar.exception == null) { |
| 843 | request.result = true; |
| 844 | } else { |
| 845 | request.result = false; |
| 846 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 847 | } |
| 848 | notifyRequester(request); |
| 849 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 850 | break; |
| 851 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 852 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 853 | request = (MainThreadRequest) msg.obj; |
| 854 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 855 | if (defaultPhone != null) { |
| 856 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 857 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 858 | break; |
| 859 | |
| 860 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 861 | ar = (AsyncResult) msg.obj; |
| 862 | request = (MainThreadRequest) ar.userObj; |
| 863 | if (ar.exception == null && ar.result != null) { |
| 864 | request.result = ar.result; |
| 865 | } else { |
| 866 | if (ar.result == null) { |
| 867 | loge("queryModemActivityInfo: Empty response"); |
| 868 | } else if (ar.exception instanceof CommandException) { |
| 869 | loge("queryModemActivityInfo: CommandException: " + |
| 870 | ar.exception); |
| 871 | } else { |
| 872 | loge("queryModemActivityInfo: Unknown exception"); |
| 873 | } |
| 874 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 875 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 876 | if (request.result == null) { |
| 877 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 878 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 879 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 880 | break; |
| 881 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 882 | case CMD_SET_ALLOWED_CARRIERS: |
| 883 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 884 | CarrierRestrictionRules argument = |
| 885 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 886 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 887 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 888 | break; |
| 889 | |
| 890 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 891 | ar = (AsyncResult) msg.obj; |
| 892 | request = (MainThreadRequest) ar.userObj; |
| 893 | if (ar.exception == null && ar.result != null) { |
| 894 | request.result = ar.result; |
| 895 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 896 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 897 | if (ar.exception instanceof CommandException) { |
| 898 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 899 | CommandException.Error error = |
| 900 | ((CommandException) (ar.exception)).getCommandError(); |
| 901 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 902 | request.result = |
| 903 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 904 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 905 | } else { |
| 906 | loge("setAllowedCarriers: Unknown exception"); |
| 907 | } |
| 908 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 909 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 910 | break; |
| 911 | |
| 912 | case CMD_GET_ALLOWED_CARRIERS: |
| 913 | request = (MainThreadRequest) msg.obj; |
| 914 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 915 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 916 | break; |
| 917 | |
| 918 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 919 | ar = (AsyncResult) msg.obj; |
| 920 | request = (MainThreadRequest) ar.userObj; |
| 921 | if (ar.exception == null && ar.result != null) { |
| 922 | request.result = ar.result; |
| 923 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 924 | request.result = new IllegalStateException( |
| 925 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 926 | if (ar.result == null) { |
| 927 | loge("getAllowedCarriers: Empty response"); |
| 928 | } else if (ar.exception instanceof CommandException) { |
| 929 | loge("getAllowedCarriers: CommandException: " + |
| 930 | ar.exception); |
| 931 | } else { |
| 932 | loge("getAllowedCarriers: Unknown exception"); |
| 933 | } |
| 934 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 935 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 936 | break; |
| 937 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 938 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 939 | ar = (AsyncResult) msg.obj; |
| 940 | request = (MainThreadRequest) ar.userObj; |
| 941 | if (ar.exception == null && ar.result != null) { |
| 942 | request.result = ar.result; |
| 943 | } else { |
| 944 | request.result = new IllegalArgumentException( |
| 945 | "Failed to retrieve Forbidden Plmns"); |
| 946 | if (ar.result == null) { |
| 947 | loge("getForbiddenPlmns: Empty response"); |
| 948 | } else { |
| 949 | loge("getForbiddenPlmns: Unknown exception"); |
| 950 | } |
| 951 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 952 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 953 | break; |
| 954 | |
| 955 | case CMD_GET_FORBIDDEN_PLMNS: |
| 956 | request = (MainThreadRequest) msg.obj; |
| 957 | uiccCard = getUiccCardFromRequest(request); |
| 958 | if (uiccCard == null) { |
| 959 | loge("getForbiddenPlmns() UiccCard is null"); |
| 960 | request.result = new IllegalArgumentException( |
| 961 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 962 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 963 | break; |
| 964 | } |
| 965 | Integer appType = (Integer) request.argument; |
| 966 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 967 | if (uiccApp == null) { |
| 968 | loge("getForbiddenPlmns() no app with specified type -- " |
| 969 | + appType); |
| 970 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 971 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 972 | break; |
| 973 | } else { |
| 974 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 975 | + " specified type -- " + appType); |
| 976 | } |
| 977 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 978 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 979 | onCompleted); |
| 980 | break; |
| 981 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 982 | case CMD_SWITCH_SLOTS: |
| 983 | request = (MainThreadRequest) msg.obj; |
| 984 | int[] physicalSlots = (int[]) request.argument; |
| 985 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 986 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 987 | break; |
| 988 | |
| 989 | case EVENT_SWITCH_SLOTS_DONE: |
| 990 | ar = (AsyncResult) msg.obj; |
| 991 | request = (MainThreadRequest) ar.userObj; |
| 992 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 993 | notifyRequester(request); |
| 994 | break; |
| 995 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 996 | request = (MainThreadRequest) msg.obj; |
| 997 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 998 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 999 | break; |
| 1000 | |
| 1001 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1002 | ar = (AsyncResult) msg.obj; |
| 1003 | request = (MainThreadRequest) ar.userObj; |
| 1004 | if (ar.exception != null) { |
| 1005 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1006 | } else { |
| 1007 | int mode = ((int[]) ar.result)[0]; |
| 1008 | if (mode == 0) { |
| 1009 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1010 | } else { |
| 1011 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1012 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1013 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1014 | notifyRequester(request); |
| 1015 | break; |
| 1016 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1017 | request = (MainThreadRequest) msg.obj; |
| 1018 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1019 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1020 | break; |
| 1021 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1022 | ar = (AsyncResult) msg.obj; |
| 1023 | request = (MainThreadRequest) ar.userObj; |
| 1024 | if (ar.exception != null) { |
| 1025 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1026 | } else { |
| 1027 | request.result = ((int[]) ar.result)[0]; |
| 1028 | } |
| 1029 | notifyRequester(request); |
| 1030 | break; |
| 1031 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1032 | request = (MainThreadRequest) msg.obj; |
| 1033 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1034 | int mode = (int) request.argument; |
| 1035 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1036 | break; |
| 1037 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1038 | ar = (AsyncResult) msg.obj; |
| 1039 | request = (MainThreadRequest) ar.userObj; |
| 1040 | request.result = ar.exception == null; |
| 1041 | notifyRequester(request); |
| 1042 | break; |
| 1043 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1044 | request = (MainThreadRequest) msg.obj; |
| 1045 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1046 | int subscriptionMode = (int) request.argument; |
| 1047 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1048 | break; |
| 1049 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1050 | ar = (AsyncResult) msg.obj; |
| 1051 | request = (MainThreadRequest) ar.userObj; |
| 1052 | request.result = ar.exception == null; |
| 1053 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1054 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1055 | case CMD_GET_ALL_CELL_INFO: |
| 1056 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1057 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1058 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1059 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1060 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1061 | ar = (AsyncResult) msg.obj; |
| 1062 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1063 | // If a timeout occurs, the response will be null |
| 1064 | request.result = (ar.exception == null && ar.result != null) |
| 1065 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1066 | synchronized (request) { |
| 1067 | request.notifyAll(); |
| 1068 | } |
| 1069 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1070 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1071 | request = (MainThreadRequest) msg.obj; |
| 1072 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1073 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1074 | break; |
| 1075 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1076 | ar = (AsyncResult) msg.obj; |
| 1077 | request = (MainThreadRequest) ar.userObj; |
| 1078 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1079 | try { |
| 1080 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1081 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1082 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1083 | new android.os.ParcelableException(ar.exception)); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1084 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1085 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1086 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1087 | } else { |
| 1088 | // use the result as returned |
| 1089 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1090 | } |
| 1091 | } catch (RemoteException re) { |
| 1092 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1093 | } |
| 1094 | break; |
| 1095 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1096 | request = (MainThreadRequest) msg.obj; |
| 1097 | WorkSource ws = (WorkSource) request.argument; |
| 1098 | Phone phone = getPhoneFromRequest(request); |
| 1099 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1100 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1101 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1102 | ar = (AsyncResult) msg.obj; |
| 1103 | request = (MainThreadRequest) ar.userObj; |
| 1104 | if (ar.exception == null) { |
| 1105 | request.result = ar.result; |
| 1106 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1107 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1108 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1109 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1110 | } |
| 1111 | |
| 1112 | synchronized (request) { |
| 1113 | request.notifyAll(); |
| 1114 | } |
| 1115 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1116 | case CMD_MODEM_REBOOT: |
| 1117 | request = (MainThreadRequest) msg.obj; |
| 1118 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1119 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1120 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1121 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1122 | handleNullReturnEvent(msg, "rebootModem"); |
| 1123 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1124 | case CMD_REQUEST_ENABLE_MODEM: |
| 1125 | request = (MainThreadRequest) msg.obj; |
| 1126 | boolean enable = (boolean) request.argument; |
| 1127 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1128 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1129 | PhoneConfigurationManager.getInstance() |
| 1130 | .enablePhone(request.phone, enable, onCompleted); |
| 1131 | break; |
| 1132 | case EVENT_ENABLE_MODEM_DONE: |
| 1133 | ar = (AsyncResult) msg.obj; |
| 1134 | request = (MainThreadRequest) ar.userObj; |
| 1135 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1136 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1137 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1138 | if ((boolean) request.result) { |
| 1139 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1140 | updateModemStateMetrics(); |
| 1141 | } else { |
| 1142 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1143 | + ar.exception); |
| 1144 | } |
| 1145 | notifyRequester(request); |
| 1146 | break; |
| 1147 | case CMD_GET_MODEM_STATUS: |
| 1148 | request = (MainThreadRequest) msg.obj; |
| 1149 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1150 | PhoneConfigurationManager.getInstance() |
| 1151 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1152 | break; |
| 1153 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1154 | ar = (AsyncResult) msg.obj; |
| 1155 | request = (MainThreadRequest) ar.userObj; |
| 1156 | int id = request.phone.getPhoneId(); |
| 1157 | if (ar.exception == null && ar.result != null) { |
| 1158 | request.result = ar.result; |
| 1159 | //update the cache as modem status has changed |
| 1160 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1161 | (boolean) request.result); |
| 1162 | } else { |
| 1163 | // Return true if modem status cannot be retrieved. For most cases, |
| 1164 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1165 | // and disable modem are not supported. Modem is always on. |
| 1166 | // TODO: this should be fixed in R to support a third |
| 1167 | // status UNKNOWN b/131631629 |
| 1168 | request.result = true; |
| 1169 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1170 | + ar.exception); |
| 1171 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1172 | notifyRequester(request); |
| 1173 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1174 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1175 | ar = (AsyncResult) msg.obj; |
| 1176 | request = (MainThreadRequest) ar.userObj; |
| 1177 | if (ar.exception == null && ar.result != null) { |
| 1178 | request.result = ar.result; |
| 1179 | } else { |
| 1180 | request.result = -1; |
| 1181 | loge("Failed to set Forbidden Plmns"); |
| 1182 | if (ar.result == null) { |
| 1183 | loge("setForbidenPlmns: Empty response"); |
| 1184 | } else if (ar.exception != null) { |
| 1185 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1186 | request.result = -1; |
| 1187 | } else { |
| 1188 | loge("setForbiddenPlmns: Unknown exception"); |
| 1189 | } |
| 1190 | } |
| 1191 | notifyRequester(request); |
| 1192 | break; |
| 1193 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1194 | request = (MainThreadRequest) msg.obj; |
| 1195 | uiccCard = getUiccCardFromRequest(request); |
| 1196 | if (uiccCard == null) { |
| 1197 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1198 | request.result = -1; |
| 1199 | notifyRequester(request); |
| 1200 | break; |
| 1201 | } |
| 1202 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1203 | (Pair<Integer, List<String>>) request.argument; |
| 1204 | appType = setFplmnsArgs.first; |
| 1205 | List<String> fplmns = setFplmnsArgs.second; |
| 1206 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1207 | if (uiccApp == null) { |
| 1208 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1209 | request.result = -1; |
| 1210 | loge("Failed to get UICC App"); |
| 1211 | notifyRequester(request); |
| 1212 | } else { |
| 1213 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1214 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1215 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1216 | } |
| 1217 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1218 | default: |
| 1219 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1220 | break; |
| 1221 | } |
| 1222 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1223 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1224 | private void notifyRequester(MainThreadRequest request) { |
| 1225 | synchronized (request) { |
| 1226 | request.notifyAll(); |
| 1227 | } |
| 1228 | } |
| 1229 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1230 | private void handleNullReturnEvent(Message msg, String command) { |
| 1231 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1232 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1233 | if (ar.exception == null) { |
| 1234 | request.result = true; |
| 1235 | } else { |
| 1236 | request.result = false; |
| 1237 | if (ar.exception instanceof CommandException) { |
| 1238 | loge(command + ": CommandException: " + ar.exception); |
| 1239 | } else { |
| 1240 | loge(command + ": Unknown exception"); |
| 1241 | } |
| 1242 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1243 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1244 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | /** |
| 1248 | * Posts the specified command to be executed on the main thread, |
| 1249 | * waits for the request to complete, and returns the result. |
| 1250 | * @see #sendRequestAsync |
| 1251 | */ |
| 1252 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1253 | return sendRequest( |
| 1254 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | /** |
| 1258 | * Posts the specified command to be executed on the main thread, |
| 1259 | * waits for the request to complete, and returns the result. |
| 1260 | * @see #sendRequestAsync |
| 1261 | */ |
| 1262 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1263 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1264 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | /** |
| 1268 | * Posts the specified command to be executed on the main thread, |
| 1269 | * waits for the request to complete, and returns the result. |
| 1270 | * @see #sendRequestAsync |
| 1271 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1272 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1273 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | /** |
| 1277 | * Posts the specified command to be executed on the main thread, |
| 1278 | * waits for the request to complete, and returns the result. |
| 1279 | * @see #sendRequestAsync |
| 1280 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1281 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1282 | return sendRequest(command, argument, subId, null, workSource); |
| 1283 | } |
| 1284 | |
| 1285 | /** |
| 1286 | * Posts the specified command to be executed on the main thread, |
| 1287 | * waits for the request to complete, and returns the result. |
| 1288 | * @see #sendRequestAsync |
| 1289 | */ |
| 1290 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1291 | return sendRequest( |
| 1292 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1293 | } |
| 1294 | |
| 1295 | /** |
| 1296 | * Posts the specified command to be executed on the main thread, |
| 1297 | * waits for the request to complete, and returns the result. |
| 1298 | * @see #sendRequestAsync |
| 1299 | */ |
| 1300 | private Object sendRequest( |
| 1301 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1302 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1303 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1304 | } |
| 1305 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1306 | MainThreadRequest request = null; |
| 1307 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1308 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1309 | } else if (phone != null) { |
| 1310 | request = new MainThreadRequest(argument, phone, workSource); |
| 1311 | } else { |
| 1312 | request = new MainThreadRequest(argument, subId, workSource); |
| 1313 | } |
| 1314 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1315 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1316 | msg.sendToTarget(); |
| 1317 | |
| 1318 | // Wait for the request to complete |
| 1319 | synchronized (request) { |
| 1320 | while (request.result == null) { |
| 1321 | try { |
| 1322 | request.wait(); |
| 1323 | } catch (InterruptedException e) { |
| 1324 | // Do nothing, go back and wait until the request is complete |
| 1325 | } |
| 1326 | } |
| 1327 | } |
| 1328 | return request.result; |
| 1329 | } |
| 1330 | |
| 1331 | /** |
| 1332 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1333 | * Posts the specified command to be executed on the main thread, and |
| 1334 | * returns immediately. |
| 1335 | * @see #sendRequest |
| 1336 | */ |
| 1337 | private void sendRequestAsync(int command) { |
| 1338 | mMainThreadHandler.sendEmptyMessage(command); |
| 1339 | } |
| 1340 | |
| 1341 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1342 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1343 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1344 | */ |
| 1345 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1346 | sendRequestAsync(command, argument, null, null); |
| 1347 | } |
| 1348 | |
| 1349 | /** |
| 1350 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1351 | * @see {@link #sendRequest(int,Object)} |
| 1352 | */ |
| 1353 | private void sendRequestAsync( |
| 1354 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1355 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1356 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1357 | msg.sendToTarget(); |
| 1358 | } |
| 1359 | |
| 1360 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1361 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1362 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1363 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1364 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1365 | synchronized (PhoneInterfaceManager.class) { |
| 1366 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1367 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1368 | } else { |
| 1369 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1370 | } |
| 1371 | return sInstance; |
| 1372 | } |
| 1373 | } |
| 1374 | |
| 1375 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1376 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1377 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1378 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1379 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1380 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1381 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1382 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1383 | mTelephonySharedPreferences = |
| 1384 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1385 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1386 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1387 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1388 | publish(); |
| 1389 | } |
| 1390 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1391 | private Phone getDefaultPhone() { |
| 1392 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1393 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1394 | } |
| 1395 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1396 | private void publish() { |
| 1397 | if (DBG) log("publish: " + this); |
| 1398 | |
| 1399 | ServiceManager.addService("phone", this); |
| 1400 | } |
| 1401 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1402 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1403 | if (request.phone != null) { |
| 1404 | return request.phone; |
| 1405 | } else { |
| 1406 | return getPhoneFromSubId(request.subId); |
| 1407 | } |
| 1408 | } |
| 1409 | |
| 1410 | private Phone getPhoneFromSubId(int subId) { |
| 1411 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1412 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1413 | } |
| 1414 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1415 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1416 | Phone phone = getPhoneFromRequest(request); |
| 1417 | return phone == null ? null : |
| 1418 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1419 | } |
| 1420 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1421 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1422 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1423 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1424 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1425 | |
| 1426 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1427 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1428 | } |
| 1429 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1430 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1431 | if (DBG) log("dial: " + number); |
| 1432 | // No permission check needed here: This is just a wrapper around the |
| 1433 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1434 | // the UI before it does anything. |
| 1435 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1436 | final long identity = Binder.clearCallingIdentity(); |
| 1437 | try { |
| 1438 | String url = createTelUrl(number); |
| 1439 | if (url == null) { |
| 1440 | return; |
| 1441 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1442 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1443 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1444 | PhoneConstants.State state = mCM.getState(subId); |
| 1445 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1446 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1447 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1448 | mApp.startActivity(intent); |
| 1449 | } |
| 1450 | } finally { |
| 1451 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1456 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1459 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1460 | if (DBG) log("call: " + number); |
| 1461 | |
| 1462 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1463 | // need to do a permission check since we're calling startActivity() |
| 1464 | // from the context of the phone app. |
| 1465 | enforceCallPermission(); |
| 1466 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1467 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1468 | != AppOpsManager.MODE_ALLOWED) { |
| 1469 | return; |
| 1470 | } |
| 1471 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1472 | final long identity = Binder.clearCallingIdentity(); |
| 1473 | try { |
| 1474 | String url = createTelUrl(number); |
| 1475 | if (url == null) { |
| 1476 | return; |
| 1477 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1478 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1479 | boolean isValid = false; |
| 1480 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1481 | if (slist != null) { |
| 1482 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1483 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1484 | isValid = true; |
| 1485 | break; |
| 1486 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1487 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1488 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1489 | if (!isValid) { |
| 1490 | return; |
| 1491 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1492 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1493 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1494 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1495 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1496 | mApp.startActivity(intent); |
| 1497 | } finally { |
| 1498 | Binder.restoreCallingIdentity(identity); |
| 1499 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1502 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1503 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1504 | } |
| 1505 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1506 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1507 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1508 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1509 | } |
| 1510 | |
| 1511 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1512 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1513 | } |
| 1514 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1515 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1516 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1517 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1518 | } |
| 1519 | |
| 1520 | /** {@hide} */ |
| 1521 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1522 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1523 | } |
| 1524 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1525 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1526 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1527 | |
| 1528 | final long identity = Binder.clearCallingIdentity(); |
| 1529 | try { |
| 1530 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1531 | checkSimPin.start(); |
| 1532 | return checkSimPin.unlockSim(null, pin); |
| 1533 | } finally { |
| 1534 | Binder.restoreCallingIdentity(identity); |
| 1535 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1536 | } |
| 1537 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1538 | /** {@hide} */ |
| 1539 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1540 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1541 | } |
| 1542 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1543 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1544 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1545 | |
| 1546 | final long identity = Binder.clearCallingIdentity(); |
| 1547 | try { |
| 1548 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1549 | checkSimPuk.start(); |
| 1550 | return checkSimPuk.unlockSim(puk, pin); |
| 1551 | } finally { |
| 1552 | Binder.restoreCallingIdentity(identity); |
| 1553 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1557 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1558 | * a synchronous one. |
| 1559 | */ |
| 1560 | private static class UnlockSim extends Thread { |
| 1561 | |
| 1562 | private final IccCard mSimCard; |
| 1563 | |
| 1564 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1565 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1566 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1567 | |
| 1568 | // For replies from SimCard interface |
| 1569 | private Handler mHandler; |
| 1570 | |
| 1571 | // For async handler to identify request type |
| 1572 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1573 | |
| 1574 | public UnlockSim(IccCard simCard) { |
| 1575 | mSimCard = simCard; |
| 1576 | } |
| 1577 | |
| 1578 | @Override |
| 1579 | public void run() { |
| 1580 | Looper.prepare(); |
| 1581 | synchronized (UnlockSim.this) { |
| 1582 | mHandler = new Handler() { |
| 1583 | @Override |
| 1584 | public void handleMessage(Message msg) { |
| 1585 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1586 | switch (msg.what) { |
| 1587 | case SUPPLY_PIN_COMPLETE: |
| 1588 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1589 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1590 | mRetryCount = msg.arg1; |
| 1591 | if (ar.exception != null) { |
| 1592 | if (ar.exception instanceof CommandException && |
| 1593 | ((CommandException)(ar.exception)).getCommandError() |
| 1594 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1595 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1596 | } else { |
| 1597 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1598 | } |
| 1599 | } else { |
| 1600 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1601 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1602 | mDone = true; |
| 1603 | UnlockSim.this.notifyAll(); |
| 1604 | } |
| 1605 | break; |
| 1606 | } |
| 1607 | } |
| 1608 | }; |
| 1609 | UnlockSim.this.notifyAll(); |
| 1610 | } |
| 1611 | Looper.loop(); |
| 1612 | } |
| 1613 | |
| 1614 | /* |
| 1615 | * Use PIN or PUK to unlock SIM card |
| 1616 | * |
| 1617 | * If PUK is null, unlock SIM card with PIN |
| 1618 | * |
| 1619 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1620 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1621 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1622 | |
| 1623 | while (mHandler == null) { |
| 1624 | try { |
| 1625 | wait(); |
| 1626 | } catch (InterruptedException e) { |
| 1627 | Thread.currentThread().interrupt(); |
| 1628 | } |
| 1629 | } |
| 1630 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1631 | |
| 1632 | if (puk == null) { |
| 1633 | mSimCard.supplyPin(pin, callback); |
| 1634 | } else { |
| 1635 | mSimCard.supplyPuk(puk, pin, callback); |
| 1636 | } |
| 1637 | |
| 1638 | while (!mDone) { |
| 1639 | try { |
| 1640 | Log.d(LOG_TAG, "wait for done"); |
| 1641 | wait(); |
| 1642 | } catch (InterruptedException e) { |
| 1643 | // Restore the interrupted status |
| 1644 | Thread.currentThread().interrupt(); |
| 1645 | } |
| 1646 | } |
| 1647 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1648 | int[] resultArray = new int[2]; |
| 1649 | resultArray[0] = mResult; |
| 1650 | resultArray[1] = mRetryCount; |
| 1651 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1652 | } |
| 1653 | } |
| 1654 | |
| 1655 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1656 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1657 | |
| 1658 | } |
| 1659 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1660 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1661 | // No permission check needed here: this call is harmless, and it's |
| 1662 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1663 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1664 | final long identity = Binder.clearCallingIdentity(); |
| 1665 | try { |
| 1666 | final Phone phone = getPhone(subId); |
| 1667 | if (phone != null) { |
| 1668 | phone.updateServiceLocation(); |
| 1669 | } |
| 1670 | } finally { |
| 1671 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1672 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1673 | } |
| 1674 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1675 | @Override |
| 1676 | public boolean isRadioOn(String callingPackage) { |
| 1677 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1678 | } |
| 1679 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1680 | @Override |
| 1681 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1682 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1683 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1684 | return false; |
| 1685 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1686 | |
| 1687 | final long identity = Binder.clearCallingIdentity(); |
| 1688 | try { |
| 1689 | return isRadioOnForSubscriber(subId); |
| 1690 | } finally { |
| 1691 | Binder.restoreCallingIdentity(identity); |
| 1692 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1696 | final long identity = Binder.clearCallingIdentity(); |
| 1697 | try { |
| 1698 | final Phone phone = getPhone(subId); |
| 1699 | if (phone != null) { |
| 1700 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1701 | } else { |
| 1702 | return false; |
| 1703 | } |
| 1704 | } finally { |
| 1705 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1706 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1710 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1711 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1712 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1713 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1714 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1715 | |
| 1716 | final long identity = Binder.clearCallingIdentity(); |
| 1717 | try { |
| 1718 | final Phone phone = getPhone(subId); |
| 1719 | if (phone != null) { |
| 1720 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1721 | } |
| 1722 | } finally { |
| 1723 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1724 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1728 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1729 | } |
| 1730 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1731 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1732 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1733 | |
| 1734 | final long identity = Binder.clearCallingIdentity(); |
| 1735 | try { |
| 1736 | final Phone phone = getPhone(subId); |
| 1737 | if (phone == null) { |
| 1738 | return false; |
| 1739 | } |
| 1740 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1741 | toggleRadioOnOffForSubscriber(subId); |
| 1742 | } |
| 1743 | return true; |
| 1744 | } finally { |
| 1745 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1746 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1747 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1748 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1749 | public boolean needMobileRadioShutdown() { |
| 1750 | /* |
| 1751 | * If any of the Radios are available, it will need to be |
| 1752 | * shutdown. So return true if any Radio is available. |
| 1753 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1754 | final long identity = Binder.clearCallingIdentity(); |
| 1755 | try { |
| 1756 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1757 | Phone phone = PhoneFactory.getPhone(i); |
| 1758 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1759 | } |
| 1760 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1761 | return false; |
| 1762 | } finally { |
| 1763 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1764 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1767 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1768 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1769 | enforceModifyPermission(); |
| 1770 | |
| 1771 | final long identity = Binder.clearCallingIdentity(); |
| 1772 | try { |
| 1773 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1774 | logv("Shutting down Phone " + i); |
| 1775 | shutdownRadioUsingPhoneId(i); |
| 1776 | } |
| 1777 | } finally { |
| 1778 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1779 | } |
| 1780 | } |
| 1781 | |
| 1782 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1783 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1784 | if (phone != null && phone.isRadioAvailable()) { |
| 1785 | phone.shutdownRadio(); |
| 1786 | } |
| 1787 | } |
| 1788 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1789 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1790 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1791 | |
| 1792 | final long identity = Binder.clearCallingIdentity(); |
| 1793 | try { |
| 1794 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1795 | if (defaultPhone != null) { |
| 1796 | defaultPhone.setRadioPower(turnOn); |
| 1797 | return true; |
| 1798 | } else { |
| 1799 | loge("There's no default phone."); |
| 1800 | return false; |
| 1801 | } |
| 1802 | } finally { |
| 1803 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1804 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1807 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1808 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1809 | |
| 1810 | final long identity = Binder.clearCallingIdentity(); |
| 1811 | try { |
| 1812 | final Phone phone = getPhone(subId); |
| 1813 | if (phone != null) { |
| 1814 | phone.setRadioPower(turnOn); |
| 1815 | return true; |
| 1816 | } else { |
| 1817 | return false; |
| 1818 | } |
| 1819 | } finally { |
| 1820 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1821 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1824 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1825 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1826 | public boolean enableDataConnectivity() { |
| 1827 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1828 | |
| 1829 | final long identity = Binder.clearCallingIdentity(); |
| 1830 | try { |
| 1831 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1832 | final Phone phone = getPhone(subId); |
| 1833 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1834 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1835 | return true; |
| 1836 | } else { |
| 1837 | return false; |
| 1838 | } |
| 1839 | } finally { |
| 1840 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1841 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1842 | } |
| 1843 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1844 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1845 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1846 | public boolean disableDataConnectivity() { |
| 1847 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1848 | |
| 1849 | final long identity = Binder.clearCallingIdentity(); |
| 1850 | try { |
| 1851 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1852 | final Phone phone = getPhone(subId); |
| 1853 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1854 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1855 | return true; |
| 1856 | } else { |
| 1857 | return false; |
| 1858 | } |
| 1859 | } finally { |
| 1860 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1861 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1862 | } |
| 1863 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1864 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1865 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1866 | final long identity = Binder.clearCallingIdentity(); |
| 1867 | try { |
| 1868 | final Phone phone = getPhone(subId); |
| 1869 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1870 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1871 | } else { |
| 1872 | return false; |
| 1873 | } |
| 1874 | } finally { |
| 1875 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1876 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1877 | } |
| 1878 | |
| 1879 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1880 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1881 | } |
| 1882 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1883 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1884 | enforceCallPermission(); |
| 1885 | |
| 1886 | final long identity = Binder.clearCallingIdentity(); |
| 1887 | try { |
| 1888 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1889 | return; |
| 1890 | } |
| 1891 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1892 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1893 | } finally { |
| 1894 | Binder.restoreCallingIdentity(identity); |
| 1895 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1896 | }; |
| 1897 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1898 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1899 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1900 | |
| 1901 | final long identity = Binder.clearCallingIdentity(); |
| 1902 | try { |
| 1903 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1904 | return false; |
| 1905 | } |
| 1906 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1907 | } finally { |
| 1908 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1909 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1910 | } |
| 1911 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1912 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1913 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1914 | } |
| 1915 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1916 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1917 | final long identity = Binder.clearCallingIdentity(); |
| 1918 | try { |
| 1919 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1920 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1921 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1922 | } finally { |
| 1923 | Binder.restoreCallingIdentity(identity); |
| 1924 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1925 | } |
| 1926 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1927 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 1928 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1929 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1930 | } |
| 1931 | |
| 1932 | @Override |
| 1933 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1934 | final long identity = Binder.clearCallingIdentity(); |
| 1935 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1936 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1937 | if (phone != null) { |
| 1938 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1939 | } else { |
| 1940 | return PhoneConstantConversions.convertDataState( |
| 1941 | PhoneConstants.DataState.DISCONNECTED); |
| 1942 | } |
| 1943 | } finally { |
| 1944 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1945 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1946 | } |
| 1947 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1948 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 1949 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1950 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1951 | } |
| 1952 | |
| 1953 | @Override |
| 1954 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1955 | final long identity = Binder.clearCallingIdentity(); |
| 1956 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1957 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1958 | if (phone != null) { |
| 1959 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1960 | } else { |
| 1961 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1962 | } |
| 1963 | } finally { |
| 1964 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1965 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1969 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1970 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1971 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1972 | |
| 1973 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 1974 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 1975 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 1976 | .setCallingPackage(callingPackage) |
| 1977 | .setCallingPid(Binder.getCallingPid()) |
| 1978 | .setCallingUid(Binder.getCallingUid()) |
| 1979 | .setMethod("getCellLocation") |
| 1980 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 1981 | .build()); |
| 1982 | switch (locationResult) { |
| 1983 | case DENIED_HARD: |
| 1984 | throw new SecurityException("Not allowed to access cell location"); |
| 1985 | case DENIED_SOFT: |
| 1986 | return new Bundle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1987 | } |
| 1988 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1989 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1990 | final long identity = Binder.clearCallingIdentity(); |
| 1991 | try { |
| 1992 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1993 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1994 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1995 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1996 | cl.fillInNotifierBundle(data); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1997 | return data; |
| 1998 | } finally { |
| 1999 | Binder.restoreCallingIdentity(identity); |
| 2000 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2001 | } |
| 2002 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2003 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2004 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 2005 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2006 | // registered cell info, so return a NULL country instead. |
| 2007 | final long identity = Binder.clearCallingIdentity(); |
| 2008 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2009 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2010 | // Get default phone in this case. |
| 2011 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2012 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2013 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2014 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2015 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2016 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 2017 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 2018 | return ""; |
| 2019 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2020 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2021 | if (phone != null) { |
| 2022 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2023 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2024 | if (sst != null) { |
| 2025 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2026 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2027 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2028 | return lt.getCurrentCountry(); |
| 2029 | } else if (emergencyNumberTracker != null) { |
| 2030 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2031 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2032 | } |
| 2033 | } |
| 2034 | } |
| 2035 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2036 | } finally { |
| 2037 | Binder.restoreCallingIdentity(identity); |
| 2038 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2042 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2043 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2044 | } |
| 2045 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2046 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2047 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2048 | mApp.enforceCallingOrSelfPermission( |
| 2049 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2050 | |
| 2051 | final long identity = Binder.clearCallingIdentity(); |
| 2052 | try { |
| 2053 | final Phone phone = getPhone(subId); |
| 2054 | if (phone != null) { |
| 2055 | phone.enableLocationUpdates(); |
| 2056 | } |
| 2057 | } finally { |
| 2058 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2059 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | @Override |
| 2063 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2064 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2065 | } |
| 2066 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2067 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2068 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2069 | mApp.enforceCallingOrSelfPermission( |
| 2070 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2071 | |
| 2072 | final long identity = Binder.clearCallingIdentity(); |
| 2073 | try { |
| 2074 | final Phone phone = getPhone(subId); |
| 2075 | if (phone != null) { |
| 2076 | phone.disableLocationUpdates(); |
| 2077 | } |
| 2078 | } finally { |
| 2079 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2080 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2081 | } |
| 2082 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2083 | /** |
| 2084 | * Returns the target SDK version number for a given package name. |
| 2085 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2086 | * This call MUST be invoked before clearing the calling UID. |
| 2087 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2088 | * @return target SDK if the package is found or INT_MAX. |
| 2089 | */ |
| 2090 | private int getTargetSdk(String packageName) { |
| 2091 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2092 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 54d2030 | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2093 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2094 | if (ai != null) return ai.targetSdkVersion; |
| 2095 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2096 | loge("Failed to get package info for pkg=" |
| 2097 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2098 | } |
| 2099 | return Integer.MAX_VALUE; |
| 2100 | } |
| 2101 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2102 | @Override |
| 2103 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2104 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 2105 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2106 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2107 | throw new SecurityException( |
| 2108 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2109 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2110 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2111 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2112 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2113 | return null; |
| 2114 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2115 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2116 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2117 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2118 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 2119 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2120 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2121 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2122 | for (CellInfo ci : info) { |
| 2123 | if (ci instanceof CellInfoGsm) { |
| 2124 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2125 | } else if (ci instanceof CellInfoWcdma) { |
| 2126 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2127 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2128 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2129 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2130 | } |
| 2131 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2132 | private List<CellInfo> getCachedCellInfo() { |
| 2133 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2134 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2135 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2136 | if (info != null) cellInfos.addAll(info); |
| 2137 | } |
| 2138 | return cellInfos; |
| 2139 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2140 | |
| 2141 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2142 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2143 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2144 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2145 | |
| 2146 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2147 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2148 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2149 | .setCallingPackage(callingPackage) |
| 2150 | .setCallingPid(Binder.getCallingPid()) |
| 2151 | .setCallingUid(Binder.getCallingUid()) |
| 2152 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2153 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2154 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2155 | .build()); |
| 2156 | switch (locationResult) { |
| 2157 | case DENIED_HARD: |
| 2158 | throw new SecurityException("Not allowed to access cell info"); |
| 2159 | case DENIED_SOFT: |
| 2160 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2161 | } |
| 2162 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2163 | final int targetSdk = getTargetSdk(callingPackage); |
| 2164 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2165 | return getCachedCellInfo(); |
| 2166 | } |
| 2167 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2168 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2169 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2170 | final long identity = Binder.clearCallingIdentity(); |
| 2171 | try { |
| 2172 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2173 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2174 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2175 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2176 | if (info != null) cellInfos.addAll(info); |
| 2177 | } |
| 2178 | return cellInfos; |
| 2179 | } finally { |
| 2180 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2181 | } |
| 2182 | } |
| 2183 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2184 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2185 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2186 | requestCellInfoUpdateInternal( |
| 2187 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2188 | } |
| 2189 | |
| 2190 | @Override |
| 2191 | public void requestCellInfoUpdateWithWorkSource( |
| 2192 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2193 | enforceModifyPermission(); |
| 2194 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2195 | } |
| 2196 | |
| 2197 | private void requestCellInfoUpdateInternal( |
| 2198 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2199 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2200 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2201 | |
| 2202 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2203 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2204 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2205 | .setCallingPackage(callingPackage) |
| 2206 | .setCallingPid(Binder.getCallingPid()) |
| 2207 | .setCallingUid(Binder.getCallingUid()) |
| 2208 | .setMethod("requestCellInfoUpdate") |
| 2209 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2210 | .build()); |
| 2211 | switch (locationResult) { |
| 2212 | case DENIED_HARD: |
| 2213 | throw new SecurityException("Not allowed to access cell info"); |
| 2214 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2215 | try { |
| 2216 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2217 | } catch (RemoteException re) { |
| 2218 | // Drop without consequences |
| 2219 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2220 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2221 | } |
| 2222 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2223 | |
| 2224 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2225 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2226 | |
| 2227 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2228 | } |
| 2229 | |
| 2230 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2231 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2232 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2233 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2234 | |
| 2235 | final long identity = Binder.clearCallingIdentity(); |
| 2236 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2237 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2238 | } finally { |
| 2239 | Binder.restoreCallingIdentity(identity); |
| 2240 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2241 | } |
| 2242 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2243 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2244 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2245 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2246 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2247 | return null; |
| 2248 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2249 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2250 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2251 | callingPackage, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2252 | return null; |
| 2253 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2254 | |
| 2255 | final long identity = Binder.clearCallingIdentity(); |
| 2256 | try { |
| 2257 | return phone.getImei(); |
| 2258 | } finally { |
| 2259 | Binder.restoreCallingIdentity(identity); |
| 2260 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2264 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2265 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2266 | String tac = null; |
| 2267 | if (phone != null) { |
| 2268 | String imei = phone.getImei(); |
| 2269 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2270 | } |
| 2271 | return tac; |
| 2272 | } |
| 2273 | |
| 2274 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2275 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2276 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2277 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2278 | return null; |
| 2279 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2280 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2281 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2282 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2283 | callingPackage, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2284 | return null; |
| 2285 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2286 | |
| 2287 | final long identity = Binder.clearCallingIdentity(); |
| 2288 | try { |
| 2289 | return phone.getMeid(); |
| 2290 | } finally { |
| 2291 | Binder.restoreCallingIdentity(identity); |
| 2292 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2293 | } |
| 2294 | |
| 2295 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2296 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2297 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2298 | String manufacturerCode = null; |
| 2299 | if (phone != null) { |
| 2300 | String meid = phone.getMeid(); |
| 2301 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2302 | } |
| 2303 | return manufacturerCode; |
| 2304 | } |
| 2305 | |
| 2306 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2307 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2308 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2309 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2310 | return null; |
| 2311 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2312 | int subId = phone.getSubId(); |
| 2313 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2314 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2315 | return null; |
| 2316 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2317 | |
| 2318 | final long identity = Binder.clearCallingIdentity(); |
| 2319 | try { |
| 2320 | return phone.getDeviceSvn(); |
| 2321 | } finally { |
| 2322 | Binder.restoreCallingIdentity(identity); |
| 2323 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2324 | } |
| 2325 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2326 | @Override |
| 2327 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2328 | final long identity = Binder.clearCallingIdentity(); |
| 2329 | try { |
| 2330 | final Phone phone = getPhone(subId); |
| 2331 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2332 | } finally { |
| 2333 | Binder.restoreCallingIdentity(identity); |
| 2334 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | @Override |
| 2338 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2339 | final long identity = Binder.clearCallingIdentity(); |
| 2340 | try { |
| 2341 | final Phone phone = getPhone(subId); |
| 2342 | return phone == null ? null : phone.getCarrierName(); |
| 2343 | } finally { |
| 2344 | Binder.restoreCallingIdentity(identity); |
| 2345 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2346 | } |
| 2347 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2348 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2349 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2350 | final long identity = Binder.clearCallingIdentity(); |
| 2351 | try { |
| 2352 | final Phone phone = getPhone(subId); |
| 2353 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2354 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2355 | } finally { |
| 2356 | Binder.restoreCallingIdentity(identity); |
| 2357 | } |
| 2358 | } |
| 2359 | |
| 2360 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2361 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2362 | final long identity = Binder.clearCallingIdentity(); |
| 2363 | try { |
| 2364 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2365 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2366 | } finally { |
| 2367 | Binder.restoreCallingIdentity(identity); |
| 2368 | } |
| 2369 | } |
| 2370 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2371 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2372 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2373 | if (!isSubscriptionMccMnc) { |
| 2374 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2375 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2376 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2377 | if (phone == null) { |
| 2378 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2379 | } |
| 2380 | final long identity = Binder.clearCallingIdentity(); |
| 2381 | try { |
| 2382 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2383 | } finally { |
| 2384 | Binder.restoreCallingIdentity(identity); |
| 2385 | } |
| 2386 | } |
| 2387 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2388 | // |
| 2389 | // Internal helper methods. |
| 2390 | // |
| 2391 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2392 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2393 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2394 | * |
| 2395 | * @throws SecurityException if the caller does not have the required permission |
| 2396 | */ |
| 2397 | private void enforceModifyPermission() { |
| 2398 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2399 | } |
| 2400 | |
| 2401 | /** |
| 2402 | * Make sure the caller has the CALL_PHONE permission. |
| 2403 | * |
| 2404 | * @throws SecurityException if the caller does not have the required permission |
| 2405 | */ |
| 2406 | private void enforceCallPermission() { |
| 2407 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2408 | } |
| 2409 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2410 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2411 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2412 | "ConnectivityService"); |
| 2413 | } |
| 2414 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2415 | private String createTelUrl(String number) { |
| 2416 | if (TextUtils.isEmpty(number)) { |
| 2417 | return null; |
| 2418 | } |
| 2419 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2420 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2421 | } |
| 2422 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2423 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2424 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2425 | } |
| 2426 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2427 | private static void logv(String msg) { |
| 2428 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2429 | } |
| 2430 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2431 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2432 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2433 | } |
| 2434 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2435 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2436 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2437 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2438 | } |
| 2439 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2440 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2441 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2442 | final long identity = Binder.clearCallingIdentity(); |
| 2443 | try { |
| 2444 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2445 | if (phone == null) { |
| 2446 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2447 | } else { |
| 2448 | return phone.getPhoneType(); |
| 2449 | } |
| 2450 | } finally { |
| 2451 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2452 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2453 | } |
| 2454 | |
| 2455 | /** |
| 2456 | * Returns the CDMA ERI icon index to display |
| 2457 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2458 | @Override |
| 2459 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2460 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2461 | } |
| 2462 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2463 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2464 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2465 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2466 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2467 | return -1; |
| 2468 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2469 | |
| 2470 | final long identity = Binder.clearCallingIdentity(); |
| 2471 | try { |
| 2472 | final Phone phone = getPhone(subId); |
| 2473 | if (phone != null) { |
| 2474 | return phone.getCdmaEriIconIndex(); |
| 2475 | } else { |
| 2476 | return -1; |
| 2477 | } |
| 2478 | } finally { |
| 2479 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2480 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | /** |
| 2484 | * Returns the CDMA ERI icon mode, |
| 2485 | * 0 - ON |
| 2486 | * 1 - FLASHING |
| 2487 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2488 | @Override |
| 2489 | public int getCdmaEriIconMode(String callingPackage) { |
| 2490 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2491 | } |
| 2492 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2493 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2494 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2495 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2496 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2497 | return -1; |
| 2498 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2499 | |
| 2500 | final long identity = Binder.clearCallingIdentity(); |
| 2501 | try { |
| 2502 | final Phone phone = getPhone(subId); |
| 2503 | if (phone != null) { |
| 2504 | return phone.getCdmaEriIconMode(); |
| 2505 | } else { |
| 2506 | return -1; |
| 2507 | } |
| 2508 | } finally { |
| 2509 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2510 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | /** |
| 2514 | * Returns the CDMA ERI text, |
| 2515 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2516 | @Override |
| 2517 | public String getCdmaEriText(String callingPackage) { |
| 2518 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2519 | } |
| 2520 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2521 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2522 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2523 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2524 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2525 | return null; |
| 2526 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2527 | |
| 2528 | final long identity = Binder.clearCallingIdentity(); |
| 2529 | try { |
| 2530 | final Phone phone = getPhone(subId); |
| 2531 | if (phone != null) { |
| 2532 | return phone.getCdmaEriText(); |
| 2533 | } else { |
| 2534 | return null; |
| 2535 | } |
| 2536 | } finally { |
| 2537 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2538 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2542 | * Returns the CDMA MDN. |
| 2543 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2544 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2545 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2546 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2547 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2548 | |
| 2549 | final long identity = Binder.clearCallingIdentity(); |
| 2550 | try { |
| 2551 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2552 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2553 | return phone.getLine1Number(); |
| 2554 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2555 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2556 | return null; |
| 2557 | } |
| 2558 | } finally { |
| 2559 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2560 | } |
| 2561 | } |
| 2562 | |
| 2563 | /** |
| 2564 | * Returns the CDMA MIN. |
| 2565 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2566 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2567 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2568 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2569 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2570 | |
| 2571 | final long identity = Binder.clearCallingIdentity(); |
| 2572 | try { |
| 2573 | final Phone phone = getPhone(subId); |
| 2574 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2575 | return phone.getCdmaMin(); |
| 2576 | } else { |
| 2577 | return null; |
| 2578 | } |
| 2579 | } finally { |
| 2580 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2581 | } |
| 2582 | } |
| 2583 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2584 | @Override |
| 2585 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2586 | INumberVerificationCallback callback, String callingPackage) { |
| 2587 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2588 | != PERMISSION_GRANTED) { |
| 2589 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2590 | } |
| 2591 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2592 | |
| 2593 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2594 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2595 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2596 | } |
| 2597 | |
| 2598 | if (range == null) { |
| 2599 | throw new NullPointerException("Range must be non-null"); |
| 2600 | } |
| 2601 | |
| 2602 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2603 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2604 | |
| 2605 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2606 | } |
| 2607 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2608 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2609 | * Returns true if CDMA provisioning needs to run. |
| 2610 | */ |
| 2611 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2612 | final long identity = Binder.clearCallingIdentity(); |
| 2613 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2614 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2615 | } finally { |
| 2616 | Binder.restoreCallingIdentity(identity); |
| 2617 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2618 | } |
| 2619 | |
| 2620 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2621 | * Sets the voice mail number of a given subId. |
| 2622 | */ |
| 2623 | @Override |
| 2624 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2625 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2626 | |
| 2627 | final long identity = Binder.clearCallingIdentity(); |
| 2628 | try { |
| 2629 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2630 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2631 | return success; |
| 2632 | } finally { |
| 2633 | Binder.restoreCallingIdentity(identity); |
| 2634 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2635 | } |
| 2636 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2637 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2638 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2639 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2640 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2641 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2642 | throw new SecurityException("caller must be system dialer"); |
| 2643 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2644 | |
| 2645 | final long identity = Binder.clearCallingIdentity(); |
| 2646 | try { |
| 2647 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2648 | if (phoneAccountHandle == null) { |
| 2649 | return null; |
| 2650 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2651 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2652 | } finally { |
| 2653 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2654 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2655 | } |
| 2656 | |
| 2657 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2658 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2659 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2660 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2661 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2662 | return null; |
| 2663 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2664 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2665 | final long identity = Binder.clearCallingIdentity(); |
| 2666 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2667 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2668 | } finally { |
| 2669 | Binder.restoreCallingIdentity(identity); |
| 2670 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2674 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2675 | VisualVoicemailSmsFilterSettings settings) { |
| 2676 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2677 | |
| 2678 | final long identity = Binder.clearCallingIdentity(); |
| 2679 | try { |
| 2680 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2681 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2682 | } finally { |
| 2683 | Binder.restoreCallingIdentity(identity); |
| 2684 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2685 | } |
| 2686 | |
| 2687 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2688 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2689 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2690 | |
| 2691 | final long identity = Binder.clearCallingIdentity(); |
| 2692 | try { |
| 2693 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2694 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2695 | } finally { |
| 2696 | Binder.restoreCallingIdentity(identity); |
| 2697 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2698 | } |
| 2699 | |
| 2700 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2701 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2702 | String callingPackage, int subId) { |
| 2703 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2704 | |
| 2705 | final long identity = Binder.clearCallingIdentity(); |
| 2706 | try { |
| 2707 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2708 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2709 | } finally { |
| 2710 | Binder.restoreCallingIdentity(identity); |
| 2711 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2712 | } |
| 2713 | |
| 2714 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2715 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2716 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2717 | |
| 2718 | final long identity = Binder.clearCallingIdentity(); |
| 2719 | try { |
| 2720 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2721 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2722 | } finally { |
| 2723 | Binder.restoreCallingIdentity(identity); |
| 2724 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2725 | } |
| 2726 | |
| 2727 | @Override |
| 2728 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2729 | String number, int port, String text, PendingIntent sentIntent) { |
| 2730 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2731 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2732 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2733 | SmsController smsController = PhoneFactory.getSmsController(); |
| 2734 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 2735 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2736 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2737 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2738 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2739 | * Sets the voice activation state of a given subId. |
| 2740 | */ |
| 2741 | @Override |
| 2742 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2743 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2744 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2745 | |
| 2746 | final long identity = Binder.clearCallingIdentity(); |
| 2747 | try { |
| 2748 | final Phone phone = getPhone(subId); |
| 2749 | if (phone != null) { |
| 2750 | phone.setVoiceActivationState(activationState); |
| 2751 | } else { |
| 2752 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2753 | } |
| 2754 | } finally { |
| 2755 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2756 | } |
| 2757 | } |
| 2758 | |
| 2759 | /** |
| 2760 | * Sets the data activation state of a given subId. |
| 2761 | */ |
| 2762 | @Override |
| 2763 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2764 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2765 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2766 | |
| 2767 | final long identity = Binder.clearCallingIdentity(); |
| 2768 | try { |
| 2769 | final Phone phone = getPhone(subId); |
| 2770 | if (phone != null) { |
| 2771 | phone.setDataActivationState(activationState); |
| 2772 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 2773 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2774 | } |
| 2775 | } finally { |
| 2776 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2777 | } |
| 2778 | } |
| 2779 | |
| 2780 | /** |
| 2781 | * Returns the voice activation state of a given subId. |
| 2782 | */ |
| 2783 | @Override |
| 2784 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2785 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2786 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2787 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2788 | final long identity = Binder.clearCallingIdentity(); |
| 2789 | try { |
| 2790 | if (phone != null) { |
| 2791 | return phone.getVoiceActivationState(); |
| 2792 | } else { |
| 2793 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2794 | } |
| 2795 | } finally { |
| 2796 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2797 | } |
| 2798 | } |
| 2799 | |
| 2800 | /** |
| 2801 | * Returns the data activation state of a given subId. |
| 2802 | */ |
| 2803 | @Override |
| 2804 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2805 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2806 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2807 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2808 | final long identity = Binder.clearCallingIdentity(); |
| 2809 | try { |
| 2810 | if (phone != null) { |
| 2811 | return phone.getDataActivationState(); |
| 2812 | } else { |
| 2813 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2814 | } |
| 2815 | } finally { |
| 2816 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2817 | } |
| 2818 | } |
| 2819 | |
| 2820 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2821 | * Returns the unread count of voicemails for a subId |
| 2822 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2823 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2824 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2825 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2826 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2827 | return 0; |
| 2828 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2829 | final long identity = Binder.clearCallingIdentity(); |
| 2830 | try { |
| 2831 | final Phone phone = getPhone(subId); |
| 2832 | if (phone != null) { |
| 2833 | return phone.getVoiceMessageCount(); |
| 2834 | } else { |
| 2835 | return 0; |
| 2836 | } |
| 2837 | } finally { |
| 2838 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2839 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2840 | } |
| 2841 | |
| 2842 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2843 | * returns true, if the device is in a state where both voice and data |
| 2844 | * are supported simultaneously. This can change based on location or network condition. |
| 2845 | */ |
| 2846 | @Override |
| 2847 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2848 | final long identity = Binder.clearCallingIdentity(); |
| 2849 | try { |
| 2850 | final Phone phone = getPhone(subId); |
| 2851 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2852 | } finally { |
| 2853 | Binder.restoreCallingIdentity(identity); |
| 2854 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2855 | } |
| 2856 | |
| 2857 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2858 | * Send the dialer code if called from the current default dialer or the caller has |
| 2859 | * carrier privilege. |
| 2860 | * @param inputCode The dialer code to send |
| 2861 | */ |
| 2862 | @Override |
| 2863 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2864 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2865 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2866 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2867 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2868 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2869 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2870 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2871 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2872 | |
| 2873 | final long identity = Binder.clearCallingIdentity(); |
| 2874 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2875 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2876 | } finally { |
| 2877 | Binder.restoreCallingIdentity(identity); |
| 2878 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2879 | } |
| 2880 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2881 | @Override |
| 2882 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2883 | if (!isActiveSubscription(subId)) { |
| 2884 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2885 | } |
| 2886 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2887 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2888 | } |
| 2889 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2890 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2891 | public boolean isInEmergencySmsMode() { |
| 2892 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 2893 | final long identity = Binder.clearCallingIdentity(); |
| 2894 | try { |
| 2895 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2896 | if (phone.isInEmergencySmsMode()) { |
| 2897 | return true; |
| 2898 | } |
| 2899 | } |
| 2900 | } finally { |
| 2901 | Binder.restoreCallingIdentity(identity); |
| 2902 | } |
| 2903 | return false; |
| 2904 | } |
| 2905 | |
| 2906 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2907 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2908 | throws RemoteException { |
| 2909 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame^] | 2910 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 2911 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 2912 | "IMS not available on device."); |
| 2913 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2914 | final long token = Binder.clearCallingIdentity(); |
| 2915 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2916 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2917 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2918 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2919 | } catch (ImsException e) { |
| 2920 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2921 | } finally { |
| 2922 | Binder.restoreCallingIdentity(token); |
| 2923 | } |
| 2924 | } |
| 2925 | |
| 2926 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2927 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2928 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2929 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2930 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2931 | } |
| 2932 | Binder.withCleanCallingIdentity(() -> { |
| 2933 | try { |
| 2934 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2935 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2936 | .removeRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2937 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2938 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2939 | + "is inactive, ignoring unregister."); |
| 2940 | // If the subscription is no longer active, just return, since the callback |
| 2941 | // will already have been removed internally. |
| 2942 | } |
| 2943 | }); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2944 | } |
| 2945 | |
| 2946 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2947 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2948 | throws RemoteException { |
| 2949 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame^] | 2950 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 2951 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 2952 | "IMS not available on device."); |
| 2953 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2954 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2955 | final long token = Binder.clearCallingIdentity(); |
| 2956 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2957 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2958 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2959 | } catch (ImsException e) { |
| 2960 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2961 | } finally { |
| 2962 | Binder.restoreCallingIdentity(token); |
| 2963 | } |
| 2964 | } |
| 2965 | |
| 2966 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2967 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2968 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2969 | |
| 2970 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2971 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2972 | } |
| 2973 | Binder.withCleanCallingIdentity(() -> { |
| 2974 | try { |
| 2975 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2976 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2977 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2978 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2979 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2980 | + "is inactive, ignoring unregister."); |
| 2981 | // If the subscription is no longer active, just return, since the callback |
| 2982 | // will already have been removed internally. |
| 2983 | } |
| 2984 | }); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2985 | } |
| 2986 | |
| 2987 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2988 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2989 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2990 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2991 | final long token = Binder.clearCallingIdentity(); |
| 2992 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2993 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2994 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2995 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2996 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2997 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2998 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2999 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3000 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3001 | } finally { |
| 3002 | Binder.restoreCallingIdentity(token); |
| 3003 | } |
| 3004 | } |
| 3005 | |
| 3006 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3007 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3008 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3009 | final long token = Binder.clearCallingIdentity(); |
| 3010 | try { |
| 3011 | Phone phone = getPhone(subId); |
| 3012 | if (phone == null) return false; |
| 3013 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 3014 | } finally { |
| 3015 | Binder.restoreCallingIdentity(token); |
| 3016 | } |
| 3017 | } |
| 3018 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame^] | 3019 | /** |
| 3020 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3021 | * subscription. |
| 3022 | * @param subId The subscription to use to check the configuration. |
| 3023 | * @param callback The callback that will be used to send the result. |
| 3024 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3025 | * @param transportType The transport type of the MmTelFeature capability. |
| 3026 | */ |
| 3027 | @Override |
| 3028 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3029 | int transportType) { |
| 3030 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3031 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3032 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3033 | "IMS not available on device."); |
| 3034 | } |
| 3035 | final long token = Binder.clearCallingIdentity(); |
| 3036 | try { |
| 3037 | int slotId = getSlotIndex(subId); |
| 3038 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3039 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3040 | + subId + "'"); |
| 3041 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3042 | } |
| 3043 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3044 | transportType, aBoolean -> { |
| 3045 | try { |
| 3046 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3047 | } catch (RemoteException e) { |
| 3048 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3049 | + "running. Ignore"); |
| 3050 | } |
| 3051 | }); |
| 3052 | } finally { |
| 3053 | Binder.restoreCallingIdentity(token); |
| 3054 | } |
| 3055 | } |
| 3056 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3057 | @Override |
| 3058 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 3059 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 3060 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3061 | final long token = Binder.clearCallingIdentity(); |
| 3062 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3063 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3064 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3065 | } catch (ImsException e) { |
| 3066 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3067 | } finally { |
| 3068 | Binder.restoreCallingIdentity(token); |
| 3069 | } |
| 3070 | } |
| 3071 | |
| 3072 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3073 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3074 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3075 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3076 | final long identity = Binder.clearCallingIdentity(); |
| 3077 | try { |
| 3078 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3079 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3080 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3081 | } catch (ImsException e) { |
| 3082 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3083 | } finally { |
| 3084 | Binder.restoreCallingIdentity(identity); |
| 3085 | } |
| 3086 | } |
| 3087 | |
| 3088 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3089 | public boolean isVtSettingEnabled(int subId) { |
| 3090 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3091 | final long identity = Binder.clearCallingIdentity(); |
| 3092 | try { |
| 3093 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3094 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3095 | } catch (ImsException e) { |
| 3096 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3097 | } finally { |
| 3098 | Binder.restoreCallingIdentity(identity); |
| 3099 | } |
| 3100 | } |
| 3101 | |
| 3102 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3103 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3104 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3105 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3106 | final long identity = Binder.clearCallingIdentity(); |
| 3107 | try { |
| 3108 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3109 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3110 | } catch (ImsException e) { |
| 3111 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3112 | } finally { |
| 3113 | Binder.restoreCallingIdentity(identity); |
| 3114 | } |
| 3115 | } |
| 3116 | |
| 3117 | @Override |
| 3118 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 3119 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 3120 | final long identity = Binder.clearCallingIdentity(); |
| 3121 | try { |
| 3122 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3123 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3124 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3125 | } catch (ImsException e) { |
| 3126 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3127 | } finally { |
| 3128 | Binder.restoreCallingIdentity(identity); |
| 3129 | } |
| 3130 | } |
| 3131 | |
| 3132 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3133 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3134 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3135 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3136 | final long identity = Binder.clearCallingIdentity(); |
| 3137 | try { |
| 3138 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3139 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3140 | } catch (ImsException e) { |
| 3141 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3142 | } finally { |
| 3143 | Binder.restoreCallingIdentity(identity); |
| 3144 | } |
| 3145 | } |
| 3146 | |
| 3147 | @Override |
| 3148 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 3149 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3150 | final long identity = Binder.clearCallingIdentity(); |
| 3151 | try { |
| 3152 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3153 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3154 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3155 | } catch (ImsException e) { |
| 3156 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3157 | } finally { |
| 3158 | Binder.restoreCallingIdentity(identity); |
| 3159 | } |
| 3160 | } |
| 3161 | |
| 3162 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3163 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3164 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3165 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3166 | final long identity = Binder.clearCallingIdentity(); |
| 3167 | try { |
| 3168 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3169 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3170 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3171 | } catch (ImsException e) { |
| 3172 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3173 | } finally { |
| 3174 | Binder.restoreCallingIdentity(identity); |
| 3175 | } |
| 3176 | } |
| 3177 | |
| 3178 | @Override |
| 3179 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3180 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3181 | "setVoWiFiNonPersistent"); |
| 3182 | final long identity = Binder.clearCallingIdentity(); |
| 3183 | try { |
| 3184 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3185 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3186 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3187 | } catch (ImsException e) { |
| 3188 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3189 | } finally { |
| 3190 | Binder.restoreCallingIdentity(identity); |
| 3191 | } |
| 3192 | } |
| 3193 | |
| 3194 | @Override |
| 3195 | public int getVoWiFiModeSetting(int subId) { |
| 3196 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3197 | final long identity = Binder.clearCallingIdentity(); |
| 3198 | try { |
| 3199 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3200 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3201 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3202 | } catch (ImsException e) { |
| 3203 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3204 | } finally { |
| 3205 | Binder.restoreCallingIdentity(identity); |
| 3206 | } |
| 3207 | } |
| 3208 | |
| 3209 | @Override |
| 3210 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3211 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3212 | "setVoWiFiModeSetting"); |
| 3213 | final long identity = Binder.clearCallingIdentity(); |
| 3214 | try { |
| 3215 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3216 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3217 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3218 | } catch (ImsException e) { |
| 3219 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3220 | } finally { |
| 3221 | Binder.restoreCallingIdentity(identity); |
| 3222 | } |
| 3223 | } |
| 3224 | |
| 3225 | @Override |
| 3226 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3227 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3228 | final long identity = Binder.clearCallingIdentity(); |
| 3229 | try { |
| 3230 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3231 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3232 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3233 | } catch (ImsException e) { |
| 3234 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3235 | } finally { |
| 3236 | Binder.restoreCallingIdentity(identity); |
| 3237 | } |
| 3238 | } |
| 3239 | |
| 3240 | @Override |
| 3241 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3242 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3243 | "setVoWiFiRoamingModeSetting"); |
| 3244 | final long identity = Binder.clearCallingIdentity(); |
| 3245 | try { |
| 3246 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3247 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3248 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3249 | } catch (ImsException e) { |
| 3250 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3251 | } finally { |
| 3252 | Binder.restoreCallingIdentity(identity); |
| 3253 | } |
| 3254 | } |
| 3255 | |
| 3256 | @Override |
| 3257 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3258 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3259 | "setRttCapabilityEnabled"); |
| 3260 | final long identity = Binder.clearCallingIdentity(); |
| 3261 | try { |
| 3262 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3263 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3264 | } catch (ImsException e) { |
| 3265 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3266 | } finally { |
| 3267 | Binder.restoreCallingIdentity(identity); |
| 3268 | } |
| 3269 | } |
| 3270 | |
| 3271 | @Override |
| 3272 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3273 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3274 | final long identity = Binder.clearCallingIdentity(); |
| 3275 | try { |
| 3276 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3277 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3278 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3279 | } catch (ImsException e) { |
| 3280 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3281 | } finally { |
| 3282 | Binder.restoreCallingIdentity(identity); |
| 3283 | } |
| 3284 | } |
| 3285 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3286 | @Override |
| 3287 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3288 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3289 | final long identity = Binder.clearCallingIdentity(); |
| 3290 | try { |
| 3291 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3292 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3293 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3294 | } catch (ImsException e) { |
| 3295 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3296 | } finally { |
| 3297 | Binder.restoreCallingIdentity(identity); |
| 3298 | } |
| 3299 | } |
| 3300 | |
| 3301 | @Override |
| 3302 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3303 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3304 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3305 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3306 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3307 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3308 | try { |
| 3309 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3310 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3311 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3312 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3313 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3314 | + "is inactive, ignoring unregister."); |
| 3315 | // If the subscription is no longer active, just return, since the callback will already |
| 3316 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3317 | } finally { |
| 3318 | Binder.restoreCallingIdentity(identity); |
| 3319 | } |
| 3320 | } |
| 3321 | |
| 3322 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3323 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3324 | boolean isProvisioned) { |
| 3325 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3326 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3327 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3328 | } |
| 3329 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3330 | "setProvisioningStatusForCapability"); |
| 3331 | final long identity = Binder.clearCallingIdentity(); |
| 3332 | try { |
| 3333 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3334 | Phone phone = getPhone(subId); |
| 3335 | if (phone == null) { |
| 3336 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3337 | + subId); |
| 3338 | return; |
| 3339 | } |
| 3340 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3341 | return; |
| 3342 | } |
| 3343 | |
| 3344 | // this capability requires provisioning, route to the correct API. |
| 3345 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3346 | switch (capability) { |
| 3347 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3348 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3349 | ims.setVolteProvisioned(isProvisioned); |
| 3350 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3351 | ims.setWfcProvisioned(isProvisioned); |
| 3352 | } |
| 3353 | break; |
| 3354 | } |
| 3355 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3356 | // There is currently no difference in VT provisioning type. |
| 3357 | ims.setVtProvisioned(isProvisioned); |
| 3358 | break; |
| 3359 | } |
| 3360 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3361 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3362 | // change the capability of the feature instead if needed. |
| 3363 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3364 | == isProvisioned) { |
| 3365 | // No change in provisioning. |
| 3366 | return; |
| 3367 | } |
| 3368 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3369 | try { |
| 3370 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3371 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3372 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3373 | + ", Exception" + e.getMessage()); |
| 3374 | } |
| 3375 | break; |
| 3376 | } |
| 3377 | default: { |
| 3378 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3379 | + capability + "', which does not require provisioning."); |
| 3380 | } |
| 3381 | } |
| 3382 | |
| 3383 | } finally { |
| 3384 | Binder.restoreCallingIdentity(identity); |
| 3385 | } |
| 3386 | } |
| 3387 | |
| 3388 | @Override |
| 3389 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3390 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3391 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3392 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3393 | } |
| 3394 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3395 | final long identity = Binder.clearCallingIdentity(); |
| 3396 | try { |
| 3397 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3398 | Phone phone = getPhone(subId); |
| 3399 | if (phone == null) { |
| 3400 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3401 | + subId); |
| 3402 | // We will fail with "true" as the provisioning status because this is the default |
| 3403 | // if we do not require provisioning. |
| 3404 | return true; |
| 3405 | } |
| 3406 | |
| 3407 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3408 | return true; |
| 3409 | } |
| 3410 | |
| 3411 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3412 | switch (capability) { |
| 3413 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3414 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3415 | return ims.isVolteProvisionedOnDevice(); |
| 3416 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3417 | return ims.isWfcProvisionedOnDevice(); |
| 3418 | } |
| 3419 | // This should never happen, since we are checking tech above to make sure it |
| 3420 | // is either LTE or IWLAN. |
| 3421 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3422 | + "capability."); |
| 3423 | } |
| 3424 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3425 | // There is currently no difference in VT provisioning type. |
| 3426 | return ims.isVtProvisionedOnDevice(); |
| 3427 | } |
| 3428 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3429 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3430 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3431 | } |
| 3432 | default: { |
| 3433 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3434 | + capability + "', which does not require provisioning."); |
| 3435 | } |
| 3436 | } |
| 3437 | |
| 3438 | } finally { |
| 3439 | Binder.restoreCallingIdentity(identity); |
| 3440 | } |
| 3441 | } |
| 3442 | |
| 3443 | @Override |
| 3444 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3445 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3446 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3447 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3448 | } |
| 3449 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3450 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3451 | return (provisionedBits & capability) > 0; |
| 3452 | } |
| 3453 | |
| 3454 | @Override |
| 3455 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3456 | boolean isProvisioned) { |
| 3457 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3458 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3459 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3460 | } |
| 3461 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3462 | "setProvisioningStatusForCapability"); |
| 3463 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3464 | // If the current provisioning status for capability already matches isProvisioned, |
| 3465 | // do nothing. |
| 3466 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3467 | return; |
| 3468 | } |
| 3469 | if (isProvisioned) { |
| 3470 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3471 | } else { |
| 3472 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3473 | } |
| 3474 | } |
| 3475 | |
| 3476 | /** |
| 3477 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3478 | * technology. The bitfield should mirror the bitfield defined by |
| 3479 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3480 | */ |
| 3481 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3482 | String key = getMmTelProvisioningKey(subId, tech); |
| 3483 | // Default is no capabilities are provisioned. |
| 3484 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3485 | } |
| 3486 | |
| 3487 | /** |
| 3488 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3489 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3490 | * technology specified. |
| 3491 | * |
| 3492 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3493 | */ |
| 3494 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3495 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3496 | String key = getMmTelProvisioningKey(subId, tech); |
| 3497 | editor.putInt(key, newField); |
| 3498 | editor.commit(); |
| 3499 | } |
| 3500 | |
| 3501 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3502 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3503 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3504 | } |
| 3505 | |
| 3506 | /** |
| 3507 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3508 | * carrier associated with the subscription id. |
| 3509 | */ |
| 3510 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3511 | int capability) { |
| 3512 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3513 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3514 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 3515 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3516 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3517 | false); |
| 3518 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3519 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3520 | |
| 3521 | // First check to make sure that the capability requires provisioning. |
| 3522 | switch (capability) { |
| 3523 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3524 | // intentional fallthrough |
| 3525 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3526 | if (requireVoiceVtProvisioning) { |
| 3527 | // Voice and Video requires provisioning |
| 3528 | return true; |
| 3529 | } |
| 3530 | break; |
| 3531 | } |
| 3532 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3533 | if (requireUtProvisioning) { |
| 3534 | // UT requires provisioning |
| 3535 | return true; |
| 3536 | } |
| 3537 | break; |
| 3538 | } |
| 3539 | } |
| 3540 | return false; |
| 3541 | } |
| 3542 | |
| 3543 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3544 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3545 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3546 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3547 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3548 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3549 | final long identity = Binder.clearCallingIdentity(); |
| 3550 | try { |
| 3551 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3552 | int slotId = getSlotIndex(subId); |
| 3553 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3554 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3555 | + subId + "' for key:" + key); |
| 3556 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3557 | } |
| 3558 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3559 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3560 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3561 | + subId + "' for key:" + key); |
| 3562 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3563 | } finally { |
| 3564 | Binder.restoreCallingIdentity(identity); |
| 3565 | } |
| 3566 | } |
| 3567 | |
| 3568 | @Override |
| 3569 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3570 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3571 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3572 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3573 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3574 | final long identity = Binder.clearCallingIdentity(); |
| 3575 | try { |
| 3576 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3577 | int slotId = getSlotIndex(subId); |
| 3578 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3579 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3580 | + subId + "' for key:" + key); |
| 3581 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3582 | } |
| 3583 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3584 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3585 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3586 | + subId + "' for key:" + key); |
| 3587 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3588 | } finally { |
| 3589 | Binder.restoreCallingIdentity(identity); |
| 3590 | } |
| 3591 | } |
| 3592 | |
| 3593 | @Override |
| 3594 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3595 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3596 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3597 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3598 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3599 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3600 | final long identity = Binder.clearCallingIdentity(); |
| 3601 | try { |
| 3602 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3603 | int slotId = getSlotIndex(subId); |
| 3604 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3605 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3606 | + subId + "' for key:" + key); |
| 3607 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3608 | } |
| 3609 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3610 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3611 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3612 | + "' for key:" + key); |
| 3613 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3614 | } finally { |
| 3615 | Binder.restoreCallingIdentity(identity); |
| 3616 | } |
| 3617 | } |
| 3618 | |
| 3619 | @Override |
| 3620 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3621 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3622 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3623 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3624 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3625 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3626 | final long identity = Binder.clearCallingIdentity(); |
| 3627 | try { |
| 3628 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3629 | int slotId = getSlotIndex(subId); |
| 3630 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3631 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3632 | + subId + "' for key:" + key); |
| 3633 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3634 | } |
| 3635 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3636 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3637 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3638 | + "' for key:" + key); |
| 3639 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3640 | } finally { |
| 3641 | Binder.restoreCallingIdentity(identity); |
| 3642 | } |
| 3643 | } |
| 3644 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3645 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3646 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3647 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3648 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 3649 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3650 | } |
| 3651 | return slotId; |
| 3652 | } |
| 3653 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3654 | private int getSlotIndex(int subId) { |
| 3655 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3656 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3657 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3658 | } |
| 3659 | return slotId; |
| 3660 | } |
| 3661 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3662 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3663 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3664 | */ |
| 3665 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3666 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 3667 | final int targetSdk = getTargetSdk(callingPackage); |
| 3668 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
| 3669 | return getDataNetworkTypeForSubscriber(subId, callingPackage); |
| 3670 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3671 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
| 3672 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3673 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3674 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3675 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3676 | final long identity = Binder.clearCallingIdentity(); |
| 3677 | try { |
| 3678 | final Phone phone = getPhone(subId); |
| 3679 | if (phone != null) { |
| 3680 | return phone.getServiceState().getDataNetworkType(); |
| 3681 | } else { |
| 3682 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3683 | } |
| 3684 | } finally { |
| 3685 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3686 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3687 | } |
| 3688 | |
| 3689 | /** |
| 3690 | * Returns the data network type |
| 3691 | */ |
| 3692 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3693 | public int getDataNetworkType(String callingPackage) { |
| 3694 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3695 | } |
| 3696 | |
| 3697 | /** |
| 3698 | * Returns the data network type for a subId |
| 3699 | */ |
| 3700 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3701 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3702 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3703 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3704 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3705 | } |
| 3706 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3707 | final long identity = Binder.clearCallingIdentity(); |
| 3708 | try { |
| 3709 | final Phone phone = getPhone(subId); |
| 3710 | if (phone != null) { |
| 3711 | return phone.getServiceState().getDataNetworkType(); |
| 3712 | } else { |
| 3713 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3714 | } |
| 3715 | } finally { |
| 3716 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3717 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3718 | } |
| 3719 | |
| 3720 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3721 | * Returns the Voice network type for a subId |
| 3722 | */ |
| 3723 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3724 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3725 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3726 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3727 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3728 | } |
| 3729 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3730 | final long identity = Binder.clearCallingIdentity(); |
| 3731 | try { |
| 3732 | final Phone phone = getPhone(subId); |
| 3733 | if (phone != null) { |
| 3734 | return phone.getServiceState().getVoiceNetworkType(); |
| 3735 | } else { |
| 3736 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3737 | } |
| 3738 | } finally { |
| 3739 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3740 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3741 | } |
| 3742 | |
| 3743 | /** |
| 3744 | * @return true if a ICC card is present |
| 3745 | */ |
| 3746 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3747 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3748 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3749 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3750 | } |
| 3751 | |
| 3752 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3753 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3754 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3755 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3756 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3757 | final long identity = Binder.clearCallingIdentity(); |
| 3758 | try { |
| 3759 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3760 | if (phone != null) { |
| 3761 | return phone.getIccCard().hasIccCard(); |
| 3762 | } else { |
| 3763 | return false; |
| 3764 | } |
| 3765 | } finally { |
| 3766 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3767 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3768 | } |
| 3769 | |
| 3770 | /** |
| 3771 | * Return if the current radio is LTE on CDMA. This |
| 3772 | * is a tri-state return value as for a period of time |
| 3773 | * the mode may be unknown. |
| 3774 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3775 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3776 | * @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] | 3777 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3778 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3779 | @Override |
| 3780 | public int getLteOnCdmaMode(String callingPackage) { |
| 3781 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3782 | } |
| 3783 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3784 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3785 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3786 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3787 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3788 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3789 | } |
| 3790 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3791 | final long identity = Binder.clearCallingIdentity(); |
| 3792 | try { |
| 3793 | final Phone phone = getPhone(subId); |
| 3794 | if (phone == null) { |
| 3795 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3796 | } else { |
| 3797 | return phone.getLteOnCdmaMode(); |
| 3798 | } |
| 3799 | } finally { |
| 3800 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3801 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3802 | } |
| 3803 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3804 | /** |
| 3805 | * {@hide} |
| 3806 | * Returns Default subId, 0 in the case of single standby. |
| 3807 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3808 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3809 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3810 | } |
| 3811 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3812 | private int getSlotForDefaultSubscription() { |
| 3813 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3814 | } |
| 3815 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3816 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3817 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3818 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3819 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3820 | private boolean isActiveSubscription(int subId) { |
| 3821 | return mSubscriptionController.isActiveSubId(subId); |
| 3822 | } |
| 3823 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3824 | /** |
| 3825 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3826 | */ |
| 3827 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3828 | final long identity = Binder.clearCallingIdentity(); |
| 3829 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3830 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3831 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3832 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3833 | } finally { |
| 3834 | Binder.restoreCallingIdentity(identity); |
| 3835 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3836 | } |
| 3837 | |
| 3838 | /** |
| 3839 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3840 | */ |
| 3841 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3842 | final long identity = Binder.clearCallingIdentity(); |
| 3843 | try { |
| 3844 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3845 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3846 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3847 | } finally { |
| 3848 | Binder.restoreCallingIdentity(identity); |
| 3849 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3850 | } |
| 3851 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3852 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3853 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3854 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3855 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3856 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3857 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 3858 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 3859 | if (phoneId == -1) { |
| 3860 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 3861 | + " does not correspond to an active phone"); |
| 3862 | } |
| 3863 | return PhoneFactory.getPhone(phoneId); |
| 3864 | } |
| 3865 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3866 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3867 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3868 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3869 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3870 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3871 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3872 | if (DBG) { |
| 3873 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3874 | } |
| 3875 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 3876 | p2); |
| 3877 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3878 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3879 | |
| 3880 | @Override |
| 3881 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 3882 | int slotIndex, String callingPackage, String aid, int p2) { |
| 3883 | enforceModifyPermission(); |
| 3884 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3885 | if (DBG) { |
| 3886 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 3887 | } |
| 3888 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3889 | callingPackage, aid, p2); |
| 3890 | } |
| 3891 | |
| 3892 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 3893 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3894 | final long identity = Binder.clearCallingIdentity(); |
| 3895 | try { |
| 3896 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3897 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3898 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3899 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3900 | if (bestComponent == null |
| 3901 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3902 | loge("The calling package is not allowed to access ISD-R."); |
| 3903 | throw new SecurityException( |
| 3904 | "The calling package is not allowed to access ISD-R."); |
| 3905 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3906 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3907 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3908 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3909 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 3910 | null /* workSource */); |
| 3911 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3912 | return response; |
| 3913 | } finally { |
| 3914 | Binder.restoreCallingIdentity(identity); |
| 3915 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3916 | } |
| 3917 | |
| 3918 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3919 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3920 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3921 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3922 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3923 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 3924 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3925 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3926 | @Override |
| 3927 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 3928 | enforceModifyPermission(); |
| 3929 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 3930 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3931 | channel); |
| 3932 | } |
| 3933 | |
| 3934 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3935 | final long identity = Binder.clearCallingIdentity(); |
| 3936 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3937 | if (channel < 0) { |
| 3938 | return false; |
| 3939 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3940 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 3941 | null /* workSource */); |
| 3942 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3943 | return success; |
| 3944 | } finally { |
| 3945 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3946 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3947 | } |
| 3948 | |
| 3949 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3950 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3951 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3952 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3953 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3954 | if (DBG) { |
| 3955 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3956 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3957 | + p3 + " data=" + data); |
| 3958 | } |
| 3959 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 3960 | command, p1, p2, p3, data); |
| 3961 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3962 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3963 | @Override |
| 3964 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 3965 | int command, int p1, int p2, int p3, String data) { |
| 3966 | enforceModifyPermission(); |
| 3967 | if (DBG) { |
| 3968 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 3969 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3970 | + p3 + " data=" + data); |
| 3971 | } |
| 3972 | return iccTransmitApduLogicalChannelWithPermission( |
| 3973 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 3974 | data); |
| 3975 | } |
| 3976 | |
| 3977 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 3978 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3979 | final long identity = Binder.clearCallingIdentity(); |
| 3980 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 3981 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3982 | return ""; |
| 3983 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3984 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3985 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3986 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 3987 | null /* workSource */); |
| 3988 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3989 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3990 | // Append the returned status code to the end of the response payload. |
| 3991 | String s = Integer.toHexString( |
| 3992 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3993 | if (response.payload != null) { |
| 3994 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3995 | } |
| 3996 | return s; |
| 3997 | } finally { |
| 3998 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3999 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4000 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4001 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4002 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4003 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4004 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4005 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4006 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4007 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4008 | if (DBG) { |
| 4009 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4010 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4011 | } |
| 4012 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4013 | cla, command, p1, p2, p3, data); |
| 4014 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4015 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4016 | @Override |
| 4017 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4018 | int command, int p1, int p2, int p3, String data) { |
| 4019 | enforceModifyPermission(); |
| 4020 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4021 | if (DBG) { |
| 4022 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4023 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4024 | + " data=" + data); |
| 4025 | } |
| 4026 | |
| 4027 | return iccTransmitApduBasicChannelWithPermission( |
| 4028 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4029 | p2, p3, data); |
| 4030 | } |
| 4031 | |
| 4032 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4033 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4034 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4035 | final long identity = Binder.clearCallingIdentity(); |
| 4036 | try { |
| 4037 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4038 | && TextUtils.equals(ISDR_AID, data)) { |
| 4039 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4040 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4041 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4042 | if (bestComponent == null |
| 4043 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4044 | loge("The calling package is not allowed to select ISD-R."); |
| 4045 | throw new SecurityException( |
| 4046 | "The calling package is not allowed to select ISD-R."); |
| 4047 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4048 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4049 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4050 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4051 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4052 | null /* workSource */); |
| 4053 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4054 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4055 | // Append the returned status code to the end of the response payload. |
| 4056 | String s = Integer.toHexString( |
| 4057 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4058 | if (response.payload != null) { |
| 4059 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4060 | } |
| 4061 | return s; |
| 4062 | } finally { |
| 4063 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4064 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4065 | } |
| 4066 | |
| 4067 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4068 | 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] | 4069 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4070 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4071 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4072 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4073 | final long identity = Binder.clearCallingIdentity(); |
| 4074 | try { |
| 4075 | if (DBG) { |
| 4076 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4077 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4078 | } |
| 4079 | |
| 4080 | IccIoResult response = |
| 4081 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4082 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4083 | subId); |
| 4084 | |
| 4085 | if (DBG) { |
| 4086 | log("Exchange SIM_IO [R]" + response); |
| 4087 | } |
| 4088 | |
| 4089 | byte[] result = null; |
| 4090 | int length = 2; |
| 4091 | if (response.payload != null) { |
| 4092 | length = 2 + response.payload.length; |
| 4093 | result = new byte[length]; |
| 4094 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4095 | } else { |
| 4096 | result = new byte[length]; |
| 4097 | } |
| 4098 | |
| 4099 | result[length - 1] = (byte) response.sw2; |
| 4100 | result[length - 2] = (byte) response.sw1; |
| 4101 | return result; |
| 4102 | } finally { |
| 4103 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4104 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4105 | } |
| 4106 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4107 | /** |
| 4108 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4109 | * on a particular subscription |
| 4110 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4111 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 4112 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4113 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 4114 | return null; |
| 4115 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4116 | |
| 4117 | final long identity = Binder.clearCallingIdentity(); |
| 4118 | try { |
| 4119 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4120 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4121 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4122 | return null; |
| 4123 | } |
| 4124 | Object response = sendRequest( |
| 4125 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4126 | if (response instanceof String[]) { |
| 4127 | return (String[]) response; |
| 4128 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4129 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4130 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4131 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4132 | } finally { |
| 4133 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4134 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4135 | } |
| 4136 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4137 | /** |
| 4138 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4139 | * subscription. |
| 4140 | * |
| 4141 | * @param subId the id of the subscription. |
| 4142 | * @param appType the uicc app type, must be USIM or SIM. |
| 4143 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4144 | * @param callingPackage the op Package name. |
| 4145 | * @return number of fplmns that is successfully written to the SIM. |
| 4146 | */ |
| 4147 | public int setForbiddenPlmns( |
| 4148 | int subId, int appType, List<String> fplmns, String callingPackage) { |
| 4149 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4150 | mApp, subId, callingPackage, "setForbiddenPlmns")) { |
| 4151 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4152 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4153 | } |
| 4154 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4155 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4156 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4157 | } |
| 4158 | if (fplmns == null) { |
| 4159 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4160 | } |
| 4161 | for (String fplmn : fplmns) { |
| 4162 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4163 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4164 | } |
| 4165 | } |
| 4166 | final long identity = Binder.clearCallingIdentity(); |
| 4167 | try { |
| 4168 | Object response = sendRequest( |
| 4169 | CMD_SET_FORBIDDEN_PLMNS, |
| 4170 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4171 | subId); |
| 4172 | return (int) response; |
| 4173 | } finally { |
| 4174 | Binder.restoreCallingIdentity(identity); |
| 4175 | } |
| 4176 | } |
| 4177 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4178 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4179 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4180 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4181 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4182 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4183 | final long identity = Binder.clearCallingIdentity(); |
| 4184 | try { |
| 4185 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4186 | if (response.payload == null) { |
| 4187 | return ""; |
| 4188 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4189 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4190 | // Append the returned status code to the end of the response payload. |
| 4191 | String s = Integer.toHexString( |
| 4192 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4193 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4194 | return s; |
| 4195 | } finally { |
| 4196 | Binder.restoreCallingIdentity(identity); |
| 4197 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4198 | } |
| 4199 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4200 | /** |
| 4201 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4202 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4203 | * |
| 4204 | * @param itemID the ID of the item to read |
| 4205 | * @return the NV item as a String, or null on error. |
| 4206 | */ |
| 4207 | @Override |
| 4208 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4209 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4210 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4211 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4212 | |
| 4213 | final long identity = Binder.clearCallingIdentity(); |
| 4214 | try { |
| 4215 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4216 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4217 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4218 | return value; |
| 4219 | } finally { |
| 4220 | Binder.restoreCallingIdentity(identity); |
| 4221 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4222 | } |
| 4223 | |
| 4224 | /** |
| 4225 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4226 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4227 | * |
| 4228 | * @param itemID the ID of the item to read |
| 4229 | * @param itemValue the value to write, as a String |
| 4230 | * @return true on success; false on any failure |
| 4231 | */ |
| 4232 | @Override |
| 4233 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4234 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4235 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4236 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4237 | |
| 4238 | final long identity = Binder.clearCallingIdentity(); |
| 4239 | try { |
| 4240 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4241 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4242 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4243 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4244 | return success; |
| 4245 | } finally { |
| 4246 | Binder.restoreCallingIdentity(identity); |
| 4247 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4248 | } |
| 4249 | |
| 4250 | /** |
| 4251 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4252 | * Used for device configuration by some CDMA operators. |
| 4253 | * |
| 4254 | * @param preferredRoamingList byte array containing the new PRL |
| 4255 | * @return true on success; false on any failure |
| 4256 | */ |
| 4257 | @Override |
| 4258 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4259 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4260 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4261 | |
| 4262 | final long identity = Binder.clearCallingIdentity(); |
| 4263 | try { |
| 4264 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4265 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4266 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4267 | return success; |
| 4268 | } finally { |
| 4269 | Binder.restoreCallingIdentity(identity); |
| 4270 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4271 | } |
| 4272 | |
| 4273 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4274 | * 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] | 4275 | * Used for device configuration by some CDMA operators. |
| 4276 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4277 | * @param slotIndex - device slot. |
| 4278 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4279 | * @return true on success; false on any failure |
| 4280 | */ |
| 4281 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4282 | public boolean resetModemConfig(int slotIndex) { |
| 4283 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4284 | if (phone != null) { |
| 4285 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4286 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4287 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4288 | final long identity = Binder.clearCallingIdentity(); |
| 4289 | try { |
| 4290 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4291 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4292 | return success; |
| 4293 | } finally { |
| 4294 | Binder.restoreCallingIdentity(identity); |
| 4295 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4296 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4297 | return false; |
| 4298 | } |
| 4299 | |
| 4300 | /** |
| 4301 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4302 | * |
| 4303 | * @param slotIndex - device slot. |
| 4304 | * |
| 4305 | * @return true on success; false on any failure |
| 4306 | */ |
| 4307 | @Override |
| 4308 | public boolean rebootModem(int slotIndex) { |
| 4309 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4310 | if (phone != null) { |
| 4311 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4312 | mApp, phone.getSubId(), "rebootModem"); |
| 4313 | |
| 4314 | final long identity = Binder.clearCallingIdentity(); |
| 4315 | try { |
| 4316 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4317 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4318 | return success; |
| 4319 | } finally { |
| 4320 | Binder.restoreCallingIdentity(identity); |
| 4321 | } |
| 4322 | } |
| 4323 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4324 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4325 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4326 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4327 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4328 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4329 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4330 | return new String[0]; |
| 4331 | } |
| 4332 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4333 | final long identity = Binder.clearCallingIdentity(); |
| 4334 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4335 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4336 | } finally { |
| 4337 | Binder.restoreCallingIdentity(identity); |
| 4338 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4339 | } |
| 4340 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4341 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4342 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4343 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4344 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4345 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4346 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4347 | |
| 4348 | final long identity = Binder.clearCallingIdentity(); |
| 4349 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4350 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4351 | if (resolver == null) { |
| 4352 | // may happen if the device does not support IMS. |
| 4353 | return; |
| 4354 | } |
| 4355 | resolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4356 | } finally { |
| 4357 | Binder.restoreCallingIdentity(identity); |
| 4358 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4359 | } |
| 4360 | |
| 4361 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4362 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4363 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4364 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4365 | public void disableIms(int slotId) { |
| 4366 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4367 | |
| 4368 | final long identity = Binder.clearCallingIdentity(); |
| 4369 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4370 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4371 | if (resolver == null) { |
| 4372 | // may happen if the device does not support IMS. |
| 4373 | return; |
| 4374 | } |
| 4375 | resolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4376 | } finally { |
| 4377 | Binder.restoreCallingIdentity(identity); |
| 4378 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4379 | } |
| 4380 | |
| 4381 | /** |
| 4382 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4383 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4384 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4385 | */ |
| 4386 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4387 | IImsServiceFeatureCallback callback) { |
| 4388 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4389 | |
| 4390 | final long identity = Binder.clearCallingIdentity(); |
| 4391 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4392 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4393 | if (resolver == null) { |
| 4394 | // may happen if the device does not support IMS. |
| 4395 | return null; |
| 4396 | } |
| 4397 | return resolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4398 | } finally { |
| 4399 | Binder.restoreCallingIdentity(identity); |
| 4400 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4401 | } |
| 4402 | |
| 4403 | /** |
| 4404 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4405 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4406 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4407 | * listener for feature updates. |
| 4408 | */ |
| 4409 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4410 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4411 | |
| 4412 | final long identity = Binder.clearCallingIdentity(); |
| 4413 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4414 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4415 | if (resolver == null) { |
| 4416 | // may happen if the device does not support IMS. |
| 4417 | return null; |
| 4418 | } |
| 4419 | return resolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4420 | } finally { |
| 4421 | Binder.restoreCallingIdentity(identity); |
| 4422 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4423 | } |
| 4424 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4425 | /** |
| 4426 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4427 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4428 | */ |
| 4429 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4430 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4431 | |
| 4432 | final long identity = Binder.clearCallingIdentity(); |
| 4433 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4434 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4435 | if (resolver == null) { |
| 4436 | // may happen if the device does not support IMS. |
| 4437 | return null; |
| 4438 | } |
| 4439 | return resolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4440 | } finally { |
| 4441 | Binder.restoreCallingIdentity(identity); |
| 4442 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4443 | } |
| 4444 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4445 | /** |
| 4446 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4447 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4448 | */ |
| 4449 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4450 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4451 | |
| 4452 | final long identity = Binder.clearCallingIdentity(); |
| 4453 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4454 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4455 | if (resolver == null) { |
| 4456 | // may happen if the device does not support IMS. |
| 4457 | return null; |
| 4458 | } |
| 4459 | return resolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4460 | } finally { |
| 4461 | Binder.restoreCallingIdentity(identity); |
| 4462 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4463 | } |
| 4464 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4465 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4466 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4467 | * |
| 4468 | * @param slotId the slot ID that the ImsService should bind for. |
| 4469 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4470 | * ImsService is the device default ImsService. |
| 4471 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4472 | * to. |
| 4473 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4474 | * @hide |
| 4475 | */ |
| 4476 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4477 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4478 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4479 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4480 | "setImsService"); |
| 4481 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4482 | final long identity = Binder.clearCallingIdentity(); |
| 4483 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4484 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4485 | if (resolver == null) { |
| 4486 | // may happen if the device does not support IMS. |
| 4487 | return false; |
| 4488 | } |
| 4489 | return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService, |
| 4490 | packageName); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4491 | } finally { |
| 4492 | Binder.restoreCallingIdentity(identity); |
| 4493 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4494 | } |
| 4495 | |
| 4496 | /** |
| 4497 | * Return the ImsService configuration. |
| 4498 | * |
| 4499 | * @param slotId The slot that the ImsService is associated with. |
| 4500 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4501 | * the device default. |
| 4502 | * @return the package name of the ImsService configuration. |
| 4503 | */ |
| 4504 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4505 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4506 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4507 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4508 | "getImsService"); |
| 4509 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4510 | final long identity = Binder.clearCallingIdentity(); |
| 4511 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4512 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4513 | if (resolver == null) { |
| 4514 | // may happen if the device does not support IMS. |
| 4515 | return ""; |
| 4516 | } |
| 4517 | return resolver.getImsServiceConfiguration(slotId, isCarrierImsService); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4518 | } finally { |
| 4519 | Binder.restoreCallingIdentity(identity); |
| 4520 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4521 | } |
| 4522 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame^] | 4523 | /** |
| 4524 | * Get the MmTelFeature state associated with the requested subscription id. |
| 4525 | * @param subId The subscription that the MmTelFeature is associated with. |
| 4526 | * @param callback A callback with an integer containing the |
| 4527 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 4528 | */ |
| 4529 | @Override |
| 4530 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 4531 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 4532 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4533 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4534 | "IMS not available on device."); |
| 4535 | } |
| 4536 | final long token = Binder.clearCallingIdentity(); |
| 4537 | try { |
| 4538 | int slotId = getSlotIndex(subId); |
| 4539 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4540 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 4541 | + subId + "'"); |
| 4542 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4543 | } |
| 4544 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 4545 | try { |
| 4546 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 4547 | } catch (RemoteException e) { |
| 4548 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 4549 | + "Ignore"); |
| 4550 | } |
| 4551 | }); |
| 4552 | } finally { |
| 4553 | Binder.restoreCallingIdentity(token); |
| 4554 | } |
| 4555 | } |
| 4556 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4557 | public void setImsRegistrationState(boolean registered) { |
| 4558 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4559 | |
| 4560 | final long identity = Binder.clearCallingIdentity(); |
| 4561 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4562 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4563 | } finally { |
| 4564 | Binder.restoreCallingIdentity(identity); |
| 4565 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4566 | } |
| 4567 | |
| 4568 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4569 | * Set the network selection mode to automatic. |
| 4570 | * |
| 4571 | */ |
| 4572 | @Override |
| 4573 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4574 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4575 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4576 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4577 | if (!isActiveSubscription(subId)) { |
| 4578 | return; |
| 4579 | } |
| 4580 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4581 | final long identity = Binder.clearCallingIdentity(); |
| 4582 | try { |
| 4583 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4584 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4585 | } finally { |
| 4586 | Binder.restoreCallingIdentity(identity); |
| 4587 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4588 | } |
| 4589 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4590 | /** |
| 4591 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4592 | * |
| 4593 | * @param subId the id of the subscription. |
| 4594 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4595 | * the operator to attach to. |
| 4596 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4597 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4598 | * normal network selection next time. |
| 4599 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4600 | */ |
| 4601 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4602 | public boolean setNetworkSelectionModeManual( |
| 4603 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4604 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4605 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4606 | |
| 4607 | if (!isActiveSubscription(subId)) { |
| 4608 | return false; |
| 4609 | } |
| 4610 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4611 | final long identity = Binder.clearCallingIdentity(); |
| 4612 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4613 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4614 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4615 | if (DBG) { |
| 4616 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4617 | + " operator: " + operatorInfo); |
| 4618 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4619 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4620 | } finally { |
| 4621 | Binder.restoreCallingIdentity(identity); |
| 4622 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4623 | } |
| 4624 | |
| 4625 | /** |
| 4626 | * Scans for available networks. |
| 4627 | */ |
| 4628 | @Override |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4629 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4630 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4631 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4632 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4633 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4634 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4635 | .setCallingPackage(callingPackage) |
| 4636 | .setCallingPid(Binder.getCallingPid()) |
| 4637 | .setCallingUid(Binder.getCallingUid()) |
| 4638 | .setMethod("getCellNetworkScanResults") |
| 4639 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4640 | .build()); |
| 4641 | switch (locationResult) { |
| 4642 | case DENIED_HARD: |
| 4643 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4644 | case DENIED_SOFT: |
| 4645 | return null; |
| 4646 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4647 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4648 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4649 | try { |
| 4650 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4651 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4652 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4653 | } finally { |
| 4654 | Binder.restoreCallingIdentity(identity); |
| 4655 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4656 | } |
| 4657 | |
| 4658 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4659 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4660 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4661 | * @param subId id of the subscription |
| 4662 | * @param request contains the radio access networks with bands/channels to scan |
| 4663 | * @param messenger callback messenger for scan results or errors |
| 4664 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4665 | * @return the id of the requested scan which can be used to stop the scan. |
| 4666 | */ |
| 4667 | @Override |
| 4668 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4669 | IBinder binder, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4670 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4671 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4672 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4673 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4674 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4675 | .setCallingPackage(callingPackage) |
| 4676 | .setCallingPid(Binder.getCallingPid()) |
| 4677 | .setCallingUid(Binder.getCallingUid()) |
| 4678 | .setMethod("requestNetworkScan") |
| 4679 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4680 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4681 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4682 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4683 | if (e != null) { |
| 4684 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 4685 | throw e; |
| 4686 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 4687 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4688 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 4689 | } |
| 4690 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4691 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4692 | int callingUid = Binder.getCallingUid(); |
| 4693 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4694 | final long identity = Binder.clearCallingIdentity(); |
| 4695 | try { |
| 4696 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4697 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4698 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4699 | } finally { |
| 4700 | Binder.restoreCallingIdentity(identity); |
| 4701 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4702 | } |
| 4703 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4704 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4705 | NetworkScanRequest request, int subId) { |
| 4706 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 4707 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 4708 | boolean hasNetworkScanPermission = |
| 4709 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 4710 | == PERMISSION_GRANTED; |
| 4711 | |
| 4712 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 4713 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 4714 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4715 | } |
| 4716 | |
| 4717 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 4718 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4719 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 4720 | return new SecurityException("Specific channels must not be" |
| 4721 | + " scanned without location access."); |
| 4722 | } |
| 4723 | } |
| 4724 | } |
| 4725 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4726 | return null; |
| 4727 | } |
| 4728 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4729 | /** |
| 4730 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4731 | * |
| 4732 | * @param subId id of the subscription |
| 4733 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4734 | */ |
| 4735 | @Override |
| 4736 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4737 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4738 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4739 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4740 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4741 | final long identity = Binder.clearCallingIdentity(); |
| 4742 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4743 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4744 | } finally { |
| 4745 | Binder.restoreCallingIdentity(identity); |
| 4746 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4747 | } |
| 4748 | |
| 4749 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4750 | * Get the calculated preferred network type. |
| 4751 | * Used for debugging incorrect network type. |
| 4752 | * |
| 4753 | * @return the preferred network type, defined in RILConstants.java. |
| 4754 | */ |
| 4755 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4756 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4757 | final Phone defaultPhone = getDefaultPhone(); |
| 4758 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4759 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4760 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4761 | } |
| 4762 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4763 | final long identity = Binder.clearCallingIdentity(); |
| 4764 | try { |
| 4765 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4766 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4767 | } finally { |
| 4768 | Binder.restoreCallingIdentity(identity); |
| 4769 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4770 | } |
| 4771 | |
| 4772 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4773 | * Get the preferred network type. |
| 4774 | * Used for device configuration by some CDMA operators. |
| 4775 | * |
| 4776 | * @return the preferred network type, defined in RILConstants.java. |
| 4777 | */ |
| 4778 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4779 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4780 | TelephonyPermissions |
| 4781 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4782 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4783 | |
| 4784 | final long identity = Binder.clearCallingIdentity(); |
| 4785 | try { |
| 4786 | if (DBG) log("getPreferredNetworkType"); |
| 4787 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4788 | int networkType = (result != null ? result[0] : -1); |
| 4789 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4790 | return networkType; |
| 4791 | } finally { |
| 4792 | Binder.restoreCallingIdentity(identity); |
| 4793 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4794 | } |
| 4795 | |
| 4796 | /** |
| 4797 | * Set the preferred network type. |
| 4798 | * Used for device configuration by some CDMA operators. |
| 4799 | * |
| 4800 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4801 | * @return true on success; false on any failure. |
| 4802 | */ |
| 4803 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4804 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4805 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4806 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4807 | |
| 4808 | final long identity = Binder.clearCallingIdentity(); |
| 4809 | try { |
| 4810 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4811 | Boolean success = (Boolean) sendRequest( |
| 4812 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4813 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4814 | if (success) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4815 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4816 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4817 | } |
| 4818 | return success; |
| 4819 | } finally { |
| 4820 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4821 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4822 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4823 | |
| 4824 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4825 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4826 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4827 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4828 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4829 | * @hide |
| 4830 | */ |
| 4831 | @Override |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4832 | public boolean getTetherApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4833 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4834 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4835 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4836 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4837 | if (phone != null) { |
| 4838 | return phone.hasMatchedTetherApnSetting(); |
| 4839 | } else { |
| 4840 | return false; |
| 4841 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4842 | } finally { |
| 4843 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4844 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4845 | } |
| 4846 | |
| 4847 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4848 | * Set mobile data enabled |
| 4849 | * Used by the user through settings etc to turn on/off mobile data |
| 4850 | * |
| 4851 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4852 | */ |
| 4853 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4854 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4855 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4856 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4857 | |
| 4858 | final long identity = Binder.clearCallingIdentity(); |
| 4859 | try { |
| 4860 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4861 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4862 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4863 | if (phone != null) { |
| 4864 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4865 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4866 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4867 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4868 | } |
| 4869 | } finally { |
| 4870 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4871 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4872 | } |
| 4873 | |
| 4874 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4875 | * Get the user enabled state of Mobile Data. |
| 4876 | * |
| 4877 | * TODO: remove and use isUserDataEnabled. |
| 4878 | * This can't be removed now because some vendor codes |
| 4879 | * calls through ITelephony directly while they should |
| 4880 | * use TelephonyManager. |
| 4881 | * |
| 4882 | * @return true on enabled |
| 4883 | */ |
| 4884 | @Override |
| 4885 | public boolean getDataEnabled(int subId) { |
| 4886 | return isUserDataEnabled(subId); |
| 4887 | } |
| 4888 | |
| 4889 | /** |
| 4890 | * Get whether mobile data is enabled per user setting. |
| 4891 | * |
| 4892 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4893 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4894 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4895 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4896 | * |
| 4897 | * @return {@code true} if data is enabled else {@code false} |
| 4898 | */ |
| 4899 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4900 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4901 | try { |
| 4902 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4903 | null); |
| 4904 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4905 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4906 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4907 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4908 | |
| 4909 | final long identity = Binder.clearCallingIdentity(); |
| 4910 | try { |
| 4911 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4912 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4913 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4914 | if (phone != null) { |
| 4915 | boolean retVal = phone.isUserDataEnabled(); |
| 4916 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4917 | return retVal; |
| 4918 | } else { |
| 4919 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4920 | return false; |
| 4921 | } |
| 4922 | } finally { |
| 4923 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4924 | } |
| 4925 | } |
| 4926 | |
| 4927 | /** |
| 4928 | * Get whether mobile data is enabled. |
| 4929 | * |
| 4930 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4931 | * whether mobile data is actually enabled. |
| 4932 | * |
| 4933 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4934 | * |
| 4935 | * @return {@code true} if data is enabled else {@code false} |
| 4936 | */ |
| 4937 | @Override |
| 4938 | public boolean isDataEnabled(int subId) { |
| 4939 | try { |
| 4940 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4941 | null); |
| 4942 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4943 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4944 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4945 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4946 | |
| 4947 | final long identity = Binder.clearCallingIdentity(); |
| 4948 | try { |
| 4949 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4950 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4951 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4952 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4953 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4954 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4955 | return retVal; |
| 4956 | } else { |
| 4957 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4958 | return false; |
| 4959 | } |
| 4960 | } finally { |
| 4961 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4962 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4963 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4964 | |
| 4965 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4966 | public int getCarrierPrivilegeStatus(int subId) { |
| 4967 | final Phone phone = getPhone(subId); |
| 4968 | if (phone == null) { |
| 4969 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4970 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4971 | } |
| 4972 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4973 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4974 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4975 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4976 | } |
| 4977 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4978 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4979 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4980 | |
| 4981 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4982 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4983 | final Phone phone = getPhone(subId); |
| 4984 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4985 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4986 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4987 | } |
| 4988 | UiccProfile profile = |
| 4989 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4990 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4991 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4992 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4993 | } |
| 4994 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 4995 | } |
| 4996 | |
| 4997 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4998 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 4999 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5000 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5001 | } |
| 5002 | |
| 5003 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5004 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5005 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5006 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5007 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5008 | } |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5009 | |
| 5010 | return card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5011 | } |
| 5012 | |
| 5013 | @Override |
| 5014 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5015 | if (TextUtils.isEmpty(pkgName)) |
| 5016 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5017 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5018 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5019 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5020 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5021 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5022 | continue; |
| 5023 | } |
| 5024 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5025 | result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5026 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5027 | break; |
| 5028 | } |
| 5029 | } |
| 5030 | |
| 5031 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5032 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5033 | |
| 5034 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5035 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5036 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5037 | loge("phoneId " + phoneId + " is not valid."); |
| 5038 | return null; |
| 5039 | } |
| 5040 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5041 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5042 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5043 | return null ; |
| 5044 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5045 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5046 | } |
| 5047 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5048 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5049 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5050 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5051 | List<String> privilegedPackages = new ArrayList<>(); |
| 5052 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5053 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5054 | // has UICC in that slot. |
| 5055 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5056 | if (card.hasCarrierPrivilegeRules()) { |
| 5057 | if (packages == null) { |
| 5058 | // Only check packages in user 0 for now |
| 5059 | packages = pm.getInstalledPackagesAsUser( |
| 5060 | PackageManager.MATCH_DISABLED_COMPONENTS |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5061 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 5062 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5063 | } |
| 5064 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5065 | PackageInfo pkgInfo = packages.get(p); |
| 5066 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5067 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5068 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5069 | privilegedPackages.add(pkgInfo.packageName); |
| 5070 | } |
| 5071 | } |
| 5072 | } |
| 5073 | } |
| 5074 | return privilegedPackages; |
| 5075 | } |
| 5076 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5077 | @Override |
| 5078 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
| 5079 | List<String> privilegedPackages = new ArrayList<>(); |
| 5080 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5081 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5082 | } |
| 5083 | return privilegedPackages; |
| 5084 | } |
| 5085 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5086 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5087 | final Phone phone = getPhone(subId); |
| 5088 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5089 | if (card == null) { |
| 5090 | loge("getIccId: No UICC"); |
| 5091 | return null; |
| 5092 | } |
| 5093 | String iccId = card.getIccId(); |
| 5094 | if (TextUtils.isEmpty(iccId)) { |
| 5095 | loge("getIccId: ICC ID is null or empty."); |
| 5096 | return null; |
| 5097 | } |
| 5098 | return iccId; |
| 5099 | } |
| 5100 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5101 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5102 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5103 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5104 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5105 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5106 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5107 | final long identity = Binder.clearCallingIdentity(); |
| 5108 | try { |
| 5109 | final String iccId = getIccId(subId); |
| 5110 | final Phone phone = getPhone(subId); |
| 5111 | if (phone == null) { |
| 5112 | return false; |
| 5113 | } |
| 5114 | final String subscriberId = phone.getSubscriberId(); |
| 5115 | |
| 5116 | if (DBG_MERGE) { |
| 5117 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 5118 | + subscriberId + " to " + number); |
| 5119 | } |
| 5120 | |
| 5121 | if (TextUtils.isEmpty(iccId)) { |
| 5122 | return false; |
| 5123 | } |
| 5124 | |
| 5125 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5126 | |
| 5127 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5128 | if (alphaTag == null) { |
| 5129 | editor.remove(alphaTagPrefKey); |
| 5130 | } else { |
| 5131 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5132 | } |
| 5133 | |
| 5134 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5135 | // track all merged IMSIs based on line number |
| 5136 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5137 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5138 | if (number == null) { |
| 5139 | editor.remove(numberPrefKey); |
| 5140 | editor.remove(subscriberPrefKey); |
| 5141 | } else { |
| 5142 | editor.putString(numberPrefKey, number); |
| 5143 | editor.putString(subscriberPrefKey, subscriberId); |
| 5144 | } |
| 5145 | |
| 5146 | editor.commit(); |
| 5147 | return true; |
| 5148 | } finally { |
| 5149 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5150 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5151 | } |
| 5152 | |
| 5153 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5154 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5155 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5156 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5157 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5158 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5159 | return null; |
| 5160 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5161 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5162 | final long identity = Binder.clearCallingIdentity(); |
| 5163 | try { |
| 5164 | String iccId = getIccId(subId); |
| 5165 | if (iccId != null) { |
| 5166 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5167 | if (DBG_MERGE) { |
| 5168 | log("getLine1NumberForDisplay returning " |
| 5169 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5170 | } |
| 5171 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5172 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5173 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5174 | return null; |
| 5175 | } finally { |
| 5176 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5177 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5178 | } |
| 5179 | |
| 5180 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5181 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5182 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5183 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5184 | return null; |
| 5185 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5186 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5187 | final long identity = Binder.clearCallingIdentity(); |
| 5188 | try { |
| 5189 | String iccId = getIccId(subId); |
| 5190 | if (iccId != null) { |
| 5191 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5192 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5193 | } |
| 5194 | return null; |
| 5195 | } finally { |
| 5196 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5197 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5198 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5199 | |
| 5200 | @Override |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5201 | public String[] getMergedSubscriberIds(int subId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5202 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5203 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5204 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5205 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 5206 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5207 | return null; |
| 5208 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5209 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5210 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 5211 | // the process, where TelephonyManager was instantiated. |
| 5212 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5213 | final long identity = Binder.clearCallingIdentity(); |
| 5214 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5215 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5216 | final TelephonyManager tele = TelephonyManager.from(context); |
| 5217 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5218 | |
| 5219 | // Figure out what subscribers are currently active |
| 5220 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5221 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5222 | // Only consider subs which match the current subId |
| 5223 | // This logic can be simplified. See b/131189269 for progress. |
| 5224 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5225 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 5226 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5227 | |
| 5228 | // First pass, find a number override for an active subscriber |
| 5229 | String mergeNumber = null; |
| 5230 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 5231 | for (String key : prefs.keySet()) { |
| 5232 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 5233 | final String subscriberId = (String) prefs.get(key); |
| 5234 | if (activeSubscriberIds.contains(subscriberId)) { |
| 5235 | final String iccId = key.substring( |
| 5236 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 5237 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5238 | mergeNumber = (String) prefs.get(numberKey); |
| 5239 | if (DBG_MERGE) { |
| 5240 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 5241 | + " for active subscriber " + subscriberId); |
| 5242 | } |
| 5243 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 5244 | break; |
| 5245 | } |
| 5246 | } |
| 5247 | } |
| 5248 | } |
| 5249 | |
| 5250 | // Shortcut when no active merged subscribers |
| 5251 | if (TextUtils.isEmpty(mergeNumber)) { |
| 5252 | return null; |
| 5253 | } |
| 5254 | |
| 5255 | // Second pass, find all subscribers under that line override |
| 5256 | final ArraySet<String> result = new ArraySet<>(); |
| 5257 | for (String key : prefs.keySet()) { |
| 5258 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5259 | final String number = (String) prefs.get(key); |
| 5260 | if (mergeNumber.equals(number)) { |
| 5261 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5262 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5263 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5264 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5265 | result.add(subscriberId); |
| 5266 | } |
| 5267 | } |
| 5268 | } |
| 5269 | } |
| 5270 | |
| 5271 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5272 | Arrays.sort(resultArray); |
| 5273 | if (DBG_MERGE) { |
| 5274 | Slog.d(LOG_TAG, |
| 5275 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5276 | } |
| 5277 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5278 | } finally { |
| 5279 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5280 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5281 | } |
| 5282 | |
| 5283 | @Override |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5284 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 5285 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 5286 | |
| 5287 | final long identity = Binder.clearCallingIdentity(); |
| 5288 | try { |
| 5289 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 5290 | TelephonyManager.class); |
| 5291 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 5292 | if (subscriberId == null) { |
| 5293 | if (DBG) { |
| 5294 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 5295 | + subId); |
| 5296 | } |
| 5297 | return null; |
| 5298 | } |
| 5299 | |
| 5300 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 5301 | .getSubscriptionInfo(subId); |
| 5302 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 5303 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 5304 | if (groupUuid == null) { |
| 5305 | return new String[]{subscriberId}; |
| 5306 | } |
| 5307 | |
| 5308 | // Get all subscriberIds from the group. |
| 5309 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 5310 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
| 5311 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName()); |
| 5312 | for (SubscriptionInfo subInfo : groupInfos) { |
| 5313 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 5314 | if (subscriberId != null) { |
| 5315 | mergedSubscriberIds.add(subscriberId); |
| 5316 | } |
| 5317 | } |
| 5318 | |
| 5319 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 5320 | } finally { |
| 5321 | Binder.restoreCallingIdentity(identity); |
| 5322 | |
| 5323 | } |
| 5324 | } |
| 5325 | |
| 5326 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5327 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5328 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5329 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5330 | |
| 5331 | final long identity = Binder.clearCallingIdentity(); |
| 5332 | try { |
| 5333 | final Phone phone = getPhone(subId); |
| 5334 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5335 | } finally { |
| 5336 | Binder.restoreCallingIdentity(identity); |
| 5337 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5338 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5339 | |
| 5340 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5341 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5342 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5343 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5344 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5345 | |
| 5346 | final long identity = Binder.clearCallingIdentity(); |
| 5347 | try { |
| 5348 | final Phone phone = getPhone(subId); |
| 5349 | if (phone == null) { |
| 5350 | return false; |
| 5351 | } |
| 5352 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5353 | cdmaNonRoamingList); |
| 5354 | } finally { |
| 5355 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5356 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5357 | } |
| 5358 | |
| 5359 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5360 | @Deprecated |
| 5361 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5362 | enforceModifyPermission(); |
| 5363 | |
| 5364 | int returnValue = 0; |
| 5365 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5366 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5367 | if(result.exception == null) { |
| 5368 | if (result.result != null) { |
| 5369 | byte[] responseData = (byte[])(result.result); |
| 5370 | if(responseData.length > oemResp.length) { |
| 5371 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5372 | responseData.length + "bytes. Buffer Size is " + |
| 5373 | oemResp.length + "bytes."); |
| 5374 | } |
| 5375 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5376 | returnValue = responseData.length; |
| 5377 | } |
| 5378 | } else { |
| 5379 | CommandException ex = (CommandException) result.exception; |
| 5380 | returnValue = ex.getCommandError().ordinal(); |
| 5381 | if(returnValue > 0) returnValue *= -1; |
| 5382 | } |
| 5383 | } catch (RuntimeException e) { |
| 5384 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5385 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5386 | if(returnValue > 0) returnValue *= -1; |
| 5387 | } |
| 5388 | |
| 5389 | return returnValue; |
| 5390 | } |
| 5391 | |
| 5392 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5393 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5394 | try { |
| 5395 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5396 | } catch (RuntimeException e) { |
| 5397 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5398 | } |
| 5399 | } |
| 5400 | |
| 5401 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5402 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5403 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5404 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5405 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5406 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5407 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5408 | final long identity = Binder.clearCallingIdentity(); |
| 5409 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5410 | TelephonyPermissions |
| 5411 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5412 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5413 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5414 | } finally { |
| 5415 | Binder.restoreCallingIdentity(identity); |
| 5416 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5417 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5418 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5419 | |
| 5420 | @Override |
| 5421 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5422 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5423 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5424 | |
| 5425 | final long identity = Binder.clearCallingIdentity(); |
| 5426 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5427 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5428 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5429 | } finally { |
| 5430 | Binder.restoreCallingIdentity(identity); |
| 5431 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5432 | } |
| 5433 | |
| 5434 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5435 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5436 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5437 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5438 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5439 | return false; |
| 5440 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5441 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5442 | final long identity = Binder.clearCallingIdentity(); |
| 5443 | try { |
| 5444 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5445 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5446 | // In the long run, we may instead need to check if there exists a connection service |
| 5447 | // which can support video calling. |
| 5448 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5449 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5450 | return imsManager.isVtEnabledByPlatform() |
| 5451 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5452 | && imsManager.isVtEnabledByUser(); |
| 5453 | } finally { |
| 5454 | Binder.restoreCallingIdentity(identity); |
| 5455 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5456 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5457 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5458 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5459 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 5460 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5461 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5462 | return false; |
| 5463 | } |
| 5464 | |
| 5465 | final long identity = Binder.clearCallingIdentity(); |
| 5466 | try { |
| 5467 | CarrierConfigManager configManager = |
| 5468 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5469 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5470 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5471 | } finally { |
| 5472 | Binder.restoreCallingIdentity(identity); |
| 5473 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5474 | } |
| 5475 | |
| 5476 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5477 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 5478 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5479 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5480 | return false; |
| 5481 | } |
| 5482 | |
| 5483 | final long identity = Binder.clearCallingIdentity(); |
| 5484 | try { |
| 5485 | CarrierConfigManager configManager = |
| 5486 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5487 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5488 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5489 | } finally { |
| 5490 | Binder.restoreCallingIdentity(identity); |
| 5491 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5492 | } |
| 5493 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5494 | @Override |
| 5495 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5496 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5497 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5498 | } |
| 5499 | |
| 5500 | @Override |
| 5501 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5502 | final long identity = Binder.clearCallingIdentity(); |
| 5503 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5504 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5505 | } finally { |
| 5506 | Binder.restoreCallingIdentity(identity); |
| 5507 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5508 | } |
| 5509 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5510 | /** |
| 5511 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5512 | * support for the feature and device firmware support. |
| 5513 | * |
| 5514 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5515 | */ |
| 5516 | @Override |
| 5517 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5518 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5519 | final Phone phone = getPhone(subscriptionId); |
| 5520 | if (phone == null) { |
| 5521 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5522 | return false; |
| 5523 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5524 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5525 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5526 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5527 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5528 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5529 | return isCarrierSupported && isDeviceSupported; |
| 5530 | } finally { |
| 5531 | Binder.restoreCallingIdentity(identity); |
| 5532 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5533 | } |
| 5534 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5535 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5536 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 5537 | * RTT setting, will return true if the device and carrier both support RTT. |
| 5538 | * Otherwise. only returns true if the device and carrier both also support RTT. |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5539 | */ |
| 5540 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5541 | final long identity = Binder.clearCallingIdentity(); |
| 5542 | try { |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5543 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 5544 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5545 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5546 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 5547 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 5548 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5549 | } finally { |
| 5550 | Binder.restoreCallingIdentity(identity); |
| 5551 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5552 | } |
| 5553 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5554 | /** |
| 5555 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5556 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5557 | * |
| 5558 | * <p>Requires Permission: |
| 5559 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5560 | */ |
| 5561 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5562 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5563 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5564 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5565 | return null; |
| 5566 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5567 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 5568 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 5569 | callingPackage, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5570 | return null; |
| 5571 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5572 | |
| 5573 | final long identity = Binder.clearCallingIdentity(); |
| 5574 | try { |
| 5575 | return phone.getDeviceId(); |
| 5576 | } finally { |
| 5577 | Binder.restoreCallingIdentity(identity); |
| 5578 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5579 | } |
| 5580 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5581 | /** |
| 5582 | * {@hide} |
| 5583 | * Returns the IMS Registration Status on a particular subid |
| 5584 | * |
| 5585 | * @param subId |
| 5586 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5587 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5588 | Phone phone = getPhone(subId); |
| 5589 | if (phone != null) { |
| 5590 | return phone.isImsRegistered(); |
| 5591 | } else { |
| 5592 | return false; |
| 5593 | } |
| 5594 | } |
| 5595 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5596 | @Override |
| 5597 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5598 | final long identity = Binder.clearCallingIdentity(); |
| 5599 | try { |
| 5600 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5601 | } finally { |
| 5602 | Binder.restoreCallingIdentity(identity); |
| 5603 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5604 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5605 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5606 | @Override |
| 5607 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 5608 | final long identity = Binder.clearCallingIdentity(); |
| 5609 | try { |
| 5610 | Phone phone = getPhone(subscriptionId); |
| 5611 | if (phone == null) { |
| 5612 | return null; |
| 5613 | } |
| 5614 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 5615 | } finally { |
| 5616 | Binder.restoreCallingIdentity(identity); |
| 5617 | } |
| 5618 | } |
| 5619 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5620 | /** |
| 5621 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5622 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5623 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5624 | final long identity = Binder.clearCallingIdentity(); |
| 5625 | try { |
| 5626 | Phone phone = getPhone(subId); |
| 5627 | if (phone != null) { |
| 5628 | return phone.isWifiCallingEnabled(); |
| 5629 | } else { |
| 5630 | return false; |
| 5631 | } |
| 5632 | } finally { |
| 5633 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5634 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5635 | } |
| 5636 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5637 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5638 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5639 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5640 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5641 | final long identity = Binder.clearCallingIdentity(); |
| 5642 | try { |
| 5643 | Phone phone = getPhone(subId); |
| 5644 | if (phone != null) { |
| 5645 | return phone.isVideoEnabled(); |
| 5646 | } else { |
| 5647 | return false; |
| 5648 | } |
| 5649 | } finally { |
| 5650 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5651 | } |
| 5652 | } |
| 5653 | |
| 5654 | /** |
| 5655 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5656 | * defined in {@link ImsRegistrationImplBase}. |
| 5657 | */ |
| 5658 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5659 | final long identity = Binder.clearCallingIdentity(); |
| 5660 | try { |
| 5661 | Phone phone = getPhone(subId); |
| 5662 | if (phone != null) { |
| 5663 | return phone.getImsRegistrationTech(); |
| 5664 | } else { |
| 5665 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5666 | } |
| 5667 | } finally { |
| 5668 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5669 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5670 | } |
| 5671 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5672 | @Override |
| 5673 | public void factoryReset(int subId) { |
| 5674 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5675 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5676 | return; |
| 5677 | } |
| 5678 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5679 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5680 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5681 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5682 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5683 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5684 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5685 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5686 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5687 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5688 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5689 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5690 | // There has been issues when Sms raw table somehow stores orphan |
| 5691 | // fragments. They lead to garbled message when new fragments come |
| 5692 | // in and combined with those stale ones. In case this happens again, |
| 5693 | // user can reset all network settings which will clean up this table. |
| 5694 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame^] | 5695 | // Clean up IMS settings as well here. |
| 5696 | int slotId = getSlotIndex(subId); |
| 5697 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5698 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 5699 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5700 | } finally { |
| 5701 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5702 | } |
| 5703 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5704 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5705 | private void cleanUpSmsRawTable(Context context) { |
| 5706 | ContentResolver resolver = context.getContentResolver(); |
| 5707 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 5708 | resolver.delete(uri, null, null); |
| 5709 | } |
| 5710 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5711 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5712 | public String getSimLocaleForSubscriber(int subId) { |
| 5713 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5714 | final Phone phone = getPhone(subId); |
| 5715 | if (phone == null) { |
| 5716 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 5717 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5718 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5719 | final long identity = Binder.clearCallingIdentity(); |
| 5720 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5721 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5722 | phone.getContext().getOpPackageName()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 5723 | if (info == null) { |
| 5724 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 5725 | return null; |
| 5726 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5727 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5728 | // preferences (EF-PL and EF-LI)... |
| 5729 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5730 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5731 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5732 | if (localeFromDefaultSim != null) { |
| 5733 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5734 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5735 | + localeFromDefaultSim); |
| 5736 | return localeFromDefaultSim.toLanguageTag(); |
| 5737 | } else { |
| 5738 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5739 | } |
| 5740 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5741 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5742 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5743 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5744 | // the SIM and carrier preferences does not include a country we add the country |
| 5745 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5746 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5747 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5748 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5749 | return mccLocale.toLanguageTag(); |
| 5750 | } |
| 5751 | |
| 5752 | if (DBG) log("No locale found - returning null"); |
| 5753 | return null; |
| 5754 | } finally { |
| 5755 | Binder.restoreCallingIdentity(identity); |
| 5756 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5757 | } |
| 5758 | |
| 5759 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5760 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5761 | } |
| 5762 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5763 | /** |
| 5764 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5765 | */ |
| 5766 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5767 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5768 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5769 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5770 | private final ModemActivityInfo mLastModemActivityInfo = |
| 5771 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 5772 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5773 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5774 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5775 | * representing the state of the modem. |
| 5776 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5777 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5778 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5779 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5780 | */ |
| 5781 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5782 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5783 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5784 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5785 | |
| 5786 | final long identity = Binder.clearCallingIdentity(); |
| 5787 | try { |
| 5788 | ModemActivityInfo ret = null; |
| 5789 | synchronized (mLastModemActivityInfo) { |
| 5790 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5791 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5792 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5793 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5794 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 5795 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5796 | mergedTxTimeMs[i] = info.getTxTimeMillis()[i] |
| 5797 | + mLastModemActivityInfo.getTxTimeMillis()[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5798 | } |
| 5799 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5800 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 5801 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5802 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5803 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 5804 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 5805 | mLastModemActivityInfo.setRxTimeMillis( |
| 5806 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 5807 | mLastModemActivityInfo.setEnergyUsed( |
| 5808 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5809 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5810 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5811 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5812 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 5813 | mLastModemActivityInfo.getTxTimeMillis(), |
| 5814 | mLastModemActivityInfo.getRxTimeMillis(), |
| 5815 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5816 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5817 | Bundle bundle = new Bundle(); |
| 5818 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 5819 | result.send(0, bundle); |
| 5820 | } finally { |
| 5821 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5822 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5823 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5824 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5825 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 5826 | // less than total activity duration. |
| 5827 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 5828 | if (info == null) { |
| 5829 | return false; |
| 5830 | } |
| 5831 | int activityDurationMs = |
| 5832 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 5833 | int totalTxTimeMs = 0; |
| 5834 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 5835 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 5836 | } |
| 5837 | return (info.isValid() |
| 5838 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 5839 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 5840 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 5841 | && (totalTxTimeMs <= activityDurationMs)); |
| 5842 | } |
| 5843 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5844 | /** |
| 5845 | * {@hide} |
| 5846 | * Returns the service state information on specified subscription. |
| 5847 | */ |
| 5848 | @Override |
| 5849 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5850 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5851 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5852 | return null; |
| 5853 | } |
| 5854 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5855 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 5856 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5857 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5858 | .setCallingPackage(callingPackage) |
| 5859 | .setCallingPid(Binder.getCallingPid()) |
| 5860 | .setCallingUid(Binder.getCallingUid()) |
| 5861 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5862 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5863 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5864 | .build()); |
| 5865 | |
| 5866 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 5867 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5868 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5869 | .setCallingPackage(callingPackage) |
| 5870 | .setCallingPid(Binder.getCallingPid()) |
| 5871 | .setCallingUid(Binder.getCallingUid()) |
| 5872 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5873 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5874 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5875 | .build()); |
| 5876 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 5877 | boolean hasFinePermission = |
| 5878 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5879 | boolean hasCoarsePermission = |
| 5880 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5881 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5882 | final long identity = Binder.clearCallingIdentity(); |
| 5883 | try { |
| 5884 | final Phone phone = getPhone(subId); |
| 5885 | if (phone == null) { |
| 5886 | return null; |
| 5887 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5888 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5889 | ServiceState ss = phone.getServiceState(); |
| 5890 | |
| 5891 | // Scrub out the location info in ServiceState depending on what level of access |
| 5892 | // the caller has. |
| 5893 | if (hasFinePermission) return ss; |
| 5894 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 5895 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5896 | } finally { |
| 5897 | Binder.restoreCallingIdentity(identity); |
| 5898 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5899 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5900 | |
| 5901 | /** |
| 5902 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5903 | * |
| 5904 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5905 | * voicemail ringtone. |
| 5906 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5907 | * PhoneAccount. |
| 5908 | */ |
| 5909 | @Override |
| 5910 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5911 | final long identity = Binder.clearCallingIdentity(); |
| 5912 | try { |
| 5913 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5914 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5915 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5916 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5917 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5918 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5919 | } finally { |
| 5920 | Binder.restoreCallingIdentity(identity); |
| 5921 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5922 | } |
| 5923 | |
| 5924 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5925 | * Sets the per-account voicemail ringtone. |
| 5926 | * |
| 5927 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5928 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5929 | * |
| 5930 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5931 | * voicemail ringtone. |
| 5932 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5933 | * PhoneAccount. |
| 5934 | */ |
| 5935 | @Override |
| 5936 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5937 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5938 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5939 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5940 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5941 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5942 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5943 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5944 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5945 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5946 | |
| 5947 | final long identity = Binder.clearCallingIdentity(); |
| 5948 | try { |
| 5949 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5950 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5951 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5952 | } |
| 5953 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5954 | } finally { |
| 5955 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5956 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5957 | } |
| 5958 | |
| 5959 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5960 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5961 | * |
| 5962 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5963 | * voicemail vibration setting. |
| 5964 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5965 | */ |
| 5966 | @Override |
| 5967 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5968 | final long identity = Binder.clearCallingIdentity(); |
| 5969 | try { |
| 5970 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5971 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5972 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5973 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5974 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5975 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5976 | } finally { |
| 5977 | Binder.restoreCallingIdentity(identity); |
| 5978 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5979 | } |
| 5980 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5981 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5982 | * Sets the per-account voicemail vibration. |
| 5983 | * |
| 5984 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5985 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5986 | * |
| 5987 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5988 | * voicemail vibration setting. |
| 5989 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5990 | * specific PhoneAccount. |
| 5991 | */ |
| 5992 | @Override |
| 5993 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5994 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5995 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5996 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5997 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5998 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5999 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6000 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6001 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6002 | } |
| 6003 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6004 | final long identity = Binder.clearCallingIdentity(); |
| 6005 | try { |
| 6006 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6007 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6008 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6009 | } |
| 6010 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6011 | } finally { |
| 6012 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6013 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6014 | } |
| 6015 | |
| 6016 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6017 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6018 | * |
| 6019 | * @throws SecurityException if the caller does not have the required permission |
| 6020 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6021 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6022 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6023 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6024 | } |
| 6025 | |
| 6026 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6027 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6028 | * permission. |
| 6029 | * |
| 6030 | * @throws SecurityException if the caller does not have the required permission |
| 6031 | */ |
| 6032 | private void enforceSendSmsPermission() { |
| 6033 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6034 | } |
| 6035 | |
| 6036 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6037 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6038 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6039 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6040 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6041 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6042 | final long identity = Binder.clearCallingIdentity(); |
| 6043 | try { |
| 6044 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6045 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6046 | if (componentName == null) { |
| 6047 | throw new SecurityException( |
| 6048 | "Caller not current active visual voicemail package[null]"); |
| 6049 | } |
| 6050 | String vvmPackage = componentName.getPackageName(); |
| 6051 | if (!callingPackage.equals(vvmPackage)) { |
| 6052 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6053 | + vvmPackage + "]"); |
| 6054 | } |
| 6055 | } finally { |
| 6056 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6057 | } |
| 6058 | } |
| 6059 | |
| 6060 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6061 | * Return the application ID for the app type. |
| 6062 | * |
| 6063 | * @param subId the subscription ID that this request applies to. |
| 6064 | * @param appType the uicc app type. |
| 6065 | * @return Application ID for specificied app type, or null if no uicc. |
| 6066 | */ |
| 6067 | @Override |
| 6068 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6069 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6070 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6071 | |
| 6072 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6073 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6074 | if (phone == null) { |
| 6075 | return null; |
| 6076 | } |
| 6077 | String aid = null; |
| 6078 | try { |
| 6079 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6080 | .getApplicationByType(appType).getAid(); |
| 6081 | } catch (Exception e) { |
| 6082 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6083 | } |
| 6084 | return aid; |
| 6085 | } finally { |
| 6086 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6087 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6088 | } |
| 6089 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6090 | /** |
| 6091 | * Return the Electronic Serial Number. |
| 6092 | * |
| 6093 | * @param subId the subscription ID that this request applies to. |
| 6094 | * @return ESN or null if error. |
| 6095 | */ |
| 6096 | @Override |
| 6097 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6098 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6099 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6100 | |
| 6101 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6102 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6103 | if (phone == null) { |
| 6104 | return null; |
| 6105 | } |
| 6106 | String esn = null; |
| 6107 | try { |
| 6108 | esn = phone.getEsn(); |
| 6109 | } catch (Exception e) { |
| 6110 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6111 | } |
| 6112 | return esn; |
| 6113 | } finally { |
| 6114 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6115 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6116 | } |
| 6117 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6118 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6119 | * Return the Preferred Roaming List Version. |
| 6120 | * |
| 6121 | * @param subId the subscription ID that this request applies to. |
| 6122 | * @return PRLVersion or null if error. |
| 6123 | */ |
| 6124 | @Override |
| 6125 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6126 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6127 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6128 | |
| 6129 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6130 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6131 | if (phone == null) { |
| 6132 | return null; |
| 6133 | } |
| 6134 | String cdmaPrlVersion = null; |
| 6135 | try { |
| 6136 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6137 | } catch (Exception e) { |
| 6138 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6139 | } |
| 6140 | return cdmaPrlVersion; |
| 6141 | } finally { |
| 6142 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6143 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6144 | } |
| 6145 | |
| 6146 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6147 | * Get snapshot of Telephony histograms |
| 6148 | * @return List of Telephony histograms |
| 6149 | * @hide |
| 6150 | */ |
| 6151 | @Override |
| 6152 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6153 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6154 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6155 | |
| 6156 | final long identity = Binder.clearCallingIdentity(); |
| 6157 | try { |
| 6158 | return RIL.getTelephonyRILTimingHistograms(); |
| 6159 | } finally { |
| 6160 | Binder.restoreCallingIdentity(identity); |
| 6161 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6162 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6163 | |
| 6164 | /** |
| 6165 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6166 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6167 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6168 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6169 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6170 | * @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] | 6171 | */ |
| 6172 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6173 | @TelephonyManager.SetCarrierRestrictionResult |
| 6174 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6175 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6176 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6177 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6178 | if (carrierRestrictionRules == null) { |
| 6179 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6180 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6181 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6182 | final long identity = Binder.clearCallingIdentity(); |
| 6183 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6184 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6185 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6186 | } finally { |
| 6187 | Binder.restoreCallingIdentity(identity); |
| 6188 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6189 | } |
| 6190 | |
| 6191 | /** |
| 6192 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6193 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 6194 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6195 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6196 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6197 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6198 | */ |
| 6199 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6200 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6201 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6202 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6203 | |
| 6204 | final long identity = Binder.clearCallingIdentity(); |
| 6205 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6206 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 6207 | if (response instanceof CarrierRestrictionRules) { |
| 6208 | return (CarrierRestrictionRules) response; |
| 6209 | } |
| 6210 | // Response is an Exception of some kind, |
| 6211 | // which is signalled to the user as a NULL retval |
| 6212 | return null; |
| 6213 | } catch (Exception e) { |
| 6214 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 6215 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6216 | } finally { |
| 6217 | Binder.restoreCallingIdentity(identity); |
| 6218 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6219 | } |
| 6220 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6221 | /** |
| 6222 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 6223 | * @param subId the subscription ID that this action applies to. |
| 6224 | * @param enabled control enable or disable metered apns. |
| 6225 | * {@hide} |
| 6226 | */ |
| 6227 | @Override |
| 6228 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 6229 | enforceModifyPermission(); |
| 6230 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6231 | |
| 6232 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6233 | if (phone == null) { |
| 6234 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 6235 | return; |
| 6236 | } |
| 6237 | try { |
| 6238 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 6239 | } catch (Exception e) { |
| 6240 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6241 | } finally { |
| 6242 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6243 | } |
| 6244 | } |
| 6245 | |
| 6246 | /** |
| 6247 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 6248 | * @param subId the subscription ID that this action applies to. |
| 6249 | * @param enabled control enable or disable radio. |
| 6250 | * {@hide} |
| 6251 | */ |
| 6252 | @Override |
| 6253 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 6254 | enforceModifyPermission(); |
| 6255 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6256 | |
| 6257 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6258 | if (phone == null) { |
| 6259 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 6260 | return; |
| 6261 | } |
| 6262 | try { |
| 6263 | phone.carrierActionSetRadioEnabled(enabled); |
| 6264 | } catch (Exception e) { |
| 6265 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6266 | } finally { |
| 6267 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6268 | } |
| 6269 | } |
| 6270 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6271 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6272 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 6273 | * network status based on which carrier apps could apply actions accordingly, |
| 6274 | * enable/disable default url handler for example. |
| 6275 | * |
| 6276 | * @param subId the subscription ID that this action applies to. |
| 6277 | * @param report control start/stop reporting the default network status. |
| 6278 | * {@hide} |
| 6279 | */ |
| 6280 | @Override |
| 6281 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 6282 | enforceModifyPermission(); |
| 6283 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6284 | |
| 6285 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6286 | if (phone == null) { |
| 6287 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 6288 | return; |
| 6289 | } |
| 6290 | try { |
| 6291 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 6292 | } catch (Exception e) { |
| 6293 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6294 | } finally { |
| 6295 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6296 | } |
| 6297 | } |
| 6298 | |
| 6299 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 6300 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 6301 | * @param subId the subscription ID that this action applies to. |
| 6302 | * {@hide} |
| 6303 | */ |
| 6304 | @Override |
| 6305 | public void carrierActionResetAll(int subId) { |
| 6306 | enforceModifyPermission(); |
| 6307 | final Phone phone = getPhone(subId); |
| 6308 | if (phone == null) { |
| 6309 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 6310 | return; |
| 6311 | } |
| 6312 | try { |
| 6313 | phone.carrierActionResetAll(); |
| 6314 | } catch (Exception e) { |
| 6315 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 6316 | } |
| 6317 | } |
| 6318 | |
| 6319 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6320 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 6321 | * bug report is being generated. |
| 6322 | */ |
| 6323 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 6324 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6325 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6326 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 6327 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 6328 | + Binder.getCallingPid() |
| 6329 | + ", uid=" + Binder.getCallingUid() |
| 6330 | + "without permission " |
| 6331 | + android.Manifest.permission.DUMP); |
| 6332 | return; |
| 6333 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6334 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6335 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6336 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6337 | @Override |
| 6338 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 6339 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 6340 | throws RemoteException { |
| 6341 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 6342 | } |
| 6343 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6344 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6345 | * Get aggregated video call data usage since boot. |
| 6346 | * |
| 6347 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6348 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6349 | * {@hide} |
| 6350 | */ |
| 6351 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6352 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6353 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 6354 | null); |
| 6355 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6356 | final long identity = Binder.clearCallingIdentity(); |
| 6357 | try { |
| 6358 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 6359 | // records the delta with the corresponding network identity. |
| 6360 | // We just return the total video call data usage snapshot since boot. |
| 6361 | Phone phone = getPhone(subId); |
| 6362 | if (phone != null) { |
| 6363 | return phone.getVtDataUsage(perUidStats); |
| 6364 | } |
| 6365 | return null; |
| 6366 | } finally { |
| 6367 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6368 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6369 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6370 | |
| 6371 | /** |
| 6372 | * Policy control of data connection. Usually used when data limit is passed. |
| 6373 | * @param enabled True if enabling the data, otherwise disabling. |
| 6374 | * @param subId Subscription index |
| 6375 | * {@hide} |
| 6376 | */ |
| 6377 | @Override |
| 6378 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6379 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6380 | |
| 6381 | final long identity = Binder.clearCallingIdentity(); |
| 6382 | try { |
| 6383 | Phone phone = getPhone(subId); |
| 6384 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6385 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6386 | } |
| 6387 | } finally { |
| 6388 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6389 | } |
| 6390 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6391 | |
| 6392 | /** |
| 6393 | * Get Client request stats |
| 6394 | * @return List of Client Request Stats |
| 6395 | * @hide |
| 6396 | */ |
| 6397 | @Override |
| 6398 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6399 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6400 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6401 | return null; |
| 6402 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6403 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6404 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6405 | final long identity = Binder.clearCallingIdentity(); |
| 6406 | try { |
| 6407 | if (phone != null) { |
| 6408 | return phone.getClientRequestStats(); |
| 6409 | } |
| 6410 | |
| 6411 | return null; |
| 6412 | } finally { |
| 6413 | Binder.restoreCallingIdentity(identity); |
| 6414 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6415 | } |
| 6416 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6417 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6418 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6419 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6420 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6421 | |
| 6422 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6423 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6424 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6425 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6426 | * @param state State of SIM (power down, power up, pass through) |
| 6427 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6428 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6429 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6430 | * |
| 6431 | **/ |
| 6432 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6433 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6434 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6435 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6436 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6437 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6438 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6439 | final long identity = Binder.clearCallingIdentity(); |
| 6440 | try { |
| 6441 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6442 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6443 | } |
| 6444 | } finally { |
| 6445 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6446 | } |
| 6447 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6448 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6449 | private boolean isUssdApiAllowed(int subId) { |
| 6450 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6451 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6452 | if (configManager == null) { |
| 6453 | return false; |
| 6454 | } |
| 6455 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6456 | if (pb == null) { |
| 6457 | return false; |
| 6458 | } |
| 6459 | return pb.getBoolean( |
| 6460 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6461 | } |
| 6462 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6463 | /** |
| 6464 | * Check if phone is in emergency callback mode |
| 6465 | * @return true if phone is in emergency callback mode |
| 6466 | * @param subId sub id |
| 6467 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6468 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6469 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6470 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6471 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6472 | |
| 6473 | final long identity = Binder.clearCallingIdentity(); |
| 6474 | try { |
| 6475 | if (phone != null) { |
| 6476 | return phone.isInEcm(); |
| 6477 | } else { |
| 6478 | return false; |
| 6479 | } |
| 6480 | } finally { |
| 6481 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6482 | } |
| 6483 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6484 | |
| 6485 | /** |
| 6486 | * Get the current signal strength information for the given subscription. |
| 6487 | * Because this information is not updated when the device is in a low power state |
| 6488 | * it should not be relied-upon to be current. |
| 6489 | * @param subId Subscription index |
| 6490 | * @return the most recent cached signal strength info from the modem |
| 6491 | */ |
| 6492 | @Override |
| 6493 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6494 | final long identity = Binder.clearCallingIdentity(); |
| 6495 | try { |
| 6496 | Phone p = getPhone(subId); |
| 6497 | if (p == null) { |
| 6498 | return null; |
| 6499 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6500 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6501 | return p.getSignalStrength(); |
| 6502 | } finally { |
| 6503 | Binder.restoreCallingIdentity(identity); |
| 6504 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6505 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6506 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6507 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6508 | * Get the current modem radio state for the given slot. |
| 6509 | * @param slotIndex slot index. |
| 6510 | * @param callingPackage the name of the package making the call. |
| 6511 | * @return the current radio power state from the modem |
| 6512 | */ |
| 6513 | @Override |
| 6514 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 6515 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6516 | if (phone != null) { |
| 6517 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6518 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 6519 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6520 | } |
| 6521 | |
| 6522 | final long identity = Binder.clearCallingIdentity(); |
| 6523 | try { |
| 6524 | return phone.getRadioPowerState(); |
| 6525 | } finally { |
| 6526 | Binder.restoreCallingIdentity(identity); |
| 6527 | } |
| 6528 | } |
| 6529 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6530 | } |
| 6531 | |
| 6532 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6533 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6534 | * |
| 6535 | * <p>Requires one of the following permissions: |
| 6536 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6537 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6538 | * privileges. |
| 6539 | * |
| 6540 | * @param subId subscription id |
| 6541 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6542 | * {@code false}. |
| 6543 | */ |
| 6544 | @Override |
| 6545 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6546 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6547 | null /* message */); |
| 6548 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6549 | boolean isEnabled = false; |
| 6550 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6551 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6552 | Phone phone = getPhone(subId); |
| 6553 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6554 | } catch (Exception e) { |
| 6555 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6556 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6557 | } finally { |
| 6558 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6559 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6560 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6561 | } |
| 6562 | |
| 6563 | |
| 6564 | /** |
| 6565 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6566 | * |
| 6567 | * <p> Requires permission: |
| 6568 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6569 | * privileges. |
| 6570 | * |
| 6571 | * @param subId subscription id |
| 6572 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6573 | */ |
| 6574 | @Override |
| 6575 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6576 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6577 | mApp, subId, "setDataRoamingEnabled"); |
| 6578 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6579 | final long identity = Binder.clearCallingIdentity(); |
| 6580 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6581 | Phone phone = getPhone(subId); |
| 6582 | if (phone != null) { |
| 6583 | phone.setDataRoamingEnabled(isEnabled); |
| 6584 | } |
| 6585 | } finally { |
| 6586 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6587 | } |
| 6588 | } |
| 6589 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6590 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6591 | public boolean isManualNetworkSelectionAllowed(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6592 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6593 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6594 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6595 | boolean isAllowed = true; |
| 6596 | final long identity = Binder.clearCallingIdentity(); |
| 6597 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6598 | Phone phone = getPhone(subId); |
| 6599 | if (phone != null) { |
| 6600 | isAllowed = phone.isCspPlmnEnabled(); |
| 6601 | } |
| 6602 | } finally { |
| 6603 | Binder.restoreCallingIdentity(identity); |
| 6604 | } |
| 6605 | return isAllowed; |
| 6606 | } |
| 6607 | |
| 6608 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6609 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6610 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6611 | try { |
| 6612 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6613 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6614 | } catch (SecurityException e) { |
| 6615 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6616 | // has carrier privileges on an active UICC |
| 6617 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6618 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6619 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6620 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6621 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6622 | |
| 6623 | final long identity = Binder.clearCallingIdentity(); |
| 6624 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6625 | UiccController uiccController = UiccController.getInstance(); |
| 6626 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6627 | if (hasReadPermission) { |
| 6628 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6629 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6630 | |
| 6631 | // Remove private info if the caller doesn't have access |
| 6632 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6633 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6634 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 6635 | // is available |
| 6636 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 6637 | if (card == null || card.getUiccProfile() == null) { |
| 6638 | // assume no access if the card or profile is unavailable |
| 6639 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6640 | continue; |
| 6641 | } |
| 6642 | UiccProfile profile = card.getUiccProfile(); |
| 6643 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6644 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6645 | filteredInfos.add(cardInfo); |
| 6646 | } else { |
| 6647 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6648 | } |
| 6649 | } |
| 6650 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6651 | } finally { |
| 6652 | Binder.restoreCallingIdentity(identity); |
| 6653 | } |
| 6654 | } |
| 6655 | |
| 6656 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6657 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6658 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6659 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6660 | final long identity = Binder.clearCallingIdentity(); |
| 6661 | try { |
| 6662 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6663 | if (slots == null) { |
| 6664 | Rlog.i(LOG_TAG, "slots is null."); |
| 6665 | return null; |
| 6666 | } |
| 6667 | |
| 6668 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6669 | for (int i = 0; i < slots.length; i++) { |
| 6670 | UiccSlot slot = slots[i]; |
| 6671 | if (slot == null) { |
| 6672 | continue; |
| 6673 | } |
| 6674 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6675 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6676 | UiccCard card = slot.getUiccCard(); |
| 6677 | if (card != null) { |
| 6678 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6679 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 6680 | cardId = slot.getEid(); |
| 6681 | if (TextUtils.isEmpty(cardId)) { |
| 6682 | cardId = slot.getIccId(); |
| 6683 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6684 | } |
| 6685 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 6686 | if (cardId != null) { |
| 6687 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 6688 | // if cardId is an EID, it's all digits so this is fine |
| 6689 | cardId = IccUtils.stripTrailingFs(cardId); |
| 6690 | } |
| 6691 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6692 | int cardState = 0; |
| 6693 | switch (slot.getCardState()) { |
| 6694 | case CARDSTATE_ABSENT: |
| 6695 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6696 | break; |
| 6697 | case CARDSTATE_PRESENT: |
| 6698 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6699 | break; |
| 6700 | case CARDSTATE_ERROR: |
| 6701 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6702 | break; |
| 6703 | case CARDSTATE_RESTRICTED: |
| 6704 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6705 | break; |
| 6706 | default: |
| 6707 | break; |
| 6708 | |
| 6709 | } |
| 6710 | |
| 6711 | infos[i] = new UiccSlotInfo( |
| 6712 | slot.isActive(), |
| 6713 | slot.isEuicc(), |
| 6714 | cardId, |
| 6715 | cardState, |
| 6716 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6717 | slot.isExtendedApduSupported(), |
| 6718 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6719 | } |
| 6720 | return infos; |
| 6721 | } finally { |
| 6722 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6723 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6724 | } |
| 6725 | |
| 6726 | @Override |
| 6727 | public boolean switchSlots(int[] physicalSlots) { |
| 6728 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6729 | |
| 6730 | final long identity = Binder.clearCallingIdentity(); |
| 6731 | try { |
| 6732 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6733 | } finally { |
| 6734 | Binder.restoreCallingIdentity(identity); |
| 6735 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6736 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6737 | |
| 6738 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6739 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6740 | final long identity = Binder.clearCallingIdentity(); |
| 6741 | try { |
| 6742 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6743 | } finally { |
| 6744 | Binder.restoreCallingIdentity(identity); |
| 6745 | } |
| 6746 | } |
| 6747 | |
| 6748 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6749 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6750 | enforceModifyPermission(); |
| 6751 | final Phone phone = getPhone(subId); |
| 6752 | if (phone == null) { |
| 6753 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6754 | return; |
| 6755 | } |
| 6756 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6757 | final long identity = Binder.clearCallingIdentity(); |
| 6758 | try { |
| 6759 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6760 | } finally { |
| 6761 | Binder.restoreCallingIdentity(identity); |
| 6762 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6763 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6764 | |
| 6765 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6766 | * A test API to reload the UICC profile. |
| 6767 | * |
| 6768 | * <p>Requires that the calling app has permission |
| 6769 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6770 | * @hide |
| 6771 | */ |
| 6772 | @Override |
| 6773 | public void refreshUiccProfile(int subId) { |
| 6774 | enforceModifyPermission(); |
| 6775 | |
| 6776 | final long identity = Binder.clearCallingIdentity(); |
| 6777 | try { |
| 6778 | Phone phone = getPhone(subId); |
| 6779 | if (phone == null) { |
| 6780 | return; |
| 6781 | } |
| 6782 | UiccCard uiccCard = phone.getUiccCard(); |
| 6783 | if (uiccCard == null) { |
| 6784 | return; |
| 6785 | } |
| 6786 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6787 | if (uiccProfile == null) { |
| 6788 | return; |
| 6789 | } |
| 6790 | uiccProfile.refresh(); |
| 6791 | } finally { |
| 6792 | Binder.restoreCallingIdentity(identity); |
| 6793 | } |
| 6794 | } |
| 6795 | |
| 6796 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6797 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6798 | */ |
| 6799 | private boolean getDefaultDataEnabled() { |
| 6800 | return "true".equalsIgnoreCase( |
| 6801 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6802 | } |
| 6803 | |
| 6804 | /** |
| 6805 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6806 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6807 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6808 | */ |
| 6809 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6810 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6811 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6812 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6813 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6814 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6815 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 6816 | return isDataRoamingEnabled; |
| 6817 | } |
| 6818 | |
| 6819 | /** |
| 6820 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 6821 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 6822 | */ |
| 6823 | private int getDefaultNetworkType(int subId) { |
| 6824 | return Integer.parseInt( |
| 6825 | TelephonyManager.getTelephonyProperty( |
| 6826 | mSubscriptionController.getPhoneId(subId), |
| 6827 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 6828 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 6829 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6830 | |
| 6831 | @Override |
| 6832 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6833 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6834 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6835 | |
| 6836 | final long identity = Binder.clearCallingIdentity(); |
| 6837 | try { |
| 6838 | final Phone phone = getPhone(subId); |
| 6839 | if (phone == null) { |
| 6840 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 6841 | return; |
| 6842 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6843 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 6844 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6845 | } finally { |
| 6846 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6847 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6848 | } |
| 6849 | |
| 6850 | @Override |
| 6851 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6852 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6853 | |
| 6854 | final long identity = Binder.clearCallingIdentity(); |
| 6855 | try { |
| 6856 | final Phone phone = getPhone(subId); |
| 6857 | if (phone == null) { |
| 6858 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 6859 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 6860 | } |
| 6861 | return phone.getCarrierIdListVersion(); |
| 6862 | } finally { |
| 6863 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6864 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6865 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6866 | |
| 6867 | @Override |
| 6868 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 6869 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6870 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 6871 | return -1; |
| 6872 | } |
| 6873 | |
| 6874 | final long identity = Binder.clearCallingIdentity(); |
| 6875 | try { |
| 6876 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 6877 | } finally { |
| 6878 | Binder.restoreCallingIdentity(identity); |
| 6879 | } |
| 6880 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6881 | |
| 6882 | @Override |
| 6883 | public int getCdmaRoamingMode(int subId) { |
| 6884 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6885 | mApp, subId, "getCdmaRoamingMode"); |
| 6886 | |
| 6887 | final long identity = Binder.clearCallingIdentity(); |
| 6888 | try { |
| 6889 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 6890 | } finally { |
| 6891 | Binder.restoreCallingIdentity(identity); |
| 6892 | } |
| 6893 | } |
| 6894 | |
| 6895 | @Override |
| 6896 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 6897 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6898 | mApp, subId, "setCdmaRoamingMode"); |
| 6899 | |
| 6900 | final long identity = Binder.clearCallingIdentity(); |
| 6901 | try { |
| 6902 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 6903 | } finally { |
| 6904 | Binder.restoreCallingIdentity(identity); |
| 6905 | } |
| 6906 | } |
| 6907 | |
| 6908 | @Override |
| 6909 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 6910 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6911 | mApp, subId, "setCdmaSubscriptionMode"); |
| 6912 | |
| 6913 | final long identity = Binder.clearCallingIdentity(); |
| 6914 | try { |
| 6915 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 6916 | } finally { |
| 6917 | Binder.restoreCallingIdentity(identity); |
| 6918 | } |
| 6919 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 6920 | |
| 6921 | private void ensureUserRunning(int userId) { |
| 6922 | if (!mUserManager.isUserRunning(userId)) { |
| 6923 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 6924 | } |
| 6925 | } |
| 6926 | |
| 6927 | /** |
| 6928 | * Returns a list of SMS apps on a given user. |
| 6929 | * |
| 6930 | * Only the shell user (UID 2000 or 0) can call it. |
| 6931 | * Target user must be running. |
| 6932 | */ |
| 6933 | @Override |
| 6934 | public String[] getSmsApps(int userId) { |
| 6935 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 6936 | ensureUserRunning(userId); |
| 6937 | |
| 6938 | final Collection<SmsApplicationData> apps = |
| 6939 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 6940 | |
| 6941 | String[] ret = new String[apps.size()]; |
| 6942 | int i = 0; |
| 6943 | for (SmsApplicationData app : apps) { |
| 6944 | ret[i++] = app.mPackageName; |
| 6945 | } |
| 6946 | return ret; |
| 6947 | } |
| 6948 | |
| 6949 | /** |
| 6950 | * Returns the default SMS app package name on a given user. |
| 6951 | * |
| 6952 | * Only the shell user (UID 2000 or 0) can call it. |
| 6953 | * Target user must be running. |
| 6954 | */ |
| 6955 | @Override |
| 6956 | public String getDefaultSmsApp(int userId) { |
| 6957 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 6958 | ensureUserRunning(userId); |
| 6959 | |
| 6960 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 6961 | /* updateIfNeeded= */ true, userId); |
| 6962 | return cn == null ? null : cn.getPackageName(); |
| 6963 | } |
| 6964 | |
| 6965 | /** |
| 6966 | * Set a package as the default SMS app on a given user. |
| 6967 | * |
| 6968 | * Only the shell user (UID 2000 or 0) can call it. |
| 6969 | * Target user must be running. |
| 6970 | */ |
| 6971 | @Override |
| 6972 | public void setDefaultSmsApp(int userId, String packageName) { |
| 6973 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6974 | ensureUserRunning(userId); |
| 6975 | |
| 6976 | boolean found = false; |
| 6977 | for (String pkg : getSmsApps(userId)) { |
| 6978 | if (TextUtils.equals(packageName, pkg)) { |
| 6979 | found = true; |
| 6980 | break; |
| 6981 | } |
| 6982 | } |
| 6983 | if (!found) { |
| 6984 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6985 | } |
| 6986 | |
| 6987 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6988 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6989 | |
| 6990 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6991 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6992 | String callingPackage) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6993 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6994 | mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6995 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6996 | } |
| 6997 | final long identity = Binder.clearCallingIdentity(); |
| 6998 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6999 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7000 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7001 | if (phone.getEmergencyNumberTracker() != null |
| 7002 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7003 | emergencyNumberListInternal.put( |
| 7004 | phone.getSubId(), |
| 7005 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7006 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7007 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7008 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7009 | } finally { |
| 7010 | Binder.restoreCallingIdentity(identity); |
| 7011 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7012 | } |
| 7013 | |
| 7014 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7015 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7016 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7017 | if (!exactMatch) { |
| 7018 | TelephonyPermissions |
| 7019 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7020 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7021 | } |
| 7022 | final long identity = Binder.clearCallingIdentity(); |
| 7023 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7024 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7025 | if (phone.getEmergencyNumberTracker() != null |
| 7026 | && phone.getEmergencyNumberTracker() != null) { |
| 7027 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7028 | number, exactMatch)) { |
| 7029 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7030 | } |
| 7031 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7032 | } |
| 7033 | return false; |
| 7034 | } finally { |
| 7035 | Binder.restoreCallingIdentity(identity); |
| 7036 | } |
| 7037 | } |
| 7038 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7039 | /** |
| 7040 | * Update emergency number list for test mode. |
| 7041 | */ |
| 7042 | @Override |
| 7043 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7044 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7045 | "updateEmergencyNumberListTestMode"); |
| 7046 | |
| 7047 | final long identity = Binder.clearCallingIdentity(); |
| 7048 | try { |
| 7049 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7050 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7051 | if (tracker != null) { |
| 7052 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7053 | } |
| 7054 | } |
| 7055 | } finally { |
| 7056 | Binder.restoreCallingIdentity(identity); |
| 7057 | } |
| 7058 | } |
| 7059 | |
| 7060 | /** |
| 7061 | * Get the full emergency number list for test mode. |
| 7062 | */ |
| 7063 | @Override |
| 7064 | public List<String> getEmergencyNumberListTestMode() { |
| 7065 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7066 | "getEmergencyNumberListTestMode"); |
| 7067 | |
| 7068 | final long identity = Binder.clearCallingIdentity(); |
| 7069 | try { |
| 7070 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7071 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7072 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7073 | if (tracker != null) { |
| 7074 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7075 | emergencyNumbers.add(num.getNumber()); |
| 7076 | } |
| 7077 | } |
| 7078 | } |
| 7079 | return new ArrayList<>(emergencyNumbers); |
| 7080 | } finally { |
| 7081 | Binder.restoreCallingIdentity(identity); |
| 7082 | } |
| 7083 | } |
| 7084 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7085 | @Override |
| 7086 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7087 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7088 | Phone phone = getPhone(subId); |
| 7089 | if (phone == null) { |
| 7090 | return null; |
| 7091 | } |
| 7092 | final long identity = Binder.clearCallingIdentity(); |
| 7093 | try { |
| 7094 | UiccProfile profile = UiccController.getInstance() |
| 7095 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7096 | if (profile != null) { |
| 7097 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7098 | } |
| 7099 | } finally { |
| 7100 | Binder.restoreCallingIdentity(identity); |
| 7101 | } |
| 7102 | return null; |
| 7103 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7104 | |
| 7105 | /** |
| 7106 | * Enable or disable a modem stack. |
| 7107 | */ |
| 7108 | @Override |
| 7109 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7110 | enforceModifyPermission(); |
| 7111 | |
| 7112 | final long identity = Binder.clearCallingIdentity(); |
| 7113 | try { |
| 7114 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7115 | if (phone == null) { |
| 7116 | return false; |
| 7117 | } else { |
| 7118 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7119 | } |
| 7120 | } finally { |
| 7121 | Binder.restoreCallingIdentity(identity); |
| 7122 | } |
| 7123 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7124 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7125 | /** |
| 7126 | * Whether a modem stack is enabled or not. |
| 7127 | */ |
| 7128 | @Override |
| 7129 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) { |
| 7130 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7131 | if (phone == null) return false; |
| 7132 | |
| 7133 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7134 | mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) { |
| 7135 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7136 | } |
| 7137 | |
| 7138 | final long identity = Binder.clearCallingIdentity(); |
| 7139 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7140 | try { |
| 7141 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7142 | } catch (NoSuchElementException ex) { |
| 7143 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7144 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7145 | } finally { |
| 7146 | Binder.restoreCallingIdentity(identity); |
| 7147 | } |
| 7148 | } |
| 7149 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7150 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7151 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7152 | enforceModifyPermission(); |
| 7153 | |
| 7154 | final long identity = Binder.clearCallingIdentity(); |
| 7155 | try { |
| 7156 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7157 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7158 | .commit(); |
| 7159 | } finally { |
| 7160 | Binder.restoreCallingIdentity(identity); |
| 7161 | } |
| 7162 | } |
| 7163 | |
| 7164 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7165 | @TelephonyManager.IsMultiSimSupportedResult |
| 7166 | public int isMultiSimSupported(String callingPackage) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7167 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7168 | getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) { |
| 7169 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7170 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7171 | |
| 7172 | final long identity = Binder.clearCallingIdentity(); |
| 7173 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7174 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7175 | } finally { |
| 7176 | Binder.restoreCallingIdentity(identity); |
| 7177 | } |
| 7178 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7179 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7180 | @TelephonyManager.IsMultiSimSupportedResult |
| 7181 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7182 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7183 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7184 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7185 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7186 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7187 | } |
| 7188 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7189 | // supported by the modem, indicate that it is restricted. |
| 7190 | PhoneCapability staticCapability = |
| 7191 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7192 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7193 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7194 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7195 | } |
| 7196 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7197 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7198 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7199 | } |
| 7200 | // Check if support of multiple SIMs is restricted by carrier |
| 7201 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7202 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7203 | } |
| 7204 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7205 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7206 | } |
| 7207 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7208 | /** |
| 7209 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7210 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7211 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7212 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7213 | * @param numOfSims number of active sims we want to switch to |
| 7214 | */ |
| 7215 | @Override |
| 7216 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7217 | if (numOfSims == 1) { |
| 7218 | enforceModifyPermission(); |
| 7219 | } else { |
| 7220 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7221 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 7222 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7223 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7224 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7225 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7226 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7227 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7228 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 7229 | return; |
| 7230 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7231 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 7232 | } finally { |
| 7233 | Binder.restoreCallingIdentity(identity); |
| 7234 | } |
| 7235 | } |
| 7236 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 7237 | @Override |
| 7238 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 7239 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 7240 | Phone phone = getPhone(subId); |
| 7241 | if (phone == null) { |
| 7242 | return false; |
| 7243 | } |
| 7244 | final long identity = Binder.clearCallingIdentity(); |
| 7245 | try { |
| 7246 | UiccCard uiccCard = phone.getUiccCard(); |
| 7247 | if (uiccCard == null) { |
| 7248 | return false; |
| 7249 | } |
| 7250 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7251 | if (uiccProfile == null) { |
| 7252 | return false; |
| 7253 | } |
| 7254 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 7255 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 7256 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 7257 | } |
| 7258 | return false; |
| 7259 | } finally { |
| 7260 | Binder.restoreCallingIdentity(identity); |
| 7261 | } |
| 7262 | } |
| 7263 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7264 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7265 | * Get whether making changes to modem configurations will trigger reboot. |
| 7266 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7267 | */ |
| 7268 | @Override |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7269 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) { |
| 7270 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7271 | mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) { |
| 7272 | return false; |
| 7273 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7274 | final long identity = Binder.clearCallingIdentity(); |
| 7275 | try { |
| 7276 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 7277 | } finally { |
| 7278 | Binder.restoreCallingIdentity(identity); |
| 7279 | } |
| 7280 | } |
| 7281 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 7282 | private void updateModemStateMetrics() { |
| 7283 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 7284 | // TODO: check the state for each modem if the api is ready. |
| 7285 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 7286 | } |
| 7287 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 7288 | @Override |
| 7289 | public int[] getSlotsMapping() { |
| 7290 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 7291 | |
| 7292 | final long identity = Binder.clearCallingIdentity(); |
| 7293 | try { |
| 7294 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 7295 | // All logical slots should have a mapping to a physical slot. |
| 7296 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 7297 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 7298 | for (int i = 0; i < slotInfos.length; i++) { |
| 7299 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 7300 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 7301 | } |
| 7302 | } |
| 7303 | return logicalSlotsMapping; |
| 7304 | } finally { |
| 7305 | Binder.restoreCallingIdentity(identity); |
| 7306 | } |
| 7307 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 7308 | |
| 7309 | /** |
| 7310 | * Get the IRadio HAL Version |
| 7311 | */ |
| 7312 | @Override |
| 7313 | public int getRadioHalVersion() { |
| 7314 | Phone phone = getDefaultPhone(); |
| 7315 | if (phone == null) return -1; |
| 7316 | HalVersion hv = phone.getHalVersion(); |
| 7317 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 7318 | return hv.major * 100 + hv.minor; |
| 7319 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7320 | |
| 7321 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7322 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 7323 | * corresponding network requests on a subId. |
| 7324 | * |
| 7325 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7326 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7327 | * 2) APN is un-metered for this subscription, or |
| 7328 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
| 7329 | * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. |
| 7330 | * |
| 7331 | * @return whether data is allowed for a apn type. |
| 7332 | * |
| 7333 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7334 | */ |
| 7335 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7336 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7337 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7338 | mApp, subId, callingPackage, "isDataEnabledForApn")) { |
| 7339 | throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7340 | } |
| 7341 | |
| 7342 | // Now that all security checks passes, perform the operation as ourselves. |
| 7343 | final long identity = Binder.clearCallingIdentity(); |
| 7344 | try { |
| 7345 | Phone phone = getPhone(subId); |
| 7346 | if (phone == null) return false; |
| 7347 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7348 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7349 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 7350 | } finally { |
| 7351 | Binder.restoreCallingIdentity(identity); |
| 7352 | } |
| 7353 | } |
| 7354 | |
| 7355 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7356 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7357 | enforceReadPrivilegedPermission("isApnMetered"); |
| 7358 | |
| 7359 | // Now that all security checks passes, perform the operation as ourselves. |
| 7360 | final long identity = Binder.clearCallingIdentity(); |
| 7361 | try { |
| 7362 | Phone phone = getPhone(subId); |
| 7363 | if (phone == null) return true; // By default return true. |
| 7364 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7365 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7366 | } finally { |
| 7367 | Binder.restoreCallingIdentity(identity); |
| 7368 | } |
| 7369 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7370 | |
| 7371 | @Override |
| 7372 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
| 7373 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 7374 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 7375 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 7376 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 7377 | } |
| 7378 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 7379 | Intent intent = new Intent(); |
| 7380 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 7381 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 7382 | // Bring up choose default SMS subscription dialog right now |
| 7383 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 7384 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 7385 | mApp.startActivity(intent); |
| 7386 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 7387 | |
| 7388 | @Override |
| 7389 | public String getMmsUAProfUrl(int subId) { |
| 7390 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7391 | final long identity = Binder.clearCallingIdentity(); |
| 7392 | try { |
| 7393 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7394 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 7395 | } finally { |
| 7396 | Binder.restoreCallingIdentity(identity); |
| 7397 | } |
| 7398 | } |
| 7399 | |
| 7400 | @Override |
| 7401 | public String getMmsUserAgent(int subId) { |
| 7402 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7403 | final long identity = Binder.clearCallingIdentity(); |
| 7404 | try { |
| 7405 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7406 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 7407 | } finally { |
| 7408 | Binder.restoreCallingIdentity(identity); |
| 7409 | } |
| 7410 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 7411 | |
| 7412 | @Override |
| 7413 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 7414 | enforceModifyPermission(); |
| 7415 | |
| 7416 | // Now that all security checks passes, perform the operation as ourselves. |
| 7417 | final long identity = Binder.clearCallingIdentity(); |
| 7418 | try { |
| 7419 | Phone phone = getPhone(subId); |
| 7420 | if (phone == null) return false; |
| 7421 | |
| 7422 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 7423 | } finally { |
| 7424 | Binder.restoreCallingIdentity(identity); |
| 7425 | } |
| 7426 | } |
| 7427 | |
| 7428 | @Override |
| 7429 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 7430 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 7431 | |
| 7432 | // Now that all security checks passes, perform the operation as ourselves. |
| 7433 | final long identity = Binder.clearCallingIdentity(); |
| 7434 | try { |
| 7435 | Phone phone = getPhone(subId); |
| 7436 | if (phone == null) return false; |
| 7437 | |
| 7438 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 7439 | } finally { |
| 7440 | Binder.restoreCallingIdentity(identity); |
| 7441 | } |
| 7442 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 7443 | |
| 7444 | /** |
| 7445 | * Updates whether conference event pacakge handling is enabled. |
| 7446 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 7447 | * otherwise. |
| 7448 | */ |
| 7449 | @Override |
| 7450 | public void setCepEnabled(boolean isCepEnabled) { |
| 7451 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 7452 | |
| 7453 | final long identity = Binder.clearCallingIdentity(); |
| 7454 | try { |
| 7455 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 7456 | for (Phone phone : PhoneFactory.getPhones()) { |
| 7457 | Phone defaultPhone = phone.getImsPhone(); |
| 7458 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7459 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7460 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 7461 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 7462 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 7463 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 7464 | + imsPhone.getMsisdn()); |
| 7465 | } |
| 7466 | } |
| 7467 | } finally { |
| 7468 | Binder.restoreCallingIdentity(identity); |
| 7469 | } |
| 7470 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 7471 | } |