| 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; | 
| Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 25 | import android.annotation.NonNull; | 
| Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.app.AppOpsManager; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.app.PendingIntent; | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 29 | import android.content.ComponentName; | 
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 30 | import android.content.ContentResolver; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 31 | import android.content.Context; | 
 | 32 | import android.content.Intent; | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 33 | import android.content.SharedPreferences; | 
| Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 34 | import android.content.pm.ApplicationInfo; | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 35 | import android.content.pm.ComponentInfo; | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 36 | import android.content.pm.PackageInfo; | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 37 | import android.content.pm.PackageManager; | 
| 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; | 
| Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 48 | import android.os.ParcelFileDescriptor; | 
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 49 | import android.os.ParcelUuid; | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 50 | import android.os.PersistableBundle; | 
| Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 51 | import android.os.Process; | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 52 | import android.os.RemoteException; | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 53 | import android.os.ResultReceiver; | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 54 | import android.os.ServiceSpecificException; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.UserHandle; | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 56 | import android.os.UserManager; | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 57 | import android.os.WorkSource; | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 58 | import android.preference.PreferenceManager; | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 59 | import android.provider.DeviceConfig; | 
| 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; | 
| Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 62 | import android.sysprop.TelephonyProperties; | 
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 63 | import android.telecom.PhoneAccount; | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 64 | import android.telecom.PhoneAccountHandle; | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 65 | import android.telecom.TelecomManager; | 
| Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 66 | import android.telephony.Annotation.ApnType; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 67 | import android.telephony.CallForwardingInfo; | 
| Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 68 | import android.telephony.CarrierConfigManager; | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 69 | import android.telephony.CarrierRestrictionRules; | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 70 | import android.telephony.CellIdentity; | 
| Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 71 | import android.telephony.CellIdentityCdma; | 
 | 72 | import android.telephony.CellIdentityGsm; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 73 | import android.telephony.CellInfo; | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 74 | import android.telephony.CellInfoGsm; | 
 | 75 | import android.telephony.CellInfoWcdma; | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 76 | import android.telephony.ClientRequestStats; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 77 | import android.telephony.ICellInfoCallback; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 78 | import android.telephony.IccOpenLogicalChannelResponse; | 
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 79 | import android.telephony.LocationAccessPolicy; | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 80 | import android.telephony.ModemActivityInfo; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 81 | import android.telephony.NeighboringCellInfo; | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 82 | import android.telephony.NetworkScanRequest; | 
| Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 83 | import android.telephony.PhoneCapability; | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 84 | import android.telephony.PhoneNumberRange; | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 85 | import android.telephony.RadioAccessFamily; | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 86 | import android.telephony.RadioAccessSpecifier; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 87 | import android.telephony.ServiceState; | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 88 | import android.telephony.SignalStrength; | 
| Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 89 | import android.telephony.SubscriptionInfo; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 90 | import android.telephony.SubscriptionManager; | 
| Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 91 | import android.telephony.TelephonyFrameworkInitializer; | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 92 | import android.telephony.TelephonyHistogram; | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 93 | import android.telephony.TelephonyManager; | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 94 | import android.telephony.TelephonyScanManager; | 
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 95 | import android.telephony.UiccCardInfo; | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 96 | import android.telephony.UiccSlotInfo; | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 97 | import android.telephony.UssdResponse; | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 98 | import android.telephony.VisualVoicemailSmsFilterSettings; | 
| Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 99 | import android.telephony.data.ApnSetting; | 
 | 100 | import android.telephony.emergency.EmergencyNumber; | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 101 | import android.telephony.ims.ImsException; | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 102 | import android.telephony.ims.ProvisioningManager; | 
| Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 103 | import android.telephony.ims.RegistrationManager; | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 104 | import android.telephony.ims.aidl.IImsCapabilityCallback; | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsConfig; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsConfigCallback; | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 107 | import android.telephony.ims.aidl.IImsMmTelFeature; | 
 | 108 | import android.telephony.ims.aidl.IImsRcsFeature; | 
 | 109 | import android.telephony.ims.aidl.IImsRegistration; | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 110 | import android.telephony.ims.aidl.IImsRegistrationCallback; | 
| Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 111 | import android.telephony.ims.feature.ImsFeature; | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 112 | import android.telephony.ims.feature.MmTelFeature; | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 113 | import android.telephony.ims.feature.RcsFeature; | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 114 | import android.telephony.ims.stub.ImsConfigImplBase; | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 115 | import android.telephony.ims.stub.ImsRegistrationImplBase; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 116 | import android.text.TextUtils; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 117 | import android.util.ArraySet; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 118 | import android.util.Log; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 119 | import android.util.Pair; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 120 |  | 
| Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 121 | import com.android.ims.ImsManager; | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 122 | import com.android.ims.internal.IImsServiceFeatureCallback; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 123 | import com.android.internal.telephony.CallForwardInfo; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.CallManager; | 
| Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CallStateException; | 
| pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.CarrierInfoManager; | 
| chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 127 | import com.android.internal.telephony.CarrierResolver; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.CellNetworkScanResult; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.CommandException; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 130 | import com.android.internal.telephony.CommandsInterface; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.DefaultPhoneNotifier; | 
| Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.HalVersion; | 
| Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 133 | import com.android.internal.telephony.IBooleanConsumer; | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.IIntegerConsumer; | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 135 | import com.android.internal.telephony.INumberVerificationCallback; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.ITelephony; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 137 | import com.android.internal.telephony.IccCard; | 
| Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.LocaleTracker; | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.NetworkScanRequestTracker; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.OperatorInfo; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.Phone; | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.PhoneConfigurationManager; | 
| Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.PhoneConstantConversions; | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.PhoneConstants; | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.PhoneFactory; | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.ProxyController; | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.RIL; | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.RILConstants; | 
| Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.ServiceStateTracker; | 
| Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.SmsController; | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.SmsPermissions; | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.SubscriptionController; | 
| Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 153 | import com.android.internal.telephony.TelephonyIntents; | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.TelephonyPermissions; | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; | 
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.euicc.EuiccConnector; | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.ims.ImsResolver; | 
| Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.imsphone.ImsPhone; | 
 | 160 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; | 
| Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.metrics.TelephonyMetrics; | 
| Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.IccIoResult; | 
| changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.IccRecords; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.IccUtils; | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.SIMRecords; | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.UiccCard; | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.uicc.UiccCardApplication; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.uicc.UiccController; | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.uicc.UiccProfile; | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 171 | import com.android.internal.telephony.uicc.UiccSlot; | 
| zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 172 | import com.android.internal.telephony.util.LocaleUtils; | 
| fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 174 | import com.android.internal.util.HexDump; | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 175 | import com.android.phone.settings.PickSmsSubscriptionActivity; | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 176 | import com.android.phone.vvm.PhoneAccountHandleConverter; | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 177 | import com.android.phone.vvm.RemoteVvmTaskManager; | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 178 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; | 
| Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 179 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; | 
| Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 180 | import com.android.telephony.Rlog; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 181 |  | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 182 | import java.io.FileDescriptor; | 
 | 183 | import java.io.PrintWriter; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 184 | import java.util.ArrayList; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 185 | import java.util.Arrays; | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 186 | import java.util.HashMap; | 
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 187 | import java.util.HashSet; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 188 | import java.util.List; | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 189 | import java.util.Locale; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 190 | import java.util.Map; | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 191 | import java.util.NoSuchElementException; | 
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 192 | import java.util.Set; | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 193 | import java.util.concurrent.atomic.AtomicBoolean; | 
| Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 194 | import java.util.function.Consumer; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 195 |  | 
 | 196 | /** | 
 | 197 |  * Implementation of the ITelephony interface. | 
 | 198 |  */ | 
| Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 199 | public class PhoneInterfaceManager extends ITelephony.Stub { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 200 |     private static final String LOG_TAG = "PhoneInterfaceManager"; | 
 | 201 |     private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); | 
 | 202 |     private static final boolean DBG_LOC = false; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 203 |     private static final boolean DBG_MERGE = false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 204 |  | 
 | 205 |     // Message codes used with mMainThreadHandler | 
 | 206 |     private static final int CMD_HANDLE_PIN_MMI = 1; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 207 |     private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; | 
 | 208 |     private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 209 |     private static final int CMD_OPEN_CHANNEL = 9; | 
 | 210 |     private static final int EVENT_OPEN_CHANNEL_DONE = 10; | 
 | 211 |     private static final int CMD_CLOSE_CHANNEL = 11; | 
 | 212 |     private static final int EVENT_CLOSE_CHANNEL_DONE = 12; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 213 |     private static final int CMD_NV_READ_ITEM = 13; | 
 | 214 |     private static final int EVENT_NV_READ_ITEM_DONE = 14; | 
 | 215 |     private static final int CMD_NV_WRITE_ITEM = 15; | 
 | 216 |     private static final int EVENT_NV_WRITE_ITEM_DONE = 16; | 
 | 217 |     private static final int CMD_NV_WRITE_CDMA_PRL = 17; | 
 | 218 |     private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 219 |     private static final int CMD_RESET_MODEM_CONFIG = 19; | 
 | 220 |     private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 221 |     private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; | 
 | 222 |     private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; | 
 | 223 |     private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; | 
 | 224 |     private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; | 
| Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 225 |     private static final int CMD_SEND_ENVELOPE = 25; | 
 | 226 |     private static final int EVENT_SEND_ENVELOPE_DONE = 26; | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 227 |     private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; | 
 | 228 |     private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; | 
| Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 229 |     private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; | 
 | 230 |     private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; | 
 | 231 |     private static final int CMD_EXCHANGE_SIM_IO = 31; | 
 | 232 |     private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 233 |     private static final int CMD_SET_VOICEMAIL_NUMBER = 33; | 
 | 234 |     private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 235 |     private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; | 
 | 236 |     private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 237 |     private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; | 
 | 238 |     private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 239 |     private static final int CMD_PERFORM_NETWORK_SCAN = 39; | 
 | 240 |     private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; | 
 | 241 |     private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; | 
 | 242 |     private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 243 |     private static final int CMD_SET_ALLOWED_CARRIERS = 43; | 
 | 244 |     private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; | 
 | 245 |     private static final int CMD_GET_ALLOWED_CARRIERS = 45; | 
 | 246 |     private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 247 |     private static final int CMD_HANDLE_USSD_REQUEST = 47; | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 248 |     private static final int CMD_GET_FORBIDDEN_PLMNS = 48; | 
 | 249 |     private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 250 |     private static final int CMD_SWITCH_SLOTS = 50; | 
 | 251 |     private static final int EVENT_SWITCH_SLOTS_DONE = 51; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 252 |     private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; | 
 | 253 |     private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; | 
 | 254 |     private static final int CMD_GET_CDMA_ROAMING_MODE = 54; | 
 | 255 |     private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; | 
 | 256 |     private static final int CMD_SET_CDMA_ROAMING_MODE = 56; | 
 | 257 |     private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; | 
 | 258 |     private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; | 
 | 259 |     private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 260 |     private static final int CMD_GET_ALL_CELL_INFO = 60; | 
 | 261 |     private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; | 
 | 262 |     private static final int CMD_GET_CELL_LOCATION = 62; | 
 | 263 |     private static final int EVENT_GET_CELL_LOCATION_DONE = 63; | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 264 |     private static final int CMD_MODEM_REBOOT = 64; | 
 | 265 |     private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 266 |     private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; | 
 | 267 |     private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 268 |     private static final int CMD_REQUEST_ENABLE_MODEM = 68; | 
 | 269 |     private static final int EVENT_ENABLE_MODEM_DONE = 69; | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 270 |     private static final int CMD_GET_MODEM_STATUS = 70; | 
 | 271 |     private static final int EVENT_GET_MODEM_STATUS_DONE = 71; | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 272 |     private static final int CMD_SET_FORBIDDEN_PLMNS = 72; | 
 | 273 |     private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 274 |     private static final int CMD_ERASE_MODEM_CONFIG = 74; | 
 | 275 |     private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 276 |     private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; | 
 | 277 |     private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; | 
 | 278 |     private static final int CMD_SET_ICC_LOCK_ENABLED = 78; | 
 | 279 |     private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; | 
| Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 280 |     private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; | 
 | 281 |     private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 282 |     private static final int MSG_NOTIFY_USER_ACTIVITY = 82; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 283 |     private static final int CMD_GET_CALL_FORWARDING = 83; | 
 | 284 |     private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; | 
 | 285 |     private static final int CMD_SET_CALL_FORWARDING = 85; | 
 | 286 |     private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; | 
 | 287 |     private static final int CMD_GET_CALL_WAITING = 87; | 
 | 288 |     private static final int EVENT_GET_CALL_WAITING_DONE = 88; | 
 | 289 |     private static final int CMD_SET_CALL_WAITING = 89; | 
 | 290 |     private static final int EVENT_SET_CALL_WAITING_DONE = 90; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 291 |  | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 292 |     // Parameters of select command. | 
 | 293 |     private static final int SELECT_COMMAND = 0xA4; | 
 | 294 |     private static final int SELECT_P1 = 0x04; | 
 | 295 |     private static final int SELECT_P2 = 0; | 
 | 296 |     private static final int SELECT_P3 = 0x10; | 
 | 297 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 298 |     /** The singleton instance. */ | 
 | 299 |     private static PhoneInterfaceManager sInstance; | 
 | 300 |  | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 301 |     private PhoneGlobals mApp; | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 302 |     private CallManager mCM; | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 303 |     private ImsResolver mImsResolver; | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 304 |     private UserManager mUserManager; | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 305 |     private AppOpsManager mAppOps; | 
 | 306 |     private MainThreadHandler mMainThreadHandler; | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 307 |     private SubscriptionController mSubscriptionController; | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 308 |     private SharedPreferences mTelephonySharedPreferences; | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 309 |     private PhoneConfigurationManager mPhoneConfigurationManager; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 310 |  | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 311 |     /** User Activity */ | 
 | 312 |     private AtomicBoolean mNotifyUserActivity; | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 313 |     private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; | 
 | 314 |  | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 315 |     private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; | 
 | 316 |     private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 317 |     private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 318 |     private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; | 
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 319 |  | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 320 |     // String to store multi SIM allowed | 
 | 321 |     private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; | 
 | 322 |  | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 323 |     // The AID of ISD-R. | 
 | 324 |     private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; | 
 | 325 |  | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 326 |     private NetworkScanRequestTracker mNetworkScanRequestTracker; | 
 | 327 |  | 
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 328 |     private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; | 
 | 329 |     private static final int MANUFACTURER_CODE_LENGTH = 8; | 
 | 330 |  | 
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 331 |     /** | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 332 |      * Experiment flag to enable erase modem config on reset network, default value is false | 
 | 333 |      */ | 
 | 334 |     public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = | 
 | 335 |             "reset_network_erase_modem_config_enabled"; | 
 | 336 |  | 
 | 337 |     /** | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 338 |      * A request object to use for transmitting data to an ICC. | 
 | 339 |      */ | 
 | 340 |     private static final class IccAPDUArgument { | 
 | 341 |         public int channel, cla, command, p1, p2, p3; | 
 | 342 |         public String data; | 
 | 343 |  | 
 | 344 |         public IccAPDUArgument(int channel, int cla, int command, | 
 | 345 |                 int p1, int p2, int p3, String data) { | 
 | 346 |             this.channel = channel; | 
 | 347 |             this.cla = cla; | 
 | 348 |             this.command = command; | 
 | 349 |             this.p1 = p1; | 
 | 350 |             this.p2 = p2; | 
 | 351 |             this.p3 = p3; | 
 | 352 |             this.data = data; | 
 | 353 |         } | 
 | 354 |     } | 
 | 355 |  | 
 | 356 |     /** | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 357 |      * A request object to use for transmitting data to an ICC. | 
 | 358 |      */ | 
 | 359 |     private static final class ManualNetworkSelectionArgument { | 
 | 360 |         public OperatorInfo operatorInfo; | 
 | 361 |         public boolean persistSelection; | 
 | 362 |  | 
 | 363 |         public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { | 
 | 364 |             this.operatorInfo = operatorInfo; | 
 | 365 |             this.persistSelection = persistSelection; | 
 | 366 |         } | 
 | 367 |     } | 
 | 368 |  | 
 | 369 |     /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 370 |      * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the | 
 | 371 |      * request after sending. The main thread will notify the request when it is complete. | 
 | 372 |      */ | 
 | 373 |     private static final class MainThreadRequest { | 
 | 374 |         /** The argument to use for the request */ | 
 | 375 |         public Object argument; | 
 | 376 |         /** The result of the request that is run on the main thread */ | 
 | 377 |         public Object result; | 
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 378 |         // The subscriber id that this request applies to. Defaults to | 
 | 379 |         // SubscriptionManager.INVALID_SUBSCRIPTION_ID | 
 | 380 |         public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 381 |  | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 382 |         // In cases where subId is unavailable, the caller needs to specify the phone. | 
 | 383 |         public Phone phone; | 
 | 384 |  | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 385 |         public WorkSource workSource; | 
 | 386 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 387 |         public MainThreadRequest(Object argument) { | 
 | 388 |             this.argument = argument; | 
 | 389 |         } | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 390 |  | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 391 |         MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { | 
 | 392 |             this.argument = argument; | 
 | 393 |             if (phone != null) { | 
 | 394 |                 this.phone = phone; | 
 | 395 |             } | 
 | 396 |             this.workSource = workSource; | 
 | 397 |         } | 
 | 398 |  | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 399 |         MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 400 |             this.argument = argument; | 
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 401 |             if (subId != null) { | 
 | 402 |                 this.subId = subId; | 
 | 403 |             } | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 404 |             this.workSource = workSource; | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 405 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 406 |     } | 
 | 407 |  | 
| Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 408 |     private static final class IncomingThirdPartyCallArgs { | 
 | 409 |         public final ComponentName component; | 
 | 410 |         public final String callId; | 
 | 411 |         public final String callerDisplayName; | 
 | 412 |  | 
 | 413 |         public IncomingThirdPartyCallArgs(ComponentName component, String callId, | 
 | 414 |                 String callerDisplayName) { | 
 | 415 |             this.component = component; | 
 | 416 |             this.callId = callId; | 
 | 417 |             this.callerDisplayName = callerDisplayName; | 
 | 418 |         } | 
 | 419 |     } | 
 | 420 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 421 |     /** | 
 | 422 |      * A handler that processes messages on the main thread in the phone process. Since many | 
 | 423 |      * of the Phone calls are not thread safe this is needed to shuttle the requests from the | 
 | 424 |      * inbound binder threads to the main thread in the phone process.  The Binder thread | 
 | 425 |      * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting | 
 | 426 |      * on, which will be notified when the operation completes and will contain the result of the | 
 | 427 |      * request. | 
 | 428 |      * | 
 | 429 |      * <p>If a MainThreadRequest object is provided in the msg.obj field, | 
 | 430 |      * note that request.result must be set to something non-null for the calling thread to | 
 | 431 |      * unblock. | 
 | 432 |      */ | 
 | 433 |     private final class MainThreadHandler extends Handler { | 
 | 434 |         @Override | 
 | 435 |         public void handleMessage(Message msg) { | 
 | 436 |             MainThreadRequest request; | 
 | 437 |             Message onCompleted; | 
 | 438 |             AsyncResult ar; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 439 |             UiccCard uiccCard; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 440 |             IccAPDUArgument iccArgument; | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 441 |             final Phone defaultPhone = getDefaultPhone(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 442 |  | 
 | 443 |             switch (msg.what) { | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 444 |                 case CMD_HANDLE_USSD_REQUEST: { | 
 | 445 |                     request = (MainThreadRequest) msg.obj; | 
 | 446 |                     final Phone phone = getPhoneFromRequest(request); | 
 | 447 |                     Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; | 
 | 448 |                     String ussdRequest =  ussdObject.first; | 
 | 449 |                     ResultReceiver wrappedCallback = ussdObject.second; | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 450 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 451 |                     if (!isUssdApiAllowed(request.subId)) { | 
 | 452 |                         // Carrier does not support use of this API, return failure. | 
 | 453 |                         Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); | 
 | 454 |                         UssdResponse response = new UssdResponse(ussdRequest, null); | 
 | 455 |                         Bundle returnData = new Bundle(); | 
 | 456 |                         returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); | 
 | 457 |                         wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 458 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 459 |                         request.result = true; | 
 | 460 |                         notifyRequester(request); | 
 | 461 |                         return; | 
 | 462 |                     } | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 463 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 464 |                     try { | 
 | 465 |                         request.result = phone != null | 
 | 466 |                                 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; | 
 | 467 |                     } catch (CallStateException cse) { | 
 | 468 |                         request.result = false; | 
 | 469 |                     } | 
 | 470 |                     // Wake up the requesting thread | 
 | 471 |                     notifyRequester(request); | 
 | 472 |                     break; | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 473 |                 } | 
 | 474 |  | 
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 475 |                 case CMD_HANDLE_PIN_MMI: { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 476 |                     request = (MainThreadRequest) msg.obj; | 
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 477 |                     final Phone phone = getPhoneFromRequest(request); | 
 | 478 |                     request.result = phone != null ? | 
 | 479 |                             getPhoneFromRequest(request).handlePinMmi((String) request.argument) | 
 | 480 |                             : false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 481 |                     // Wake up the requesting thread | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 482 |                     notifyRequester(request); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 483 |                     break; | 
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 484 |                 } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 485 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 486 |                 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 487 |                     request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 488 |                     iccArgument = (IccAPDUArgument) request.argument; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 489 |                     uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 490 |                     if (uiccCard == null) { | 
 | 491 |                         loge("iccTransmitApduLogicalChannel: No UICC"); | 
 | 492 |                         request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 493 |                         notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 494 |                     } else { | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 495 |                         onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, | 
 | 496 |                             request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 497 |                         uiccCard.iccTransmitApduLogicalChannel( | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 498 |                             iccArgument.channel, iccArgument.cla, iccArgument.command, | 
 | 499 |                             iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 500 |                             onCompleted); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 501 |                     } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 502 |                     break; | 
 | 503 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 504 |                 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 505 |                     ar = (AsyncResult) msg.obj; | 
 | 506 |                     request = (MainThreadRequest) ar.userObj; | 
 | 507 |                     if (ar.exception == null && ar.result != null) { | 
 | 508 |                         request.result = ar.result; | 
 | 509 |                     } else { | 
 | 510 |                         request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
 | 511 |                         if (ar.result == null) { | 
 | 512 |                             loge("iccTransmitApduLogicalChannel: Empty response"); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 513 |                         } else if (ar.exception instanceof CommandException) { | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 514 |                             loge("iccTransmitApduLogicalChannel: CommandException: " + | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 515 |                                     ar.exception); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 516 |                         } else { | 
 | 517 |                             loge("iccTransmitApduLogicalChannel: Unknown exception"); | 
 | 518 |                         } | 
 | 519 |                     } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 520 |                     notifyRequester(request); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 521 |                     break; | 
 | 522 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 523 |                 case CMD_TRANSMIT_APDU_BASIC_CHANNEL: | 
 | 524 |                     request = (MainThreadRequest) msg.obj; | 
 | 525 |                     iccArgument = (IccAPDUArgument) request.argument; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 526 |                     uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 527 |                     if (uiccCard == null) { | 
 | 528 |                         loge("iccTransmitApduBasicChannel: No UICC"); | 
 | 529 |                         request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 530 |                         notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 531 |                     } else { | 
 | 532 |                         onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, | 
 | 533 |                             request); | 
 | 534 |                         uiccCard.iccTransmitApduBasicChannel( | 
 | 535 |                             iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, | 
 | 536 |                             iccArgument.p3, iccArgument.data, onCompleted); | 
 | 537 |                     } | 
 | 538 |                     break; | 
 | 539 |  | 
 | 540 |                 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: | 
 | 541 |                     ar = (AsyncResult) msg.obj; | 
 | 542 |                     request = (MainThreadRequest) ar.userObj; | 
 | 543 |                     if (ar.exception == null && ar.result != null) { | 
 | 544 |                         request.result = ar.result; | 
 | 545 |                     } else { | 
 | 546 |                         request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
 | 547 |                         if (ar.result == null) { | 
 | 548 |                             loge("iccTransmitApduBasicChannel: Empty response"); | 
 | 549 |                         } else if (ar.exception instanceof CommandException) { | 
 | 550 |                             loge("iccTransmitApduBasicChannel: CommandException: " + | 
 | 551 |                                     ar.exception); | 
 | 552 |                         } else { | 
 | 553 |                             loge("iccTransmitApduBasicChannel: Unknown exception"); | 
 | 554 |                         } | 
 | 555 |                     } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 556 |                     notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 557 |                     break; | 
 | 558 |  | 
 | 559 |                 case CMD_EXCHANGE_SIM_IO: | 
 | 560 |                     request = (MainThreadRequest) msg.obj; | 
 | 561 |                     iccArgument = (IccAPDUArgument) request.argument; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 562 |                     uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 563 |                     if (uiccCard == null) { | 
 | 564 |                         loge("iccExchangeSimIO: No UICC"); | 
 | 565 |                         request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 566 |                         notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 567 |                     } else { | 
 | 568 |                         onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, | 
 | 569 |                                 request); | 
 | 570 |                         uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ | 
 | 571 |                                 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, | 
 | 572 |                                 iccArgument.data, onCompleted); | 
 | 573 |                     } | 
 | 574 |                     break; | 
 | 575 |  | 
 | 576 |                 case EVENT_EXCHANGE_SIM_IO_DONE: | 
 | 577 |                     ar = (AsyncResult) msg.obj; | 
 | 578 |                     request = (MainThreadRequest) ar.userObj; | 
 | 579 |                     if (ar.exception == null && ar.result != null) { | 
 | 580 |                         request.result = ar.result; | 
 | 581 |                     } else { | 
 | 582 |                         request.result = new IccIoResult(0x6f, 0, (byte[])null); | 
 | 583 |                     } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 584 |                     notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 585 |                     break; | 
 | 586 |  | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 587 |                 case CMD_SEND_ENVELOPE: | 
 | 588 |                     request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 589 |                     uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 590 |                     if (uiccCard == null) { | 
 | 591 |                         loge("sendEnvelopeWithStatus: No UICC"); | 
 | 592 |                         request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 593 |                         notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 594 |                     } else { | 
 | 595 |                         onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); | 
 | 596 |                         uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); | 
 | 597 |                     } | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 598 |                     break; | 
 | 599 |  | 
 | 600 |                 case EVENT_SEND_ENVELOPE_DONE: | 
 | 601 |                     ar = (AsyncResult) msg.obj; | 
 | 602 |                     request = (MainThreadRequest) ar.userObj; | 
| Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 603 |                     if (ar.exception == null && ar.result != null) { | 
 | 604 |                         request.result = ar.result; | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 605 |                     } else { | 
| Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 606 |                         request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
 | 607 |                         if (ar.result == null) { | 
 | 608 |                             loge("sendEnvelopeWithStatus: Empty response"); | 
 | 609 |                         } else if (ar.exception instanceof CommandException) { | 
 | 610 |                             loge("sendEnvelopeWithStatus: CommandException: " + | 
 | 611 |                                     ar.exception); | 
 | 612 |                         } else { | 
 | 613 |                             loge("sendEnvelopeWithStatus: exception:" + ar.exception); | 
 | 614 |                         } | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 615 |                     } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 616 |                     notifyRequester(request); | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 617 |                     break; | 
 | 618 |  | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 619 |                 case CMD_OPEN_CHANNEL: | 
 | 620 |                     request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 621 |                     uiccCard = getUiccCardFromRequest(request); | 
| Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 622 |                     Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 623 |                     if (uiccCard == null) { | 
 | 624 |                         loge("iccOpenLogicalChannel: No UICC"); | 
| Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 625 |                         request.result = new IccOpenLogicalChannelResponse(-1, | 
 | 626 |                             IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 627 |                         notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 628 |                     } else { | 
 | 629 |                         onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); | 
| Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 630 |                         uiccCard.iccOpenLogicalChannel(openChannelArgs.first, | 
 | 631 |                                 openChannelArgs.second, onCompleted); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 632 |                     } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 633 |                     break; | 
 | 634 |  | 
 | 635 |                 case EVENT_OPEN_CHANNEL_DONE: | 
 | 636 |                     ar = (AsyncResult) msg.obj; | 
 | 637 |                     request = (MainThreadRequest) ar.userObj; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 638 |                     IccOpenLogicalChannelResponse openChannelResp; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 639 |                     if (ar.exception == null && ar.result != null) { | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 640 |                         int[] result = (int[]) ar.result; | 
 | 641 |                         int channelId = result[0]; | 
 | 642 |                         byte[] selectResponse = null; | 
 | 643 |                         if (result.length > 1) { | 
 | 644 |                             selectResponse = new byte[result.length - 1]; | 
 | 645 |                             for (int i = 1; i < result.length; ++i) { | 
 | 646 |                                 selectResponse[i - 1] = (byte) result[i]; | 
 | 647 |                             } | 
 | 648 |                         } | 
 | 649 |                         openChannelResp = new IccOpenLogicalChannelResponse(channelId, | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 650 |                             IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 651 |                     } else { | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 652 |                         if (ar.result == null) { | 
 | 653 |                             loge("iccOpenLogicalChannel: Empty response"); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 654 |                         } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 655 |                         if (ar.exception != null) { | 
 | 656 |                             loge("iccOpenLogicalChannel: Exception: " + ar.exception); | 
 | 657 |                         } | 
 | 658 |  | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 659 |                         int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; | 
| Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 660 |                         if (ar.exception instanceof CommandException) { | 
 | 661 |                             CommandException.Error error = | 
 | 662 |                                 ((CommandException) (ar.exception)).getCommandError(); | 
 | 663 |                             if (error == CommandException.Error.MISSING_RESOURCE) { | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 664 |                                 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; | 
| Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 665 |                             } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 666 |                                 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 667 |                             } | 
 | 668 |                         } | 
 | 669 |                         openChannelResp = new IccOpenLogicalChannelResponse( | 
 | 670 |                             IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 671 |                     } | 
| Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 672 |                     request.result = openChannelResp; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 673 |                     notifyRequester(request); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 674 |                     break; | 
 | 675 |  | 
 | 676 |                 case CMD_CLOSE_CHANNEL: | 
 | 677 |                     request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 678 |                     uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 679 |                     if (uiccCard == null) { | 
 | 680 |                         loge("iccCloseLogicalChannel: No UICC"); | 
| Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 681 |                         request.result = false; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 682 |                         notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 683 |                     } else { | 
 | 684 |                         onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); | 
 | 685 |                         uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); | 
 | 686 |                     } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 687 |                     break; | 
 | 688 |  | 
 | 689 |                 case EVENT_CLOSE_CHANNEL_DONE: | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 690 |                     handleNullReturnEvent(msg, "iccCloseLogicalChannel"); | 
 | 691 |                     break; | 
 | 692 |  | 
 | 693 |                 case CMD_NV_READ_ITEM: | 
 | 694 |                     request = (MainThreadRequest) msg.obj; | 
 | 695 |                     onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 696 |                     defaultPhone.nvReadItem((Integer) request.argument, onCompleted, | 
 | 697 |                             request.workSource); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 698 |                     break; | 
 | 699 |  | 
 | 700 |                 case EVENT_NV_READ_ITEM_DONE: | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 701 |                     ar = (AsyncResult) msg.obj; | 
 | 702 |                     request = (MainThreadRequest) ar.userObj; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 703 |                     if (ar.exception == null && ar.result != null) { | 
 | 704 |                         request.result = ar.result;     // String | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 705 |                     } else { | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 706 |                         request.result = ""; | 
 | 707 |                         if (ar.result == null) { | 
 | 708 |                             loge("nvReadItem: Empty response"); | 
 | 709 |                         } else if (ar.exception instanceof CommandException) { | 
 | 710 |                             loge("nvReadItem: CommandException: " + | 
 | 711 |                                     ar.exception); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 712 |                         } else { | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 713 |                             loge("nvReadItem: Unknown exception"); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 714 |                         } | 
 | 715 |                     } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 716 |                     notifyRequester(request); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 717 |                     break; | 
 | 718 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 719 |                 case CMD_NV_WRITE_ITEM: | 
 | 720 |                     request = (MainThreadRequest) msg.obj; | 
 | 721 |                     onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); | 
 | 722 |                     Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 723 |                     defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 724 |                             request.workSource); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 725 |                     break; | 
 | 726 |  | 
 | 727 |                 case EVENT_NV_WRITE_ITEM_DONE: | 
 | 728 |                     handleNullReturnEvent(msg, "nvWriteItem"); | 
 | 729 |                     break; | 
 | 730 |  | 
 | 731 |                 case CMD_NV_WRITE_CDMA_PRL: | 
 | 732 |                     request = (MainThreadRequest) msg.obj; | 
 | 733 |                     onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 734 |                     defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 735 |                     break; | 
 | 736 |  | 
 | 737 |                 case EVENT_NV_WRITE_CDMA_PRL_DONE: | 
 | 738 |                     handleNullReturnEvent(msg, "nvWriteCdmaPrl"); | 
 | 739 |                     break; | 
 | 740 |  | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 741 |                 case CMD_RESET_MODEM_CONFIG: | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 742 |                     request = (MainThreadRequest) msg.obj; | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 743 |                     onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 744 |                     defaultPhone.resetModemConfig(onCompleted); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 745 |                     break; | 
 | 746 |  | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 747 |                 case EVENT_RESET_MODEM_CONFIG_DONE: | 
 | 748 |                     handleNullReturnEvent(msg, "resetModemConfig"); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 749 |                     break; | 
 | 750 |  | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 751 |                 case CMD_GET_PREFERRED_NETWORK_TYPE: | 
 | 752 |                     request = (MainThreadRequest) msg.obj; | 
 | 753 |                     onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 754 |                     getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 755 |                     break; | 
 | 756 |  | 
 | 757 |                 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: | 
 | 758 |                     ar = (AsyncResult) msg.obj; | 
 | 759 |                     request = (MainThreadRequest) ar.userObj; | 
 | 760 |                     if (ar.exception == null && ar.result != null) { | 
 | 761 |                         request.result = ar.result;     // Integer | 
 | 762 |                     } else { | 
| Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 763 |                         request.result = null; | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 764 |                         if (ar.result == null) { | 
 | 765 |                             loge("getPreferredNetworkType: Empty response"); | 
 | 766 |                         } else if (ar.exception instanceof CommandException) { | 
 | 767 |                             loge("getPreferredNetworkType: CommandException: " + | 
 | 768 |                                     ar.exception); | 
 | 769 |                         } else { | 
 | 770 |                             loge("getPreferredNetworkType: Unknown exception"); | 
 | 771 |                         } | 
 | 772 |                     } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 773 |                     notifyRequester(request); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 774 |                     break; | 
 | 775 |  | 
 | 776 |                 case CMD_SET_PREFERRED_NETWORK_TYPE: | 
 | 777 |                     request = (MainThreadRequest) msg.obj; | 
 | 778 |                     onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); | 
 | 779 |                     int networkType = (Integer) request.argument; | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 780 |                     getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 781 |                     break; | 
 | 782 |  | 
 | 783 |                 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: | 
 | 784 |                     handleNullReturnEvent(msg, "setPreferredNetworkType"); | 
 | 785 |                     break; | 
 | 786 |  | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 787 |                 case CMD_INVOKE_OEM_RIL_REQUEST_RAW: | 
 | 788 |                     request = (MainThreadRequest)msg.obj; | 
 | 789 |                     onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 790 |                     defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 791 |                     break; | 
 | 792 |  | 
 | 793 |                 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: | 
 | 794 |                     ar = (AsyncResult)msg.obj; | 
 | 795 |                     request = (MainThreadRequest)ar.userObj; | 
 | 796 |                     request.result = ar; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 797 |                     notifyRequester(request); | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 798 |                     break; | 
 | 799 |  | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 800 |                 case CMD_SET_VOICEMAIL_NUMBER: | 
 | 801 |                     request = (MainThreadRequest) msg.obj; | 
 | 802 |                     onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); | 
 | 803 |                     Pair<String, String> tagNum = (Pair<String, String>) request.argument; | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 804 |                     getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, | 
 | 805 |                             onCompleted); | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 806 |                     break; | 
 | 807 |  | 
 | 808 |                 case EVENT_SET_VOICEMAIL_NUMBER_DONE: | 
 | 809 |                     handleNullReturnEvent(msg, "setVoicemailNumber"); | 
 | 810 |                     break; | 
 | 811 |  | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 812 |                 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: | 
 | 813 |                     request = (MainThreadRequest) msg.obj; | 
 | 814 |                     onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, | 
 | 815 |                             request); | 
 | 816 |                     getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); | 
 | 817 |                     break; | 
 | 818 |  | 
 | 819 |                 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: | 
 | 820 |                     handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); | 
 | 821 |                     break; | 
 | 822 |  | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 823 |                 case CMD_PERFORM_NETWORK_SCAN: | 
 | 824 |                     request = (MainThreadRequest) msg.obj; | 
 | 825 |                     onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); | 
 | 826 |                     getPhoneFromRequest(request).getAvailableNetworks(onCompleted); | 
 | 827 |                     break; | 
 | 828 |  | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 829 |                 case CMD_GET_CALL_FORWARDING: | 
 | 830 |                     request = (MainThreadRequest) msg.obj; | 
 | 831 |                     onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); | 
 | 832 |                     int callForwardingReason = (Integer) request.argument; | 
 | 833 |                     getPhoneFromRequest(request).getCallForwardingOption( | 
 | 834 |                             callForwardingReason, onCompleted); | 
 | 835 |                     break; | 
 | 836 |  | 
 | 837 |                 case EVENT_GET_CALL_FORWARDING_DONE: | 
 | 838 |                     ar = (AsyncResult) msg.obj; | 
 | 839 |                     request = (MainThreadRequest) ar.userObj; | 
 | 840 |                     CallForwardingInfo callForwardingInfo = null; | 
 | 841 |                     if (ar.exception == null && ar.result != null) { | 
 | 842 |                         CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; | 
 | 843 |                         for (CallForwardInfo callForwardInfo : callForwardInfos) { | 
 | 844 |                             // Service Class is a bit mask per 3gpp 27.007. Search for | 
 | 845 |                             // any service for voice call. | 
 | 846 |                             if ((callForwardInfo.serviceClass | 
 | 847 |                                     & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { | 
 | 848 |                                 callForwardingInfo = new CallForwardingInfo( | 
 | 849 |                                         callForwardInfo.serviceClass, callForwardInfo.reason, | 
 | 850 |                                                 callForwardInfo.number, | 
 | 851 |                                                         callForwardInfo.timeSeconds); | 
 | 852 |                                 break; | 
 | 853 |                             } | 
 | 854 |                         } | 
 | 855 |                         // Didn't find a call forward info for voice call. | 
 | 856 |                         if (callForwardingInfo == null) { | 
 | 857 |                             callForwardingInfo = new CallForwardingInfo( | 
 | 858 |                                     CallForwardingInfo.STATUS_UNKNOWN_ERROR, | 
 | 859 |                                             0 /* reason */, null /* number */, 0 /* timeout */); | 
 | 860 |                         } | 
 | 861 |                     } else { | 
 | 862 |                         if (ar.result == null) { | 
 | 863 |                             loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); | 
 | 864 |                         } | 
 | 865 |                         if (ar.exception != null) { | 
 | 866 |                             loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); | 
 | 867 |                         } | 
 | 868 |                         int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR; | 
 | 869 |                         if (ar.exception instanceof CommandException) { | 
 | 870 |                             CommandException.Error error = | 
 | 871 |                                     ((CommandException) (ar.exception)).getCommandError(); | 
 | 872 |                             if (error == CommandException.Error.FDN_CHECK_FAILURE) { | 
 | 873 |                                 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE; | 
 | 874 |                             } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
 | 875 |                                 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED; | 
 | 876 |                             } | 
 | 877 |                         } | 
 | 878 |                         callForwardingInfo = new CallForwardingInfo( | 
 | 879 |                                 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */); | 
 | 880 |                     } | 
 | 881 |                     request.result = callForwardingInfo; | 
 | 882 |                     notifyRequester(request); | 
 | 883 |                     break; | 
 | 884 |  | 
 | 885 |                 case CMD_SET_CALL_FORWARDING: | 
 | 886 |                     request = (MainThreadRequest) msg.obj; | 
 | 887 |                     onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); | 
 | 888 |                     CallForwardingInfo callForwardingInfoToSet = | 
 | 889 |                             (CallForwardingInfo) request.argument; | 
 | 890 |                     getPhoneFromRequest(request).setCallForwardingOption( | 
 | 891 |                             callForwardingInfoToSet.getStatus(), | 
 | 892 |                             callForwardingInfoToSet.getReason(), | 
 | 893 |                             callForwardingInfoToSet.getNumber(), | 
 | 894 |                             callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); | 
 | 895 |                     break; | 
 | 896 |  | 
 | 897 |                 case EVENT_SET_CALL_FORWARDING_DONE: | 
 | 898 |                     ar = (AsyncResult) msg.obj; | 
 | 899 |                     request = (MainThreadRequest) ar.userObj; | 
 | 900 |                     if (ar.exception == null) { | 
 | 901 |                         request.result = true; | 
 | 902 |                     } else { | 
 | 903 |                         request.result = false; | 
 | 904 |                         loge("setCallForwarding exception: " + ar.exception); | 
 | 905 |                     } | 
 | 906 |                     notifyRequester(request); | 
 | 907 |                     break; | 
 | 908 |  | 
 | 909 |                 case CMD_GET_CALL_WAITING: | 
 | 910 |                     request = (MainThreadRequest) msg.obj; | 
 | 911 |                     onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); | 
 | 912 |                     getPhoneFromRequest(request).getCallWaiting(onCompleted); | 
 | 913 |                     break; | 
 | 914 |  | 
 | 915 |                 case EVENT_GET_CALL_WAITING_DONE: | 
 | 916 |                     ar = (AsyncResult) msg.obj; | 
 | 917 |                     request = (MainThreadRequest) ar.userObj; | 
 | 918 |                     int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; | 
 | 919 |                     if (ar.exception == null && ar.result != null) { | 
| Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 920 |                         int[] callForwardResults = (int[]) ar.result; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 921 |                         // Service Class is a bit mask per 3gpp 27.007. | 
 | 922 |                         // Search for any service for voice call. | 
| Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 923 |                         if (callForwardResults.length > 1 | 
 | 924 |                                 && ((callForwardResults[1] | 
 | 925 |                                         & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { | 
 | 926 |                             callForwardingStatus = callForwardResults[0] == 0 | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 927 |                                     ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE | 
 | 928 |                                             : TelephonyManager.CALL_WAITING_STATUS_ACTIVE; | 
 | 929 |                         } else { | 
 | 930 |                             callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE; | 
 | 931 |                         } | 
 | 932 |                     } else { | 
 | 933 |                         if (ar.result == null) { | 
 | 934 |                             loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); | 
 | 935 |                         } | 
 | 936 |                         if (ar.exception != null) { | 
 | 937 |                             loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); | 
 | 938 |                         } | 
 | 939 |                         if (ar.exception instanceof CommandException) { | 
 | 940 |                             CommandException.Error error = | 
 | 941 |                                     ((CommandException) (ar.exception)).getCommandError(); | 
 | 942 |                             if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
 | 943 |                                 callForwardingStatus = | 
 | 944 |                                         TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; | 
 | 945 |                             } | 
 | 946 |                         } | 
 | 947 |                     } | 
 | 948 |                     request.result = callForwardingStatus; | 
 | 949 |                     notifyRequester(request); | 
 | 950 |                     break; | 
 | 951 |  | 
 | 952 |                 case CMD_SET_CALL_WAITING: | 
 | 953 |                     request = (MainThreadRequest) msg.obj; | 
 | 954 |                     onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); | 
 | 955 |                     boolean isEnable = (Boolean) request.argument; | 
 | 956 |                     getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted); | 
 | 957 |                     break; | 
 | 958 |  | 
 | 959 |                 case EVENT_SET_CALL_WAITING_DONE: | 
 | 960 |                     ar = (AsyncResult) msg.obj; | 
 | 961 |                     request = (MainThreadRequest) ar.userObj; | 
 | 962 |                     if (ar.exception == null) { | 
 | 963 |                         request.result = true; | 
 | 964 |                     } else { | 
 | 965 |                         request.result = false; | 
 | 966 |                         loge("setCallWaiting exception: " + ar.exception); | 
 | 967 |                     } | 
 | 968 |                     notifyRequester(request); | 
 | 969 |                     break; | 
 | 970 |  | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 971 |                 case EVENT_PERFORM_NETWORK_SCAN_DONE: | 
 | 972 |                     ar = (AsyncResult) msg.obj; | 
 | 973 |                     request = (MainThreadRequest) ar.userObj; | 
 | 974 |                     CellNetworkScanResult cellScanResult; | 
 | 975 |                     if (ar.exception == null && ar.result != null) { | 
 | 976 |                         cellScanResult = new CellNetworkScanResult( | 
 | 977 |                                 CellNetworkScanResult.STATUS_SUCCESS, | 
 | 978 |                                 (List<OperatorInfo>) ar.result); | 
 | 979 |                     } else { | 
 | 980 |                         if (ar.result == null) { | 
 | 981 |                             loge("getCellNetworkScanResults: Empty response"); | 
 | 982 |                         } | 
 | 983 |                         if (ar.exception != null) { | 
 | 984 |                             loge("getCellNetworkScanResults: Exception: " + ar.exception); | 
 | 985 |                         } | 
 | 986 |                         int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; | 
 | 987 |                         if (ar.exception instanceof CommandException) { | 
 | 988 |                             CommandException.Error error = | 
 | 989 |                                 ((CommandException) (ar.exception)).getCommandError(); | 
 | 990 |                             if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { | 
 | 991 |                                 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; | 
 | 992 |                             } else if (error == CommandException.Error.GENERIC_FAILURE) { | 
 | 993 |                                 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; | 
 | 994 |                             } | 
 | 995 |                         } | 
 | 996 |                         cellScanResult = new CellNetworkScanResult(errorCode, null); | 
 | 997 |                     } | 
 | 998 |                     request.result = cellScanResult; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 999 |                     notifyRequester(request); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1000 |                     break; | 
 | 1001 |  | 
 | 1002 |                 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: | 
 | 1003 |                     request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1004 |                     ManualNetworkSelectionArgument selArg = | 
 | 1005 |                             (ManualNetworkSelectionArgument) request.argument; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1006 |                     onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, | 
 | 1007 |                             request); | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1008 |                     getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, | 
 | 1009 |                             selArg.persistSelection, onCompleted); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1010 |                     break; | 
 | 1011 |  | 
 | 1012 |                 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: | 
| Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1013 |                     ar = (AsyncResult) msg.obj; | 
 | 1014 |                     request = (MainThreadRequest) ar.userObj; | 
 | 1015 |                     if (ar.exception == null) { | 
 | 1016 |                         request.result = true; | 
 | 1017 |                     } else { | 
 | 1018 |                         request.result = false; | 
 | 1019 |                         loge("setNetworkSelectionModeManual " + ar.exception); | 
 | 1020 |                     } | 
 | 1021 |                     notifyRequester(request); | 
 | 1022 |                     mApp.onNetworkSelectionChanged(request.subId); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1023 |                     break; | 
 | 1024 |  | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1025 |                 case CMD_GET_MODEM_ACTIVITY_INFO: | 
 | 1026 |                     request = (MainThreadRequest) msg.obj; | 
 | 1027 |                     onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); | 
| James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1028 |                     if (defaultPhone != null) { | 
 | 1029 |                         defaultPhone.getModemActivityInfo(onCompleted, request.workSource); | 
 | 1030 |                     } | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1031 |                     break; | 
 | 1032 |  | 
 | 1033 |                 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: | 
 | 1034 |                     ar = (AsyncResult) msg.obj; | 
 | 1035 |                     request = (MainThreadRequest) ar.userObj; | 
 | 1036 |                     if (ar.exception == null && ar.result != null) { | 
 | 1037 |                         request.result = ar.result; | 
 | 1038 |                     } else { | 
 | 1039 |                         if (ar.result == null) { | 
 | 1040 |                             loge("queryModemActivityInfo: Empty response"); | 
 | 1041 |                         } else if (ar.exception instanceof CommandException) { | 
 | 1042 |                             loge("queryModemActivityInfo: CommandException: " + | 
 | 1043 |                                     ar.exception); | 
 | 1044 |                         } else { | 
 | 1045 |                             loge("queryModemActivityInfo: Unknown exception"); | 
 | 1046 |                         } | 
 | 1047 |                     } | 
| Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 1048 |                     // Result cannot be null. Return ModemActivityInfo with all fields set to 0. | 
 | 1049 |                     if (request.result == null) { | 
| Peter Collingbourne | c00e902 | 2019-11-26 09:56:26 -0800 | [diff] [blame] | 1050 |                         request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0); | 
| Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 1051 |                     } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1052 |                     notifyRequester(request); | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1053 |                     break; | 
 | 1054 |  | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1055 |                 case CMD_SET_ALLOWED_CARRIERS: | 
 | 1056 |                     request = (MainThreadRequest) msg.obj; | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1057 |                     CarrierRestrictionRules argument = | 
 | 1058 |                             (CarrierRestrictionRules) request.argument; | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1059 |                     onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1060 |                     defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1061 |                     break; | 
 | 1062 |  | 
 | 1063 |                 case EVENT_SET_ALLOWED_CARRIERS_DONE: | 
 | 1064 |                     ar = (AsyncResult) msg.obj; | 
 | 1065 |                     request = (MainThreadRequest) ar.userObj; | 
 | 1066 |                     if (ar.exception == null && ar.result != null) { | 
 | 1067 |                         request.result = ar.result; | 
 | 1068 |                     } else { | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1069 |                         request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; | 
 | 1070 |                         if (ar.exception instanceof CommandException) { | 
 | 1071 |                             loge("setAllowedCarriers: CommandException: " + ar.exception); | 
 | 1072 |                             CommandException.Error error = | 
 | 1073 |                                     ((CommandException) (ar.exception)).getCommandError(); | 
 | 1074 |                             if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
 | 1075 |                                 request.result = | 
 | 1076 |                                         TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; | 
 | 1077 |                             } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1078 |                         } else { | 
 | 1079 |                             loge("setAllowedCarriers: Unknown exception"); | 
 | 1080 |                         } | 
 | 1081 |                     } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1082 |                     notifyRequester(request); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1083 |                     break; | 
 | 1084 |  | 
 | 1085 |                 case CMD_GET_ALLOWED_CARRIERS: | 
 | 1086 |                     request = (MainThreadRequest) msg.obj; | 
 | 1087 |                     onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1088 |                     defaultPhone.getAllowedCarriers(onCompleted, request.workSource); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1089 |                     break; | 
 | 1090 |  | 
 | 1091 |                 case EVENT_GET_ALLOWED_CARRIERS_DONE: | 
 | 1092 |                     ar = (AsyncResult) msg.obj; | 
 | 1093 |                     request = (MainThreadRequest) ar.userObj; | 
 | 1094 |                     if (ar.exception == null && ar.result != null) { | 
 | 1095 |                         request.result = ar.result; | 
 | 1096 |                     } else { | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1097 |                         request.result = new IllegalStateException( | 
 | 1098 |                             "Failed to get carrier restrictions"); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1099 |                         if (ar.result == null) { | 
 | 1100 |                             loge("getAllowedCarriers: Empty response"); | 
 | 1101 |                         } else if (ar.exception instanceof CommandException) { | 
 | 1102 |                             loge("getAllowedCarriers: CommandException: " + | 
 | 1103 |                                     ar.exception); | 
 | 1104 |                         } else { | 
 | 1105 |                             loge("getAllowedCarriers: Unknown exception"); | 
 | 1106 |                         } | 
 | 1107 |                     } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1108 |                     notifyRequester(request); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1109 |                     break; | 
 | 1110 |  | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1111 |                 case EVENT_GET_FORBIDDEN_PLMNS_DONE: | 
 | 1112 |                     ar = (AsyncResult) msg.obj; | 
 | 1113 |                     request = (MainThreadRequest) ar.userObj; | 
 | 1114 |                     if (ar.exception == null && ar.result != null) { | 
 | 1115 |                         request.result = ar.result; | 
 | 1116 |                     } else { | 
 | 1117 |                         request.result = new IllegalArgumentException( | 
 | 1118 |                                 "Failed to retrieve Forbidden Plmns"); | 
 | 1119 |                         if (ar.result == null) { | 
 | 1120 |                             loge("getForbiddenPlmns: Empty response"); | 
 | 1121 |                         } else { | 
 | 1122 |                             loge("getForbiddenPlmns: Unknown exception"); | 
 | 1123 |                         } | 
 | 1124 |                     } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1125 |                     notifyRequester(request); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1126 |                     break; | 
 | 1127 |  | 
 | 1128 |                 case CMD_GET_FORBIDDEN_PLMNS: | 
 | 1129 |                     request = (MainThreadRequest) msg.obj; | 
 | 1130 |                     uiccCard = getUiccCardFromRequest(request); | 
 | 1131 |                     if (uiccCard == null) { | 
 | 1132 |                         loge("getForbiddenPlmns() UiccCard is null"); | 
 | 1133 |                         request.result = new IllegalArgumentException( | 
 | 1134 |                                 "getForbiddenPlmns() UiccCard is null"); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1135 |                         notifyRequester(request); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1136 |                         break; | 
 | 1137 |                     } | 
 | 1138 |                     Integer appType = (Integer) request.argument; | 
 | 1139 |                     UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); | 
 | 1140 |                     if (uiccApp == null) { | 
 | 1141 |                         loge("getForbiddenPlmns() no app with specified type -- " | 
 | 1142 |                                 + appType); | 
 | 1143 |                         request.result = new IllegalArgumentException("Failed to get UICC App"); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1144 |                         notifyRequester(request); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1145 |                         break; | 
 | 1146 |                     } else { | 
 | 1147 |                         if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() | 
 | 1148 |                                 + " specified type -- " + appType); | 
 | 1149 |                     } | 
 | 1150 |                     onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); | 
 | 1151 |                     ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( | 
 | 1152 |                               onCompleted); | 
 | 1153 |                     break; | 
 | 1154 |  | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1155 |                 case CMD_SWITCH_SLOTS: | 
 | 1156 |                     request = (MainThreadRequest) msg.obj; | 
 | 1157 |                     int[] physicalSlots = (int[]) request.argument; | 
 | 1158 |                     onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); | 
 | 1159 |                     UiccController.getInstance().switchSlots(physicalSlots, onCompleted); | 
 | 1160 |                     break; | 
 | 1161 |  | 
 | 1162 |                 case EVENT_SWITCH_SLOTS_DONE: | 
 | 1163 |                     ar = (AsyncResult) msg.obj; | 
 | 1164 |                     request = (MainThreadRequest) ar.userObj; | 
 | 1165 |                     request.result = (ar.exception == null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1166 |                     notifyRequester(request); | 
 | 1167 |                     break; | 
 | 1168 |                 case CMD_GET_NETWORK_SELECTION_MODE: | 
 | 1169 |                     request = (MainThreadRequest) msg.obj; | 
 | 1170 |                     onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); | 
 | 1171 |                     getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); | 
 | 1172 |                     break; | 
 | 1173 |  | 
 | 1174 |                 case EVENT_GET_NETWORK_SELECTION_MODE_DONE: | 
 | 1175 |                     ar = (AsyncResult) msg.obj; | 
 | 1176 |                     request = (MainThreadRequest) ar.userObj; | 
 | 1177 |                     if (ar.exception != null) { | 
 | 1178 |                         request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; | 
 | 1179 |                     } else { | 
 | 1180 |                         int mode = ((int[]) ar.result)[0]; | 
 | 1181 |                         if (mode == 0) { | 
 | 1182 |                             request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; | 
 | 1183 |                         } else { | 
 | 1184 |                             request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; | 
 | 1185 |                         } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1186 |                     } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1187 |                     notifyRequester(request); | 
 | 1188 |                     break; | 
 | 1189 |                 case CMD_GET_CDMA_ROAMING_MODE: | 
 | 1190 |                     request = (MainThreadRequest) msg.obj; | 
 | 1191 |                     onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); | 
 | 1192 |                     getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); | 
 | 1193 |                     break; | 
 | 1194 |                 case EVENT_GET_CDMA_ROAMING_MODE_DONE: | 
 | 1195 |                     ar = (AsyncResult) msg.obj; | 
 | 1196 |                     request = (MainThreadRequest) ar.userObj; | 
 | 1197 |                     if (ar.exception != null) { | 
 | 1198 |                         request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; | 
 | 1199 |                     } else { | 
 | 1200 |                         request.result = ((int[]) ar.result)[0]; | 
 | 1201 |                     } | 
 | 1202 |                     notifyRequester(request); | 
 | 1203 |                     break; | 
 | 1204 |                 case CMD_SET_CDMA_ROAMING_MODE: | 
 | 1205 |                     request = (MainThreadRequest) msg.obj; | 
 | 1206 |                     onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); | 
 | 1207 |                     int mode = (int) request.argument; | 
 | 1208 |                     getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); | 
 | 1209 |                     break; | 
 | 1210 |                 case EVENT_SET_CDMA_ROAMING_MODE_DONE: | 
 | 1211 |                     ar = (AsyncResult) msg.obj; | 
 | 1212 |                     request = (MainThreadRequest) ar.userObj; | 
 | 1213 |                     request.result = ar.exception == null; | 
 | 1214 |                     notifyRequester(request); | 
 | 1215 |                     break; | 
 | 1216 |                 case CMD_SET_CDMA_SUBSCRIPTION_MODE: | 
 | 1217 |                     request = (MainThreadRequest) msg.obj; | 
 | 1218 |                     onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); | 
 | 1219 |                     int subscriptionMode = (int) request.argument; | 
 | 1220 |                     getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); | 
 | 1221 |                     break; | 
 | 1222 |                 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: | 
 | 1223 |                     ar = (AsyncResult) msg.obj; | 
 | 1224 |                     request = (MainThreadRequest) ar.userObj; | 
 | 1225 |                     request.result = ar.exception == null; | 
 | 1226 |                     notifyRequester(request); | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1227 |                     break; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1228 |                 case CMD_GET_ALL_CELL_INFO: | 
 | 1229 |                     request = (MainThreadRequest) msg.obj; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1230 |                     onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1231 |                     request.phone.requestCellInfoUpdate(request.workSource, onCompleted); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1232 |                     break; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1233 |                 case EVENT_GET_ALL_CELL_INFO_DONE: | 
 | 1234 |                     ar = (AsyncResult) msg.obj; | 
 | 1235 |                     request = (MainThreadRequest) ar.userObj; | 
| Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1236 |                     // If a timeout occurs, the response will be null | 
 | 1237 |                     request.result = (ar.exception == null && ar.result != null) | 
 | 1238 |                             ? ar.result : new ArrayList<CellInfo>(); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1239 |                     synchronized (request) { | 
 | 1240 |                         request.notifyAll(); | 
 | 1241 |                     } | 
 | 1242 |                     break; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1243 |                 case CMD_REQUEST_CELL_INFO_UPDATE: | 
 | 1244 |                     request = (MainThreadRequest) msg.obj; | 
 | 1245 |                     request.phone.requestCellInfoUpdate(request.workSource, | 
 | 1246 |                             obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); | 
 | 1247 |                     break; | 
 | 1248 |                 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: | 
 | 1249 |                     ar = (AsyncResult) msg.obj; | 
 | 1250 |                     request = (MainThreadRequest) ar.userObj; | 
 | 1251 |                     ICellInfoCallback cb = (ICellInfoCallback) request.argument; | 
 | 1252 |                     try { | 
 | 1253 |                         if (ar.exception != null) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1254 |                             Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); | 
| Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1255 |                             cb.onError( | 
 | 1256 |                                     TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, | 
 | 1257 |                                     ar.exception.getClass().getName(), | 
 | 1258 |                                     ar.exception.toString()); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1259 |                         } else if (ar.result == null) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1260 |                             Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); | 
| Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1261 |                             cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1262 |                         } else { | 
 | 1263 |                             // use the result as returned | 
 | 1264 |                             cb.onCellInfo((List<CellInfo>) ar.result); | 
 | 1265 |                         } | 
 | 1266 |                     } catch (RemoteException re) { | 
 | 1267 |                         Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); | 
 | 1268 |                     } | 
 | 1269 |                     break; | 
 | 1270 |                 case CMD_GET_CELL_LOCATION: | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1271 |                     request = (MainThreadRequest) msg.obj; | 
 | 1272 |                     WorkSource ws = (WorkSource) request.argument; | 
 | 1273 |                     Phone phone = getPhoneFromRequest(request); | 
| Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1274 |                     phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1275 |                     break; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1276 |                 case EVENT_GET_CELL_LOCATION_DONE: | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1277 |                     ar = (AsyncResult) msg.obj; | 
 | 1278 |                     request = (MainThreadRequest) ar.userObj; | 
 | 1279 |                     if (ar.exception == null) { | 
 | 1280 |                         request.result = ar.result; | 
 | 1281 |                     } else { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1282 |                         phone = getPhoneFromRequest(request); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1283 |                         request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) | 
| Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1284 |                                 ? new CellIdentityCdma() : new CellIdentityGsm(); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1285 |                     } | 
 | 1286 |  | 
 | 1287 |                     synchronized (request) { | 
 | 1288 |                         request.notifyAll(); | 
 | 1289 |                     } | 
 | 1290 |                     break; | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1291 |                 case CMD_MODEM_REBOOT: | 
 | 1292 |                     request = (MainThreadRequest) msg.obj; | 
 | 1293 |                     onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1294 |                     defaultPhone.rebootModem(onCompleted); | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1295 |                     break; | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1296 |                 case EVENT_CMD_MODEM_REBOOT_DONE: | 
 | 1297 |                     handleNullReturnEvent(msg, "rebootModem"); | 
 | 1298 |                     break; | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1299 |                 case CMD_REQUEST_ENABLE_MODEM: | 
 | 1300 |                     request = (MainThreadRequest) msg.obj; | 
 | 1301 |                     boolean enable = (boolean) request.argument; | 
 | 1302 |                     onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); | 
| Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1303 |                     onCompleted.arg1 = enable ? 1 : 0; | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1304 |                     PhoneConfigurationManager.getInstance() | 
 | 1305 |                             .enablePhone(request.phone, enable, onCompleted); | 
 | 1306 |                     break; | 
 | 1307 |                 case EVENT_ENABLE_MODEM_DONE: | 
 | 1308 |                     ar = (AsyncResult) msg.obj; | 
 | 1309 |                     request = (MainThreadRequest) ar.userObj; | 
 | 1310 |                     request.result = (ar.exception == null); | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1311 |                     int phoneId = request.phone.getPhoneId(); | 
| Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1312 |                     //update the cache as modem status has changed | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1313 |                     if ((boolean) request.result) { | 
 | 1314 |                         mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); | 
 | 1315 |                         updateModemStateMetrics(); | 
 | 1316 |                     } else { | 
 | 1317 |                         Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." | 
 | 1318 |                                 + ar.exception); | 
 | 1319 |                     } | 
 | 1320 |                     notifyRequester(request); | 
 | 1321 |                     break; | 
 | 1322 |                 case CMD_GET_MODEM_STATUS: | 
 | 1323 |                     request = (MainThreadRequest) msg.obj; | 
 | 1324 |                     onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); | 
 | 1325 |                     PhoneConfigurationManager.getInstance() | 
 | 1326 |                             .getPhoneStatusFromModem(request.phone, onCompleted); | 
 | 1327 |                     break; | 
 | 1328 |                 case EVENT_GET_MODEM_STATUS_DONE: | 
 | 1329 |                     ar = (AsyncResult) msg.obj; | 
 | 1330 |                     request = (MainThreadRequest) ar.userObj; | 
 | 1331 |                     int id = request.phone.getPhoneId(); | 
 | 1332 |                     if (ar.exception == null && ar.result != null) { | 
 | 1333 |                         request.result = ar.result; | 
 | 1334 |                         //update the cache as modem status has changed | 
 | 1335 |                         mPhoneConfigurationManager.addToPhoneStatusCache(id, | 
 | 1336 |                                 (boolean) request.result); | 
 | 1337 |                     } else { | 
 | 1338 |                         // Return true if modem status cannot be retrieved. For most cases, | 
 | 1339 |                         // modem status is on. And for older version modems, GET_MODEM_STATUS | 
 | 1340 |                         // and disable modem are not supported. Modem is always on. | 
 | 1341 |                         // TODO: this should be fixed in R to support a third | 
 | 1342 |                         // status UNKNOWN b/131631629 | 
 | 1343 |                         request.result = true; | 
 | 1344 |                         Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." | 
 | 1345 |                                 + ar.exception); | 
 | 1346 |                     } | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1347 |                     notifyRequester(request); | 
 | 1348 |                     break; | 
| Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1349 |                 case CMD_SET_SYSTEM_SELECTION_CHANNELS: { | 
 | 1350 |                     request = (MainThreadRequest) msg.obj; | 
 | 1351 |                     onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); | 
 | 1352 |                     Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = | 
 | 1353 |                             (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; | 
 | 1354 |                     request.phone.setSystemSelectionChannels(args.first, onCompleted); | 
 | 1355 |                     break; | 
 | 1356 |                 } | 
 | 1357 |                 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { | 
 | 1358 |                     ar = (AsyncResult) msg.obj; | 
 | 1359 |                     request = (MainThreadRequest) ar.userObj; | 
 | 1360 |                     Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = | 
 | 1361 |                             (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; | 
 | 1362 |                     args.second.accept(ar.exception == null); | 
 | 1363 |                     notifyRequester(request); | 
 | 1364 |                     break; | 
 | 1365 |                 } | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1366 |                 case EVENT_SET_FORBIDDEN_PLMNS_DONE: | 
 | 1367 |                     ar = (AsyncResult) msg.obj; | 
 | 1368 |                     request = (MainThreadRequest) ar.userObj; | 
 | 1369 |                     if (ar.exception == null && ar.result != null) { | 
 | 1370 |                         request.result = ar.result; | 
 | 1371 |                     } else { | 
 | 1372 |                         request.result = -1; | 
 | 1373 |                         loge("Failed to set Forbidden Plmns"); | 
 | 1374 |                         if (ar.result == null) { | 
 | 1375 |                             loge("setForbidenPlmns: Empty response"); | 
 | 1376 |                         } else if (ar.exception != null) { | 
 | 1377 |                             loge("setForbiddenPlmns: Exception: " + ar.exception); | 
 | 1378 |                             request.result = -1; | 
 | 1379 |                         } else { | 
 | 1380 |                             loge("setForbiddenPlmns: Unknown exception"); | 
 | 1381 |                         } | 
 | 1382 |                     } | 
 | 1383 |                     notifyRequester(request); | 
 | 1384 |                     break; | 
 | 1385 |                 case CMD_SET_FORBIDDEN_PLMNS: | 
 | 1386 |                     request = (MainThreadRequest) msg.obj; | 
 | 1387 |                     uiccCard = getUiccCardFromRequest(request); | 
 | 1388 |                     if (uiccCard == null) { | 
 | 1389 |                         loge("setForbiddenPlmns: UiccCard is null"); | 
 | 1390 |                         request.result = -1; | 
 | 1391 |                         notifyRequester(request); | 
 | 1392 |                         break; | 
 | 1393 |                     } | 
 | 1394 |                     Pair<Integer, List<String>> setFplmnsArgs = | 
 | 1395 |                             (Pair<Integer, List<String>>) request.argument; | 
 | 1396 |                     appType = setFplmnsArgs.first; | 
 | 1397 |                     List<String> fplmns = setFplmnsArgs.second; | 
 | 1398 |                     uiccApp = uiccCard.getApplicationByType(appType); | 
 | 1399 |                     if (uiccApp == null) { | 
 | 1400 |                         loge("setForbiddenPlmns: no app with specified type -- " + appType); | 
 | 1401 |                         request.result = -1; | 
 | 1402 |                         loge("Failed to get UICC App"); | 
 | 1403 |                         notifyRequester(request); | 
 | 1404 |                     } else { | 
 | 1405 |                         onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); | 
 | 1406 |                         ((SIMRecords) uiccApp.getIccRecords()) | 
 | 1407 |                                 .setForbiddenPlmns(onCompleted, fplmns); | 
 | 1408 |                     } | 
| yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1409 |                     break; | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1410 |                 case CMD_ERASE_MODEM_CONFIG: | 
 | 1411 |                     request = (MainThreadRequest) msg.obj; | 
 | 1412 |                     onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); | 
 | 1413 |                     defaultPhone.eraseModemConfig(onCompleted); | 
 | 1414 |                     break; | 
 | 1415 |                 case EVENT_ERASE_MODEM_CONFIG_DONE: | 
 | 1416 |                     handleNullReturnEvent(msg, "eraseModemConfig"); | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1417 |                     break; | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1418 |  | 
 | 1419 |                 case CMD_CHANGE_ICC_LOCK_PASSWORD: | 
 | 1420 |                     request = (MainThreadRequest) msg.obj; | 
 | 1421 |                     onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); | 
 | 1422 |                     Pair<String, String> changed = (Pair<String, String>) request.argument; | 
 | 1423 |                     getPhoneFromRequest(request).getIccCard().changeIccLockPassword( | 
 | 1424 |                             changed.first, changed.second, onCompleted); | 
 | 1425 |                     break; | 
 | 1426 |                 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: | 
 | 1427 |                     ar = (AsyncResult) msg.obj; | 
 | 1428 |                     request = (MainThreadRequest) ar.userObj; | 
 | 1429 |                     if (ar.exception == null) { | 
 | 1430 |                         request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; | 
 | 1431 |                     } else { | 
 | 1432 |                         request.result = msg.arg1; | 
 | 1433 |                     } | 
 | 1434 |                     notifyRequester(request); | 
 | 1435 |                     break; | 
 | 1436 |  | 
 | 1437 |                 case CMD_SET_ICC_LOCK_ENABLED: | 
 | 1438 |                     request = (MainThreadRequest) msg.obj; | 
 | 1439 |                     onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); | 
 | 1440 |                     Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; | 
 | 1441 |                     getPhoneFromRequest(request).getIccCard().setIccLockEnabled( | 
 | 1442 |                             enabled.first, enabled.second, onCompleted); | 
 | 1443 |                     break; | 
 | 1444 |                 case EVENT_SET_ICC_LOCK_ENABLED_DONE: | 
 | 1445 |                     ar = (AsyncResult) msg.obj; | 
 | 1446 |                     request = (MainThreadRequest) ar.userObj; | 
 | 1447 |                     if (ar.exception == null) { | 
 | 1448 |                         request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; | 
 | 1449 |                     } else { | 
 | 1450 |                         request.result = msg.arg1; | 
 | 1451 |                     } | 
 | 1452 |                     notifyRequester(request); | 
 | 1453 |                     break; | 
 | 1454 |  | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1455 |                 case MSG_NOTIFY_USER_ACTIVITY: | 
 | 1456 |                     removeMessages(MSG_NOTIFY_USER_ACTIVITY); | 
| Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1457 |                     Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1458 |                     intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); | 
 | 1459 |                     getDefaultPhone().getContext().sendBroadcastAsUser( | 
 | 1460 |                             intent, UserHandle.ALL, permission.USER_ACTIVITY); | 
 | 1461 |                     break; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1462 |                 default: | 
 | 1463 |                     Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); | 
 | 1464 |                     break; | 
 | 1465 |             } | 
 | 1466 |         } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1467 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1468 |         private void notifyRequester(MainThreadRequest request) { | 
 | 1469 |             synchronized (request) { | 
 | 1470 |                 request.notifyAll(); | 
 | 1471 |             } | 
 | 1472 |         } | 
 | 1473 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1474 |         private void handleNullReturnEvent(Message msg, String command) { | 
 | 1475 |             AsyncResult ar = (AsyncResult) msg.obj; | 
 | 1476 |             MainThreadRequest request = (MainThreadRequest) ar.userObj; | 
 | 1477 |             if (ar.exception == null) { | 
 | 1478 |                 request.result = true; | 
 | 1479 |             } else { | 
 | 1480 |                 request.result = false; | 
 | 1481 |                 if (ar.exception instanceof CommandException) { | 
 | 1482 |                     loge(command + ": CommandException: " + ar.exception); | 
 | 1483 |                 } else { | 
 | 1484 |                     loge(command + ": Unknown exception"); | 
 | 1485 |                 } | 
 | 1486 |             } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1487 |             notifyRequester(request); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1488 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1489 |     } | 
 | 1490 |  | 
 | 1491 |     /** | 
 | 1492 |      * Posts the specified command to be executed on the main thread, | 
 | 1493 |      * waits for the request to complete, and returns the result. | 
 | 1494 |      * @see #sendRequestAsync | 
 | 1495 |      */ | 
 | 1496 |     private Object sendRequest(int command, Object argument) { | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1497 |         return sendRequest( | 
 | 1498 |                 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1499 |     } | 
 | 1500 |  | 
 | 1501 |     /** | 
 | 1502 |      * Posts the specified command to be executed on the main thread, | 
 | 1503 |      * waits for the request to complete, and returns the result. | 
 | 1504 |      * @see #sendRequestAsync | 
 | 1505 |      */ | 
 | 1506 |     private Object sendRequest(int command, Object argument, WorkSource workSource) { | 
 | 1507 |         return sendRequest(command, argument,  SubscriptionManager.INVALID_SUBSCRIPTION_ID, | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1508 |                 null, workSource); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1509 |     } | 
 | 1510 |  | 
 | 1511 |     /** | 
 | 1512 |      * Posts the specified command to be executed on the main thread, | 
 | 1513 |      * waits for the request to complete, and returns the result. | 
 | 1514 |      * @see #sendRequestAsync | 
 | 1515 |      */ | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1516 |     private Object sendRequest(int command, Object argument, Integer subId) { | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1517 |         return sendRequest(command, argument, subId, null, null); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1518 |     } | 
 | 1519 |  | 
 | 1520 |     /** | 
 | 1521 |      * Posts the specified command to be executed on the main thread, | 
 | 1522 |      * waits for the request to complete, and returns the result. | 
 | 1523 |      * @see #sendRequestAsync | 
 | 1524 |      */ | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1525 |     private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { | 
 | 1526 |         return sendRequest(command, argument, subId, null, workSource); | 
 | 1527 |     } | 
 | 1528 |  | 
 | 1529 |     /** | 
 | 1530 |      * Posts the specified command to be executed on the main thread, | 
 | 1531 |      * waits for the request to complete, and returns the result. | 
 | 1532 |      * @see #sendRequestAsync | 
 | 1533 |      */ | 
 | 1534 |     private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { | 
 | 1535 |         return sendRequest( | 
 | 1536 |                 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); | 
 | 1537 |     } | 
 | 1538 |  | 
 | 1539 |     /** | 
 | 1540 |      * Posts the specified command to be executed on the main thread, | 
 | 1541 |      * waits for the request to complete, and returns the result. | 
 | 1542 |      * @see #sendRequestAsync | 
 | 1543 |      */ | 
 | 1544 |     private Object sendRequest( | 
 | 1545 |             int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1546 |         if (Looper.myLooper() == mMainThreadHandler.getLooper()) { | 
 | 1547 |             throw new RuntimeException("This method will deadlock if called from the main thread."); | 
 | 1548 |         } | 
 | 1549 |  | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1550 |         MainThreadRequest request = null; | 
 | 1551 |         if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { | 
 | 1552 |             throw new IllegalArgumentException("subId and phone cannot both be specified!"); | 
 | 1553 |         } else if (phone != null) { | 
 | 1554 |             request = new MainThreadRequest(argument, phone, workSource); | 
 | 1555 |         } else { | 
 | 1556 |             request = new MainThreadRequest(argument, subId, workSource); | 
 | 1557 |         } | 
 | 1558 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1559 |         Message msg = mMainThreadHandler.obtainMessage(command, request); | 
 | 1560 |         msg.sendToTarget(); | 
 | 1561 |  | 
 | 1562 |         // Wait for the request to complete | 
 | 1563 |         synchronized (request) { | 
 | 1564 |             while (request.result == null) { | 
 | 1565 |                 try { | 
 | 1566 |                     request.wait(); | 
 | 1567 |                 } catch (InterruptedException e) { | 
 | 1568 |                     // Do nothing, go back and wait until the request is complete | 
 | 1569 |                 } | 
 | 1570 |             } | 
 | 1571 |         } | 
 | 1572 |         return request.result; | 
 | 1573 |     } | 
 | 1574 |  | 
 | 1575 |     /** | 
 | 1576 |      * Asynchronous ("fire and forget") version of sendRequest(): | 
 | 1577 |      * Posts the specified command to be executed on the main thread, and | 
 | 1578 |      * returns immediately. | 
 | 1579 |      * @see #sendRequest | 
 | 1580 |      */ | 
 | 1581 |     private void sendRequestAsync(int command) { | 
 | 1582 |         mMainThreadHandler.sendEmptyMessage(command); | 
 | 1583 |     } | 
 | 1584 |  | 
 | 1585 |     /** | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1586 |      * Same as {@link #sendRequestAsync(int)} except it takes an argument. | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1587 |      * @see {@link #sendRequest(int)} | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1588 |      */ | 
 | 1589 |     private void sendRequestAsync(int command, Object argument) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1590 |         sendRequestAsync(command, argument, null, null); | 
 | 1591 |     } | 
 | 1592 |  | 
 | 1593 |     /** | 
 | 1594 |      * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. | 
 | 1595 |      * @see {@link #sendRequest(int,Object)} | 
 | 1596 |      */ | 
 | 1597 |     private void sendRequestAsync( | 
 | 1598 |             int command, Object argument, Phone phone, WorkSource workSource) { | 
 | 1599 |         MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1600 |         Message msg = mMainThreadHandler.obtainMessage(command, request); | 
 | 1601 |         msg.sendToTarget(); | 
 | 1602 |     } | 
 | 1603 |  | 
 | 1604 |     /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1605 |      * Initialize the singleton PhoneInterfaceManager instance. | 
 | 1606 |      * This is only done once, at startup, from PhoneApp.onCreate(). | 
 | 1607 |      */ | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1608 |     /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1609 |         synchronized (PhoneInterfaceManager.class) { | 
 | 1610 |             if (sInstance == null) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1611 |                 sInstance = new PhoneInterfaceManager(app); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1612 |             } else { | 
 | 1613 |                 Log.wtf(LOG_TAG, "init() called multiple times!  sInstance = " + sInstance); | 
 | 1614 |             } | 
 | 1615 |             return sInstance; | 
 | 1616 |         } | 
 | 1617 |     } | 
 | 1618 |  | 
 | 1619 |     /** Private constructor; @see init() */ | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1620 |     private PhoneInterfaceManager(PhoneGlobals app) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1621 |         mApp = app; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1622 |         mCM = PhoneGlobals.getInstance().mCM; | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1623 |         mImsResolver = PhoneGlobals.getInstance().getImsResolver(); | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1624 |         mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1625 |         mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); | 
 | 1626 |         mMainThreadHandler = new MainThreadHandler(); | 
| Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1627 |         mSubscriptionController = SubscriptionController.getInstance(); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1628 |         mTelephonySharedPreferences = | 
 | 1629 |                 PreferenceManager.getDefaultSharedPreferences(mApp); | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1630 |         mNetworkScanRequestTracker = new NetworkScanRequestTracker(); | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1631 |         mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); | 
| Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 1632 |         mNotifyUserActivity = new AtomicBoolean(false); | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1633 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1634 |         publish(); | 
 | 1635 |     } | 
 | 1636 |  | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1637 |     private Phone getDefaultPhone() { | 
 | 1638 |         Phone thePhone = getPhone(getDefaultSubscription()); | 
 | 1639 |         return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); | 
 | 1640 |     } | 
 | 1641 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1642 |     private void publish() { | 
 | 1643 |         if (DBG) log("publish: " + this); | 
 | 1644 |  | 
| Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1645 |         TelephonyFrameworkInitializer | 
 | 1646 |                 .getTelephonyServiceManager() | 
 | 1647 |                 .getTelephonyServiceRegisterer() | 
 | 1648 |                 .register(this); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1649 |     } | 
 | 1650 |  | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1651 |     private Phone getPhoneFromRequest(MainThreadRequest request) { | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1652 |         if (request.phone != null) { | 
 | 1653 |             return request.phone; | 
 | 1654 |         } else { | 
 | 1655 |             return getPhoneFromSubId(request.subId); | 
 | 1656 |         } | 
 | 1657 |     } | 
 | 1658 |  | 
 | 1659 |     private Phone getPhoneFromSubId(int subId) { | 
 | 1660 |         return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) | 
 | 1661 |                 ? getDefaultPhone() : getPhone(subId); | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1662 |     } | 
 | 1663 |  | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1664 |     private UiccCard getUiccCardFromRequest(MainThreadRequest request) { | 
 | 1665 |         Phone phone = getPhoneFromRequest(request); | 
 | 1666 |         return phone == null ? null : | 
 | 1667 |                 UiccController.getInstance().getUiccCard(phone.getPhoneId()); | 
 | 1668 |     } | 
 | 1669 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1670 |     // returns phone associated with the subId. | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1671 |     private Phone getPhone(int subId) { | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1672 |         return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1673 |     } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1674 |  | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1675 |     private void sendEraseModemConfig(Phone phone) { | 
 | 1676 |         if (phone != null) { | 
 | 1677 |             TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 1678 |                   mApp, phone.getSubId(), "eraseModemConfig"); | 
 | 1679 |             final long identity = Binder.clearCallingIdentity(); | 
 | 1680 |             try { | 
 | 1681 |                 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); | 
 | 1682 |                 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); | 
 | 1683 |             } finally { | 
 | 1684 |                 Binder.restoreCallingIdentity(identity); | 
 | 1685 |             } | 
 | 1686 |         } | 
 | 1687 |     } | 
 | 1688 |  | 
| Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1689 |     private boolean isImsAvailableOnDevice() { | 
 | 1690 |         PackageManager pm = getDefaultPhone().getContext().getPackageManager(); | 
 | 1691 |         if (pm == null) { | 
 | 1692 |             // For some reason package manger is not available.. This will fail internally anyway, | 
 | 1693 |             // so do not throw error and allow. | 
 | 1694 |             return true; | 
 | 1695 |         } | 
 | 1696 |         return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); | 
 | 1697 |     } | 
 | 1698 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1699 |     public void dial(String number) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1700 |         dialForSubscriber(getPreferredVoiceSubscription(), number); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1701 |     } | 
 | 1702 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1703 |     public void dialForSubscriber(int subId, String number) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1704 |         if (DBG) log("dial: " + number); | 
 | 1705 |         // No permission check needed here: This is just a wrapper around the | 
 | 1706 |         // ACTION_DIAL intent, which is available to any app since it puts up | 
 | 1707 |         // the UI before it does anything. | 
 | 1708 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1709 |         final long identity = Binder.clearCallingIdentity(); | 
 | 1710 |         try { | 
 | 1711 |             String url = createTelUrl(number); | 
 | 1712 |             if (url == null) { | 
 | 1713 |                 return; | 
 | 1714 |             } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1715 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1716 |             // PENDING: should we just silently fail if phone is offhook or ringing? | 
 | 1717 |             PhoneConstants.State state = mCM.getState(subId); | 
 | 1718 |             if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { | 
 | 1719 |                 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); | 
 | 1720 |                 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 
 | 1721 |                 mApp.startActivity(intent); | 
 | 1722 |             } | 
 | 1723 |         } finally { | 
 | 1724 |             Binder.restoreCallingIdentity(identity); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1725 |         } | 
 | 1726 |     } | 
 | 1727 |  | 
 | 1728 |     public void call(String callingPackage, String number) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1729 |         callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1730 |     } | 
 | 1731 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1732 |     public void callForSubscriber(int subId, String callingPackage, String number) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1733 |         if (DBG) log("call: " + number); | 
 | 1734 |  | 
 | 1735 |         // This is just a wrapper around the ACTION_CALL intent, but we still | 
 | 1736 |         // need to do a permission check since we're calling startActivity() | 
 | 1737 |         // from the context of the phone app. | 
 | 1738 |         enforceCallPermission(); | 
 | 1739 |  | 
| Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1740 |         if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1741 |                 != AppOpsManager.MODE_ALLOWED) { | 
 | 1742 |             return; | 
 | 1743 |         } | 
 | 1744 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1745 |         final long identity = Binder.clearCallingIdentity(); | 
 | 1746 |         try { | 
 | 1747 |             String url = createTelUrl(number); | 
 | 1748 |             if (url == null) { | 
 | 1749 |                 return; | 
 | 1750 |             } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1751 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1752 |             boolean isValid = false; | 
 | 1753 |             final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); | 
 | 1754 |             if (slist != null) { | 
 | 1755 |                 for (SubscriptionInfo subInfoRecord : slist) { | 
 | 1756 |                     if (subInfoRecord.getSubscriptionId() == subId) { | 
 | 1757 |                         isValid = true; | 
 | 1758 |                         break; | 
 | 1759 |                     } | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1760 |                 } | 
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1761 |             } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1762 |             if (!isValid) { | 
 | 1763 |                 return; | 
 | 1764 |             } | 
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1765 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1766 |             Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); | 
 | 1767 |             intent.putExtra(SUBSCRIPTION_KEY, subId); | 
 | 1768 |             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 
 | 1769 |             mApp.startActivity(intent); | 
 | 1770 |         } finally { | 
 | 1771 |             Binder.restoreCallingIdentity(identity); | 
 | 1772 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1773 |     } | 
 | 1774 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1775 |     public boolean supplyPinForSubscriber(int subId, String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1776 |         int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1777 |         return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; | 
 | 1778 |     } | 
 | 1779 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1780 |     public boolean supplyPukForSubscriber(int subId, String puk, String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1781 |         int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1782 |         return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; | 
 | 1783 |     } | 
 | 1784 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1785 |     public int[] supplyPinReportResultForSubscriber(int subId, String pin) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1786 |         enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1787 |  | 
 | 1788 |         final long identity = Binder.clearCallingIdentity(); | 
 | 1789 |         try { | 
 | 1790 |             final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); | 
 | 1791 |             checkSimPin.start(); | 
 | 1792 |             return checkSimPin.unlockSim(null, pin); | 
 | 1793 |         } finally { | 
 | 1794 |             Binder.restoreCallingIdentity(identity); | 
 | 1795 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1796 |     } | 
 | 1797 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1798 |     public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1799 |         enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1800 |  | 
 | 1801 |         final long identity = Binder.clearCallingIdentity(); | 
 | 1802 |         try { | 
 | 1803 |             final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); | 
 | 1804 |             checkSimPuk.start(); | 
 | 1805 |             return checkSimPuk.unlockSim(puk, pin); | 
 | 1806 |         } finally { | 
 | 1807 |             Binder.restoreCallingIdentity(identity); | 
 | 1808 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1809 |     } | 
 | 1810 |  | 
 | 1811 |     /** | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1812 |      * Helper thread to turn async call to SimCard#supplyPin into | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1813 |      * a synchronous one. | 
 | 1814 |      */ | 
 | 1815 |     private static class UnlockSim extends Thread { | 
 | 1816 |  | 
 | 1817 |         private final IccCard mSimCard; | 
 | 1818 |  | 
 | 1819 |         private boolean mDone = false; | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1820 |         private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; | 
 | 1821 |         private int mRetryCount = -1; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1822 |  | 
 | 1823 |         // For replies from SimCard interface | 
 | 1824 |         private Handler mHandler; | 
 | 1825 |  | 
 | 1826 |         // For async handler to identify request type | 
 | 1827 |         private static final int SUPPLY_PIN_COMPLETE = 100; | 
 | 1828 |  | 
 | 1829 |         public UnlockSim(IccCard simCard) { | 
 | 1830 |             mSimCard = simCard; | 
 | 1831 |         } | 
 | 1832 |  | 
 | 1833 |         @Override | 
 | 1834 |         public void run() { | 
 | 1835 |             Looper.prepare(); | 
 | 1836 |             synchronized (UnlockSim.this) { | 
 | 1837 |                 mHandler = new Handler() { | 
 | 1838 |                     @Override | 
 | 1839 |                     public void handleMessage(Message msg) { | 
 | 1840 |                         AsyncResult ar = (AsyncResult) msg.obj; | 
 | 1841 |                         switch (msg.what) { | 
 | 1842 |                             case SUPPLY_PIN_COMPLETE: | 
 | 1843 |                                 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); | 
 | 1844 |                                 synchronized (UnlockSim.this) { | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1845 |                                     mRetryCount = msg.arg1; | 
 | 1846 |                                     if (ar.exception != null) { | 
 | 1847 |                                         if (ar.exception instanceof CommandException && | 
 | 1848 |                                                 ((CommandException)(ar.exception)).getCommandError() | 
 | 1849 |                                                 == CommandException.Error.PASSWORD_INCORRECT) { | 
 | 1850 |                                             mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; | 
 | 1851 |                                         } else { | 
 | 1852 |                                             mResult = PhoneConstants.PIN_GENERAL_FAILURE; | 
 | 1853 |                                         } | 
 | 1854 |                                     } else { | 
 | 1855 |                                         mResult = PhoneConstants.PIN_RESULT_SUCCESS; | 
 | 1856 |                                     } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1857 |                                     mDone = true; | 
 | 1858 |                                     UnlockSim.this.notifyAll(); | 
 | 1859 |                                 } | 
 | 1860 |                                 break; | 
 | 1861 |                         } | 
 | 1862 |                     } | 
 | 1863 |                 }; | 
 | 1864 |                 UnlockSim.this.notifyAll(); | 
 | 1865 |             } | 
 | 1866 |             Looper.loop(); | 
 | 1867 |         } | 
 | 1868 |  | 
 | 1869 |         /* | 
 | 1870 |          * Use PIN or PUK to unlock SIM card | 
 | 1871 |          * | 
 | 1872 |          * If PUK is null, unlock SIM card with PIN | 
 | 1873 |          * | 
 | 1874 |          * If PUK is not null, unlock SIM card with PUK and set PIN code | 
 | 1875 |          */ | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1876 |         synchronized int[] unlockSim(String puk, String pin) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1877 |  | 
 | 1878 |             while (mHandler == null) { | 
 | 1879 |                 try { | 
 | 1880 |                     wait(); | 
 | 1881 |                 } catch (InterruptedException e) { | 
 | 1882 |                     Thread.currentThread().interrupt(); | 
 | 1883 |                 } | 
 | 1884 |             } | 
 | 1885 |             Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); | 
 | 1886 |  | 
 | 1887 |             if (puk == null) { | 
 | 1888 |                 mSimCard.supplyPin(pin, callback); | 
 | 1889 |             } else { | 
 | 1890 |                 mSimCard.supplyPuk(puk, pin, callback); | 
 | 1891 |             } | 
 | 1892 |  | 
 | 1893 |             while (!mDone) { | 
 | 1894 |                 try { | 
 | 1895 |                     Log.d(LOG_TAG, "wait for done"); | 
 | 1896 |                     wait(); | 
 | 1897 |                 } catch (InterruptedException e) { | 
 | 1898 |                     // Restore the interrupted status | 
 | 1899 |                     Thread.currentThread().interrupt(); | 
 | 1900 |                 } | 
 | 1901 |             } | 
 | 1902 |             Log.d(LOG_TAG, "done"); | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1903 |             int[] resultArray = new int[2]; | 
 | 1904 |             resultArray[0] = mResult; | 
 | 1905 |             resultArray[1] = mRetryCount; | 
 | 1906 |             return resultArray; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1907 |         } | 
 | 1908 |     } | 
 | 1909 |  | 
 | 1910 |     public void updateServiceLocation() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1911 |         updateServiceLocationForSubscriber(getDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1912 |  | 
 | 1913 |     } | 
 | 1914 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1915 |     public void updateServiceLocationForSubscriber(int subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1916 |         // No permission check needed here: this call is harmless, and it's | 
 | 1917 |         // needed for the ServiceState.requestStateUpdate() call (which is | 
 | 1918 |         // already intentionally exposed to 3rd parties.) | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1919 |         final long identity = Binder.clearCallingIdentity(); | 
 | 1920 |         try { | 
 | 1921 |             final Phone phone = getPhone(subId); | 
 | 1922 |             if (phone != null) { | 
 | 1923 |                 phone.updateServiceLocation(); | 
 | 1924 |             } | 
 | 1925 |         } finally { | 
 | 1926 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1927 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1928 |     } | 
 | 1929 |  | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1930 |     @Deprecated | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1931 |     @Override | 
 | 1932 |     public boolean isRadioOn(String callingPackage) { | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1933 |         return isRadioOnWithFeature(callingPackage, null); | 
 | 1934 |     } | 
 | 1935 |  | 
 | 1936 |  | 
 | 1937 |     @Override | 
 | 1938 |     public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { | 
 | 1939 |         return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, | 
 | 1940 |                 callingFeatureId); | 
 | 1941 |     } | 
 | 1942 |  | 
 | 1943 |     @Deprecated | 
 | 1944 |     @Override | 
 | 1945 |     public boolean isRadioOnForSubscriber(int subId, String callingPackage) { | 
 | 1946 |         return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1947 |     } | 
 | 1948 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1949 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1950 |     public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, | 
 | 1951 |             String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1952 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1953 |                 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1954 |             return false; | 
 | 1955 |         } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1956 |  | 
 | 1957 |         final long identity = Binder.clearCallingIdentity(); | 
 | 1958 |         try { | 
 | 1959 |             return isRadioOnForSubscriber(subId); | 
 | 1960 |         } finally { | 
 | 1961 |             Binder.restoreCallingIdentity(identity); | 
 | 1962 |         } | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1963 |     } | 
 | 1964 |  | 
 | 1965 |     private boolean isRadioOnForSubscriber(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1966 |         final long identity = Binder.clearCallingIdentity(); | 
 | 1967 |         try { | 
 | 1968 |             final Phone phone = getPhone(subId); | 
 | 1969 |             if (phone != null) { | 
 | 1970 |                 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; | 
 | 1971 |             } else { | 
 | 1972 |                 return false; | 
 | 1973 |             } | 
 | 1974 |         } finally { | 
 | 1975 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1976 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1977 |     } | 
 | 1978 |  | 
 | 1979 |     public void toggleRadioOnOff() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1980 |         toggleRadioOnOffForSubscriber(getDefaultSubscription()); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1981 |     } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1982 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1983 |     public void toggleRadioOnOffForSubscriber(int subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1984 |         enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1985 |  | 
 | 1986 |         final long identity = Binder.clearCallingIdentity(); | 
 | 1987 |         try { | 
 | 1988 |             final Phone phone = getPhone(subId); | 
 | 1989 |             if (phone != null) { | 
 | 1990 |                 phone.setRadioPower(!isRadioOnForSubscriber(subId)); | 
 | 1991 |             } | 
 | 1992 |         } finally { | 
 | 1993 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1994 |         } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1995 |     } | 
 | 1996 |  | 
 | 1997 |     public boolean setRadio(boolean turnOn) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1998 |         return setRadioForSubscriber(getDefaultSubscription(), turnOn); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1999 |     } | 
 | 2000 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2001 |     public boolean setRadioForSubscriber(int subId, boolean turnOn) { | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2002 |         enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2003 |  | 
 | 2004 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2005 |         try { | 
 | 2006 |             final Phone phone = getPhone(subId); | 
 | 2007 |             if (phone == null) { | 
 | 2008 |                 return false; | 
 | 2009 |             } | 
 | 2010 |             if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { | 
 | 2011 |                 toggleRadioOnOffForSubscriber(subId); | 
 | 2012 |             } | 
 | 2013 |             return true; | 
 | 2014 |         } finally { | 
 | 2015 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2016 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2017 |     } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2018 |  | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2019 |     public boolean needMobileRadioShutdown() { | 
| Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2020 |         enforceReadPrivilegedPermission("needMobileRadioShutdown"); | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2021 |         /* | 
 | 2022 |          * If any of the Radios are available, it will need to be | 
 | 2023 |          * shutdown. So return true if any Radio is available. | 
 | 2024 |          */ | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2025 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2026 |         try { | 
 | 2027 |             for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
 | 2028 |                 Phone phone = PhoneFactory.getPhone(i); | 
 | 2029 |                 if (phone != null && phone.isRadioAvailable()) return true; | 
 | 2030 |             } | 
 | 2031 |             logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); | 
 | 2032 |             return false; | 
 | 2033 |         } finally { | 
 | 2034 |             Binder.restoreCallingIdentity(identity); | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2035 |         } | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2036 |     } | 
 | 2037 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2038 |     @Override | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2039 |     public void shutdownMobileRadios() { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2040 |         enforceModifyPermission(); | 
 | 2041 |  | 
 | 2042 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2043 |         try { | 
 | 2044 |             for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
 | 2045 |                 logv("Shutting down Phone " + i); | 
 | 2046 |                 shutdownRadioUsingPhoneId(i); | 
 | 2047 |             } | 
 | 2048 |         } finally { | 
 | 2049 |             Binder.restoreCallingIdentity(identity); | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2050 |         } | 
 | 2051 |     } | 
 | 2052 |  | 
 | 2053 |     private void shutdownRadioUsingPhoneId(int phoneId) { | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2054 |         Phone phone = PhoneFactory.getPhone(phoneId); | 
 | 2055 |         if (phone != null && phone.isRadioAvailable()) { | 
 | 2056 |             phone.shutdownRadio(); | 
 | 2057 |         } | 
 | 2058 |     } | 
 | 2059 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2060 |     public boolean setRadioPower(boolean turnOn) { | 
| Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2061 |         enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2062 |  | 
 | 2063 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2064 |         try { | 
 | 2065 |             final Phone defaultPhone = PhoneFactory.getDefaultPhone(); | 
 | 2066 |             if (defaultPhone != null) { | 
 | 2067 |                 defaultPhone.setRadioPower(turnOn); | 
 | 2068 |                 return true; | 
 | 2069 |             } else { | 
 | 2070 |                 loge("There's no default phone."); | 
 | 2071 |                 return false; | 
 | 2072 |             } | 
 | 2073 |         } finally { | 
 | 2074 |             Binder.restoreCallingIdentity(identity); | 
| Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2075 |         } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2076 |     } | 
 | 2077 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2078 |     public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2079 |         enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2080 |  | 
 | 2081 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2082 |         try { | 
 | 2083 |             final Phone phone = getPhone(subId); | 
 | 2084 |             if (phone != null) { | 
 | 2085 |                 phone.setRadioPower(turnOn); | 
 | 2086 |                 return true; | 
 | 2087 |             } else { | 
 | 2088 |                 return false; | 
 | 2089 |             } | 
 | 2090 |         } finally { | 
 | 2091 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2092 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2093 |     } | 
 | 2094 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2095 |     // FIXME: subId version needed | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2096 |     @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2097 |     public boolean enableDataConnectivity() { | 
 | 2098 |         enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2099 |  | 
 | 2100 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2101 |         try { | 
 | 2102 |             int subId = mSubscriptionController.getDefaultDataSubId(); | 
 | 2103 |             final Phone phone = getPhone(subId); | 
 | 2104 |             if (phone != null) { | 
| Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2105 |                 phone.getDataEnabledSettings().setUserDataEnabled(true); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2106 |                 return true; | 
 | 2107 |             } else { | 
 | 2108 |                 return false; | 
 | 2109 |             } | 
 | 2110 |         } finally { | 
 | 2111 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2112 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2113 |     } | 
 | 2114 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2115 |     // FIXME: subId version needed | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2116 |     @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2117 |     public boolean disableDataConnectivity() { | 
 | 2118 |         enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2119 |  | 
 | 2120 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2121 |         try { | 
 | 2122 |             int subId = mSubscriptionController.getDefaultDataSubId(); | 
 | 2123 |             final Phone phone = getPhone(subId); | 
 | 2124 |             if (phone != null) { | 
| Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2125 |                 phone.getDataEnabledSettings().setUserDataEnabled(false); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2126 |                 return true; | 
 | 2127 |             } else { | 
 | 2128 |                 return false; | 
 | 2129 |             } | 
 | 2130 |         } finally { | 
 | 2131 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2132 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2133 |     } | 
 | 2134 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2135 |     @Override | 
| Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2136 |     public boolean isDataConnectivityPossible(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2137 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2138 |         try { | 
 | 2139 |             final Phone phone = getPhone(subId); | 
 | 2140 |             if (phone != null) { | 
| Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2141 |                 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2142 |             } else { | 
 | 2143 |                 return false; | 
 | 2144 |             } | 
 | 2145 |         } finally { | 
 | 2146 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2147 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2148 |     } | 
 | 2149 |  | 
 | 2150 |     public boolean handlePinMmi(String dialString) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2151 |         return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2152 |     } | 
 | 2153 |  | 
| pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2154 |     public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2155 |         enforceCallPermission(); | 
 | 2156 |  | 
 | 2157 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2158 |         try { | 
 | 2159 |             if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
 | 2160 |                 return; | 
 | 2161 |             } | 
 | 2162 |             Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); | 
 | 2163 |             sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); | 
 | 2164 |         } finally { | 
 | 2165 |             Binder.restoreCallingIdentity(identity); | 
 | 2166 |         } | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2167 |     }; | 
 | 2168 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2169 |     public boolean handlePinMmiForSubscriber(int subId, String dialString) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2170 |         enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2171 |  | 
 | 2172 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2173 |         try { | 
 | 2174 |             if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
 | 2175 |                 return false; | 
 | 2176 |             } | 
 | 2177 |             return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); | 
 | 2178 |         } finally { | 
 | 2179 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2180 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2181 |     } | 
 | 2182 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2183 |     public int getCallState() { | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2184 |         return getCallStateForSlot(getSlotForDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2185 |     } | 
 | 2186 |  | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2187 |     public int getCallStateForSlot(int slotIndex) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2188 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2189 |         try { | 
 | 2190 |             Phone phone = PhoneFactory.getPhone(slotIndex); | 
 | 2191 |             return phone == null ? TelephonyManager.CALL_STATE_IDLE : | 
 | 2192 |                     PhoneConstantConversions.convertCallState(phone.getState()); | 
 | 2193 |         } finally { | 
 | 2194 |             Binder.restoreCallingIdentity(identity); | 
 | 2195 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2196 |     } | 
 | 2197 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2198 |     @Override | 
| Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2199 |     public int getDataState() { | 
| Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2200 |         return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); | 
 | 2201 |     } | 
 | 2202 |  | 
 | 2203 |     @Override | 
 | 2204 |     public int getDataStateForSubId(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2205 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2206 |         try { | 
| Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2207 |             final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2208 |             if (phone != null) { | 
 | 2209 |                 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); | 
 | 2210 |             } else { | 
 | 2211 |                 return PhoneConstantConversions.convertDataState( | 
 | 2212 |                         PhoneConstants.DataState.DISCONNECTED); | 
 | 2213 |             } | 
 | 2214 |         } finally { | 
 | 2215 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2216 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2217 |     } | 
 | 2218 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2219 |     @Override | 
| Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2220 |     public int getDataActivity() { | 
| Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2221 |         return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); | 
 | 2222 |     } | 
 | 2223 |  | 
 | 2224 |     @Override | 
 | 2225 |     public int getDataActivityForSubId(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2226 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2227 |         try { | 
| Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2228 |             final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2229 |             if (phone != null) { | 
 | 2230 |                 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); | 
 | 2231 |             } else { | 
 | 2232 |                 return TelephonyManager.DATA_ACTIVITY_NONE; | 
 | 2233 |             } | 
 | 2234 |         } finally { | 
 | 2235 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2236 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2237 |     } | 
 | 2238 |  | 
 | 2239 |     @Override | 
| Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2240 |     public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2241 |         mApp.getSystemService(AppOpsManager.class) | 
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2242 |                 .checkPackage(Binder.getCallingUid(), callingPackage); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2243 |  | 
 | 2244 |         LocationAccessPolicy.LocationPermissionResult locationResult = | 
 | 2245 |                 LocationAccessPolicy.checkLocationPermission(mApp, | 
 | 2246 |                         new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
 | 2247 |                                 .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2248 |                                 .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2249 |                                 .setCallingPid(Binder.getCallingPid()) | 
 | 2250 |                                 .setCallingUid(Binder.getCallingUid()) | 
 | 2251 |                                 .setMethod("getCellLocation") | 
| Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2252 |                                 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2253 |                                 .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
 | 2254 |                                 .build()); | 
 | 2255 |         switch (locationResult) { | 
 | 2256 |             case DENIED_HARD: | 
 | 2257 |                 throw new SecurityException("Not allowed to access cell location"); | 
 | 2258 |             case DENIED_SOFT: | 
| Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2259 |                 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) | 
 | 2260 |                         ? new CellIdentityCdma() : new CellIdentityGsm(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2261 |         } | 
 | 2262 |  | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2263 |         WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2264 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2265 |         try { | 
 | 2266 |             if (DBG_LOC) log("getCellLocation: is active user"); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2267 |             int subId = mSubscriptionController.getDefaultDataSubId(); | 
| Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2268 |             return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2269 |         } finally { | 
 | 2270 |             Binder.restoreCallingIdentity(identity); | 
 | 2271 |         } | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2272 |     } | 
 | 2273 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2274 |     @Override | 
| Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2275 |     public String getNetworkCountryIsoForPhone(int phoneId) { | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2276 |         // Reporting the correct network country is ambiguous when IWLAN could conflict with | 
 | 2277 |         // registered cell info, so return a NULL country instead. | 
 | 2278 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2279 |         try { | 
| Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2280 |             if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { | 
 | 2281 |                 // Get default phone in this case. | 
 | 2282 |                 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; | 
 | 2283 |             } | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2284 |             final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); | 
| Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2285 |             // Todo: fix this when we can get the actual cellular network info when the device | 
 | 2286 |             // is on IWLAN. | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2287 |             if (TelephonyManager.NETWORK_TYPE_IWLAN | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2288 |                     == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(), | 
 | 2289 |                     mApp.getFeatureId())) { | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2290 |                 return ""; | 
 | 2291 |             } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2292 |             Phone phone = PhoneFactory.getPhone(phoneId); | 
 | 2293 |             if (phone != null) { | 
 | 2294 |                 ServiceStateTracker sst = phone.getServiceStateTracker(); | 
| sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2295 |                 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2296 |                 if (sst != null) { | 
 | 2297 |                     LocaleTracker lt = sst.getLocaleTracker(); | 
 | 2298 |                     if (lt != null) { | 
| sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2299 |                         if (!TextUtils.isEmpty(lt.getCurrentCountry())) { | 
 | 2300 |                             return lt.getCurrentCountry(); | 
 | 2301 |                         } else if (emergencyNumberTracker != null) { | 
 | 2302 |                             return emergencyNumberTracker.getEmergencyCountryIso(); | 
 | 2303 |                         } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2304 |                     } | 
 | 2305 |                 } | 
 | 2306 |             } | 
 | 2307 |             return ""; | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2308 |         } finally { | 
 | 2309 |             Binder.restoreCallingIdentity(identity); | 
 | 2310 |         } | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2311 |     } | 
 | 2312 |  | 
 | 2313 |     @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2314 |     public void enableLocationUpdates() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2315 |         enableLocationUpdatesForSubscriber(getDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2316 |     } | 
 | 2317 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2318 |     @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2319 |     public void enableLocationUpdatesForSubscriber(int subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2320 |         mApp.enforceCallingOrSelfPermission( | 
 | 2321 |                 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2322 |  | 
 | 2323 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2324 |         try { | 
 | 2325 |             final Phone phone = getPhone(subId); | 
 | 2326 |             if (phone != null) { | 
 | 2327 |                 phone.enableLocationUpdates(); | 
 | 2328 |             } | 
 | 2329 |         } finally { | 
 | 2330 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2331 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2332 |     } | 
 | 2333 |  | 
 | 2334 |     @Override | 
 | 2335 |     public void disableLocationUpdates() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2336 |         disableLocationUpdatesForSubscriber(getDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2337 |     } | 
 | 2338 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2339 |     @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2340 |     public void disableLocationUpdatesForSubscriber(int subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2341 |         mApp.enforceCallingOrSelfPermission( | 
 | 2342 |                 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2343 |  | 
 | 2344 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2345 |         try { | 
 | 2346 |             final Phone phone = getPhone(subId); | 
 | 2347 |             if (phone != null) { | 
 | 2348 |                 phone.disableLocationUpdates(); | 
 | 2349 |             } | 
 | 2350 |         } finally { | 
 | 2351 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2352 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2353 |     } | 
 | 2354 |  | 
| Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2355 |     /** | 
 | 2356 |      * Returns the target SDK version number for a given package name. | 
 | 2357 |      * | 
| Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2358 |      * This call MUST be invoked before clearing the calling UID. | 
 | 2359 |      * | 
| Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2360 |      * @return target SDK if the package is found or INT_MAX. | 
 | 2361 |      */ | 
 | 2362 |     private int getTargetSdk(String packageName) { | 
 | 2363 |         try { | 
| Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2364 |             final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( | 
| Chen Xu | 0150f0e | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2365 |                     packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); | 
| Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2366 |             if (ai != null) return ai.targetSdkVersion; | 
 | 2367 |         } catch (PackageManager.NameNotFoundException unexpected) { | 
| Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2368 |             loge("Failed to get package info for pkg=" | 
 | 2369 |                     + packageName + ", uid=" + Binder.getCallingUid()); | 
| Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2370 |         } | 
 | 2371 |         return Integer.MAX_VALUE; | 
 | 2372 |     } | 
 | 2373 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2374 |     @Override | 
 | 2375 |     @SuppressWarnings("unchecked") | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2376 |     public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, | 
 | 2377 |             String callingFeatureId) { | 
| Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2378 |         final int targetSdk = getTargetSdk(callingPackage); | 
| Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2379 |         if (targetSdk >= android.os.Build.VERSION_CODES.Q) { | 
 | 2380 |             throw new SecurityException( | 
 | 2381 |                     "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); | 
 | 2382 |         } | 
| Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2383 |  | 
| Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2384 |         if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2385 |                 callingPackage) != AppOpsManager.MODE_ALLOWED) { | 
 | 2386 |             return null; | 
 | 2387 |         } | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2388 |  | 
| Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2389 |         if (DBG_LOC) log("getNeighboringCellInfo: is active user"); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2390 |  | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2391 |         List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2392 |         if (info == null) return null; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2393 |  | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2394 |         List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); | 
 | 2395 |         for (CellInfo ci : info) { | 
 | 2396 |             if (ci instanceof CellInfoGsm) { | 
 | 2397 |                 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); | 
 | 2398 |             } else if (ci instanceof CellInfoWcdma) { | 
 | 2399 |                 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); | 
 | 2400 |             } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2401 |         } | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2402 |         return (neighbors.size()) > 0 ? neighbors : null; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2403 |     } | 
 | 2404 |  | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2405 |     private List<CellInfo> getCachedCellInfo() { | 
 | 2406 |         List<CellInfo> cellInfos = new ArrayList<CellInfo>(); | 
 | 2407 |         for (Phone phone : PhoneFactory.getPhones()) { | 
 | 2408 |             List<CellInfo> info = phone.getAllCellInfo(); | 
 | 2409 |             if (info != null) cellInfos.addAll(info); | 
 | 2410 |         } | 
 | 2411 |         return cellInfos; | 
 | 2412 |     } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2413 |  | 
 | 2414 |     @Override | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2415 |     public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2416 |         mApp.getSystemService(AppOpsManager.class) | 
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2417 |                 .checkPackage(Binder.getCallingUid(), callingPackage); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2418 |  | 
 | 2419 |         LocationAccessPolicy.LocationPermissionResult locationResult = | 
 | 2420 |                 LocationAccessPolicy.checkLocationPermission(mApp, | 
 | 2421 |                         new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
 | 2422 |                                 .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2423 |                                 .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2424 |                                 .setCallingPid(Binder.getCallingPid()) | 
 | 2425 |                                 .setCallingUid(Binder.getCallingUid()) | 
 | 2426 |                                 .setMethod("getAllCellInfo") | 
| Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2427 |                                 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2428 |                                 .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
 | 2429 |                                 .build()); | 
 | 2430 |         switch (locationResult) { | 
 | 2431 |             case DENIED_HARD: | 
 | 2432 |                 throw new SecurityException("Not allowed to access cell info"); | 
 | 2433 |             case DENIED_SOFT: | 
 | 2434 |                 return new ArrayList<>(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2435 |         } | 
 | 2436 |  | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2437 |         final int targetSdk = getTargetSdk(callingPackage); | 
 | 2438 |         if (targetSdk >= android.os.Build.VERSION_CODES.Q) { | 
 | 2439 |             return getCachedCellInfo(); | 
 | 2440 |         } | 
 | 2441 |  | 
| Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2442 |         if (DBG_LOC) log("getAllCellInfo: is active user"); | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2443 |         WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2444 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2445 |         try { | 
 | 2446 |             List<CellInfo> cellInfos = new ArrayList<CellInfo>(); | 
 | 2447 |             for (Phone phone : PhoneFactory.getPhones()) { | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2448 |                 final List<CellInfo> info = (List<CellInfo>) sendRequest( | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2449 |                         CMD_GET_ALL_CELL_INFO, null, phone, workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2450 |                 if (info != null) cellInfos.addAll(info); | 
 | 2451 |             } | 
 | 2452 |             return cellInfos; | 
 | 2453 |         } finally { | 
 | 2454 |             Binder.restoreCallingIdentity(identity); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2455 |         } | 
 | 2456 |     } | 
 | 2457 |  | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2458 |     @Override | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2459 |     public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, | 
 | 2460 |             String callingFeatureId) { | 
 | 2461 |         requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, | 
 | 2462 |                 getWorkSource(Binder.getCallingUid())); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2463 |     } | 
 | 2464 |  | 
 | 2465 |     @Override | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2466 |     public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, | 
 | 2467 |             String callingPackage, String callingFeatureId, WorkSource workSource) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2468 |         enforceModifyPermission(); | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2469 |         requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2470 |     } | 
 | 2471 |  | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2472 |     private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, | 
 | 2473 |             String callingPackage, String callingFeatureId, WorkSource workSource) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2474 |         mApp.getSystemService(AppOpsManager.class) | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2475 |                 .checkPackage(Binder.getCallingUid(), callingPackage); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2476 |  | 
 | 2477 |         LocationAccessPolicy.LocationPermissionResult locationResult = | 
 | 2478 |                 LocationAccessPolicy.checkLocationPermission(mApp, | 
 | 2479 |                         new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
 | 2480 |                                 .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2481 |                                 .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2482 |                                 .setCallingPid(Binder.getCallingPid()) | 
 | 2483 |                                 .setCallingUid(Binder.getCallingUid()) | 
 | 2484 |                                 .setMethod("requestCellInfoUpdate") | 
 | 2485 |                                 .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
 | 2486 |                                 .build()); | 
 | 2487 |         switch (locationResult) { | 
 | 2488 |             case DENIED_HARD: | 
 | 2489 |                 throw new SecurityException("Not allowed to access cell info"); | 
 | 2490 |             case DENIED_SOFT: | 
| Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2491 |                 try { | 
 | 2492 |                     cb.onCellInfo(new ArrayList<CellInfo>()); | 
 | 2493 |                 } catch (RemoteException re) { | 
 | 2494 |                     // Drop without consequences | 
 | 2495 |                 } | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2496 |                 return; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2497 |         } | 
 | 2498 |  | 
| Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2499 |  | 
 | 2500 |         final Phone phone = getPhoneFromSubId(subId); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2501 |         if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); | 
 | 2502 |  | 
 | 2503 |         sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); | 
 | 2504 |     } | 
 | 2505 |  | 
 | 2506 |     @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2507 |     public void setCellInfoListRate(int rateInMillis) { | 
| Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2508 |         enforceModifyPermission(); | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2509 |         WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2510 |  | 
 | 2511 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2512 |         try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2513 |             getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2514 |         } finally { | 
 | 2515 |             Binder.restoreCallingIdentity(identity); | 
 | 2516 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2517 |     } | 
 | 2518 |  | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2519 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2520 |     public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2521 |         Phone phone = PhoneFactory.getPhone(slotIndex); | 
 | 2522 |         if (phone == null) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2523 |             return null; | 
 | 2524 |         } | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2525 |         int subId = phone.getSubId(); | 
| Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2526 |         if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2527 |                 callingPackage, callingFeatureId, "getImeiForSlot")) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2528 |             return null; | 
 | 2529 |         } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2530 |  | 
 | 2531 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2532 |         try { | 
 | 2533 |             return phone.getImei(); | 
 | 2534 |         } finally { | 
 | 2535 |             Binder.restoreCallingIdentity(identity); | 
 | 2536 |         } | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2537 |     } | 
 | 2538 |  | 
 | 2539 |     @Override | 
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2540 |     public String getTypeAllocationCodeForSlot(int slotIndex) { | 
 | 2541 |         Phone phone = PhoneFactory.getPhone(slotIndex); | 
 | 2542 |         String tac = null; | 
 | 2543 |         if (phone != null) { | 
 | 2544 |             String imei = phone.getImei(); | 
 | 2545 |             tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); | 
 | 2546 |         } | 
 | 2547 |         return tac; | 
 | 2548 |     } | 
 | 2549 |  | 
 | 2550 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2551 |     public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2552 |         Phone phone = PhoneFactory.getPhone(slotIndex); | 
 | 2553 |         if (phone == null) { | 
| Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2554 |             return null; | 
 | 2555 |         } | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2556 |  | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2557 |         int subId = phone.getSubId(); | 
| Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2558 |         if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2559 |                 callingPackage, callingFeatureId, "getMeidForSlot")) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2560 |             return null; | 
 | 2561 |         } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2562 |  | 
 | 2563 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2564 |         try { | 
 | 2565 |             return phone.getMeid(); | 
 | 2566 |         } finally { | 
 | 2567 |             Binder.restoreCallingIdentity(identity); | 
 | 2568 |         } | 
| Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2569 |     } | 
 | 2570 |  | 
 | 2571 |     @Override | 
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2572 |     public String getManufacturerCodeForSlot(int slotIndex) { | 
 | 2573 |         Phone phone = PhoneFactory.getPhone(slotIndex); | 
 | 2574 |         String manufacturerCode = null; | 
 | 2575 |         if (phone != null) { | 
 | 2576 |             String meid = phone.getMeid(); | 
 | 2577 |             manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); | 
 | 2578 |         } | 
 | 2579 |         return manufacturerCode; | 
 | 2580 |     } | 
 | 2581 |  | 
 | 2582 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2583 |     public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, | 
 | 2584 |             String callingFeatureId) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2585 |         Phone phone = PhoneFactory.getPhone(slotIndex); | 
 | 2586 |         if (phone == null) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2587 |             return null; | 
 | 2588 |         } | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2589 |         int subId = phone.getSubId(); | 
 | 2590 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2591 |                 mApp, subId, callingPackage, callingFeatureId, | 
 | 2592 |                 "getDeviceSoftwareVersionForSlot")) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2593 |             return null; | 
 | 2594 |         } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2595 |  | 
 | 2596 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2597 |         try { | 
 | 2598 |             return phone.getDeviceSvn(); | 
 | 2599 |         } finally { | 
 | 2600 |             Binder.restoreCallingIdentity(identity); | 
 | 2601 |         } | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2602 |     } | 
 | 2603 |  | 
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2604 |     @Override | 
 | 2605 |     public int getSubscriptionCarrierId(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2606 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2607 |         try { | 
 | 2608 |             final Phone phone = getPhone(subId); | 
 | 2609 |             return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); | 
 | 2610 |         } finally { | 
 | 2611 |             Binder.restoreCallingIdentity(identity); | 
 | 2612 |         } | 
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2613 |     } | 
 | 2614 |  | 
 | 2615 |     @Override | 
 | 2616 |     public String getSubscriptionCarrierName(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2617 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2618 |         try { | 
 | 2619 |             final Phone phone = getPhone(subId); | 
 | 2620 |             return phone == null ? null : phone.getCarrierName(); | 
 | 2621 |         } finally { | 
 | 2622 |             Binder.restoreCallingIdentity(identity); | 
 | 2623 |         } | 
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2624 |     } | 
 | 2625 |  | 
| calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2626 |     @Override | 
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2627 |     public int getSubscriptionSpecificCarrierId(int subId) { | 
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2628 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2629 |         try { | 
 | 2630 |             final Phone phone = getPhone(subId); | 
 | 2631 |             return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID | 
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2632 |                     : phone.getSpecificCarrierId(); | 
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2633 |         } finally { | 
 | 2634 |             Binder.restoreCallingIdentity(identity); | 
 | 2635 |         } | 
 | 2636 |     } | 
 | 2637 |  | 
 | 2638 |     @Override | 
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2639 |     public String getSubscriptionSpecificCarrierName(int subId) { | 
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2640 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2641 |         try { | 
 | 2642 |             final Phone phone = getPhone(subId); | 
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2643 |             return phone == null ? null : phone.getSpecificCarrierName(); | 
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2644 |         } finally { | 
 | 2645 |             Binder.restoreCallingIdentity(identity); | 
 | 2646 |         } | 
 | 2647 |     } | 
 | 2648 |  | 
| chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2649 |     @Override | 
| chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2650 |     public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { | 
 | 2651 |         if (!isSubscriptionMccMnc) { | 
 | 2652 |             enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); | 
 | 2653 |         } | 
| chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2654 |         final Phone phone = PhoneFactory.getPhone(slotIndex); | 
 | 2655 |         if (phone == null) { | 
 | 2656 |             return TelephonyManager.UNKNOWN_CARRIER_ID; | 
 | 2657 |         } | 
 | 2658 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2659 |         try { | 
 | 2660 |             return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); | 
 | 2661 |         } finally { | 
 | 2662 |             Binder.restoreCallingIdentity(identity); | 
 | 2663 |         } | 
 | 2664 |     } | 
 | 2665 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2666 |     // | 
 | 2667 |     // Internal helper methods. | 
 | 2668 |     // | 
 | 2669 |  | 
| Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2670 |     /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2671 |      * Make sure the caller has the MODIFY_PHONE_STATE permission. | 
 | 2672 |      * | 
 | 2673 |      * @throws SecurityException if the caller does not have the required permission | 
 | 2674 |      */ | 
 | 2675 |     private void enforceModifyPermission() { | 
 | 2676 |         mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); | 
 | 2677 |     } | 
 | 2678 |  | 
| Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2679 |     /** | 
 | 2680 |      * Make sure the caller is system. | 
 | 2681 |      * | 
 | 2682 |      * @throws SecurityException if the caller is not system. | 
 | 2683 |      */ | 
 | 2684 |     private void enforceSystemCaller() { | 
 | 2685 |         if (Binder.getCallingUid() != Process.SYSTEM_UID) { | 
 | 2686 |             throw new SecurityException("Caller must be system"); | 
 | 2687 |         } | 
 | 2688 |     } | 
 | 2689 |  | 
| Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2690 |     private void enforceActiveEmergencySessionPermission() { | 
 | 2691 |         mApp.enforceCallingOrSelfPermission( | 
 | 2692 |                 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); | 
 | 2693 |     } | 
 | 2694 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2695 |     /** | 
 | 2696 |      * Make sure the caller has the CALL_PHONE permission. | 
 | 2697 |      * | 
 | 2698 |      * @throws SecurityException if the caller does not have the required permission | 
 | 2699 |      */ | 
 | 2700 |     private void enforceCallPermission() { | 
 | 2701 |         mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); | 
 | 2702 |     } | 
 | 2703 |  | 
| paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2704 |     private void enforceSettingsPermission() { | 
 | 2705 |         mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2706 |     } | 
 | 2707 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2708 |     private String createTelUrl(String number) { | 
 | 2709 |         if (TextUtils.isEmpty(number)) { | 
 | 2710 |             return null; | 
 | 2711 |         } | 
 | 2712 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2713 |         return "tel:" + number; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2714 |     } | 
 | 2715 |  | 
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2716 |     private static void log(String msg) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2717 |         Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); | 
 | 2718 |     } | 
 | 2719 |  | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2720 |     private static void logv(String msg) { | 
 | 2721 |         Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); | 
 | 2722 |     } | 
 | 2723 |  | 
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2724 |     private static void loge(String msg) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2725 |         Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); | 
 | 2726 |     } | 
 | 2727 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2728 |     @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2729 |     public int getActivePhoneType() { | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2730 |         return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2731 |     } | 
 | 2732 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2733 |     @Override | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2734 |     public int getActivePhoneTypeForSlot(int slotIndex) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2735 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2736 |         try { | 
 | 2737 |             final Phone phone = PhoneFactory.getPhone(slotIndex); | 
 | 2738 |             if (phone == null) { | 
 | 2739 |                 return PhoneConstants.PHONE_TYPE_NONE; | 
 | 2740 |             } else { | 
 | 2741 |                 return phone.getPhoneType(); | 
 | 2742 |             } | 
 | 2743 |         } finally { | 
 | 2744 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2745 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2746 |     } | 
 | 2747 |  | 
 | 2748 |     /** | 
 | 2749 |      * Returns the CDMA ERI icon index to display | 
 | 2750 |      */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2751 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2752 |     public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { | 
 | 2753 |         return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, | 
 | 2754 |                 callingFeatureId); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2755 |     } | 
 | 2756 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2757 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2758 |     public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, | 
 | 2759 |             String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2760 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2761 |                 mApp, subId, callingPackage, callingFeatureId, | 
 | 2762 |                 "getCdmaEriIconIndexForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2763 |             return -1; | 
 | 2764 |         } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2765 |  | 
 | 2766 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2767 |         try { | 
 | 2768 |             final Phone phone = getPhone(subId); | 
 | 2769 |             if (phone != null) { | 
 | 2770 |                 return phone.getCdmaEriIconIndex(); | 
 | 2771 |             } else { | 
 | 2772 |                 return -1; | 
 | 2773 |             } | 
 | 2774 |         } finally { | 
 | 2775 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2776 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2777 |     } | 
 | 2778 |  | 
 | 2779 |     /** | 
 | 2780 |      * Returns the CDMA ERI icon mode, | 
 | 2781 |      * 0 - ON | 
 | 2782 |      * 1 - FLASHING | 
 | 2783 |      */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2784 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2785 |     public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { | 
 | 2786 |         return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, | 
 | 2787 |                 callingFeatureId); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2788 |     } | 
 | 2789 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2790 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2791 |     public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, | 
 | 2792 |             String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2793 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2794 |                 mApp, subId, callingPackage, callingFeatureId, | 
 | 2795 |                 "getCdmaEriIconModeForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2796 |             return -1; | 
 | 2797 |         } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2798 |  | 
 | 2799 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2800 |         try { | 
 | 2801 |             final Phone phone = getPhone(subId); | 
 | 2802 |             if (phone != null) { | 
 | 2803 |                 return phone.getCdmaEriIconMode(); | 
 | 2804 |             } else { | 
 | 2805 |                 return -1; | 
 | 2806 |             } | 
 | 2807 |         } finally { | 
 | 2808 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2809 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2810 |     } | 
 | 2811 |  | 
 | 2812 |     /** | 
 | 2813 |      * Returns the CDMA ERI text, | 
 | 2814 |      */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2815 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2816 |     public String getCdmaEriText(String callingPackage, String callingFeatureId) { | 
 | 2817 |         return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, | 
 | 2818 |                 callingFeatureId); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2819 |     } | 
 | 2820 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2821 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2822 |     public String getCdmaEriTextForSubscriber(int subId, String callingPackage, | 
 | 2823 |             String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2824 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2825 |                 mApp, subId, callingPackage, callingFeatureId, | 
 | 2826 |                 "getCdmaEriIconTextForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2827 |             return null; | 
 | 2828 |         } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2829 |  | 
 | 2830 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2831 |         try { | 
 | 2832 |             final Phone phone = getPhone(subId); | 
 | 2833 |             if (phone != null) { | 
 | 2834 |                 return phone.getCdmaEriText(); | 
 | 2835 |             } else { | 
 | 2836 |                 return null; | 
 | 2837 |             } | 
 | 2838 |         } finally { | 
 | 2839 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2840 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2841 |     } | 
 | 2842 |  | 
 | 2843 |     /** | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2844 |      * Returns the CDMA MDN. | 
 | 2845 |      */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2846 |     @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2847 |     public String getCdmaMdn(int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2848 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 2849 |                 mApp, subId, "getCdmaMdn"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2850 |  | 
 | 2851 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2852 |         try { | 
 | 2853 |             final Phone phone = getPhone(subId); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2854 |             if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2855 |                 return phone.getLine1Number(); | 
 | 2856 |             } else { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2857 |                 loge("getCdmaMdn: no phone found. Invalid subId: " + subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2858 |                 return null; | 
 | 2859 |             } | 
 | 2860 |         } finally { | 
 | 2861 |             Binder.restoreCallingIdentity(identity); | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2862 |         } | 
 | 2863 |     } | 
 | 2864 |  | 
 | 2865 |     /** | 
 | 2866 |      * Returns the CDMA MIN. | 
 | 2867 |      */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2868 |     @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2869 |     public String getCdmaMin(int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2870 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 2871 |                 mApp, subId, "getCdmaMin"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2872 |  | 
 | 2873 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2874 |         try { | 
 | 2875 |             final Phone phone = getPhone(subId); | 
 | 2876 |             if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { | 
 | 2877 |                 return phone.getCdmaMin(); | 
 | 2878 |             } else { | 
 | 2879 |                 return null; | 
 | 2880 |             } | 
 | 2881 |         } finally { | 
 | 2882 |             Binder.restoreCallingIdentity(identity); | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2883 |         } | 
 | 2884 |     } | 
 | 2885 |  | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2886 |     @Override | 
 | 2887 |     public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, | 
 | 2888 |             INumberVerificationCallback callback, String callingPackage) { | 
 | 2889 |         if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) | 
 | 2890 |                 != PERMISSION_GRANTED) { | 
 | 2891 |             throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); | 
 | 2892 |         } | 
 | 2893 |         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
 | 2894 |  | 
 | 2895 |         String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); | 
 | 2896 |         if (!TextUtils.equals(callingPackage, authorizedPackage)) { | 
 | 2897 |             throw new SecurityException("Calling package must be configured in the device config"); | 
 | 2898 |         } | 
 | 2899 |  | 
 | 2900 |         if (range == null) { | 
 | 2901 |             throw new NullPointerException("Range must be non-null"); | 
 | 2902 |         } | 
 | 2903 |  | 
 | 2904 |         timeoutMillis = Math.min(timeoutMillis, | 
| Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2905 |                 TelephonyManager.getMaxNumberVerificationTimeoutMillis()); | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2906 |  | 
 | 2907 |         NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); | 
 | 2908 |     } | 
 | 2909 |  | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2910 |     /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2911 |      * Returns true if CDMA provisioning needs to run. | 
 | 2912 |      */ | 
 | 2913 |     public boolean needsOtaServiceProvisioning() { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2914 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2915 |         try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2916 |             return getDefaultPhone().needsOtaServiceProvisioning(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2917 |         } finally { | 
 | 2918 |             Binder.restoreCallingIdentity(identity); | 
 | 2919 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2920 |     } | 
 | 2921 |  | 
 | 2922 |     /** | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2923 |      * Sets the voice mail number of a given subId. | 
 | 2924 |      */ | 
 | 2925 |     @Override | 
 | 2926 |     public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { | 
| Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2927 |         TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( | 
 | 2928 |                 mApp, subId, "setVoiceMailNumber"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2929 |  | 
 | 2930 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2931 |         try { | 
 | 2932 |             Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, | 
 | 2933 |                     new Pair<String, String>(alphaTag, number), new Integer(subId)); | 
 | 2934 |             return success; | 
 | 2935 |         } finally { | 
 | 2936 |             Binder.restoreCallingIdentity(identity); | 
 | 2937 |         } | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2938 |     } | 
 | 2939 |  | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2940 |     @Override | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2941 |     public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { | 
 | 2942 |         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2943 |         TelecomManager tm = mApp.getSystemService(TelecomManager.class); | 
 | 2944 |         String systemDialer = tm.getSystemDialerPackage(); | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2945 |         if (!TextUtils.equals(callingPackage, systemDialer)) { | 
 | 2946 |             throw new SecurityException("caller must be system dialer"); | 
 | 2947 |         } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2948 |  | 
 | 2949 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2950 |         try { | 
 | 2951 |             PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); | 
 | 2952 |             if (phoneAccountHandle == null) { | 
 | 2953 |                 return null; | 
 | 2954 |             } | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2955 |             return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2956 |         } finally { | 
 | 2957 |             Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2958 |         } | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2959 |     } | 
 | 2960 |  | 
 | 2961 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2962 |     public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, | 
 | 2963 |             int subId) { | 
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2964 |         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2965 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2966 |                 mApp, subId, callingPackage, callingFeatureId, | 
 | 2967 |                 "getVisualVoicemailPackageName")) { | 
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2968 |             return null; | 
 | 2969 |         } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2970 |  | 
| Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2971 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2972 |         try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2973 |             return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); | 
| Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2974 |         } finally { | 
 | 2975 |             Binder.restoreCallingIdentity(identity); | 
 | 2976 |         } | 
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2977 |     } | 
 | 2978 |  | 
 | 2979 |     @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2980 |     public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, | 
 | 2981 |             VisualVoicemailSmsFilterSettings settings) { | 
 | 2982 |         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2983 |  | 
 | 2984 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2985 |         try { | 
 | 2986 |             VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2987 |                     mApp, callingPackage, subId, settings); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2988 |         } finally { | 
 | 2989 |             Binder.restoreCallingIdentity(identity); | 
 | 2990 |         } | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2991 |     } | 
 | 2992 |  | 
 | 2993 |     @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2994 |     public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { | 
 | 2995 |         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2996 |  | 
 | 2997 |         final long identity = Binder.clearCallingIdentity(); | 
 | 2998 |         try { | 
 | 2999 |             VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3000 |                     mApp, callingPackage, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3001 |         } finally { | 
 | 3002 |             Binder.restoreCallingIdentity(identity); | 
 | 3003 |         } | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3004 |     } | 
 | 3005 |  | 
 | 3006 |     @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3007 |     public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( | 
 | 3008 |             String callingPackage, int subId) { | 
 | 3009 |         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3010 |  | 
 | 3011 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3012 |         try { | 
 | 3013 |             return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3014 |                     mApp, callingPackage, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3015 |         } finally { | 
 | 3016 |             Binder.restoreCallingIdentity(identity); | 
 | 3017 |         } | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3018 |     } | 
 | 3019 |  | 
 | 3020 |     @Override | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3021 |     public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3022 |         enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3023 |  | 
 | 3024 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3025 |         try { | 
 | 3026 |             return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3027 |                     mApp, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3028 |         } finally { | 
 | 3029 |             Binder.restoreCallingIdentity(identity); | 
 | 3030 |         } | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3031 |     } | 
 | 3032 |  | 
 | 3033 |     @Override | 
 | 3034 |     public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, | 
 | 3035 |             String number, int port, String text, PendingIntent sentIntent) { | 
 | 3036 |         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3037 |         enforceVisualVoicemailPackage(callingPackage, subId); | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3038 |         enforceSendSmsPermission(); | 
| Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3039 |         SmsController smsController = PhoneFactory.getSmsController(); | 
 | 3040 |         smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, | 
 | 3041 |                 sentIntent); | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3042 |     } | 
| Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3043 |  | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3044 |     /** | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3045 |      * Sets the voice activation state of a given subId. | 
 | 3046 |      */ | 
 | 3047 |     @Override | 
 | 3048 |     public void setVoiceActivationState(int subId, int activationState) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3049 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 3050 |                 mApp, subId, "setVoiceActivationState"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3051 |  | 
 | 3052 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3053 |         try { | 
 | 3054 |             final Phone phone = getPhone(subId); | 
 | 3055 |             if (phone != null) { | 
 | 3056 |                 phone.setVoiceActivationState(activationState); | 
 | 3057 |             } else { | 
 | 3058 |                 loge("setVoiceActivationState fails with invalid subId: " + subId); | 
 | 3059 |             } | 
 | 3060 |         } finally { | 
 | 3061 |             Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3062 |         } | 
 | 3063 |     } | 
 | 3064 |  | 
 | 3065 |     /** | 
 | 3066 |      * Sets the data activation state of a given subId. | 
 | 3067 |      */ | 
 | 3068 |     @Override | 
 | 3069 |     public void setDataActivationState(int subId, int activationState) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3070 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 3071 |                 mApp, subId, "setDataActivationState"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3072 |  | 
 | 3073 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3074 |         try { | 
 | 3075 |             final Phone phone = getPhone(subId); | 
 | 3076 |             if (phone != null) { | 
 | 3077 |                 phone.setDataActivationState(activationState); | 
 | 3078 |             } else { | 
| Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3079 |                 loge("setDataActivationState fails with invalid subId: " + subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3080 |             } | 
 | 3081 |         } finally { | 
 | 3082 |             Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3083 |         } | 
 | 3084 |     } | 
 | 3085 |  | 
 | 3086 |     /** | 
 | 3087 |      * Returns the voice activation state of a given subId. | 
 | 3088 |      */ | 
 | 3089 |     @Override | 
 | 3090 |     public int getVoiceActivationState(int subId, String callingPackage) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3091 |         enforceReadPrivilegedPermission("getVoiceActivationState"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3092 |  | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3093 |         final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3094 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3095 |         try { | 
 | 3096 |             if (phone != null) { | 
 | 3097 |                 return phone.getVoiceActivationState(); | 
 | 3098 |             } else { | 
 | 3099 |                 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; | 
 | 3100 |             } | 
 | 3101 |         } finally { | 
 | 3102 |             Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3103 |         } | 
 | 3104 |     } | 
 | 3105 |  | 
 | 3106 |     /** | 
 | 3107 |      * Returns the data activation state of a given subId. | 
 | 3108 |      */ | 
 | 3109 |     @Override | 
 | 3110 |     public int getDataActivationState(int subId, String callingPackage) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3111 |         enforceReadPrivilegedPermission("getDataActivationState"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3112 |  | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3113 |         final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3114 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3115 |         try { | 
 | 3116 |             if (phone != null) { | 
 | 3117 |                 return phone.getDataActivationState(); | 
 | 3118 |             } else { | 
 | 3119 |                 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; | 
 | 3120 |             } | 
 | 3121 |         } finally { | 
 | 3122 |             Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3123 |         } | 
 | 3124 |     } | 
 | 3125 |  | 
 | 3126 |     /** | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3127 |      * Returns the unread count of voicemails for a subId | 
 | 3128 |      */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3129 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3130 |     public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, | 
 | 3131 |             String callingFeatureId) { | 
| Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3132 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3133 |                 mApp, subId, callingPackage, callingFeatureId, | 
 | 3134 |                 "getVoiceMessageCountForSubscriber")) { | 
| Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3135 |             return 0; | 
 | 3136 |         } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3137 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3138 |         try { | 
 | 3139 |             final Phone phone = getPhone(subId); | 
 | 3140 |             if (phone != null) { | 
 | 3141 |                 return phone.getVoiceMessageCount(); | 
 | 3142 |             } else { | 
 | 3143 |                 return 0; | 
 | 3144 |             } | 
 | 3145 |         } finally { | 
 | 3146 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3147 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3148 |     } | 
 | 3149 |  | 
 | 3150 |     /** | 
| pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3151 |       * returns true, if the device is in a state where both voice and data | 
 | 3152 |       * are supported simultaneously. This can change based on location or network condition. | 
 | 3153 |      */ | 
 | 3154 |     @Override | 
 | 3155 |     public boolean isConcurrentVoiceAndDataAllowed(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3156 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3157 |         try { | 
 | 3158 |             final Phone phone = getPhone(subId); | 
 | 3159 |             return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); | 
 | 3160 |         } finally { | 
 | 3161 |             Binder.restoreCallingIdentity(identity); | 
 | 3162 |         } | 
| pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3163 |     } | 
 | 3164 |  | 
 | 3165 |     /** | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3166 |      * Send the dialer code if called from the current default dialer or the caller has | 
 | 3167 |      * carrier privilege. | 
 | 3168 |      * @param inputCode The dialer code to send | 
 | 3169 |      */ | 
 | 3170 |     @Override | 
 | 3171 |     public void sendDialerSpecialCode(String callingPackage, String inputCode) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3172 |         final Phone defaultPhone = getDefaultPhone(); | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3173 |         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3174 |         TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); | 
 | 3175 |         String defaultDialer = tm.getDefaultDialerPackage(); | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3176 |         if (!TextUtils.equals(callingPackage, defaultDialer)) { | 
| Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3177 |             TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3178 |                     getDefaultSubscription(), "sendDialerSpecialCode"); | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3179 |         } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3180 |  | 
 | 3181 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3182 |         try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3183 |             defaultPhone.sendDialerSpecialCode(inputCode); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3184 |         } finally { | 
 | 3185 |             Binder.restoreCallingIdentity(identity); | 
 | 3186 |         } | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3187 |     } | 
 | 3188 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3189 |     @Override | 
 | 3190 |     public int getNetworkSelectionMode(int subId) { | 
| shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3191 |         TelephonyPermissions | 
 | 3192 |                     .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
 | 3193 |                     mApp, subId, "getNetworkSelectionMode"); | 
 | 3194 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3195 |         try { | 
 | 3196 |             if (!isActiveSubscription(subId)) { | 
 | 3197 |                 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; | 
 | 3198 |             } | 
 | 3199 |             return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); | 
 | 3200 |         } finally { | 
 | 3201 |             Binder.restoreCallingIdentity(identity); | 
| Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3202 |         } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3203 |     } | 
 | 3204 |  | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3205 |     @Override | 
| Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3206 |     public boolean isInEmergencySmsMode() { | 
 | 3207 |         enforceReadPrivilegedPermission("isInEmergencySmsMode"); | 
 | 3208 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3209 |         try { | 
 | 3210 |             for (Phone phone : PhoneFactory.getPhones()) { | 
 | 3211 |                 if (phone.isInEmergencySmsMode()) { | 
 | 3212 |                     return true; | 
 | 3213 |                 } | 
 | 3214 |             } | 
 | 3215 |         } finally { | 
 | 3216 |             Binder.restoreCallingIdentity(identity); | 
 | 3217 |         } | 
 | 3218 |         return false; | 
 | 3219 |     } | 
 | 3220 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3221 |     /** | 
 | 3222 |      * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
 | 3223 |      * @param subId The subscription to use to check the configuration. | 
 | 3224 |      * @param c The callback that will be used to send the result. | 
 | 3225 |      */ | 
| Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3226 |     @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3227 |     public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) | 
 | 3228 |             throws RemoteException { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3229 |         TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
 | 3230 |                 mApp, subId, "registerImsRegistrationCallback"); | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3231 |  | 
| Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3232 |         if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
 | 3233 |             throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
 | 3234 |                     "IMS not available on device."); | 
 | 3235 |         } | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3236 |         final long token = Binder.clearCallingIdentity(); | 
 | 3237 |         try { | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3238 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3239 |             ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3240 |                     .addRegistrationCallbackForSubscription(c, subId); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3241 |         } catch (ImsException e) { | 
 | 3242 |             throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3243 |         } finally { | 
 | 3244 |             Binder.restoreCallingIdentity(token); | 
 | 3245 |         } | 
 | 3246 |     } | 
 | 3247 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3248 |     /** | 
 | 3249 |      * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
 | 3250 |      * @param subId The subscription to use to check the configuration. | 
 | 3251 |      * @param c The callback that will be used to send the result. | 
 | 3252 |      */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3253 |     @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3254 |     public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3255 |         TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
 | 3256 |                 mApp, subId, "unregisterImsRegistrationCallback"); | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3257 |         if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
 | 3258 |             throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
 | 3259 |         } | 
| Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3260 |         final long token = Binder.clearCallingIdentity(); | 
 | 3261 |         try { | 
 | 3262 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. | 
 | 3263 |             ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
 | 3264 |                     .removeRegistrationCallbackForSubscription(c, subId); | 
 | 3265 |         } catch (ImsException e) { | 
 | 3266 |             Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId | 
 | 3267 |                     + "is inactive, ignoring unregister."); | 
 | 3268 |             // If the subscription is no longer active, just return, since the callback | 
 | 3269 |             // will already have been removed internally. | 
 | 3270 |         } finally { | 
 | 3271 |             Binder.restoreCallingIdentity(token); | 
 | 3272 |         } | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3273 |     } | 
 | 3274 |  | 
| Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3275 |     /** | 
 | 3276 |      * Get the IMS service registration state for the MmTelFeature associated with this sub id. | 
 | 3277 |      */ | 
 | 3278 |     @Override | 
 | 3279 |     public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { | 
 | 3280 |         enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); | 
 | 3281 |         if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
 | 3282 |             throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
 | 3283 |                     "IMS not available on device."); | 
 | 3284 |         } | 
 | 3285 |         final long token = Binder.clearCallingIdentity(); | 
 | 3286 |         try { | 
 | 3287 |             Phone phone = getPhone(subId); | 
 | 3288 |             if (phone == null) { | 
 | 3289 |                 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" | 
 | 3290 |                         + subId + "'"); | 
 | 3291 |                 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); | 
 | 3292 |             } | 
 | 3293 |             phone.getImsRegistrationState(regState -> { | 
 | 3294 |                 try { | 
 | 3295 |                     consumer.accept((regState == null) | 
 | 3296 |                             ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); | 
 | 3297 |                 } catch (RemoteException e) { | 
 | 3298 |                     // Ignore if the remote process is no longer available to call back. | 
 | 3299 |                     Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); | 
 | 3300 |                 } | 
 | 3301 |             }); | 
 | 3302 |         } finally { | 
 | 3303 |             Binder.restoreCallingIdentity(token); | 
 | 3304 |         } | 
 | 3305 |     } | 
 | 3306 |  | 
 | 3307 |     /** | 
 | 3308 |      * Get the transport type for the IMS service registration state. | 
 | 3309 |      */ | 
 | 3310 |     @Override | 
 | 3311 |     public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3312 |         TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
 | 3313 |                 mApp, subId, "getImsMmTelRegistrationTransportType"); | 
| Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3314 |         if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
 | 3315 |             throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
 | 3316 |                     "IMS not available on device."); | 
 | 3317 |         } | 
 | 3318 |         final long token = Binder.clearCallingIdentity(); | 
 | 3319 |         try { | 
 | 3320 |             Phone phone = getPhone(subId); | 
 | 3321 |             if (phone == null) { | 
 | 3322 |                 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" | 
 | 3323 |                         + subId + "'"); | 
 | 3324 |                 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); | 
 | 3325 |             } | 
 | 3326 |             phone.getImsRegistrationTech(regTech -> { | 
 | 3327 |                 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager | 
 | 3328 |                 int regTechConverted = (regTech == null) | 
 | 3329 |                         ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; | 
 | 3330 |                 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( | 
 | 3331 |                         regTechConverted); | 
 | 3332 |                 try { | 
 | 3333 |                     consumer.accept(regTechConverted); | 
 | 3334 |                 } catch (RemoteException e) { | 
 | 3335 |                     // Ignore if the remote process is no longer available to call back. | 
 | 3336 |                     Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); | 
 | 3337 |                 } | 
 | 3338 |             }); | 
 | 3339 |         } finally { | 
 | 3340 |             Binder.restoreCallingIdentity(token); | 
 | 3341 |         } | 
 | 3342 |     } | 
 | 3343 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3344 |     /** | 
 | 3345 |      * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
 | 3346 |      * @param subId The subscription to use to check the configuration. | 
 | 3347 |      * @param c The callback that will be used to send the result. | 
 | 3348 |      */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3349 |     @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3350 |     public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) | 
 | 3351 |             throws RemoteException { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3352 |         TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
 | 3353 |                 mApp, subId, "registerMmTelCapabilityCallback"); | 
| Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3354 |         if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
 | 3355 |             throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
 | 3356 |                     "IMS not available on device."); | 
 | 3357 |         } | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3358 |         // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
 | 3359 |         final long token = Binder.clearCallingIdentity(); | 
 | 3360 |         try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3361 |             ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3362 |                     .addCapabilitiesCallbackForSubscription(c, subId); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3363 |         } catch (ImsException e) { | 
 | 3364 |             throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3365 |         } finally { | 
 | 3366 |             Binder.restoreCallingIdentity(token); | 
 | 3367 |         } | 
 | 3368 |     } | 
 | 3369 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3370 |     /** | 
 | 3371 |      * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
 | 3372 |      * @param subId The subscription to use to check the configuration. | 
 | 3373 |      * @param c The callback that will be used to send the result. | 
 | 3374 |      */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3375 |     @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3376 |     public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3377 |         TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
 | 3378 |                 mApp, subId, "unregisterMmTelCapabilityCallback"); | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3379 |         if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
 | 3380 |             throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
 | 3381 |         } | 
| Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3382 |  | 
 | 3383 |         final long token = Binder.clearCallingIdentity(); | 
 | 3384 |         try { | 
 | 3385 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. | 
 | 3386 |             ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3387 |                         .removeCapabilitiesCallbackForSubscription(c, subId); | 
| Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3388 |         } catch (ImsException e) { | 
 | 3389 |             Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId | 
 | 3390 |                      + "is inactive, ignoring unregister."); | 
 | 3391 |              // If the subscription is no longer active, just return, since the callback | 
 | 3392 |              // will already have been removed internally. | 
 | 3393 |         } finally { | 
 | 3394 |             Binder.restoreCallingIdentity(token); | 
 | 3395 |         } | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3396 |     } | 
 | 3397 |  | 
 | 3398 |     @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3399 |     public boolean isCapable(int subId, int capability, int regTech) { | 
 | 3400 |         enforceReadPrivilegedPermission("isCapable"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3401 |         // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
 | 3402 |         final long token = Binder.clearCallingIdentity(); | 
 | 3403 |         try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3404 |             return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3405 |                     getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3406 |         } catch (com.android.ims.ImsException e) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3407 |             Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); | 
 | 3408 |             return false; | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3409 |         } catch (ImsException e) { | 
| Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3410 |             Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); | 
 | 3411 |             return false; | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3412 |         } finally { | 
 | 3413 |             Binder.restoreCallingIdentity(token); | 
 | 3414 |         } | 
 | 3415 |     } | 
 | 3416 |  | 
 | 3417 |     @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3418 |     public boolean isAvailable(int subId, int capability, int regTech) { | 
 | 3419 |         enforceReadPrivilegedPermission("isAvailable"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3420 |         final long token = Binder.clearCallingIdentity(); | 
 | 3421 |         try { | 
 | 3422 |             Phone phone = getPhone(subId); | 
 | 3423 |             if (phone == null) return false; | 
 | 3424 |             return phone.isImsCapabilityAvailable(capability, regTech); | 
 | 3425 |         } finally { | 
 | 3426 |             Binder.restoreCallingIdentity(token); | 
 | 3427 |         } | 
 | 3428 |     } | 
 | 3429 |  | 
| Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3430 |     /** | 
 | 3431 |      * Determines if the MmTel feature capability is supported by the carrier configuration for this | 
 | 3432 |      * subscription. | 
 | 3433 |      * @param subId The subscription to use to check the configuration. | 
 | 3434 |      * @param callback The callback that will be used to send the result. | 
 | 3435 |      * @param capability The MmTelFeature capability that will be used to send the result. | 
 | 3436 |      * @param transportType The transport type of the MmTelFeature capability. | 
 | 3437 |      */ | 
 | 3438 |     @Override | 
 | 3439 |     public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, | 
 | 3440 |             int transportType) { | 
 | 3441 |         enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); | 
 | 3442 |         if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
 | 3443 |             throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
 | 3444 |                     "IMS not available on device."); | 
 | 3445 |         } | 
 | 3446 |         final long token = Binder.clearCallingIdentity(); | 
 | 3447 |         try { | 
 | 3448 |             int slotId = getSlotIndex(subId); | 
 | 3449 |             if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
 | 3450 |                 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" | 
 | 3451 |                         + subId + "'"); | 
 | 3452 |                 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); | 
 | 3453 |             } | 
 | 3454 |             ImsManager.getInstance(mApp, slotId).isSupported(capability, | 
 | 3455 |                     transportType, aBoolean -> { | 
 | 3456 |                         try { | 
 | 3457 |                             callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); | 
 | 3458 |                         } catch (RemoteException e) { | 
 | 3459 |                             Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " | 
 | 3460 |                                     + "running. Ignore"); | 
 | 3461 |                         } | 
 | 3462 |                     }); | 
 | 3463 |         } finally { | 
 | 3464 |             Binder.restoreCallingIdentity(token); | 
 | 3465 |         } | 
 | 3466 |     } | 
 | 3467 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3468 |     /** | 
 | 3469 |      * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
 | 3470 |      * @param subId The subscription to use to check the configuration. | 
 | 3471 |      */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3472 |     @Override | 
 | 3473 |     public boolean isAdvancedCallingSettingEnabled(int subId) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3474 |         TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
 | 3475 |                 mApp, subId, "isAdvancedCallingSettingEnabled"); | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3476 |  | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3477 |         // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
 | 3478 |         final long token = Binder.clearCallingIdentity(); | 
 | 3479 |         try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3480 |             return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3481 |                     getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3482 |         } catch (ImsException e) { | 
 | 3483 |             throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3484 |         } finally { | 
 | 3485 |             Binder.restoreCallingIdentity(token); | 
 | 3486 |         } | 
 | 3487 |     } | 
 | 3488 |  | 
 | 3489 |     @Override | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3490 |     public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3491 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3492 |                 "setAdvancedCallingSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3493 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3494 |         try { | 
 | 3495 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3496 |             ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3497 |                     getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3498 |         } catch (ImsException e) { | 
 | 3499 |             throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3500 |         } finally { | 
 | 3501 |             Binder.restoreCallingIdentity(identity); | 
 | 3502 |         } | 
 | 3503 |     } | 
 | 3504 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3505 |     /** | 
 | 3506 |      * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
 | 3507 |      * @param subId The subscription to use to check the configuration. | 
 | 3508 |      */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3509 |     @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3510 |     public boolean isVtSettingEnabled(int subId) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3511 |         TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
 | 3512 |                 mApp, subId, "isVtSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3513 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3514 |         try { | 
 | 3515 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3516 |             return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); | 
 | 3517 |         } catch (ImsException e) { | 
 | 3518 |             throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3519 |         } finally { | 
 | 3520 |             Binder.restoreCallingIdentity(identity); | 
 | 3521 |         } | 
 | 3522 |     } | 
 | 3523 |  | 
 | 3524 |     @Override | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3525 |     public void setVtSettingEnabled(int subId, boolean isEnabled) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3526 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3527 |                 "setVtSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3528 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3529 |         try { | 
 | 3530 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3531 |             ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3532 |         } catch (ImsException e) { | 
 | 3533 |             throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3534 |         } finally { | 
 | 3535 |             Binder.restoreCallingIdentity(identity); | 
 | 3536 |         } | 
 | 3537 |     } | 
 | 3538 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3539 |     /** | 
 | 3540 |      * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
 | 3541 |      * @param subId The subscription to use to check the configuration. | 
 | 3542 |      */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3543 |     @Override | 
 | 3544 |     public boolean isVoWiFiSettingEnabled(int subId) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3545 |         TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
 | 3546 |                 mApp, subId, "isVoWiFiSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3547 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3548 |         try { | 
 | 3549 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3550 |             return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3551 |                     getSlotIndexOrException(subId)).isWfcEnabledByUser(); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3552 |         } catch (ImsException e) { | 
 | 3553 |             throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3554 |         } finally { | 
 | 3555 |             Binder.restoreCallingIdentity(identity); | 
 | 3556 |         } | 
 | 3557 |     } | 
 | 3558 |  | 
 | 3559 |     @Override | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3560 |     public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3561 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3562 |                 "setVoWiFiSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3563 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3564 |         try { | 
 | 3565 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3566 |             ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3567 |         } catch (ImsException e) { | 
 | 3568 |             throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3569 |         } finally { | 
 | 3570 |             Binder.restoreCallingIdentity(identity); | 
 | 3571 |         } | 
 | 3572 |     } | 
 | 3573 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3574 |     /** | 
 | 3575 |      * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
 | 3576 |      * @param subId The subscription to use to check the configuration. | 
 | 3577 |      */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3578 |     @Override | 
 | 3579 |     public boolean isVoWiFiRoamingSettingEnabled(int subId) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3580 |         TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
 | 3581 |                 mApp, subId, "isVoWiFiRoamingSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3582 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3583 |         try { | 
 | 3584 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3585 |             return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3586 |                     getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3587 |         } catch (ImsException e) { | 
 | 3588 |             throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3589 |         } finally { | 
 | 3590 |             Binder.restoreCallingIdentity(identity); | 
 | 3591 |         } | 
 | 3592 |     } | 
 | 3593 |  | 
 | 3594 |     @Override | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3595 |     public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3596 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3597 |                 "setVoWiFiRoamingSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3598 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3599 |         try { | 
 | 3600 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3601 |             ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3602 |                     getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3603 |         } catch (ImsException e) { | 
 | 3604 |             throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3605 |         } finally { | 
 | 3606 |             Binder.restoreCallingIdentity(identity); | 
 | 3607 |         } | 
 | 3608 |     } | 
 | 3609 |  | 
 | 3610 |     @Override | 
 | 3611 |     public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { | 
 | 3612 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
 | 3613 |                 "setVoWiFiNonPersistent"); | 
 | 3614 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3615 |         try { | 
 | 3616 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3617 |             ImsManager.getInstance(mApp, | 
| Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3618 |                     getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3619 |         } catch (ImsException e) { | 
 | 3620 |             throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3621 |         } finally { | 
 | 3622 |             Binder.restoreCallingIdentity(identity); | 
 | 3623 |         } | 
 | 3624 |     } | 
 | 3625 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3626 |     /** | 
 | 3627 |      * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
 | 3628 |      * @param subId The subscription to use to check the configuration. | 
 | 3629 |      */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3630 |     @Override | 
 | 3631 |     public int getVoWiFiModeSetting(int subId) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3632 |         TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
 | 3633 |                 mApp, subId, "getVoWiFiModeSetting"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3634 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3635 |         try { | 
 | 3636 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3637 |             return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3638 |                     getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3639 |         } catch (ImsException e) { | 
 | 3640 |             throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3641 |         } finally { | 
 | 3642 |             Binder.restoreCallingIdentity(identity); | 
 | 3643 |         } | 
 | 3644 |     } | 
 | 3645 |  | 
 | 3646 |     @Override | 
 | 3647 |     public void setVoWiFiModeSetting(int subId, int mode) { | 
 | 3648 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
 | 3649 |                 "setVoWiFiModeSetting"); | 
 | 3650 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3651 |         try { | 
 | 3652 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3653 |             ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3654 |                     getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3655 |         } catch (ImsException e) { | 
 | 3656 |             throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3657 |         } finally { | 
 | 3658 |             Binder.restoreCallingIdentity(identity); | 
 | 3659 |         } | 
 | 3660 |     } | 
 | 3661 |  | 
 | 3662 |     @Override | 
 | 3663 |     public int getVoWiFiRoamingModeSetting(int subId) { | 
 | 3664 |         enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); | 
 | 3665 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3666 |         try { | 
 | 3667 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3668 |             return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3669 |                     getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3670 |         } catch (ImsException e) { | 
 | 3671 |             throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3672 |         } finally { | 
 | 3673 |             Binder.restoreCallingIdentity(identity); | 
 | 3674 |         } | 
 | 3675 |     } | 
 | 3676 |  | 
 | 3677 |     @Override | 
 | 3678 |     public void setVoWiFiRoamingModeSetting(int subId, int mode) { | 
 | 3679 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
 | 3680 |                 "setVoWiFiRoamingModeSetting"); | 
 | 3681 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3682 |         try { | 
 | 3683 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3684 |             ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3685 |                     getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3686 |         } catch (ImsException e) { | 
 | 3687 |             throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3688 |         } finally { | 
 | 3689 |             Binder.restoreCallingIdentity(identity); | 
 | 3690 |         } | 
 | 3691 |     } | 
 | 3692 |  | 
 | 3693 |     @Override | 
 | 3694 |     public void setRttCapabilitySetting(int subId, boolean isEnabled) { | 
 | 3695 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
 | 3696 |                 "setRttCapabilityEnabled"); | 
 | 3697 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3698 |         try { | 
 | 3699 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3700 |             ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); | 
 | 3701 |         } catch (ImsException e) { | 
 | 3702 |             throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3703 |         } finally { | 
 | 3704 |             Binder.restoreCallingIdentity(identity); | 
 | 3705 |         } | 
 | 3706 |     } | 
 | 3707 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3708 |     /** | 
 | 3709 |      * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
 | 3710 |      * @param subId The subscription to use to check the configuration. | 
 | 3711 |      */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3712 |     @Override | 
 | 3713 |     public boolean isTtyOverVolteEnabled(int subId) { | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3714 |         TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
 | 3715 |                 mApp, subId, "isTtyOverVolteEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3716 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3717 |         try { | 
 | 3718 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3719 |             return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3720 |                     getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3721 |         } catch (ImsException e) { | 
 | 3722 |             throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3723 |         } finally { | 
 | 3724 |             Binder.restoreCallingIdentity(identity); | 
 | 3725 |         } | 
 | 3726 |     } | 
 | 3727 |  | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3728 |     @Override | 
 | 3729 |     public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { | 
 | 3730 |         enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); | 
 | 3731 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3732 |         try { | 
| Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3733 |             if (!isImsAvailableOnDevice()) { | 
 | 3734 |                 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
 | 3735 |                         "IMS not available on device."); | 
| Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3736 |             } | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3737 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3738 |             ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3739 |                     .addProvisioningCallbackForSubscription(callback, subId); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3740 |         } catch (ImsException e) { | 
 | 3741 |             throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3742 |         } finally { | 
 | 3743 |             Binder.restoreCallingIdentity(identity); | 
 | 3744 |         } | 
 | 3745 |     } | 
 | 3746 |  | 
 | 3747 |     @Override | 
 | 3748 |     public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { | 
 | 3749 |         enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); | 
 | 3750 |         final long identity = Binder.clearCallingIdentity(); | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3751 |         if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
 | 3752 |             throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
 | 3753 |         } | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3754 |         try { | 
 | 3755 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3756 |             ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3757 |                     .removeProvisioningCallbackForSubscription(callback, subId); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3758 |         } catch (ImsException e) { | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3759 |             Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId | 
 | 3760 |                     + "is inactive, ignoring unregister."); | 
 | 3761 |             // If the subscription is no longer active, just return, since the callback will already | 
 | 3762 |             // have been removed internally. | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3763 |         } finally { | 
 | 3764 |             Binder.restoreCallingIdentity(identity); | 
 | 3765 |         } | 
 | 3766 |     } | 
 | 3767 |  | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3768 |  | 
 | 3769 |     private void checkModifyPhoneStatePermission(int subId, String message) { | 
 | 3770 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
 | 3771 |                 message); | 
 | 3772 |     } | 
 | 3773 |  | 
 | 3774 |     private boolean isImsProvisioningRequired(int subId, int capability, | 
 | 3775 |             boolean isMmtelCapability) { | 
 | 3776 |         Phone phone = getPhone(subId); | 
 | 3777 |         if (phone == null) { | 
 | 3778 |             loge("phone instance null for subid " + subId); | 
 | 3779 |             return false; | 
 | 3780 |         } | 
 | 3781 |         if (isMmtelCapability) { | 
 | 3782 |             if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { | 
 | 3783 |                 return false; | 
 | 3784 |             } | 
 | 3785 |         } else { | 
 | 3786 |             if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { | 
 | 3787 |                 return false; | 
 | 3788 |             } | 
 | 3789 |         } | 
 | 3790 |         return true; | 
 | 3791 |     } | 
 | 3792 |  | 
 | 3793 |     @Override | 
 | 3794 |     public void setRcsProvisioningStatusForCapability(int subId, int capability, | 
 | 3795 |             boolean isProvisioned) { | 
 | 3796 |         checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); | 
 | 3797 |  | 
 | 3798 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3799 |         try { | 
 | 3800 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
 | 3801 |             if (!isImsProvisioningRequired(subId, capability, false)) { | 
 | 3802 |                 return; | 
 | 3803 |             } | 
 | 3804 |  | 
 | 3805 |             // this capability requires provisioning, route to the correct API. | 
 | 3806 |             ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); | 
 | 3807 |             switch (capability) { | 
 | 3808 |                 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: | 
 | 3809 |                 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: | 
 | 3810 |                     ims.setEabProvisioned(isProvisioned); | 
 | 3811 |                     break; | 
 | 3812 |                 default: { | 
 | 3813 |                     throw new IllegalArgumentException("Tried to set provisioning for " | 
 | 3814 |                             + "rcs capability '" + capability + "', which does not require " | 
 | 3815 |                             + "provisioning."); | 
 | 3816 |                 } | 
 | 3817 |             } | 
 | 3818 |         } finally { | 
 | 3819 |             Binder.restoreCallingIdentity(identity); | 
 | 3820 |         } | 
 | 3821 |  | 
 | 3822 |     } | 
 | 3823 |  | 
 | 3824 |  | 
 | 3825 |     @Override | 
 | 3826 |     public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { | 
 | 3827 |         enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); | 
 | 3828 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3829 |         try { | 
 | 3830 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
 | 3831 |             if (!isImsProvisioningRequired(subId, capability, false)) { | 
 | 3832 |                 return true; | 
 | 3833 |             } | 
 | 3834 |  | 
 | 3835 |             ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); | 
 | 3836 |             switch (capability) { | 
 | 3837 |                 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: | 
 | 3838 |                 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: | 
 | 3839 |                     return ims.isEabProvisionedOnDevice(); | 
 | 3840 |  | 
 | 3841 |                 default: { | 
 | 3842 |                     throw new IllegalArgumentException("Tried to get rcs provisioning for " | 
 | 3843 |                             + "capability '" + capability + "', which does not require " | 
 | 3844 |                             + "provisioning."); | 
 | 3845 |                 } | 
 | 3846 |             } | 
 | 3847 |  | 
 | 3848 |         } finally { | 
 | 3849 |             Binder.restoreCallingIdentity(identity); | 
 | 3850 |         } | 
 | 3851 |     } | 
 | 3852 |  | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3853 |     @Override | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3854 |     public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, | 
 | 3855 |             boolean isProvisioned) { | 
 | 3856 |         if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN | 
 | 3857 |                 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
 | 3858 |             throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); | 
 | 3859 |         } | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3860 |         checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3861 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3862 |         try { | 
 | 3863 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3864 |             if (!isImsProvisioningRequired(subId, capability, true)) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3865 |                 return; | 
 | 3866 |             } | 
 | 3867 |  | 
 | 3868 |             // this capability requires provisioning, route to the correct API. | 
 | 3869 |             ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); | 
 | 3870 |             switch (capability) { | 
 | 3871 |                 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { | 
 | 3872 |                     if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
 | 3873 |                         ims.setVolteProvisioned(isProvisioned); | 
 | 3874 |                     } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { | 
 | 3875 |                         ims.setWfcProvisioned(isProvisioned); | 
 | 3876 |                     } | 
 | 3877 |                     break; | 
 | 3878 |                 } | 
 | 3879 |                 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { | 
 | 3880 |                     // There is currently no difference in VT provisioning type. | 
 | 3881 |                     ims.setVtProvisioned(isProvisioned); | 
 | 3882 |                     break; | 
 | 3883 |                 } | 
 | 3884 |                 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { | 
 | 3885 |                     // There is no "deprecated" UT provisioning mechanism through ImsConfig, so | 
 | 3886 |                     // change the capability of the feature instead if needed. | 
 | 3887 |                     if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) | 
 | 3888 |                             == isProvisioned) { | 
 | 3889 |                         // No change in provisioning. | 
 | 3890 |                         return; | 
 | 3891 |                     } | 
 | 3892 |                     cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); | 
 | 3893 |                     try { | 
 | 3894 |                         ims.changeMmTelCapability(capability, tech, isProvisioned); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3895 |                     } catch (com.android.ims.ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3896 |                         loge("setImsProvisioningStatusForCapability: couldn't change UT capability" | 
 | 3897 |                                 + ", Exception" + e.getMessage()); | 
 | 3898 |                     } | 
 | 3899 |                     break; | 
 | 3900 |                 } | 
 | 3901 |                 default: { | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3902 |                     throw new IllegalArgumentException("Tried to set provisioning for " | 
 | 3903 |                             + "MmTel capability '" + capability + "', which does not require " | 
 | 3904 |                             + "provisioning. "); | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3905 |                 } | 
 | 3906 |             } | 
 | 3907 |  | 
 | 3908 |         } finally { | 
 | 3909 |             Binder.restoreCallingIdentity(identity); | 
 | 3910 |         } | 
 | 3911 |     } | 
 | 3912 |  | 
 | 3913 |     @Override | 
 | 3914 |     public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { | 
 | 3915 |         if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN | 
 | 3916 |                 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
 | 3917 |             throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); | 
 | 3918 |         } | 
 | 3919 |         enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); | 
 | 3920 |         final long identity = Binder.clearCallingIdentity(); | 
 | 3921 |         try { | 
 | 3922 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3923 |             if (!isImsProvisioningRequired(subId, capability, true)) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3924 |                 return true; | 
 | 3925 |             } | 
 | 3926 |  | 
 | 3927 |             ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); | 
 | 3928 |             switch (capability) { | 
 | 3929 |                 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { | 
 | 3930 |                     if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
 | 3931 |                         return ims.isVolteProvisionedOnDevice(); | 
 | 3932 |                     } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { | 
 | 3933 |                         return ims.isWfcProvisionedOnDevice(); | 
 | 3934 |                     } | 
 | 3935 |                     // This should never happen, since we are checking tech above to make sure it | 
 | 3936 |                     // is either LTE or IWLAN. | 
 | 3937 |                     throw new IllegalArgumentException("Invalid radio technology for voice " | 
 | 3938 |                             + "capability."); | 
 | 3939 |                 } | 
 | 3940 |                 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { | 
 | 3941 |                     // There is currently no difference in VT provisioning type. | 
 | 3942 |                     return ims.isVtProvisionedOnDevice(); | 
 | 3943 |                 } | 
 | 3944 |                 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { | 
 | 3945 |                     // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. | 
 | 3946 |                     return isMmTelCapabilityProvisionedInCache(subId, capability, tech); | 
 | 3947 |                 } | 
 | 3948 |                 default: { | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3949 |                     throw new IllegalArgumentException( | 
 | 3950 |                             "Tried to get provisioning for MmTel capability '" + capability | 
 | 3951 |                                     + "', which does not require provisioning."); | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3952 |                 } | 
 | 3953 |             } | 
 | 3954 |  | 
 | 3955 |         } finally { | 
 | 3956 |             Binder.restoreCallingIdentity(identity); | 
 | 3957 |         } | 
 | 3958 |     } | 
 | 3959 |  | 
 | 3960 |     @Override | 
 | 3961 |     public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { | 
 | 3962 |         if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN | 
 | 3963 |                 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
 | 3964 |             throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); | 
 | 3965 |         } | 
 | 3966 |         enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); | 
 | 3967 |         int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); | 
 | 3968 |         return (provisionedBits & capability) > 0; | 
 | 3969 |     } | 
 | 3970 |  | 
 | 3971 |     @Override | 
 | 3972 |     public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, | 
 | 3973 |             boolean isProvisioned) { | 
 | 3974 |         if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN | 
 | 3975 |                 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
 | 3976 |             throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); | 
 | 3977 |         } | 
 | 3978 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
 | 3979 |                 "setProvisioningStatusForCapability"); | 
 | 3980 |         int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); | 
 | 3981 |         // If the current provisioning status for capability already matches isProvisioned, | 
 | 3982 |         // do nothing. | 
 | 3983 |         if (((provisionedBits & capability) > 0) == isProvisioned) { | 
 | 3984 |             return; | 
 | 3985 |         } | 
 | 3986 |         if (isProvisioned) { | 
 | 3987 |             setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); | 
 | 3988 |         } else { | 
 | 3989 |             setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); | 
 | 3990 |         } | 
 | 3991 |     } | 
 | 3992 |  | 
 | 3993 |     /** | 
 | 3994 |      * @return the bitfield containing the MmTel provisioning for the provided subscription and | 
 | 3995 |      * technology. The bitfield should mirror the bitfield defined by | 
 | 3996 |      * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. | 
 | 3997 |      */ | 
 | 3998 |     private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { | 
 | 3999 |         String key = getMmTelProvisioningKey(subId, tech); | 
 | 4000 |         // Default is no capabilities are provisioned. | 
 | 4001 |         return mTelephonySharedPreferences.getInt(key, 0 /*default*/); | 
 | 4002 |     } | 
 | 4003 |  | 
 | 4004 |     /** | 
 | 4005 |      * Sets the MmTel capability provisioning bitfield (defined by | 
 | 4006 |      *     {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and | 
 | 4007 |      *     technology specified. | 
 | 4008 |      * | 
 | 4009 |      * Note: This is a synchronous command and should not be called on UI thread. | 
 | 4010 |      */ | 
 | 4011 |     private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { | 
 | 4012 |         final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); | 
 | 4013 |         String key = getMmTelProvisioningKey(subId, tech); | 
 | 4014 |         editor.putInt(key, newField); | 
 | 4015 |         editor.commit(); | 
 | 4016 |     } | 
 | 4017 |  | 
 | 4018 |     private static String getMmTelProvisioningKey(int subId, int tech) { | 
 | 4019 |         // resulting key is provision_ims_mmtel_{subId}_{tech} | 
 | 4020 |         return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; | 
 | 4021 |     } | 
 | 4022 |  | 
 | 4023 |     /** | 
 | 4024 |      * Query CarrierConfig to see if the specified capability requires provisioning for the | 
 | 4025 |      * carrier associated with the subscription id. | 
 | 4026 |      */ | 
 | 4027 |     private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, | 
 | 4028 |             int capability) { | 
 | 4029 |         CarrierConfigManager configManager = new CarrierConfigManager(context); | 
 | 4030 |         PersistableBundle c = configManager.getConfigForSubId(subId); | 
 | 4031 |         boolean requireUtProvisioning = c.getBoolean( | 
| Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4032 |                 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4033 |                 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, | 
 | 4034 |                 false); | 
 | 4035 |         boolean requireVoiceVtProvisioning = c.getBoolean( | 
 | 4036 |                 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); | 
 | 4037 |  | 
 | 4038 |         // First check to make sure that the capability requires provisioning. | 
 | 4039 |         switch (capability) { | 
 | 4040 |             case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: | 
 | 4041 |                 // intentional fallthrough | 
 | 4042 |             case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { | 
 | 4043 |                 if (requireVoiceVtProvisioning) { | 
 | 4044 |                     // Voice and Video requires provisioning | 
 | 4045 |                     return true; | 
 | 4046 |                 } | 
 | 4047 |                 break; | 
 | 4048 |             } | 
 | 4049 |             case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { | 
 | 4050 |                 if (requireUtProvisioning) { | 
 | 4051 |                     // UT requires provisioning | 
 | 4052 |                     return true; | 
 | 4053 |                 } | 
 | 4054 |                 break; | 
 | 4055 |             } | 
 | 4056 |         } | 
 | 4057 |         return false; | 
 | 4058 |     } | 
 | 4059 |  | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4060 |     private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, | 
 | 4061 |             int capability) { | 
 | 4062 |         CarrierConfigManager configManager = new CarrierConfigManager(context); | 
 | 4063 |         PersistableBundle c = configManager.getConfigForSubId(subId); | 
 | 4064 |  | 
 | 4065 |         boolean requireRcsProvisioning = c.getBoolean( | 
 | 4066 |                 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); | 
 | 4067 |  | 
 | 4068 |         // First check to make sure that the capability requires provisioning. | 
 | 4069 |         switch (capability) { | 
 | 4070 |             case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: | 
 | 4071 |                 // intentional fallthrough | 
 | 4072 |             case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { | 
 | 4073 |                 if (requireRcsProvisioning) { | 
 | 4074 |                     // OPTION or PRESENCE requires provisioning | 
 | 4075 |                     return true; | 
 | 4076 |                 } | 
 | 4077 |                 break; | 
 | 4078 |             } | 
 | 4079 |         } | 
 | 4080 |         return false; | 
 | 4081 |     } | 
 | 4082 |  | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4083 |     @Override | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4084 |     public int getImsProvisioningInt(int subId, int key) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4085 |         if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
 | 4086 |             throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
 | 4087 |         } | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4088 |         enforceReadPrivilegedPermission("getImsProvisioningInt"); | 
 | 4089 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4090 |         try { | 
 | 4091 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4092 |             int slotId = getSlotIndex(subId); | 
 | 4093 |             if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
 | 4094 |                 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" | 
 | 4095 |                         + subId + "' for key:" + key); | 
 | 4096 |                 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; | 
 | 4097 |             } | 
 | 4098 |             return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4099 |         } catch (com.android.ims.ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4100 |             Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" | 
 | 4101 |                     + subId + "' for key:" + key); | 
 | 4102 |             return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4103 |         } finally { | 
 | 4104 |             Binder.restoreCallingIdentity(identity); | 
 | 4105 |         } | 
 | 4106 |     } | 
 | 4107 |  | 
 | 4108 |     @Override | 
 | 4109 |     public String getImsProvisioningString(int subId, int key) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4110 |         if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
 | 4111 |             throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
 | 4112 |         } | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4113 |         enforceReadPrivilegedPermission("getImsProvisioningString"); | 
 | 4114 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4115 |         try { | 
 | 4116 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4117 |             int slotId = getSlotIndex(subId); | 
 | 4118 |             if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
 | 4119 |                 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" | 
 | 4120 |                         + subId + "' for key:" + key); | 
 | 4121 |                 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; | 
 | 4122 |             } | 
 | 4123 |             return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4124 |         } catch (com.android.ims.ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4125 |             Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" | 
 | 4126 |                     + subId + "' for key:" + key); | 
 | 4127 |             return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4128 |         } finally { | 
 | 4129 |             Binder.restoreCallingIdentity(identity); | 
 | 4130 |         } | 
 | 4131 |     } | 
 | 4132 |  | 
 | 4133 |     @Override | 
 | 4134 |     public int setImsProvisioningInt(int subId, int key, int value) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4135 |         if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
 | 4136 |             throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
 | 4137 |         } | 
| Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4138 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
 | 4139 |                 "setImsProvisioningInt"); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4140 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4141 |         try { | 
 | 4142 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4143 |             int slotId = getSlotIndex(subId); | 
 | 4144 |             if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
 | 4145 |                 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" | 
 | 4146 |                         + subId + "' for key:" + key); | 
 | 4147 |                 return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
 | 4148 |             } | 
 | 4149 |             return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4150 |         } catch (com.android.ims.ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4151 |             Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId | 
 | 4152 |                     + "' for key:" + key); | 
 | 4153 |             return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4154 |         } finally { | 
 | 4155 |             Binder.restoreCallingIdentity(identity); | 
 | 4156 |         } | 
 | 4157 |     } | 
 | 4158 |  | 
 | 4159 |     @Override | 
 | 4160 |     public int setImsProvisioningString(int subId, int key, String value) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4161 |         if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
 | 4162 |             throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
 | 4163 |         } | 
| Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4164 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
 | 4165 |                 "setImsProvisioningString"); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4166 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4167 |         try { | 
 | 4168 |             // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4169 |             int slotId = getSlotIndex(subId); | 
 | 4170 |             if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
 | 4171 |                 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" | 
 | 4172 |                         + subId + "' for key:" + key); | 
 | 4173 |                 return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
 | 4174 |             } | 
 | 4175 |             return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4176 |         } catch (com.android.ims.ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4177 |             Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId | 
 | 4178 |                     + "' for key:" + key); | 
 | 4179 |             return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4180 |         } finally { | 
 | 4181 |             Binder.restoreCallingIdentity(identity); | 
 | 4182 |         } | 
 | 4183 |     } | 
 | 4184 |  | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4185 |     private int getSlotIndexOrException(int subId) throws ImsException { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4186 |         int slotId = SubscriptionManager.getSlotIndex(subId); | 
 | 4187 |         if (!SubscriptionManager.isValidSlotIndex(slotId)) { | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4188 |             throw new ImsException("Invalid Subscription Id, subId=" + subId, | 
 | 4189 |                     ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4190 |         } | 
 | 4191 |         return slotId; | 
 | 4192 |     } | 
 | 4193 |  | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4194 |     private int getSlotIndex(int subId) { | 
 | 4195 |         int slotId = SubscriptionManager.getSlotIndex(subId); | 
 | 4196 |         if (!SubscriptionManager.isValidSlotIndex(slotId)) { | 
 | 4197 |             return SubscriptionManager.INVALID_SIM_SLOT_INDEX; | 
 | 4198 |         } | 
 | 4199 |         return slotId; | 
 | 4200 |     } | 
 | 4201 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4202 |     /** | 
| Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4203 |      * Returns the data network type for a subId; does not throw SecurityException. | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4204 |      */ | 
 | 4205 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4206 |     public int getNetworkTypeForSubscriber(int subId, String callingPackage, | 
 | 4207 |             String callingFeatureId) { | 
| Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4208 |         final int targetSdk = getTargetSdk(callingPackage); | 
 | 4209 |         if (targetSdk > android.os.Build.VERSION_CODES.Q) { | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4210 |             return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); | 
| Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4211 |         } else if (targetSdk == android.os.Build.VERSION_CODES.Q | 
| Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4212 |                 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4213 |                         mApp, subId, callingPackage, callingFeatureId, | 
 | 4214 |                 "getNetworkTypeForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4215 |             return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
 | 4216 |         } | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4217 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4218 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4219 |         try { | 
 | 4220 |             final Phone phone = getPhone(subId); | 
 | 4221 |             if (phone != null) { | 
 | 4222 |                 return phone.getServiceState().getDataNetworkType(); | 
 | 4223 |             } else { | 
 | 4224 |                 return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
 | 4225 |             } | 
 | 4226 |         } finally { | 
 | 4227 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4228 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4229 |     } | 
 | 4230 |  | 
 | 4231 |     /** | 
 | 4232 |      * Returns the data network type | 
 | 4233 |      */ | 
 | 4234 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4235 |     public int getDataNetworkType(String callingPackage, String callingFeatureId) { | 
 | 4236 |         return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, | 
 | 4237 |                 callingFeatureId); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4238 |     } | 
 | 4239 |  | 
 | 4240 |     /** | 
 | 4241 |      * Returns the data network type for a subId | 
 | 4242 |      */ | 
 | 4243 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4244 |     public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, | 
 | 4245 |             String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4246 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4247 |                 mApp, subId, callingPackage, callingFeatureId, | 
 | 4248 |                 "getDataNetworkTypeForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4249 |             return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
 | 4250 |         } | 
 | 4251 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4252 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4253 |         try { | 
 | 4254 |             final Phone phone = getPhone(subId); | 
 | 4255 |             if (phone != null) { | 
 | 4256 |                 return phone.getServiceState().getDataNetworkType(); | 
 | 4257 |             } else { | 
 | 4258 |                 return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
 | 4259 |             } | 
 | 4260 |         } finally { | 
 | 4261 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4262 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4263 |     } | 
 | 4264 |  | 
 | 4265 |     /** | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4266 |      * Returns the Voice network type for a subId | 
 | 4267 |      */ | 
 | 4268 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4269 |     public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, | 
 | 4270 |             String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4271 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4272 |                 mApp, subId, callingPackage, callingFeatureId, | 
 | 4273 |                 "getDataNetworkTypeForSubscriber")) { | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4274 |             return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
 | 4275 |         } | 
 | 4276 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4277 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4278 |         try { | 
 | 4279 |             final Phone phone = getPhone(subId); | 
 | 4280 |             if (phone != null) { | 
 | 4281 |                 return phone.getServiceState().getVoiceNetworkType(); | 
 | 4282 |             } else { | 
 | 4283 |                 return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
 | 4284 |             } | 
 | 4285 |         } finally { | 
 | 4286 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4287 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4288 |     } | 
 | 4289 |  | 
 | 4290 |     /** | 
 | 4291 |      * @return true if a ICC card is present | 
 | 4292 |      */ | 
 | 4293 |     public boolean hasIccCard() { | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4294 |         // FIXME Make changes to pass defaultSimId of type int | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4295 |         return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( | 
 | 4296 |                 getDefaultSubscription())); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4297 |     } | 
 | 4298 |  | 
 | 4299 |     /** | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4300 |      * @return true if a ICC card is present for a slotIndex | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4301 |      */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4302 |     @Override | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4303 |     public boolean hasIccCardUsingSlotIndex(int slotIndex) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4304 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4305 |         try { | 
 | 4306 |             final Phone phone = PhoneFactory.getPhone(slotIndex); | 
 | 4307 |             if (phone != null) { | 
 | 4308 |                 return phone.getIccCard().hasIccCard(); | 
 | 4309 |             } else { | 
 | 4310 |                 return false; | 
 | 4311 |             } | 
 | 4312 |         } finally { | 
 | 4313 |             Binder.restoreCallingIdentity(identity); | 
| Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4314 |         } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4315 |     } | 
 | 4316 |  | 
 | 4317 |     /** | 
 | 4318 |      * Return if the current radio is LTE on CDMA. This | 
 | 4319 |      * is a tri-state return value as for a period of time | 
 | 4320 |      * the mode may be unknown. | 
 | 4321 |      * | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4322 |      * @param callingPackage the name of the package making the call. | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4323 |      * @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] | 4324 |      * or {@link Phone#LTE_ON_CDMA_TRUE} | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4325 |      */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4326 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4327 |     public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { | 
 | 4328 |         return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, | 
 | 4329 |                 callingFeatureId); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4330 |     } | 
 | 4331 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4332 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4333 |     public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, | 
 | 4334 |             String callingFeatureId) { | 
| Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4335 |         try { | 
 | 4336 |             enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); | 
 | 4337 |         } catch (SecurityException e) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4338 |             return PhoneConstants.LTE_ON_CDMA_UNKNOWN; | 
 | 4339 |         } | 
 | 4340 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4341 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4342 |         try { | 
 | 4343 |             final Phone phone = getPhone(subId); | 
 | 4344 |             if (phone == null) { | 
 | 4345 |                 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; | 
 | 4346 |             } else { | 
 | 4347 |                 return phone.getLteOnCdmaMode(); | 
 | 4348 |             } | 
 | 4349 |         } finally { | 
 | 4350 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4351 |         } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4352 |     } | 
 | 4353 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4354 |     /** | 
 | 4355 |      * {@hide} | 
 | 4356 |      * Returns Default subId, 0 in the case of single standby. | 
 | 4357 |      */ | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4358 |     private int getDefaultSubscription() { | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4359 |         return mSubscriptionController.getDefaultSubId(); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4360 |     } | 
 | 4361 |  | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4362 |     private int getSlotForDefaultSubscription() { | 
 | 4363 |         return mSubscriptionController.getPhoneId(getDefaultSubscription()); | 
 | 4364 |     } | 
 | 4365 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4366 |     private int getPreferredVoiceSubscription() { | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4367 |         return mSubscriptionController.getDefaultVoiceSubId(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4368 |     } | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4369 |  | 
| Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4370 |     private boolean isActiveSubscription(int subId) { | 
 | 4371 |         return mSubscriptionController.isActiveSubId(subId); | 
 | 4372 |     } | 
 | 4373 |  | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4374 |     /** | 
 | 4375 |      * @see android.telephony.TelephonyManager.WifiCallingChoices | 
 | 4376 |      */ | 
 | 4377 |     public int getWhenToMakeWifiCalls() { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4378 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4379 |         try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4380 |             return Settings.System.getInt(mApp.getContentResolver(), | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4381 |                     Settings.System.WHEN_TO_MAKE_WIFI_CALLS, | 
 | 4382 |                     getWhenToMakeWifiCallsDefaultPreference()); | 
 | 4383 |         } finally { | 
 | 4384 |             Binder.restoreCallingIdentity(identity); | 
 | 4385 |         } | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4386 |     } | 
 | 4387 |  | 
 | 4388 |     /** | 
 | 4389 |      * @see android.telephony.TelephonyManager.WifiCallingChoices | 
 | 4390 |      */ | 
 | 4391 |     public void setWhenToMakeWifiCalls(int preference) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4392 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4393 |         try { | 
 | 4394 |             if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4395 |             Settings.System.putInt(mApp.getContentResolver(), | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4396 |                     Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); | 
 | 4397 |         } finally { | 
 | 4398 |             Binder.restoreCallingIdentity(identity); | 
 | 4399 |         } | 
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4400 |     } | 
 | 4401 |  | 
| Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4402 |     private static int getWhenToMakeWifiCallsDefaultPreference() { | 
| Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4403 |         // TODO: Use a build property to choose this value. | 
| Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4404 |         return TelephonyManager.WifiCallingChoices.ALWAYS_USE; | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4405 |     } | 
| Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4406 |  | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4407 |     private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { | 
 | 4408 |         int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); | 
 | 4409 |         if (phoneId == -1) { | 
 | 4410 |             throw new IllegalArgumentException("Given slot index: " + slotIndex | 
 | 4411 |                     + " does not correspond to an active phone"); | 
 | 4412 |         } | 
 | 4413 |         return PhoneFactory.getPhone(phoneId); | 
 | 4414 |     } | 
 | 4415 |  | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4416 |     @Override | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4417 |     public IccOpenLogicalChannelResponse iccOpenLogicalChannel( | 
 | 4418 |             int subId, String callingPackage, String aid, int p2) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4419 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 4420 |                 mApp, subId, "iccOpenLogicalChannel"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4421 |         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4422 |         if (DBG) { | 
 | 4423 |             log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); | 
 | 4424 |         } | 
 | 4425 |         return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, | 
 | 4426 |                 p2); | 
 | 4427 |     } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4428 |  | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4429 |  | 
 | 4430 |     @Override | 
 | 4431 |     public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( | 
 | 4432 |             int slotIndex, String callingPackage, String aid, int p2) { | 
 | 4433 |         enforceModifyPermission(); | 
 | 4434 |         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
 | 4435 |         if (DBG) { | 
 | 4436 |             log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); | 
 | 4437 |         } | 
 | 4438 |         return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), | 
 | 4439 |                 callingPackage, aid, p2); | 
 | 4440 |     } | 
 | 4441 |  | 
 | 4442 |     private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, | 
 | 4443 |             String callingPackage, String aid, int p2) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4444 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4445 |         try { | 
 | 4446 |             if (TextUtils.equals(ISDR_AID, aid)) { | 
 | 4447 |                 // Only allows LPA to open logical channel to ISD-R. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4448 |                 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() | 
 | 4449 |                         .getContext().getPackageManager()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4450 |                 if (bestComponent == null | 
 | 4451 |                         || !TextUtils.equals(callingPackage, bestComponent.packageName)) { | 
 | 4452 |                     loge("The calling package is not allowed to access ISD-R."); | 
 | 4453 |                     throw new SecurityException( | 
 | 4454 |                             "The calling package is not allowed to access ISD-R."); | 
 | 4455 |                 } | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4456 |             } | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4457 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4458 |             IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4459 |                     CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, | 
 | 4460 |                     null /* workSource */); | 
 | 4461 |             if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4462 |             return response; | 
 | 4463 |         } finally { | 
 | 4464 |             Binder.restoreCallingIdentity(identity); | 
 | 4465 |         } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4466 |     } | 
 | 4467 |  | 
 | 4468 |     @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4469 |     public boolean iccCloseLogicalChannel(int subId, int channel) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4470 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 4471 |                 mApp, subId, "iccCloseLogicalChannel"); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4472 |         if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); | 
 | 4473 |         return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); | 
 | 4474 |     } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4475 |  | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4476 |     @Override | 
 | 4477 |     public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { | 
 | 4478 |         enforceModifyPermission(); | 
 | 4479 |         if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); | 
 | 4480 |         return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), | 
 | 4481 |                 channel); | 
 | 4482 |     } | 
 | 4483 |  | 
 | 4484 |     private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4485 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4486 |         try { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4487 |             if (channel < 0) { | 
 | 4488 |                 return false; | 
 | 4489 |             } | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4490 |             Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, | 
 | 4491 |                     null /* workSource */); | 
 | 4492 |             if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4493 |             return success; | 
 | 4494 |         } finally { | 
 | 4495 |             Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4496 |         } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4497 |     } | 
 | 4498 |  | 
 | 4499 |     @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4500 |     public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4501 |             int command, int p1, int p2, int p3, String data) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4502 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 4503 |                 mApp, subId, "iccTransmitApduLogicalChannel"); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4504 |         if (DBG) { | 
 | 4505 |             log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel | 
 | 4506 |                     + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" | 
 | 4507 |                     + p3 + " data=" + data); | 
 | 4508 |         } | 
 | 4509 |         return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, | 
 | 4510 |                 command, p1, p2, p3, data); | 
 | 4511 |     } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4512 |  | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4513 |     @Override | 
 | 4514 |     public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, | 
 | 4515 |             int command, int p1, int p2, int p3, String data) { | 
 | 4516 |         enforceModifyPermission(); | 
 | 4517 |         if (DBG) { | 
 | 4518 |             log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel | 
 | 4519 |                     + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" | 
 | 4520 |                     + p3 + " data=" + data); | 
 | 4521 |         } | 
 | 4522 |         return iccTransmitApduLogicalChannelWithPermission( | 
 | 4523 |                 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, | 
 | 4524 |                 data); | 
 | 4525 |     } | 
 | 4526 |  | 
 | 4527 |     private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, | 
 | 4528 |             int command, int p1, int p2, int p3, String data) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4529 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4530 |         try { | 
| Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4531 |             if (channel <= 0) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4532 |                 return ""; | 
 | 4533 |             } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4534 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4535 |             IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4536 |                     new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, | 
 | 4537 |                     null /* workSource */); | 
 | 4538 |             if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4539 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4540 |             // Append the returned status code to the end of the response payload. | 
 | 4541 |             String s = Integer.toHexString( | 
 | 4542 |                     (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); | 
 | 4543 |             if (response.payload != null) { | 
 | 4544 |                 s = IccUtils.bytesToHexString(response.payload) + s; | 
 | 4545 |             } | 
 | 4546 |             return s; | 
 | 4547 |         } finally { | 
 | 4548 |             Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4549 |         } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4550 |     } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4551 |  | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4552 |     @Override | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4553 |     public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, | 
 | 4554 |             int command, int p1, int p2, int p3, String data) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4555 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 4556 |                 mApp, subId, "iccTransmitApduBasicChannel"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4557 |         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4558 |         if (DBG) { | 
 | 4559 |             log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" | 
 | 4560 |                     + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); | 
 | 4561 |         } | 
 | 4562 |         return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, | 
 | 4563 |                 cla, command, p1, p2, p3, data); | 
 | 4564 |     } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4565 |  | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4566 |     @Override | 
 | 4567 |     public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, | 
 | 4568 |             int command, int p1, int p2, int p3, String data) { | 
 | 4569 |         enforceModifyPermission(); | 
 | 4570 |         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
 | 4571 |         if (DBG) { | 
 | 4572 |             log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla | 
 | 4573 |                     + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 | 
 | 4574 |                     + " data=" + data); | 
 | 4575 |         } | 
 | 4576 |  | 
 | 4577 |         return iccTransmitApduBasicChannelWithPermission( | 
 | 4578 |                 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, | 
 | 4579 |                 p2, p3, data); | 
 | 4580 |     } | 
 | 4581 |  | 
 | 4582 |     // open APDU basic channel assuming the caller has sufficient permissions | 
 | 4583 |     private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, | 
 | 4584 |             int cla, int command, int p1, int p2, int p3, String data) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4585 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4586 |         try { | 
 | 4587 |             if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 | 
 | 4588 |                     && TextUtils.equals(ISDR_AID, data)) { | 
 | 4589 |                 // Only allows LPA to select ISD-R. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4590 |                 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() | 
 | 4591 |                         .getContext().getPackageManager()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4592 |                 if (bestComponent == null | 
 | 4593 |                         || !TextUtils.equals(callingPackage, bestComponent.packageName)) { | 
 | 4594 |                     loge("The calling package is not allowed to select ISD-R."); | 
 | 4595 |                     throw new SecurityException( | 
 | 4596 |                             "The calling package is not allowed to select ISD-R."); | 
 | 4597 |                 } | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4598 |             } | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4599 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4600 |             IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4601 |                     new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, | 
 | 4602 |                     null /* workSource */); | 
 | 4603 |             if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4604 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4605 |             // Append the returned status code to the end of the response payload. | 
 | 4606 |             String s = Integer.toHexString( | 
 | 4607 |                     (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); | 
 | 4608 |             if (response.payload != null) { | 
 | 4609 |                 s = IccUtils.bytesToHexString(response.payload) + s; | 
 | 4610 |             } | 
 | 4611 |             return s; | 
 | 4612 |         } finally { | 
 | 4613 |             Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4614 |         } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4615 |     } | 
 | 4616 |  | 
 | 4617 |     @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4618 |     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] | 4619 |             String filePath) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4620 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 4621 |                 mApp, subId, "iccExchangeSimIO"); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4622 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4623 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4624 |         try { | 
 | 4625 |             if (DBG) { | 
 | 4626 |                 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " | 
 | 4627 |                         + p1 + " " + p2 + " " + p3 + ":" + filePath); | 
 | 4628 |             } | 
 | 4629 |  | 
 | 4630 |             IccIoResult response = | 
 | 4631 |                     (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, | 
 | 4632 |                             new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), | 
 | 4633 |                             subId); | 
 | 4634 |  | 
 | 4635 |             if (DBG) { | 
 | 4636 |                 log("Exchange SIM_IO [R]" + response); | 
 | 4637 |             } | 
 | 4638 |  | 
 | 4639 |             byte[] result = null; | 
 | 4640 |             int length = 2; | 
 | 4641 |             if (response.payload != null) { | 
 | 4642 |                 length = 2 + response.payload.length; | 
 | 4643 |                 result = new byte[length]; | 
 | 4644 |                 System.arraycopy(response.payload, 0, result, 0, response.payload.length); | 
 | 4645 |             } else { | 
 | 4646 |                 result = new byte[length]; | 
 | 4647 |             } | 
 | 4648 |  | 
 | 4649 |             result[length - 1] = (byte) response.sw2; | 
 | 4650 |             result[length - 2] = (byte) response.sw1; | 
 | 4651 |             return result; | 
 | 4652 |         } finally { | 
 | 4653 |             Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4654 |         } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4655 |     } | 
 | 4656 |  | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4657 |     /** | 
 | 4658 |      * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) | 
 | 4659 |      * on a particular subscription | 
 | 4660 |      */ | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4661 |     public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, | 
 | 4662 |             String callingFeatureId) { | 
| sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4663 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4664 |                 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { | 
| sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4665 |             return null; | 
 | 4666 |         } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4667 |  | 
 | 4668 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4669 |         try { | 
 | 4670 |             if (appType != TelephonyManager.APPTYPE_USIM | 
 | 4671 |                     && appType != TelephonyManager.APPTYPE_SIM) { | 
 | 4672 |                 loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); | 
 | 4673 |                 return null; | 
 | 4674 |             } | 
 | 4675 |             Object response = sendRequest( | 
 | 4676 |                     CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); | 
 | 4677 |             if (response instanceof String[]) { | 
 | 4678 |                 return (String[]) response; | 
 | 4679 |             } | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4680 |             // Response is an Exception of some kind | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4681 |             // which is signalled to the user as a NULL retval | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4682 |             return null; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4683 |         } finally { | 
 | 4684 |             Binder.restoreCallingIdentity(identity); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4685 |         } | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4686 |     } | 
 | 4687 |  | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4688 |     /** | 
 | 4689 |      * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular | 
 | 4690 |      * subscription. | 
 | 4691 |      * | 
 | 4692 |      * @param subId the id of the subscription. | 
 | 4693 |      * @param appType the uicc app type, must be USIM or SIM. | 
 | 4694 |      * @param fplmns the Forbiden plmns list that needed to be written to the SIM. | 
 | 4695 |      * @param callingPackage the op Package name. | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4696 |      * @param callingFeatureId the feature in the package. | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4697 |      * @return number of fplmns that is successfully written to the SIM. | 
 | 4698 |      */ | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4699 |     public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, | 
 | 4700 |             String callingFeatureId) { | 
 | 4701 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, | 
 | 4702 |                 callingFeatureId, "setForbiddenPlmns")) { | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4703 |             if (DBG) logv("no permissions for setForbiddenplmns"); | 
 | 4704 |             throw new IllegalStateException("No Permissions for setForbiddenPlmns"); | 
 | 4705 |         } | 
 | 4706 |         if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { | 
 | 4707 |             loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); | 
 | 4708 |             throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); | 
 | 4709 |         } | 
 | 4710 |         if (fplmns == null) { | 
 | 4711 |             throw new IllegalArgumentException("Fplmn List provided is null"); | 
 | 4712 |         } | 
 | 4713 |         for (String fplmn : fplmns) { | 
 | 4714 |             if (!CellIdentity.isValidPlmn(fplmn)) { | 
 | 4715 |                 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); | 
 | 4716 |             } | 
 | 4717 |         } | 
 | 4718 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4719 |         try { | 
 | 4720 |             Object response = sendRequest( | 
 | 4721 |                     CMD_SET_FORBIDDEN_PLMNS, | 
 | 4722 |                     new Pair<Integer, List<String>>(new Integer(appType), fplmns), | 
 | 4723 |                     subId); | 
 | 4724 |             return (int) response; | 
 | 4725 |         } finally { | 
 | 4726 |             Binder.restoreCallingIdentity(identity); | 
 | 4727 |         } | 
 | 4728 |     } | 
 | 4729 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4730 |     @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4731 |     public String sendEnvelopeWithStatus(int subId, String content) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4732 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 4733 |                 mApp, subId, "sendEnvelopeWithStatus"); | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4734 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4735 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4736 |         try { | 
 | 4737 |             IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); | 
 | 4738 |             if (response.payload == null) { | 
 | 4739 |                 return ""; | 
 | 4740 |             } | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4741 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4742 |             // Append the returned status code to the end of the response payload. | 
 | 4743 |             String s = Integer.toHexString( | 
 | 4744 |                     (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); | 
 | 4745 |             s = IccUtils.bytesToHexString(response.payload) + s; | 
 | 4746 |             return s; | 
 | 4747 |         } finally { | 
 | 4748 |             Binder.restoreCallingIdentity(identity); | 
 | 4749 |         } | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4750 |     } | 
 | 4751 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4752 |     /** | 
 | 4753 |      * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} | 
 | 4754 |      * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. | 
 | 4755 |      * | 
 | 4756 |      * @param itemID the ID of the item to read | 
 | 4757 |      * @return the NV item as a String, or null on error. | 
 | 4758 |      */ | 
 | 4759 |     @Override | 
 | 4760 |     public String nvReadItem(int itemID) { | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4761 |         WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4762 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 4763 |                 mApp, getDefaultSubscription(), "nvReadItem"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4764 |  | 
 | 4765 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4766 |         try { | 
 | 4767 |             if (DBG) log("nvReadItem: item " + itemID); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4768 |             String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4769 |             if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); | 
 | 4770 |             return value; | 
 | 4771 |         } finally { | 
 | 4772 |             Binder.restoreCallingIdentity(identity); | 
 | 4773 |         } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4774 |     } | 
 | 4775 |  | 
 | 4776 |     /** | 
 | 4777 |      * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} | 
 | 4778 |      * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. | 
 | 4779 |      * | 
 | 4780 |      * @param itemID the ID of the item to read | 
 | 4781 |      * @param itemValue the value to write, as a String | 
 | 4782 |      * @return true on success; false on any failure | 
 | 4783 |      */ | 
 | 4784 |     @Override | 
 | 4785 |     public boolean nvWriteItem(int itemID, String itemValue) { | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4786 |         WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4787 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 4788 |                 mApp, getDefaultSubscription(), "nvWriteItem"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4789 |  | 
 | 4790 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4791 |         try { | 
 | 4792 |             if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); | 
 | 4793 |             Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4794 |                     new Pair<Integer, String>(itemID, itemValue), workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4795 |             if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); | 
 | 4796 |             return success; | 
 | 4797 |         } finally { | 
 | 4798 |             Binder.restoreCallingIdentity(identity); | 
 | 4799 |         } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4800 |     } | 
 | 4801 |  | 
 | 4802 |     /** | 
 | 4803 |      * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. | 
 | 4804 |      * Used for device configuration by some CDMA operators. | 
 | 4805 |      * | 
 | 4806 |      * @param preferredRoamingList byte array containing the new PRL | 
 | 4807 |      * @return true on success; false on any failure | 
 | 4808 |      */ | 
 | 4809 |     @Override | 
 | 4810 |     public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4811 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 4812 |                 mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4813 |  | 
 | 4814 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4815 |         try { | 
 | 4816 |             if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); | 
 | 4817 |             Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); | 
 | 4818 |             if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); | 
 | 4819 |             return success; | 
 | 4820 |         } finally { | 
 | 4821 |             Binder.restoreCallingIdentity(identity); | 
 | 4822 |         } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4823 |     } | 
 | 4824 |  | 
 | 4825 |     /** | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4826 |      * 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] | 4827 |      * Used for device configuration by some CDMA operators. | 
 | 4828 |      * | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4829 |      * @param slotIndex - device slot. | 
 | 4830 |      * | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4831 |      * @return true on success; false on any failure | 
 | 4832 |      */ | 
 | 4833 |     @Override | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4834 |     public boolean resetModemConfig(int slotIndex) { | 
 | 4835 |         Phone phone = PhoneFactory.getPhone(slotIndex); | 
 | 4836 |         if (phone != null) { | 
 | 4837 |             TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 4838 |                     mApp, phone.getSubId(), "resetModemConfig"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4839 |  | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4840 |             final long identity = Binder.clearCallingIdentity(); | 
 | 4841 |             try { | 
 | 4842 |                 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); | 
 | 4843 |                 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); | 
 | 4844 |                 return success; | 
 | 4845 |             } finally { | 
 | 4846 |                 Binder.restoreCallingIdentity(identity); | 
 | 4847 |             } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4848 |         } | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4849 |         return false; | 
 | 4850 |     } | 
 | 4851 |  | 
 | 4852 |     /** | 
 | 4853 |      * Generate a radio modem reset. Used for device configuration by some CDMA operators. | 
 | 4854 |      * | 
 | 4855 |      * @param slotIndex - device slot. | 
 | 4856 |      * | 
 | 4857 |      * @return true on success; false on any failure | 
 | 4858 |      */ | 
 | 4859 |     @Override | 
 | 4860 |     public boolean rebootModem(int slotIndex) { | 
 | 4861 |         Phone phone = PhoneFactory.getPhone(slotIndex); | 
 | 4862 |         if (phone != null) { | 
 | 4863 |             TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 4864 |                     mApp, phone.getSubId(), "rebootModem"); | 
 | 4865 |  | 
 | 4866 |             final long identity = Binder.clearCallingIdentity(); | 
 | 4867 |             try { | 
 | 4868 |                 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); | 
 | 4869 |                 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); | 
 | 4870 |                 return success; | 
 | 4871 |             } finally { | 
 | 4872 |                 Binder.restoreCallingIdentity(identity); | 
 | 4873 |             } | 
 | 4874 |         } | 
 | 4875 |         return false; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4876 |     } | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4877 |  | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4878 |     public String[] getPcscfAddress(String apnType, String callingPackage, | 
 | 4879 |             String callingFeatureId) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4880 |         final Phone defaultPhone = getDefaultPhone(); | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4881 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), | 
 | 4882 |                 callingPackage, callingFeatureId, "getPcscfAddress")) { | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4883 |             return new String[0]; | 
 | 4884 |         } | 
 | 4885 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4886 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4887 |         try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4888 |             return defaultPhone.getPcscfAddress(apnType); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4889 |         } finally { | 
 | 4890 |             Binder.restoreCallingIdentity(identity); | 
 | 4891 |         } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4892 |     } | 
 | 4893 |  | 
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4894 |     /** | 
| Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 4895 |      * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and | 
 | 4896 |      * {@link #disableIms(int)}. | 
 | 4897 |      * @param slotIndex device slot. | 
 | 4898 |      */ | 
 | 4899 |     public void resetIms(int slotIndex) { | 
 | 4900 |         enforceModifyPermission(); | 
 | 4901 |  | 
 | 4902 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4903 |         try { | 
 | 4904 |             if (mImsResolver == null) { | 
 | 4905 |                 // may happen if the does not support IMS. | 
 | 4906 |                 return; | 
 | 4907 |             } | 
 | 4908 |             mImsResolver.disableIms(slotIndex); | 
 | 4909 |             mImsResolver.enableIms(slotIndex); | 
 | 4910 |         } finally { | 
 | 4911 |             Binder.restoreCallingIdentity(identity); | 
 | 4912 |         } | 
 | 4913 |     } | 
 | 4914 |  | 
 | 4915 |     /** | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4916 |      * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability | 
 | 4917 |      * status updates, if not already enabled. | 
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4918 |      */ | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4919 |     public void enableIms(int slotId) { | 
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4920 |         enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4921 |  | 
 | 4922 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4923 |         try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4924 |             if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4925 |                 // may happen if the device does not support IMS. | 
 | 4926 |                 return; | 
 | 4927 |             } | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4928 |             mImsResolver.enableIms(slotId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4929 |         } finally { | 
 | 4930 |             Binder.restoreCallingIdentity(identity); | 
 | 4931 |         } | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4932 |     } | 
 | 4933 |  | 
 | 4934 |     /** | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4935 |      * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature | 
 | 4936 |      * status updates to disabled. | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4937 |      */ | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4938 |     public void disableIms(int slotId) { | 
 | 4939 |         enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4940 |  | 
 | 4941 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4942 |         try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4943 |             if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4944 |                 // may happen if the device does not support IMS. | 
 | 4945 |                 return; | 
 | 4946 |             } | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4947 |             mImsResolver.disableIms(slotId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4948 |         } finally { | 
 | 4949 |             Binder.restoreCallingIdentity(identity); | 
 | 4950 |         } | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4951 |     } | 
 | 4952 |  | 
 | 4953 |     /** | 
 | 4954 |      * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel | 
 | 4955 |      * feature or {@link null} if the service is not available. If the feature is available, the | 
 | 4956 |      * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. | 
 | 4957 |      */ | 
 | 4958 |     public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4959 |             IImsServiceFeatureCallback callback) { | 
 | 4960 |         enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4961 |  | 
 | 4962 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4963 |         try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4964 |             if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4965 |                 // may happen if the device does not support IMS. | 
 | 4966 |                 return null; | 
 | 4967 |             } | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4968 |             return mImsResolver.getMmTelFeatureAndListen(slotId, callback); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4969 |         } finally { | 
 | 4970 |             Binder.restoreCallingIdentity(identity); | 
 | 4971 |         } | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4972 |     } | 
 | 4973 |  | 
 | 4974 |     /** | 
 | 4975 |      * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS | 
 | 4976 |      * feature during emergency calling or {@link null} if the service is not available. If the | 
 | 4977 |      * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a | 
 | 4978 |      * listener for feature updates. | 
 | 4979 |      */ | 
 | 4980 |     public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { | 
 | 4981 |         enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4982 |  | 
 | 4983 |         final long identity = Binder.clearCallingIdentity(); | 
 | 4984 |         try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4985 |             if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4986 |                 // may happen if the device does not support IMS. | 
 | 4987 |                 return null; | 
 | 4988 |             } | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4989 |             return mImsResolver.getRcsFeatureAndListen(slotId, callback); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4990 |         } finally { | 
 | 4991 |             Binder.restoreCallingIdentity(identity); | 
 | 4992 |         } | 
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4993 |     } | 
 | 4994 |  | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4995 |     /** | 
 | 4996 |      * Returns the {@link IImsRegistration} structure associated with the slotId and feature | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4997 |      * specified or null if IMS is not supported on the slot specified. | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4998 |      */ | 
 | 4999 |     public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { | 
 | 5000 |         enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5001 |  | 
 | 5002 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5003 |         try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5004 |             if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5005 |                 // may happen if the device does not support IMS. | 
 | 5006 |                 return null; | 
 | 5007 |             } | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5008 |             return mImsResolver.getImsRegistration(slotId, feature); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5009 |         } finally { | 
 | 5010 |             Binder.restoreCallingIdentity(identity); | 
 | 5011 |         } | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5012 |     } | 
 | 5013 |  | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5014 |     /** | 
 | 5015 |      * Returns the {@link IImsConfig} structure associated with the slotId and feature | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5016 |      * specified or null if IMS is not supported on the slot specified. | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5017 |      */ | 
 | 5018 |     public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { | 
 | 5019 |         enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5020 |  | 
 | 5021 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5022 |         try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5023 |             if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5024 |                 // may happen if the device does not support IMS. | 
 | 5025 |                 return null; | 
 | 5026 |             } | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5027 |             return mImsResolver.getImsConfig(slotId, feature); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5028 |         } finally { | 
 | 5029 |             Binder.restoreCallingIdentity(identity); | 
 | 5030 |         } | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5031 |     } | 
 | 5032 |  | 
| Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5033 |     /** | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5034 |      * Sets the ImsService Package Name that Telephony will bind to. | 
 | 5035 |      * | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5036 |      * @param slotIndex the slot ID that the ImsService should bind for. | 
 | 5037 |      * @param isCarrierService true if the ImsService is the carrier override, false if the | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5038 |      *         ImsService is the device default ImsService. | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5039 |      * @param featureTypes An integer array of feature types associated with a packageName. | 
 | 5040 |      * @param packageName The name of the package that the current configuration will be replaced | 
 | 5041 |      *                    with. | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5042 |      * @return true if setting the ImsService to bind to succeeded, false if it did not. | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5043 |      */ | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5044 |     public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, | 
 | 5045 |             int[] featureTypes, String packageName) { | 
 | 5046 |         int[] subIds = SubscriptionManager.getSubId(slotIndex); | 
 | 5047 |         TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); | 
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5048 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, | 
 | 5049 |                 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5050 |                 "setBoundImsServiceOverride"); | 
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5051 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5052 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5053 |         try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5054 |             if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5055 |                 // may happen if the device does not support IMS. | 
 | 5056 |                 return false; | 
 | 5057 |             } | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5058 |             Map<Integer, String> featureConfig = new HashMap<>(); | 
 | 5059 |             for (int featureType : featureTypes) { | 
 | 5060 |                 featureConfig.put(featureType, packageName); | 
 | 5061 |             } | 
 | 5062 |             return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, | 
 | 5063 |                     featureConfig); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5064 |         } finally { | 
 | 5065 |             Binder.restoreCallingIdentity(identity); | 
 | 5066 |         } | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5067 |     } | 
 | 5068 |  | 
 | 5069 |     /** | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5070 |      * Return the package name of the currently bound ImsService. | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5071 |      * | 
 | 5072 |      * @param slotId The slot that the ImsService is associated with. | 
 | 5073 |      * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is | 
 | 5074 |      *         the device default. | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5075 |      * @param featureType The feature associated with the queried configuration. | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5076 |      * @return the package name of the ImsService configuration. | 
 | 5077 |      */ | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5078 |     public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, | 
 | 5079 |             @ImsFeature.FeatureType int featureType) { | 
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5080 |         int[] subIds = SubscriptionManager.getSubId(slotId); | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5081 |         TelephonyPermissions | 
 | 5082 |                 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
 | 5083 |                 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), | 
 | 5084 |                 "getBoundImsServicePackage"); | 
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5085 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5086 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5087 |         try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5088 |             if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5089 |                 // may happen if the device does not support IMS. | 
 | 5090 |                 return ""; | 
 | 5091 |             } | 
| Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5092 |             // TODO: change API to query RCS separately. | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5093 |             return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, | 
 | 5094 |                     featureType); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5095 |         } finally { | 
 | 5096 |             Binder.restoreCallingIdentity(identity); | 
 | 5097 |         } | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5098 |     } | 
 | 5099 |  | 
| Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5100 |     /** | 
 | 5101 |      * Get the MmTelFeature state associated with the requested subscription id. | 
 | 5102 |      * @param subId The subscription that the MmTelFeature is associated with. | 
 | 5103 |      * @param callback A callback with an integer containing the | 
 | 5104 |      * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. | 
 | 5105 |      */ | 
 | 5106 |     @Override | 
 | 5107 |     public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { | 
 | 5108 |         enforceReadPrivilegedPermission("getImsMmTelFeatureState"); | 
 | 5109 |         if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
 | 5110 |             throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
 | 5111 |                     "IMS not available on device."); | 
 | 5112 |         } | 
 | 5113 |         final long token = Binder.clearCallingIdentity(); | 
 | 5114 |         try { | 
 | 5115 |             int slotId = getSlotIndex(subId); | 
 | 5116 |             if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
 | 5117 |                 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" | 
 | 5118 |                         + subId + "'"); | 
 | 5119 |                 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); | 
 | 5120 |             } | 
 | 5121 |             ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { | 
 | 5122 |                 try { | 
 | 5123 |                     callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); | 
 | 5124 |                 } catch (RemoteException e) { | 
 | 5125 |                     Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " | 
 | 5126 |                             + "Ignore"); | 
 | 5127 |                 } | 
 | 5128 |             }); | 
 | 5129 |         } finally { | 
 | 5130 |             Binder.restoreCallingIdentity(token); | 
 | 5131 |         } | 
 | 5132 |     } | 
 | 5133 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5134 |     public void setImsRegistrationState(boolean registered) { | 
 | 5135 |         enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5136 |  | 
 | 5137 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5138 |         try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5139 |             getDefaultPhone().setImsRegistrationState(registered); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5140 |         } finally { | 
 | 5141 |             Binder.restoreCallingIdentity(identity); | 
 | 5142 |         } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5143 |     } | 
 | 5144 |  | 
 | 5145 |     /** | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5146 |      * Set the network selection mode to automatic. | 
 | 5147 |      * | 
 | 5148 |      */ | 
 | 5149 |     @Override | 
 | 5150 |     public void setNetworkSelectionModeAutomatic(int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5151 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 5152 |                 mApp, subId, "setNetworkSelectionModeAutomatic"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5153 |  | 
 | 5154 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5155 |         try { | 
| shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5156 |             if (!isActiveSubscription(subId)) { | 
 | 5157 |                 return; | 
 | 5158 |             } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5159 |             if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); | 
 | 5160 |             sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); | 
 | 5161 |         } finally { | 
 | 5162 |             Binder.restoreCallingIdentity(identity); | 
 | 5163 |         } | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5164 |     } | 
 | 5165 |  | 
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5166 |    /** | 
 | 5167 |      * Ask the radio to connect to the input network and change selection mode to manual. | 
 | 5168 |      * | 
 | 5169 |      * @param subId the id of the subscription. | 
 | 5170 |      * @param operatorInfo the operator information, included the PLMN, long name and short name of | 
 | 5171 |      * the operator to attach to. | 
 | 5172 |      * @param persistSelection whether the selection will persist until reboot. If true, only allows | 
 | 5173 |      * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume | 
 | 5174 |      * normal network selection next time. | 
 | 5175 |      * @return {@code true} on success; {@code true} on any failure. | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5176 |      */ | 
 | 5177 |     @Override | 
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5178 |     public boolean setNetworkSelectionModeManual( | 
 | 5179 |             int subId, OperatorInfo operatorInfo, boolean persistSelection) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5180 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 5181 |                 mApp, subId, "setNetworkSelectionModeManual"); | 
| Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5182 |  | 
 | 5183 |         if (!isActiveSubscription(subId)) { | 
 | 5184 |             return false; | 
 | 5185 |         } | 
 | 5186 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5187 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5188 |         try { | 
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5189 |             ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5190 |                     persistSelection); | 
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5191 |             if (DBG) { | 
 | 5192 |                 log("setNetworkSelectionModeManual: subId: " + subId | 
 | 5193 |                         + " operator: " + operatorInfo); | 
 | 5194 |             } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5195 |             return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); | 
 | 5196 |         } finally { | 
 | 5197 |             Binder.restoreCallingIdentity(identity); | 
 | 5198 |         } | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5199 |     } | 
| shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5200 |      /** | 
 | 5201 |      * Get the manual network selection | 
 | 5202 |      * | 
 | 5203 |      * @param subId the id of the subscription. | 
 | 5204 |      * | 
 | 5205 |      * @return the previously saved user selected PLMN | 
 | 5206 |      */ | 
 | 5207 |     @Override | 
 | 5208 |     public String getManualNetworkSelectionPlmn(int subId) { | 
 | 5209 |         TelephonyPermissions | 
 | 5210 |                     .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
 | 5211 |                     mApp, subId, "getManualNetworkSelectionPlmn"); | 
 | 5212 |  | 
 | 5213 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5214 |         try { | 
 | 5215 |             if (!isActiveSubscription(subId)) { | 
 | 5216 |                 return ""; | 
 | 5217 |             } | 
 | 5218 |  | 
 | 5219 |             final Phone phone = getPhone(subId); | 
 | 5220 |             if (phone == null) { | 
 | 5221 |                 return ""; | 
 | 5222 |             } | 
 | 5223 |             OperatorInfo networkSelection = phone.getSavedNetworkSelection(); | 
 | 5224 |             return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) | 
 | 5225 |                 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); | 
 | 5226 |         } finally { | 
 | 5227 |             Binder.restoreCallingIdentity(identity); | 
 | 5228 |         } | 
 | 5229 |     } | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5230 |  | 
 | 5231 |     /** | 
 | 5232 |      * Scans for available networks. | 
 | 5233 |      */ | 
 | 5234 |     @Override | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5235 |     public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, | 
 | 5236 |             String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5237 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 5238 |                 mApp, subId, "getCellNetworkScanResults"); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5239 |         LocationAccessPolicy.LocationPermissionResult locationResult = | 
 | 5240 |                 LocationAccessPolicy.checkLocationPermission(mApp, | 
 | 5241 |                         new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
 | 5242 |                                 .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5243 |                                 .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5244 |                                 .setCallingPid(Binder.getCallingPid()) | 
 | 5245 |                                 .setCallingUid(Binder.getCallingUid()) | 
 | 5246 |                                 .setMethod("getCellNetworkScanResults") | 
 | 5247 |                                 .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
 | 5248 |                                 .build()); | 
 | 5249 |         switch (locationResult) { | 
 | 5250 |             case DENIED_HARD: | 
 | 5251 |                 throw new SecurityException("Not allowed to access scan results -- location"); | 
 | 5252 |             case DENIED_SOFT: | 
 | 5253 |                 return null; | 
 | 5254 |         } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5255 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5256 |         long identity = Binder.clearCallingIdentity(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5257 |         try { | 
 | 5258 |             if (DBG) log("getCellNetworkScanResults: subId " + subId); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5259 |             return (CellNetworkScanResult) sendRequest( | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5260 |                     CMD_PERFORM_NETWORK_SCAN, null, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5261 |         } finally { | 
 | 5262 |             Binder.restoreCallingIdentity(identity); | 
 | 5263 |         } | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5264 |     } | 
 | 5265 |  | 
 | 5266 |     /** | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5267 |      * Get the call forwarding info, given the call forwarding reason. | 
 | 5268 |      */ | 
 | 5269 |     @Override | 
 | 5270 |     public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) { | 
 | 5271 |         enforceReadPrivilegedPermission("getCallForwarding"); | 
 | 5272 |         long identity = Binder.clearCallingIdentity(); | 
 | 5273 |         try { | 
 | 5274 |             if (DBG) { | 
 | 5275 |                 log("getCallForwarding: subId " + subId | 
 | 5276 |                         + " callForwardingReason" + callForwardingReason); | 
 | 5277 |             } | 
 | 5278 |             return (CallForwardingInfo) sendRequest( | 
 | 5279 |                     CMD_GET_CALL_FORWARDING, callForwardingReason, subId); | 
 | 5280 |         } finally { | 
 | 5281 |             Binder.restoreCallingIdentity(identity); | 
 | 5282 |         } | 
 | 5283 |     } | 
 | 5284 |  | 
 | 5285 |     /** | 
 | 5286 |      * Sets the voice call forwarding info including status (enable/disable), call forwarding | 
 | 5287 |      * reason, the number to forward, and the timeout before the forwarding is attempted. | 
 | 5288 |      */ | 
 | 5289 |     @Override | 
 | 5290 |     public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) { | 
 | 5291 |         enforceModifyPermission(); | 
 | 5292 |         long identity = Binder.clearCallingIdentity(); | 
 | 5293 |         try { | 
 | 5294 |             if (DBG) { | 
 | 5295 |                 log("setCallForwarding: subId " + subId | 
 | 5296 |                         + " callForwardingInfo" + callForwardingInfo); | 
 | 5297 |             } | 
 | 5298 |             return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId); | 
 | 5299 |         } finally { | 
 | 5300 |             Binder.restoreCallingIdentity(identity); | 
 | 5301 |         } | 
 | 5302 |     } | 
 | 5303 |  | 
 | 5304 |     /** | 
 | 5305 |      * Get the call forwarding info, given the call forwarding reason. | 
 | 5306 |      */ | 
 | 5307 |     @Override | 
 | 5308 |     public int getCallWaitingStatus(int subId) { | 
 | 5309 |         enforceReadPrivilegedPermission("getCallForwarding"); | 
 | 5310 |         long identity = Binder.clearCallingIdentity(); | 
 | 5311 |         try { | 
 | 5312 |             if (DBG) log("getCallWaitingStatus: subId " + subId); | 
 | 5313 |             return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId); | 
 | 5314 |         } finally { | 
 | 5315 |             Binder.restoreCallingIdentity(identity); | 
 | 5316 |         } | 
 | 5317 |     } | 
 | 5318 |  | 
 | 5319 |     /** | 
 | 5320 |      * Sets the voice call forwarding info including status (enable/disable), call forwarding | 
 | 5321 |      * reason, the number to forward, and the timeout before the forwarding is attempted. | 
 | 5322 |      */ | 
 | 5323 |     @Override | 
 | 5324 |     public boolean setCallWaitingStatus(int subId, boolean isEnable) { | 
 | 5325 |         enforceModifyPermission(); | 
 | 5326 |         long identity = Binder.clearCallingIdentity(); | 
 | 5327 |         try { | 
 | 5328 |             if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable); | 
 | 5329 |             return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId); | 
 | 5330 |         } finally { | 
 | 5331 |             Binder.restoreCallingIdentity(identity); | 
 | 5332 |         } | 
 | 5333 |     } | 
 | 5334 |  | 
 | 5335 |     /** | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5336 |      * Starts a new network scan and returns the id of this scan. | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5337 |      * | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5338 |      * @param subId id of the subscription | 
 | 5339 |      * @param request contains the radio access networks with bands/channels to scan | 
 | 5340 |      * @param messenger callback messenger for scan results or errors | 
 | 5341 |      * @param binder for the purpose of auto clean when the user thread crashes | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5342 |      * @return the id of the requested scan which can be used to stop the scan. | 
 | 5343 |      */ | 
 | 5344 |     @Override | 
 | 5345 |     public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5346 |             IBinder binder, String callingPackage, String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5347 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 5348 |                 mApp, subId, "requestNetworkScan"); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5349 |         LocationAccessPolicy.LocationPermissionResult locationResult = | 
 | 5350 |                 LocationAccessPolicy.checkLocationPermission(mApp, | 
 | 5351 |                         new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
 | 5352 |                                 .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5353 |                                 .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5354 |                                 .setCallingPid(Binder.getCallingPid()) | 
 | 5355 |                                 .setCallingUid(Binder.getCallingUid()) | 
 | 5356 |                                 .setMethod("requestNetworkScan") | 
 | 5357 |                                 .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
 | 5358 |                                 .build()); | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5359 |         if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { | 
| Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5360 |             SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5361 |             if (e != null) { | 
 | 5362 |                 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { | 
 | 5363 |                     throw e; | 
 | 5364 |                 } else { | 
| Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5365 |                     loge(e.getMessage()); | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5366 |                     return TelephonyScanManager.INVALID_SCAN_ID; | 
 | 5367 |                 } | 
 | 5368 |             } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5369 |         } | 
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5370 |         int callingUid = Binder.getCallingUid(); | 
 | 5371 |         int callingPid = Binder.getCallingPid(); | 
| Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5372 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5373 |         try { | 
 | 5374 |             return mNetworkScanRequestTracker.startNetworkScan( | 
 | 5375 |                     request, messenger, binder, getPhone(subId), | 
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5376 |                     callingUid, callingPid, callingPackage); | 
| Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5377 |         } finally { | 
 | 5378 |             Binder.restoreCallingIdentity(identity); | 
 | 5379 |         } | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5380 |     } | 
 | 5381 |  | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5382 |     private SecurityException checkNetworkRequestForSanitizedLocationAccess( | 
| Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5383 |             NetworkScanRequest request, int subId) { | 
 | 5384 |         boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) | 
 | 5385 |                 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; | 
 | 5386 |         boolean hasNetworkScanPermission = | 
 | 5387 |                 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) | 
 | 5388 |                 == PERMISSION_GRANTED; | 
 | 5389 |  | 
 | 5390 |         if (!hasCarrierPriv && !hasNetworkScanPermission) { | 
 | 5391 |             return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" | 
 | 5392 |                     + " for network scans without location access."); | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5393 |         } | 
 | 5394 |  | 
 | 5395 |         if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { | 
 | 5396 |             for (RadioAccessSpecifier ras : request.getSpecifiers()) { | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5397 |                 if (ras.getChannels() != null && ras.getChannels().length > 0) { | 
 | 5398 |                     return new SecurityException("Specific channels must not be" | 
 | 5399 |                             + " scanned without location access."); | 
 | 5400 |                 } | 
 | 5401 |             } | 
 | 5402 |         } | 
 | 5403 |  | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5404 |         return null; | 
 | 5405 |     } | 
 | 5406 |  | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5407 |     /** | 
 | 5408 |      * Stops an existing network scan with the given scanId. | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5409 |      * | 
 | 5410 |      * @param subId id of the subscription | 
 | 5411 |      * @param scanId id of the scan that needs to be stopped | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5412 |      */ | 
 | 5413 |     @Override | 
 | 5414 |     public void stopNetworkScan(int subId, int scanId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5415 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 5416 |                 mApp, subId, "stopNetworkScan"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5417 |  | 
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5418 |         int callingUid = Binder.getCallingUid(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5419 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5420 |         try { | 
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5421 |             mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5422 |         } finally { | 
 | 5423 |             Binder.restoreCallingIdentity(identity); | 
 | 5424 |         } | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5425 |     } | 
 | 5426 |  | 
 | 5427 |     /** | 
| Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5428 |      * Get the calculated preferred network type. | 
 | 5429 |      * Used for debugging incorrect network type. | 
 | 5430 |      * | 
 | 5431 |      * @return the preferred network type, defined in RILConstants.java. | 
 | 5432 |      */ | 
 | 5433 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5434 |     public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5435 |         final Phone defaultPhone = getDefaultPhone(); | 
 | 5436 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5437 |                 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5438 |             return RILConstants.PREFERRED_NETWORK_MODE; | 
 | 5439 |         } | 
 | 5440 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5441 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5442 |         try { | 
 | 5443 |             // FIXME: need to get SubId from somewhere. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5444 |             return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5445 |         } finally { | 
 | 5446 |             Binder.restoreCallingIdentity(identity); | 
 | 5447 |         } | 
| Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5448 |     } | 
 | 5449 |  | 
 | 5450 |     /** | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5451 |      * Get the preferred network type. | 
 | 5452 |      * Used for device configuration by some CDMA operators. | 
 | 5453 |      * | 
 | 5454 |      * @return the preferred network type, defined in RILConstants.java. | 
 | 5455 |      */ | 
 | 5456 |     @Override | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5457 |     public int getPreferredNetworkType(int subId) { | 
| Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5458 |         TelephonyPermissions | 
 | 5459 |                 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
 | 5460 |                         mApp, subId, "getPreferredNetworkType"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5461 |  | 
 | 5462 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5463 |         try { | 
 | 5464 |             if (DBG) log("getPreferredNetworkType"); | 
 | 5465 |             int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); | 
 | 5466 |             int networkType = (result != null ? result[0] : -1); | 
 | 5467 |             if (DBG) log("getPreferredNetworkType: " + networkType); | 
 | 5468 |             return networkType; | 
 | 5469 |         } finally { | 
 | 5470 |             Binder.restoreCallingIdentity(identity); | 
 | 5471 |         } | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5472 |     } | 
 | 5473 |  | 
 | 5474 |     /** | 
 | 5475 |      * Set the preferred network type. | 
 | 5476 |      * Used for device configuration by some CDMA operators. | 
 | 5477 |      * | 
 | 5478 |      * @param networkType the preferred network type, defined in RILConstants.java. | 
 | 5479 |      * @return true on success; false on any failure. | 
 | 5480 |      */ | 
 | 5481 |     @Override | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5482 |     public boolean setPreferredNetworkType(int subId, int networkType) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5483 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 5484 |                 mApp, subId, "setPreferredNetworkType"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5485 |  | 
 | 5486 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5487 |         try { | 
| calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5488 |             Settings.Global.putInt(mApp.getContentResolver(), | 
 | 5489 |                     Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); | 
 | 5490 |             return setPreferredNetworkTypesInternal(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5491 |         } finally { | 
 | 5492 |             Binder.restoreCallingIdentity(identity); | 
| Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5493 |         } | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5494 |     } | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5495 |  | 
 | 5496 |     /** | 
| calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5497 |      * Get the allowed network types that store in the telephony provider. | 
 | 5498 |      * | 
 | 5499 |      * @param subId the id of the subscription. | 
 | 5500 |      * @return allowedNetworkTypes the allowed network types. | 
 | 5501 |      */ | 
 | 5502 |     @Override | 
 | 5503 |     public long getAllowedNetworkTypes(int subId) { | 
 | 5504 |         TelephonyPermissions | 
 | 5505 |                 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
 | 5506 |                     mApp, subId, "getAllowedNetworkTypes"); | 
 | 5507 |  | 
 | 5508 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5509 |         try { | 
 | 5510 |             return SubscriptionManager.getLongSubscriptionProperty( | 
 | 5511 |                     subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); | 
 | 5512 |         } finally { | 
 | 5513 |             Binder.restoreCallingIdentity(identity); | 
 | 5514 |         } | 
 | 5515 |     } | 
 | 5516 |  | 
 | 5517 |     /** | 
 | 5518 |      * Set the allowed network types. | 
 | 5519 |      * | 
 | 5520 |      * @param subId the id of the subscription. | 
 | 5521 |      * @param allowedNetworkTypes the allowed network types. | 
 | 5522 |      * @return true on success; false on any failure. | 
 | 5523 |      */ | 
 | 5524 |     @Override | 
 | 5525 |     public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { | 
 | 5526 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 5527 |                 mApp, subId, "setAllowedNetworkTypes"); | 
 | 5528 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5529 |         try { | 
 | 5530 |             SubscriptionManager.setSubscriptionProperty(subId, | 
 | 5531 |                     SubscriptionManager.ALLOWED_NETWORK_TYPES, | 
 | 5532 |                     String.valueOf(allowedNetworkTypes)); | 
 | 5533 |             return setPreferredNetworkTypesInternal(subId); | 
 | 5534 |         } finally { | 
 | 5535 |             Binder.restoreCallingIdentity(identity); | 
 | 5536 |         } | 
 | 5537 |     } | 
 | 5538 |  | 
 | 5539 |     private boolean setPreferredNetworkTypesInternal(int subId) { | 
 | 5540 |         long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType( | 
 | 5541 |                 Settings.Global.getInt(mApp.getContentResolver(), | 
 | 5542 |                         Settings.Global.PREFERRED_NETWORK_MODE + subId, | 
 | 5543 |                         RILConstants.PREFERRED_NETWORK_MODE)); | 
 | 5544 |         long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty( | 
 | 5545 |                 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); | 
 | 5546 |         int networkMode = RadioAccessFamily.getNetworkTypeFromRaf( | 
 | 5547 |                 (int) (networkTypeBitMask & allowedNetworkTypes)); | 
 | 5548 |  | 
 | 5549 |         if (DBG) { | 
 | 5550 |             log("setPreferredNetworkTypesInternal: subId " + subId | 
 | 5551 |                     + " networkTypes " + networkTypeBitMask | 
 | 5552 |                     + " allowedNetworkTypes " + allowedNetworkTypes | 
 | 5553 |                     + " networkMode " + networkMode); | 
 | 5554 |         } | 
 | 5555 |  | 
 | 5556 |         Boolean success = (Boolean) sendRequest( | 
 | 5557 |                 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId); | 
 | 5558 |         if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail")); | 
 | 5559 |         return success; | 
 | 5560 |     } | 
 | 5561 |  | 
 | 5562 |     /** | 
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5563 |      * Check whether DUN APN is required for tethering with subId. | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5564 |      * | 
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5565 |      * @param subId the id of the subscription to require tethering. | 
| Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5566 |      * @return {@code true} if DUN APN is required for tethering. | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5567 |      * @hide | 
 | 5568 |      */ | 
 | 5569 |     @Override | 
| SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5570 |     public boolean isTetheringApnRequiredForSubscriber(int subId) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5571 |         enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5572 |         final long identity = Binder.clearCallingIdentity(); | 
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5573 |         final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5574 |         try { | 
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5575 |             if (phone != null) { | 
 | 5576 |                 return phone.hasMatchedTetherApnSetting(); | 
 | 5577 |             } else { | 
 | 5578 |                 return false; | 
 | 5579 |             } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5580 |         } finally { | 
 | 5581 |             Binder.restoreCallingIdentity(identity); | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5582 |         } | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5583 |     } | 
 | 5584 |  | 
 | 5585 |     /** | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5586 |      * Set mobile data enabled | 
 | 5587 |      * Used by the user through settings etc to turn on/off mobile data | 
 | 5588 |      * | 
 | 5589 |      * @param enable {@code true} turn turn data on, else {@code false} | 
 | 5590 |      */ | 
 | 5591 |     @Override | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5592 |     public void setUserDataEnabled(int subId, boolean enable) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5593 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 5594 |                 mApp, subId, "setUserDataEnabled"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5595 |  | 
 | 5596 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5597 |         try { | 
 | 5598 |             int phoneId = mSubscriptionController.getPhoneId(subId); | 
 | 5599 |             if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); | 
 | 5600 |             Phone phone = PhoneFactory.getPhone(phoneId); | 
 | 5601 |             if (phone != null) { | 
 | 5602 |                 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); | 
| Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5603 |                 phone.getDataEnabledSettings().setUserDataEnabled(enable); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5604 |             } else { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5605 |                 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5606 |             } | 
 | 5607 |         } finally { | 
 | 5608 |             Binder.restoreCallingIdentity(identity); | 
| Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5609 |         } | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5610 |     } | 
 | 5611 |  | 
 | 5612 |     /** | 
| Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 5613 |      * Enable or disable always reporting signal strength changes from radio. | 
 | 5614 |      * | 
 | 5615 |      * @param isEnable {@code true} for enabling; {@code false} for disabling. | 
 | 5616 |      */ | 
 | 5617 |     @Override | 
 | 5618 |     public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { | 
 | 5619 |         enforceModifyPermission(); | 
 | 5620 |         enforceSystemCaller(); | 
 | 5621 |  | 
 | 5622 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5623 |         final Phone phone = getPhone(subId); | 
 | 5624 |         try { | 
 | 5625 |             if (phone != null) { | 
 | 5626 |                 if (DBG) { | 
 | 5627 |                     log("setAlwaysReportSignalStrength: subId=" + subId | 
 | 5628 |                             + " isEnable=" + isEnable); | 
 | 5629 |                 } | 
 | 5630 |                 phone.setAlwaysReportSignalStrength(isEnable); | 
 | 5631 |             } else { | 
 | 5632 |                 loge("setAlwaysReportSignalStrength: no phone found for subId=" | 
 | 5633 |                         + subId); | 
 | 5634 |             } | 
 | 5635 |         } finally { | 
 | 5636 |             Binder.restoreCallingIdentity(identity); | 
 | 5637 |         } | 
 | 5638 |     } | 
 | 5639 |  | 
 | 5640 |     /** | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5641 |      * Get the user enabled state of Mobile Data. | 
 | 5642 |      * | 
 | 5643 |      * TODO: remove and use isUserDataEnabled. | 
 | 5644 |      * This can't be removed now because some vendor codes | 
 | 5645 |      * calls through ITelephony directly while they should | 
 | 5646 |      * use TelephonyManager. | 
 | 5647 |      * | 
 | 5648 |      * @return true on enabled | 
 | 5649 |      */ | 
 | 5650 |     @Override | 
 | 5651 |     public boolean getDataEnabled(int subId) { | 
 | 5652 |         return isUserDataEnabled(subId); | 
 | 5653 |     } | 
 | 5654 |  | 
 | 5655 |     /** | 
 | 5656 |      * Get whether mobile data is enabled per user setting. | 
 | 5657 |      * | 
 | 5658 |      * There are other factors deciding whether mobile data is actually enabled, but they are | 
 | 5659 |      * not considered here. See {@link #isDataEnabled(int)} for more details. | 
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5660 |      * | 
| Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5661 |      * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5662 |      * | 
 | 5663 |      * @return {@code true} if data is enabled else {@code false} | 
 | 5664 |      */ | 
 | 5665 |     @Override | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5666 |     public boolean isUserDataEnabled(int subId) { | 
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5667 |         try { | 
 | 5668 |             mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, | 
 | 5669 |                     null); | 
 | 5670 |         } catch (Exception e) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5671 |             TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 5672 |                     mApp, subId, "isUserDataEnabled"); | 
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5673 |         } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5674 |  | 
 | 5675 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5676 |         try { | 
 | 5677 |             int phoneId = mSubscriptionController.getPhoneId(subId); | 
 | 5678 |             if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); | 
 | 5679 |             Phone phone = PhoneFactory.getPhone(phoneId); | 
 | 5680 |             if (phone != null) { | 
 | 5681 |                 boolean retVal = phone.isUserDataEnabled(); | 
 | 5682 |                 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); | 
 | 5683 |                 return retVal; | 
 | 5684 |             } else { | 
 | 5685 |                 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); | 
 | 5686 |                 return false; | 
 | 5687 |             } | 
 | 5688 |         } finally { | 
 | 5689 |             Binder.restoreCallingIdentity(identity); | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5690 |         } | 
 | 5691 |     } | 
 | 5692 |  | 
 | 5693 |     /** | 
| Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5694 |      * Checks if the device is capable of mobile data by considering whether whether the | 
 | 5695 |      * user has enabled mobile data, whether the carrier has enabled mobile data, and | 
 | 5696 |      * whether the network policy allows data connections. | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5697 |      * | 
| Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5698 |      * @return {@code true} if the overall data connection is capable; {@code false} if not. | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5699 |      */ | 
 | 5700 |     @Override | 
 | 5701 |     public boolean isDataEnabled(int subId) { | 
| Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5702 |         enforceReadPrivilegedPermission("isDataEnabled"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5703 |  | 
 | 5704 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5705 |         try { | 
 | 5706 |             int phoneId = mSubscriptionController.getPhoneId(subId); | 
 | 5707 |             if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); | 
 | 5708 |             Phone phone = PhoneFactory.getPhone(phoneId); | 
 | 5709 |             if (phone != null) { | 
| Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5710 |                 boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5711 |                 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); | 
 | 5712 |                 return retVal; | 
 | 5713 |             } else { | 
 | 5714 |                 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); | 
 | 5715 |                 return false; | 
 | 5716 |             } | 
 | 5717 |         } finally { | 
 | 5718 |             Binder.restoreCallingIdentity(identity); | 
| Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5719 |         } | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5720 |     } | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5721 |  | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5722 |     private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, | 
 | 5723 |             Phone phone) { | 
 | 5724 |         //load access rules from carrier configs, and check those as well: b/139133814 | 
 | 5725 |         SubscriptionController subController = SubscriptionController.getInstance(); | 
 | 5726 |         if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS | 
 | 5727 |                 || subController == null) return privilegeFromSim; | 
 | 5728 |  | 
 | 5729 |         int uid = Binder.getCallingUid(); | 
 | 5730 |         PackageManager pkgMgr = phone.getContext().getPackageManager(); | 
 | 5731 |         String[] packages = pkgMgr.getPackagesForUid(uid); | 
 | 5732 |  | 
 | 5733 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5734 |         try { | 
 | 5735 |             SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); | 
 | 5736 |             SubscriptionManager subManager = (SubscriptionManager) | 
 | 5737 |                     phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); | 
 | 5738 |             for (String pkg : packages) { | 
 | 5739 |                 if (subManager.canManageSubscription(subInfo, pkg)) { | 
 | 5740 |                     return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; | 
 | 5741 |                 } | 
 | 5742 |             } | 
 | 5743 |             return privilegeFromSim; | 
 | 5744 |         } finally { | 
 | 5745 |             Binder.restoreCallingIdentity(identity); | 
 | 5746 |         } | 
 | 5747 |     } | 
 | 5748 |  | 
 | 5749 |     private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, | 
 | 5750 |             String pkgName) { | 
 | 5751 |         //load access rules from carrier configs, and check those as well: b/139133814 | 
 | 5752 |         SubscriptionController subController = SubscriptionController.getInstance(); | 
 | 5753 |         if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS | 
 | 5754 |                 || subController == null) return privilegeFromSim; | 
 | 5755 |  | 
 | 5756 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5757 |         try { | 
 | 5758 |             SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); | 
 | 5759 |             SubscriptionManager subManager = (SubscriptionManager) | 
 | 5760 |                     phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); | 
 | 5761 |             return subManager.canManageSubscription(subInfo, pkgName) | 
 | 5762 |                 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; | 
 | 5763 |         } finally { | 
 | 5764 |             Binder.restoreCallingIdentity(identity); | 
 | 5765 |         } | 
 | 5766 |     } | 
 | 5767 |  | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5768 |     @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5769 |     public int getCarrierPrivilegeStatus(int subId) { | 
 | 5770 |         final Phone phone = getPhone(subId); | 
 | 5771 |         if (phone == null) { | 
 | 5772 |             loge("getCarrierPrivilegeStatus: Invalid subId"); | 
 | 5773 |             return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
 | 5774 |         } | 
 | 5775 |         UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5776 |         if (card == null) { | 
| Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5777 |             loge("getCarrierPrivilegeStatus: No UICC"); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5778 |             return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
 | 5779 |         } | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5780 |  | 
 | 5781 |         return getCarrierPrivilegeStatusFromCarrierConfigRules( | 
 | 5782 |             card.getCarrierPrivilegeStatusForCurrentTransaction( | 
 | 5783 |                 phone.getContext().getPackageManager()), phone); | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5784 |     } | 
| Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5785 |  | 
 | 5786 |     @Override | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5787 |     public int getCarrierPrivilegeStatusForUid(int subId, int uid) { | 
| Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5788 |         enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5789 |         final Phone phone = getPhone(subId); | 
 | 5790 |         if (phone == null) { | 
| Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5791 |             loge("getCarrierPrivilegeStatusForUid: Invalid subId"); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5792 |             return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
 | 5793 |         } | 
 | 5794 |         UiccProfile profile = | 
 | 5795 |                 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); | 
 | 5796 |         if (profile == null) { | 
| Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5797 |             loge("getCarrierPrivilegeStatusForUid: No UICC"); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5798 |             return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
 | 5799 |         } | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5800 |         return getCarrierPrivilegeStatusFromCarrierConfigRules( | 
| Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5801 |                 profile.getCarrierPrivilegeStatusForUid( | 
 | 5802 |                         phone.getContext().getPackageManager(), uid), phone); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5803 |     } | 
 | 5804 |  | 
 | 5805 |     @Override | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5806 |     public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { | 
 | 5807 |         if (TextUtils.isEmpty(pkgName)) { | 
| Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5808 |             return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5809 |         } | 
 | 5810 |  | 
 | 5811 |         int phoneId = SubscriptionManager.getPhoneId(subId); | 
 | 5812 |         UiccCard card = UiccController.getInstance().getUiccCard(phoneId); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5813 |         if (card == null) { | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5814 |             loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5815 |             return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
 | 5816 |         } | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5817 |         return getCarrierPrivilegeStatusFromCarrierConfigRules( | 
 | 5818 |             card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), | 
 | 5819 |             getPhone(phoneId), pkgName); | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5820 |     } | 
 | 5821 |  | 
 | 5822 |     @Override | 
 | 5823 |     public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { | 
| Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5824 |         if (TextUtils.isEmpty(pkgName)) | 
 | 5825 |             return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5826 |         int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
 | 5827 |         for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
 | 5828 |             UiccCard card = UiccController.getInstance().getUiccCard(i); | 
 | 5829 |             if (card == null) { | 
| Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5830 |               // No UICC in that slot. | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5831 |               continue; | 
 | 5832 |             } | 
 | 5833 |  | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5834 |             result = getCarrierPrivilegeStatusFromCarrierConfigRules( | 
 | 5835 |                 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), | 
 | 5836 |                 getPhone(i), pkgName); | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5837 |             if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
 | 5838 |                 break; | 
 | 5839 |             } | 
 | 5840 |         } | 
 | 5841 |  | 
 | 5842 |         return result; | 
| Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5843 |     } | 
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5844 |  | 
 | 5845 |     @Override | 
| Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5846 |     public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { | 
 | 5847 |         if (!SubscriptionManager.isValidPhoneId(phoneId)) { | 
 | 5848 |             loge("phoneId " + phoneId + " is not valid."); | 
 | 5849 |             return null; | 
 | 5850 |         } | 
 | 5851 |         UiccCard card = UiccController.getInstance().getUiccCard(phoneId); | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5852 |         if (card == null) { | 
| Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5853 |             loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5854 |             return null ; | 
 | 5855 |         } | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5856 |         return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5857 |     } | 
 | 5858 |  | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5859 |     @Override | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5860 |     public List<String> getPackagesWithCarrierPrivileges(int phoneId) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5861 |         PackageManager pm = mApp.getPackageManager(); | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5862 |         List<String> privilegedPackages = new ArrayList<>(); | 
 | 5863 |         List<PackageInfo> packages = null; | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5864 |         UiccCard card = UiccController.getInstance().getUiccCard(phoneId); | 
 | 5865 |         // has UICC in that slot. | 
 | 5866 |         if (card != null) { | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5867 |             if (card.hasCarrierPrivilegeRules()) { | 
 | 5868 |                 if (packages == null) { | 
 | 5869 |                     // Only check packages in user 0 for now | 
 | 5870 |                     packages = pm.getInstalledPackagesAsUser( | 
| Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5871 |                         PackageManager.MATCH_DISABLED_COMPONENTS | 
 | 5872 |                             | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS | 
| Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5873 |                             | PackageManager.GET_SIGNING_CERTIFICATES, | 
| Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5874 |                             UserHandle.SYSTEM.getIdentifier()); | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5875 |                 } | 
 | 5876 |                 for (int p = packages.size() - 1; p >= 0; p--) { | 
 | 5877 |                     PackageInfo pkgInfo = packages.get(p); | 
 | 5878 |                     if (pkgInfo != null && pkgInfo.packageName != null | 
 | 5879 |                             && card.getCarrierPrivilegeStatus(pkgInfo) | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5880 |                             == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5881 |                         privilegedPackages.add(pkgInfo.packageName); | 
 | 5882 |                     } | 
 | 5883 |                 } | 
 | 5884 |             } | 
 | 5885 |         } | 
 | 5886 |         return privilegedPackages; | 
 | 5887 |     } | 
 | 5888 |  | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5889 |     @Override | 
 | 5890 |     public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { | 
| Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5891 |         enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); | 
 | 5892 |  | 
 | 5893 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5894 |  | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5895 |         List<String> privilegedPackages = new ArrayList<>(); | 
| Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5896 |         try { | 
 | 5897 |             for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
 | 5898 |                 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); | 
 | 5899 |             } | 
 | 5900 |         } finally { | 
 | 5901 |             Binder.restoreCallingIdentity(identity); | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5902 |         } | 
 | 5903 |         return privilegedPackages; | 
 | 5904 |     } | 
 | 5905 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5906 |     private String getIccId(int subId) { | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5907 |         final Phone phone = getPhone(subId); | 
 | 5908 |         UiccCard card = phone == null ? null : phone.getUiccCard(); | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5909 |         if (card == null) { | 
 | 5910 |             loge("getIccId: No UICC"); | 
 | 5911 |             return null; | 
 | 5912 |         } | 
 | 5913 |         String iccId = card.getIccId(); | 
 | 5914 |         if (TextUtils.isEmpty(iccId)) { | 
 | 5915 |             loge("getIccId: ICC ID is null or empty."); | 
 | 5916 |             return null; | 
 | 5917 |         } | 
 | 5918 |         return iccId; | 
 | 5919 |     } | 
 | 5920 |  | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5921 |     @Override | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5922 |     public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, | 
 | 5923 |             String number) { | 
| Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5924 |         TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5925 |                 subId, "setLine1NumberForDisplayForSubscriber"); | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5926 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5927 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5928 |         try { | 
 | 5929 |             final String iccId = getIccId(subId); | 
 | 5930 |             final Phone phone = getPhone(subId); | 
 | 5931 |             if (phone == null) { | 
 | 5932 |                 return false; | 
 | 5933 |             } | 
 | 5934 |             final String subscriberId = phone.getSubscriberId(); | 
 | 5935 |  | 
 | 5936 |             if (DBG_MERGE) { | 
| Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5937 |                 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5938 |                         + subscriberId + " to " + number); | 
 | 5939 |             } | 
 | 5940 |  | 
 | 5941 |             if (TextUtils.isEmpty(iccId)) { | 
 | 5942 |                 return false; | 
 | 5943 |             } | 
 | 5944 |  | 
 | 5945 |             final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); | 
 | 5946 |  | 
 | 5947 |             final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; | 
 | 5948 |             if (alphaTag == null) { | 
 | 5949 |                 editor.remove(alphaTagPrefKey); | 
 | 5950 |             } else { | 
 | 5951 |                 editor.putString(alphaTagPrefKey, alphaTag); | 
 | 5952 |             } | 
 | 5953 |  | 
 | 5954 |             // Record both the line number and IMSI for this ICCID, since we need to | 
 | 5955 |             // track all merged IMSIs based on line number | 
 | 5956 |             final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; | 
 | 5957 |             final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; | 
 | 5958 |             if (number == null) { | 
 | 5959 |                 editor.remove(numberPrefKey); | 
 | 5960 |                 editor.remove(subscriberPrefKey); | 
 | 5961 |             } else { | 
 | 5962 |                 editor.putString(numberPrefKey, number); | 
 | 5963 |                 editor.putString(subscriberPrefKey, subscriberId); | 
 | 5964 |             } | 
 | 5965 |  | 
 | 5966 |             editor.commit(); | 
 | 5967 |             return true; | 
 | 5968 |         } finally { | 
 | 5969 |             Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5970 |         } | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5971 |     } | 
 | 5972 |  | 
 | 5973 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5974 |     public String getLine1NumberForDisplay(int subId, String callingPackage, | 
 | 5975 |             String callingFeatureId) { | 
| Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5976 |         // This is open to apps with WRITE_SMS. | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5977 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5978 |                 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { | 
| Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5979 |             if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5980 |             return null; | 
 | 5981 |         } | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5982 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5983 |         final long identity = Binder.clearCallingIdentity(); | 
 | 5984 |         try { | 
 | 5985 |             String iccId = getIccId(subId); | 
 | 5986 |             if (iccId != null) { | 
 | 5987 |                 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; | 
 | 5988 |                 if (DBG_MERGE) { | 
 | 5989 |                     log("getLine1NumberForDisplay returning " | 
 | 5990 |                             + mTelephonySharedPreferences.getString(numberPrefKey, null)); | 
 | 5991 |                 } | 
 | 5992 |                 return mTelephonySharedPreferences.getString(numberPrefKey, null); | 
| Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5993 |             } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5994 |             if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); | 
 | 5995 |             return null; | 
 | 5996 |         } finally { | 
 | 5997 |             Binder.restoreCallingIdentity(identity); | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5998 |         } | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5999 |     } | 
 | 6000 |  | 
 | 6001 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6002 |     public String getLine1AlphaTagForDisplay(int subId, String callingPackage, | 
 | 6003 |             String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6004 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6005 |                 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6006 |             return null; | 
 | 6007 |         } | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6008 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6009 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6010 |         try { | 
 | 6011 |             String iccId = getIccId(subId); | 
 | 6012 |             if (iccId != null) { | 
 | 6013 |                 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; | 
 | 6014 |                 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); | 
 | 6015 |             } | 
 | 6016 |             return null; | 
 | 6017 |         } finally { | 
 | 6018 |             Binder.restoreCallingIdentity(identity); | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6019 |         } | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6020 |     } | 
| Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6021 |  | 
 | 6022 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6023 |     public String[] getMergedSubscriberIds(int subId, String callingPackage, | 
 | 6024 |             String callingFeatureId) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6025 |         // This API isn't public, so no need to provide a valid subscription ID - we're not worried | 
 | 6026 |         // about carrier-privileged callers not having access. | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6027 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6028 |                 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6029 |                 callingFeatureId, "getMergedSubscriberIds")) { | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6030 |             return null; | 
 | 6031 |         } | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6032 |  | 
| Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6033 |         // Clear calling identity, when calling TelephonyManager, because callerUid must be | 
 | 6034 |         // the process, where TelephonyManager was instantiated. | 
 | 6035 |         // Otherwise AppOps check will fail. | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6036 |         final long identity  = Binder.clearCallingIdentity(); | 
 | 6037 |         try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6038 |             final Context context = mApp; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6039 |             final TelephonyManager tele = TelephonyManager.from(context); | 
 | 6040 |             final SubscriptionManager sub = SubscriptionManager.from(context); | 
 | 6041 |  | 
 | 6042 |             // Figure out what subscribers are currently active | 
 | 6043 |             final ArraySet<String> activeSubscriberIds = new ArraySet<>(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6044 |  | 
| Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6045 |             // Only consider subs which match the current subId | 
 | 6046 |             // This logic can be simplified. See b/131189269 for progress. | 
 | 6047 |             if (isActiveSubscription(subId)) { | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6048 |                 activeSubscriberIds.add(tele.getSubscriberId(subId)); | 
 | 6049 |             } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6050 |  | 
 | 6051 |             // First pass, find a number override for an active subscriber | 
 | 6052 |             String mergeNumber = null; | 
 | 6053 |             final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); | 
 | 6054 |             for (String key : prefs.keySet()) { | 
 | 6055 |                 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { | 
 | 6056 |                     final String subscriberId = (String) prefs.get(key); | 
 | 6057 |                     if (activeSubscriberIds.contains(subscriberId)) { | 
 | 6058 |                         final String iccId = key.substring( | 
 | 6059 |                                 PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); | 
 | 6060 |                         final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; | 
 | 6061 |                         mergeNumber = (String) prefs.get(numberKey); | 
 | 6062 |                         if (DBG_MERGE) { | 
| Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6063 |                             Rlog.d(LOG_TAG, "Found line number " + mergeNumber | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6064 |                                     + " for active subscriber " + subscriberId); | 
 | 6065 |                         } | 
 | 6066 |                         if (!TextUtils.isEmpty(mergeNumber)) { | 
 | 6067 |                             break; | 
 | 6068 |                         } | 
 | 6069 |                     } | 
 | 6070 |                 } | 
 | 6071 |             } | 
 | 6072 |  | 
 | 6073 |             // Shortcut when no active merged subscribers | 
 | 6074 |             if (TextUtils.isEmpty(mergeNumber)) { | 
 | 6075 |                 return null; | 
 | 6076 |             } | 
 | 6077 |  | 
 | 6078 |             // Second pass, find all subscribers under that line override | 
 | 6079 |             final ArraySet<String> result = new ArraySet<>(); | 
 | 6080 |             for (String key : prefs.keySet()) { | 
 | 6081 |                 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { | 
 | 6082 |                     final String number = (String) prefs.get(key); | 
 | 6083 |                     if (mergeNumber.equals(number)) { | 
 | 6084 |                         final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); | 
 | 6085 |                         final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; | 
 | 6086 |                         final String subscriberId = (String) prefs.get(subscriberKey); | 
 | 6087 |                         if (!TextUtils.isEmpty(subscriberId)) { | 
 | 6088 |                             result.add(subscriberId); | 
 | 6089 |                         } | 
 | 6090 |                     } | 
 | 6091 |                 } | 
 | 6092 |             } | 
 | 6093 |  | 
 | 6094 |             final String[] resultArray = result.toArray(new String[result.size()]); | 
 | 6095 |             Arrays.sort(resultArray); | 
 | 6096 |             if (DBG_MERGE) { | 
| Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6097 |                 Rlog.d(LOG_TAG, | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6098 |                         "Found subscribers " + Arrays.toString(resultArray) + " after merge"); | 
 | 6099 |             } | 
 | 6100 |             return resultArray; | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6101 |         } finally { | 
 | 6102 |             Binder.restoreCallingIdentity(identity); | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6103 |         } | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6104 |     } | 
 | 6105 |  | 
 | 6106 |     @Override | 
| zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6107 |     public String[] getMergedImsisFromGroup(int subId, String callingPackage) { | 
 | 6108 |         enforceReadPrivilegedPermission("getMergedImsisFromGroup"); | 
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6109 |  | 
 | 6110 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6111 |         try { | 
 | 6112 |             final TelephonyManager telephonyManager = mApp.getSystemService( | 
 | 6113 |                     TelephonyManager.class); | 
 | 6114 |             String subscriberId = telephonyManager.getSubscriberId(subId); | 
 | 6115 |             if (subscriberId == null) { | 
 | 6116 |                 if (DBG) { | 
| zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6117 |                     log("getMergedImsisFromGroup can't find subscriberId for subId " | 
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6118 |                             + subId); | 
 | 6119 |                 } | 
 | 6120 |                 return null; | 
 | 6121 |             } | 
 | 6122 |  | 
 | 6123 |             final SubscriptionInfo info = SubscriptionController.getInstance() | 
 | 6124 |                     .getSubscriptionInfo(subId); | 
 | 6125 |             final ParcelUuid groupUuid = info.getGroupUuid(); | 
 | 6126 |             // If it doesn't belong to any group, return just subscriberId of itself. | 
 | 6127 |             if (groupUuid == null) { | 
 | 6128 |                 return new String[]{subscriberId}; | 
 | 6129 |             } | 
 | 6130 |  | 
 | 6131 |             // Get all subscriberIds from the group. | 
 | 6132 |             final List<String> mergedSubscriberIds = new ArrayList<>(); | 
 | 6133 |             final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6134 |                     .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), | 
 | 6135 |                             mApp.getFeatureId()); | 
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6136 |             for (SubscriptionInfo subInfo : groupInfos) { | 
 | 6137 |                 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); | 
 | 6138 |                 if (subscriberId != null) { | 
 | 6139 |                     mergedSubscriberIds.add(subscriberId); | 
 | 6140 |                 } | 
 | 6141 |             } | 
 | 6142 |  | 
 | 6143 |             return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); | 
 | 6144 |         } finally { | 
 | 6145 |             Binder.restoreCallingIdentity(identity); | 
 | 6146 |  | 
 | 6147 |         } | 
 | 6148 |     } | 
 | 6149 |  | 
 | 6150 |     @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6151 |     public boolean setOperatorBrandOverride(int subId, String brand) { | 
| Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6152 |         TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6153 |                 subId, "setOperatorBrandOverride"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6154 |  | 
 | 6155 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6156 |         try { | 
 | 6157 |             final Phone phone = getPhone(subId); | 
 | 6158 |             return phone == null ? false : phone.setOperatorBrandOverride(brand); | 
 | 6159 |         } finally { | 
 | 6160 |             Binder.restoreCallingIdentity(identity); | 
 | 6161 |         } | 
| Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6162 |     } | 
| Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6163 |  | 
 | 6164 |     @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6165 |     public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, | 
| Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6166 |             List<String> gsmNonRoamingList, List<String> cdmaRoamingList, | 
 | 6167 |             List<String> cdmaNonRoamingList) { | 
| Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6168 |         TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( | 
 | 6169 |                 mApp, subId, "setRoamingOverride"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6170 |  | 
 | 6171 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6172 |         try { | 
 | 6173 |             final Phone phone = getPhone(subId); | 
 | 6174 |             if (phone == null) { | 
 | 6175 |                 return false; | 
 | 6176 |             } | 
 | 6177 |             return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, | 
 | 6178 |                     cdmaNonRoamingList); | 
 | 6179 |         } finally { | 
 | 6180 |             Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6181 |         } | 
| Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6182 |     } | 
 | 6183 |  | 
 | 6184 |     @Override | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6185 |     @Deprecated | 
 | 6186 |     public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { | 
 | 6187 |         enforceModifyPermission(); | 
 | 6188 |  | 
 | 6189 |         int returnValue = 0; | 
 | 6190 |         try { | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6191 |             AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6192 |             if(result.exception == null) { | 
 | 6193 |                 if (result.result != null) { | 
 | 6194 |                     byte[] responseData = (byte[])(result.result); | 
 | 6195 |                     if(responseData.length > oemResp.length) { | 
 | 6196 |                         Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + | 
 | 6197 |                                 responseData.length +  "bytes. Buffer Size is " + | 
 | 6198 |                                 oemResp.length + "bytes."); | 
 | 6199 |                     } | 
 | 6200 |                     System.arraycopy(responseData, 0, oemResp, 0, responseData.length); | 
 | 6201 |                     returnValue = responseData.length; | 
 | 6202 |                 } | 
 | 6203 |             } else { | 
 | 6204 |                 CommandException ex = (CommandException) result.exception; | 
 | 6205 |                 returnValue = ex.getCommandError().ordinal(); | 
 | 6206 |                 if(returnValue > 0) returnValue *= -1; | 
 | 6207 |             } | 
 | 6208 |         } catch (RuntimeException e) { | 
 | 6209 |             Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); | 
 | 6210 |             returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); | 
 | 6211 |             if(returnValue > 0) returnValue *= -1; | 
 | 6212 |         } | 
 | 6213 |  | 
 | 6214 |         return returnValue; | 
 | 6215 |     } | 
 | 6216 |  | 
 | 6217 |     @Override | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6218 |     public void setRadioCapability(RadioAccessFamily[] rafs) { | 
 | 6219 |         try { | 
 | 6220 |             ProxyController.getInstance().setRadioCapability(rafs); | 
 | 6221 |         } catch (RuntimeException e) { | 
 | 6222 |             Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); | 
 | 6223 |         } | 
 | 6224 |     } | 
 | 6225 |  | 
 | 6226 |     @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6227 |     public int getRadioAccessFamily(int phoneId, String callingPackage) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6228 |         Phone phone = PhoneFactory.getPhone(phoneId); | 
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6229 |         int raf = RadioAccessFamily.RAF_UNKNOWN; | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6230 |         if (phone == null) { | 
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6231 |             return raf; | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6232 |         } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6233 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6234 |         try { | 
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6235 |             TelephonyPermissions | 
 | 6236 |                     .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
 | 6237 |                             mApp, phone.getSubId(), "getRadioAccessFamily"); | 
 | 6238 |             raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6239 |         } finally { | 
 | 6240 |             Binder.restoreCallingIdentity(identity); | 
 | 6241 |         } | 
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6242 |         return raf; | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6243 |     } | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6244 |  | 
 | 6245 |     @Override | 
 | 6246 |     public void enableVideoCalling(boolean enable) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6247 |         final Phone defaultPhone = getDefaultPhone(); | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6248 |         enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6249 |  | 
 | 6250 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6251 |         try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6252 |             ImsManager.getInstance(defaultPhone.getContext(), | 
 | 6253 |                     defaultPhone.getPhoneId()).setVtSetting(enable); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6254 |         } finally { | 
 | 6255 |             Binder.restoreCallingIdentity(identity); | 
 | 6256 |         } | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6257 |     } | 
 | 6258 |  | 
 | 6259 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6260 |     public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6261 |         final Phone defaultPhone = getDefaultPhone(); | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6262 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), | 
 | 6263 |                 callingPackage, callingFeatureId, "isVideoCallingEnabled")) { | 
| Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6264 |             return false; | 
 | 6265 |         } | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6266 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6267 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6268 |         try { | 
 | 6269 |             // Check the user preference and the  system-level IMS setting. Even if the user has | 
 | 6270 |             // enabled video calling, if IMS is disabled we aren't able to support video calling. | 
 | 6271 |             // In the long run, we may instead need to check if there exists a connection service | 
 | 6272 |             // which can support video calling. | 
 | 6273 |             ImsManager imsManager = | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6274 |                     ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6275 |             return imsManager.isVtEnabledByPlatform() | 
 | 6276 |                     && imsManager.isEnhanced4gLteModeSettingEnabledByUser() | 
 | 6277 |                     && imsManager.isVtEnabledByUser(); | 
 | 6278 |         } finally { | 
 | 6279 |             Binder.restoreCallingIdentity(identity); | 
 | 6280 |         } | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6281 |     } | 
| Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6282 |  | 
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6283 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6284 |     public boolean canChangeDtmfToneLength(int subId, String callingPackage, | 
 | 6285 |             String callingFeatureId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6286 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6287 |                 mApp, subId, callingPackage, callingFeatureId, | 
 | 6288 |                 "isVideoCallingEnabled")) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6289 |             return false; | 
 | 6290 |         } | 
 | 6291 |  | 
 | 6292 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6293 |         try { | 
 | 6294 |             CarrierConfigManager configManager = | 
 | 6295 |                     (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6296 |             return configManager.getConfigForSubId(subId) | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6297 |                     .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); | 
 | 6298 |         } finally { | 
 | 6299 |             Binder.restoreCallingIdentity(identity); | 
 | 6300 |         } | 
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6301 |     } | 
 | 6302 |  | 
 | 6303 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6304 |     public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6305 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6306 |                 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6307 |             return false; | 
 | 6308 |         } | 
 | 6309 |  | 
 | 6310 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6311 |         try { | 
 | 6312 |             CarrierConfigManager configManager = | 
 | 6313 |                     (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6314 |             return configManager.getConfigForSubId(subId) | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6315 |                     .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); | 
 | 6316 |         } finally { | 
 | 6317 |             Binder.restoreCallingIdentity(identity); | 
 | 6318 |         } | 
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6319 |     } | 
 | 6320 |  | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6321 |     @Override | 
 | 6322 |     public boolean isTtyModeSupported() { | 
| Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6323 |         TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); | 
| Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6324 |         return telecomManager.isTtySupported(); | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6325 |     } | 
 | 6326 |  | 
 | 6327 |     @Override | 
 | 6328 |     public boolean isHearingAidCompatibilitySupported() { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6329 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6330 |         try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6331 |             return mApp.getResources().getBoolean(R.bool.hac_enabled); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6332 |         } finally { | 
 | 6333 |             Binder.restoreCallingIdentity(identity); | 
 | 6334 |         } | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6335 |     } | 
 | 6336 |  | 
| Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6337 |     /** | 
 | 6338 |      * Determines whether the device currently supports RTT (Real-time text). Based both on carrier | 
 | 6339 |      * support for the feature and device firmware support. | 
 | 6340 |      * | 
 | 6341 |      * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. | 
 | 6342 |      */ | 
 | 6343 |     @Override | 
 | 6344 |     public boolean isRttSupported(int subscriptionId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6345 |         final long identity = Binder.clearCallingIdentity(); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6346 |         final Phone phone = getPhone(subscriptionId); | 
 | 6347 |         if (phone == null) { | 
 | 6348 |             loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); | 
 | 6349 |             return false; | 
 | 6350 |         } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6351 |         try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6352 |             boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6353 |                     CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); | 
 | 6354 |             boolean isDeviceSupported = | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6355 |                     phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6356 |             return isCarrierSupported && isDeviceSupported; | 
 | 6357 |         } finally { | 
 | 6358 |             Binder.restoreCallingIdentity(identity); | 
 | 6359 |         } | 
| Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6360 |     } | 
 | 6361 |  | 
| Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6362 |     /** | 
| Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6363 |      * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set | 
 | 6364 |      * RTT setting, will return true if the device and carrier both support RTT. | 
 | 6365 |      * 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] | 6366 |      */ | 
 | 6367 |     public boolean isRttEnabled(int subscriptionId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6368 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6369 |         try { | 
| Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6370 |             boolean isRttSupported = isRttSupported(subscriptionId); | 
 | 6371 |             boolean isUserRttSettingOn = Settings.Secure.getInt( | 
 | 6372 |                     mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; | 
 | 6373 |             boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) | 
 | 6374 |                     .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); | 
 | 6375 |             return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6376 |         } finally { | 
 | 6377 |             Binder.restoreCallingIdentity(identity); | 
 | 6378 |         } | 
| Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6379 |     } | 
 | 6380 |  | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6381 |     @Deprecated | 
 | 6382 |     @Override | 
 | 6383 |     public String getDeviceId(String callingPackage) { | 
 | 6384 |         return getDeviceIdWithFeature(callingPackage, null); | 
 | 6385 |     } | 
 | 6386 |  | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6387 |     /** | 
 | 6388 |      * Returns the unique device ID of phone, for example, the IMEI for | 
 | 6389 |      * GSM and the MEID for CDMA phones. Return null if device ID is not available. | 
 | 6390 |      * | 
 | 6391 |      * <p>Requires Permission: | 
 | 6392 |      *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} | 
 | 6393 |      */ | 
 | 6394 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6395 |     public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6396 |         final Phone phone = PhoneFactory.getPhone(0); | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6397 |         if (phone == null) { | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6398 |             return null; | 
 | 6399 |         } | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6400 |         int subId = phone.getSubId(); | 
| Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6401 |         if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6402 |                 callingPackage, callingFeatureId, "getDeviceId")) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6403 |             return null; | 
 | 6404 |         } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6405 |  | 
 | 6406 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6407 |         try { | 
 | 6408 |             return phone.getDeviceId(); | 
 | 6409 |         } finally { | 
 | 6410 |             Binder.restoreCallingIdentity(identity); | 
 | 6411 |         } | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6412 |     } | 
 | 6413 |  | 
| Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6414 |     /** | 
 | 6415 |      * {@hide} | 
 | 6416 |      * Returns the IMS Registration Status on a particular subid | 
 | 6417 |      * | 
 | 6418 |      * @param subId | 
 | 6419 |      */ | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6420 |     public boolean isImsRegistered(int subId) { | 
| Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6421 |         Phone phone = getPhone(subId); | 
 | 6422 |         if (phone != null) { | 
 | 6423 |             return phone.isImsRegistered(); | 
 | 6424 |         } else { | 
 | 6425 |             return false; | 
 | 6426 |         } | 
 | 6427 |     } | 
 | 6428 |  | 
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6429 |     @Override | 
 | 6430 |     public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6431 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6432 |         try { | 
 | 6433 |             return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); | 
 | 6434 |         } finally { | 
 | 6435 |             Binder.restoreCallingIdentity(identity); | 
 | 6436 |         } | 
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6437 |     } | 
| Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6438 |  | 
| Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6439 |     @Override | 
| Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6440 |     public int getSubIdForPhoneAccountHandle( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6441 |             PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { | 
| Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6442 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6443 |                 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { | 
| Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6444 |             throw new SecurityException("Requires READ_PHONE_STATE permission."); | 
 | 6445 |         } | 
 | 6446 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6447 |         try { | 
 | 6448 |             return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); | 
 | 6449 |         } finally { | 
 | 6450 |             Binder.restoreCallingIdentity(identity); | 
 | 6451 |         } | 
 | 6452 |     } | 
 | 6453 |  | 
 | 6454 |     @Override | 
| Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6455 |     public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { | 
 | 6456 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6457 |         try { | 
 | 6458 |             Phone phone = getPhone(subscriptionId); | 
 | 6459 |             if (phone == null) { | 
 | 6460 |                 return null; | 
 | 6461 |             } | 
 | 6462 |             return PhoneUtils.makePstnPhoneAccountHandle(phone); | 
 | 6463 |         } finally { | 
 | 6464 |             Binder.restoreCallingIdentity(identity); | 
 | 6465 |         } | 
 | 6466 |     } | 
 | 6467 |  | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6468 |     /** | 
 | 6469 |      * @return the VoWiFi calling availability. | 
| Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6470 |      */ | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6471 |     public boolean isWifiCallingAvailable(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6472 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6473 |         try { | 
 | 6474 |             Phone phone = getPhone(subId); | 
 | 6475 |             if (phone != null) { | 
 | 6476 |                 return phone.isWifiCallingEnabled(); | 
 | 6477 |             } else { | 
 | 6478 |                 return false; | 
 | 6479 |             } | 
 | 6480 |         } finally { | 
 | 6481 |             Binder.restoreCallingIdentity(identity); | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6482 |         } | 
| Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6483 |     } | 
 | 6484 |  | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6485 |     /** | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6486 |      * @return the VT calling availability. | 
| Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6487 |      */ | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6488 |     public boolean isVideoTelephonyAvailable(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6489 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6490 |         try { | 
 | 6491 |             Phone phone = getPhone(subId); | 
 | 6492 |             if (phone != null) { | 
 | 6493 |                 return phone.isVideoEnabled(); | 
 | 6494 |             } else { | 
 | 6495 |                 return false; | 
 | 6496 |             } | 
 | 6497 |         } finally { | 
 | 6498 |             Binder.restoreCallingIdentity(identity); | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6499 |         } | 
 | 6500 |     } | 
 | 6501 |  | 
 | 6502 |     /** | 
 | 6503 |      * @return the IMS registration technology for the MMTEL feature. Valid return values are | 
 | 6504 |      * defined in {@link ImsRegistrationImplBase}. | 
 | 6505 |      */ | 
 | 6506 |     public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6507 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6508 |         try { | 
 | 6509 |             Phone phone = getPhone(subId); | 
 | 6510 |             if (phone != null) { | 
 | 6511 |                 return phone.getImsRegistrationTech(); | 
 | 6512 |             } else { | 
 | 6513 |                 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; | 
 | 6514 |             } | 
 | 6515 |         } finally { | 
 | 6516 |             Binder.restoreCallingIdentity(identity); | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6517 |         } | 
| Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6518 |     } | 
 | 6519 |  | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6520 |     @Override | 
 | 6521 |     public void factoryReset(int subId) { | 
| paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6522 |         enforceSettingsPermission(); | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6523 |         if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { | 
 | 6524 |             return; | 
 | 6525 |         } | 
 | 6526 |  | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6527 |         final long identity = Binder.clearCallingIdentity(); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6528 |  | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6529 |         try { | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6530 |             if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( | 
 | 6531 |                     UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6532 |                 setUserDataEnabled(subId, getDefaultDataEnabled()); | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6533 |                 setNetworkSelectionModeAutomatic(subId); | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6534 |                 setPreferredNetworkType(subId, getDefaultNetworkType(subId)); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6535 |                 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); | 
 | 6536 |                 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6537 |             } | 
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6538 |             // There has been issues when Sms raw table somehow stores orphan | 
 | 6539 |             // fragments. They lead to garbled message when new fragments come | 
 | 6540 |             // in and combined with those stale ones. In case this happens again, | 
 | 6541 |             // user can reset all network settings which will clean up this table. | 
 | 6542 |             cleanUpSmsRawTable(getDefaultPhone().getContext()); | 
| Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6543 |             // Clean up IMS settings as well here. | 
 | 6544 |             int slotId = getSlotIndex(subId); | 
 | 6545 |             if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
 | 6546 |                 ImsManager.getInstance(mApp, slotId).factoryReset(); | 
 | 6547 |             } | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6548 |  | 
 | 6549 |             // Erase modem config if erase modem on network setting is enabled. | 
 | 6550 |             String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, | 
 | 6551 |                     RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); | 
 | 6552 |             if (configValue != null && Boolean.parseBoolean(configValue)) { | 
 | 6553 |               sendEraseModemConfig(getDefaultPhone()); | 
 | 6554 |             } | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6555 |         } finally { | 
 | 6556 |             Binder.restoreCallingIdentity(identity); | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6557 |         } | 
 | 6558 |     } | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6559 |  | 
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6560 |     private void cleanUpSmsRawTable(Context context) { | 
 | 6561 |         ContentResolver resolver = context.getContentResolver(); | 
 | 6562 |         Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); | 
 | 6563 |         resolver.delete(uri, null, null); | 
 | 6564 |     } | 
 | 6565 |  | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6566 |     @Override | 
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6567 |     public String getSimLocaleForSubscriber(int subId) { | 
 | 6568 |         enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); | 
 | 6569 |         final Phone phone = getPhone(subId); | 
 | 6570 |         if (phone == null) { | 
 | 6571 |             log("getSimLocaleForSubscriber, invalid subId"); | 
| chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6572 |             return null; | 
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6573 |         } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6574 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6575 |         try { | 
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6576 |             final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6577 |                     phone.getContext().getOpPackageName(), phone.getContext().getFeatureId()); | 
| chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6578 |             if (info == null) { | 
 | 6579 |                 log("getSimLocaleForSubscriber, inactive subId: " + subId); | 
 | 6580 |                 return null; | 
 | 6581 |             } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6582 |             // Try and fetch the locale from the carrier properties or from the SIM language | 
 | 6583 |             // preferences (EF-PL and EF-LI)... | 
 | 6584 |             final int mcc = info.getMcc(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6585 |             String simLanguage = null; | 
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6586 |             final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); | 
 | 6587 |             if (localeFromDefaultSim != null) { | 
 | 6588 |                 if (!localeFromDefaultSim.getCountry().isEmpty()) { | 
 | 6589 |                     if (DBG) log("Using locale from subId: " + subId + " locale: " | 
 | 6590 |                             + localeFromDefaultSim); | 
 | 6591 |                     return localeFromDefaultSim.toLanguageTag(); | 
 | 6592 |                 } else { | 
 | 6593 |                     simLanguage = localeFromDefaultSim.getLanguage(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6594 |                 } | 
 | 6595 |             } | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6596 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6597 |             // The SIM language preferences only store a language (e.g. fr = French), not an | 
 | 6598 |             // exact locale (e.g. fr_FR = French/France). So, if the locale returned from | 
 | 6599 |             // the SIM and carrier preferences does not include a country we add the country | 
 | 6600 |             // determined from the SIM MCC to provide an exact locale. | 
| zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6601 |             final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6602 |             if (mccLocale != null) { | 
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6603 |                 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6604 |                 return mccLocale.toLanguageTag(); | 
 | 6605 |             } | 
 | 6606 |  | 
 | 6607 |             if (DBG) log("No locale found - returning null"); | 
 | 6608 |             return null; | 
 | 6609 |         } finally { | 
 | 6610 |             Binder.restoreCallingIdentity(identity); | 
 | 6611 |         } | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6612 |     } | 
 | 6613 |  | 
 | 6614 |     private List<SubscriptionInfo> getAllSubscriptionInfoList() { | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6615 |         return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), | 
 | 6616 |                 mApp.getFeatureId()); | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6617 |     } | 
 | 6618 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6619 |     /** | 
 | 6620 |      * NOTE: this method assumes permission checks are done and caller identity has been cleared. | 
 | 6621 |      */ | 
 | 6622 |     private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6623 |         return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), | 
 | 6624 |                 mApp.getFeatureId()); | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6625 |     } | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6626 |  | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6627 |     private final ModemActivityInfo mLastModemActivityInfo = | 
| Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6628 |             new ModemActivityInfo(0, 0, 0, new int[0], 0); | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6629 |  | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6630 |     /** | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6631 |      * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object | 
 | 6632 |      * representing the state of the modem. | 
 | 6633 |      * | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6634 |      * NOTE: The underlying implementation clears the modem state, so there should only ever be one | 
 | 6635 |      * caller to it. Everyone should call this class to get cumulative data. | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6636 |      * @hide | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6637 |      */ | 
 | 6638 |     @Override | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6639 |     public void requestModemActivityInfo(ResultReceiver result) { | 
 | 6640 |         enforceModifyPermission(); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6641 |         WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6642 |  | 
 | 6643 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6644 |         try { | 
 | 6645 |             ModemActivityInfo ret = null; | 
 | 6646 |             synchronized (mLastModemActivityInfo) { | 
 | 6647 |                 ModemActivityInfo info = (ModemActivityInfo) sendRequest( | 
 | 6648 |                         CMD_GET_MODEM_ACTIVITY_INFO, | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6649 |                         null, workSource); | 
| Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6650 |                 if (isModemActivityInfoValid(info)) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6651 |                     int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; | 
| Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6652 |                     int[] txTimeMs = info.getTransmitTimeMillis(); | 
 | 6653 |                     int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6654 |                     for (int i = 0; i < mergedTxTimeMs.length; i++) { | 
| Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6655 |                         mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6656 |                     } | 
 | 6657 |                     mLastModemActivityInfo.setTimestamp(info.getTimestamp()); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6658 |                     mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() | 
 | 6659 |                             + mLastModemActivityInfo.getSleepTimeMillis()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6660 |                     mLastModemActivityInfo.setIdleTimeMillis( | 
 | 6661 |                             info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); | 
| Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6662 |                     mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); | 
 | 6663 |                     mLastModemActivityInfo.setReceiveTimeMillis( | 
 | 6664 |                             info.getReceiveTimeMillis() + mLastModemActivityInfo | 
 | 6665 |                                 .getReceiveTimeMillis()); | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6666 |                 } | 
| Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6667 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6668 |                 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), | 
 | 6669 |                         mLastModemActivityInfo.getSleepTimeMillis(), | 
 | 6670 |                         mLastModemActivityInfo.getIdleTimeMillis(), | 
| Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6671 |                         mLastModemActivityInfo.getTransmitTimeMillis(), | 
 | 6672 |                         mLastModemActivityInfo.getReceiveTimeMillis()); | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6673 |             } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6674 |             Bundle bundle = new Bundle(); | 
 | 6675 |             bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); | 
 | 6676 |             result.send(0, bundle); | 
 | 6677 |         } finally { | 
 | 6678 |             Binder.restoreCallingIdentity(identity); | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6679 |         } | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6680 |     } | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6681 |  | 
| Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6682 |     // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be | 
 | 6683 |     // less than total activity duration. | 
 | 6684 |     private boolean isModemActivityInfoValid(ModemActivityInfo info) { | 
 | 6685 |         if (info == null) { | 
 | 6686 |             return false; | 
 | 6687 |         } | 
 | 6688 |         int activityDurationMs = | 
 | 6689 |             (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); | 
 | 6690 |         int totalTxTimeMs = 0; | 
| Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6691 |         int[] txTimeMs = info.getTransmitTimeMillis(); | 
 | 6692 |         for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { | 
 | 6693 |             totalTxTimeMs += txTimeMs[i]; | 
| Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6694 |         } | 
 | 6695 |         return (info.isValid() | 
 | 6696 |             && (info.getSleepTimeMillis() <= activityDurationMs) | 
 | 6697 |             && (info.getIdleTimeMillis() <= activityDurationMs) | 
| Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6698 |             && (info.getReceiveTimeMillis() <= activityDurationMs) | 
| Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6699 |             && (totalTxTimeMs <= activityDurationMs)); | 
 | 6700 |     } | 
 | 6701 |  | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6702 |     /** | 
 | 6703 |      * {@hide} | 
 | 6704 |      * Returns the service state information on specified subscription. | 
 | 6705 |      */ | 
 | 6706 |     @Override | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6707 |     public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, | 
 | 6708 |             String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6709 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6710 |                 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6711 |             return null; | 
 | 6712 |         } | 
 | 6713 |  | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6714 |         LocationAccessPolicy.LocationPermissionResult fineLocationResult = | 
 | 6715 |                 LocationAccessPolicy.checkLocationPermission(mApp, | 
 | 6716 |                         new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
 | 6717 |                                 .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6718 |                                 .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6719 |                                 .setCallingPid(Binder.getCallingPid()) | 
 | 6720 |                                 .setCallingUid(Binder.getCallingUid()) | 
 | 6721 |                                 .setMethod("getServiceStateForSubscriber") | 
| Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6722 |                                 .setLogAsInfo(true) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6723 |                                 .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
 | 6724 |                                 .build()); | 
 | 6725 |  | 
 | 6726 |         LocationAccessPolicy.LocationPermissionResult coarseLocationResult = | 
 | 6727 |                 LocationAccessPolicy.checkLocationPermission(mApp, | 
 | 6728 |                         new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
 | 6729 |                                 .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6730 |                                 .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6731 |                                 .setCallingPid(Binder.getCallingPid()) | 
 | 6732 |                                 .setCallingUid(Binder.getCallingUid()) | 
 | 6733 |                                 .setMethod("getServiceStateForSubscriber") | 
| Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6734 |                                 .setLogAsInfo(true) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6735 |                                 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) | 
 | 6736 |                                 .build()); | 
 | 6737 |         // We don't care about hard or soft here -- all we need to know is how much info to scrub. | 
 | 6738 |         boolean hasFinePermission = | 
 | 6739 |                 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; | 
 | 6740 |         boolean hasCoarsePermission = | 
 | 6741 |                 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; | 
 | 6742 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6743 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6744 |         try { | 
 | 6745 |             final Phone phone = getPhone(subId); | 
 | 6746 |             if (phone == null) { | 
 | 6747 |                 return null; | 
 | 6748 |             } | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6749 |  | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6750 |             ServiceState ss = phone.getServiceState(); | 
 | 6751 |  | 
 | 6752 |             // Scrub out the location info in ServiceState depending on what level of access | 
 | 6753 |             // the caller has. | 
 | 6754 |             if (hasFinePermission) return ss; | 
| Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6755 |             if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); | 
 | 6756 |             return ss.createLocationInfoSanitizedCopy(true); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6757 |         } finally { | 
 | 6758 |             Binder.restoreCallingIdentity(identity); | 
 | 6759 |         } | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6760 |     } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6761 |  | 
 | 6762 |     /** | 
 | 6763 |      * Returns the URI for the per-account voicemail ringtone set in Phone settings. | 
 | 6764 |      * | 
 | 6765 |      * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the | 
 | 6766 |      * voicemail ringtone. | 
 | 6767 |      * @return The URI for the ringtone to play when receiving a voicemail from a specific | 
 | 6768 |      * PhoneAccount. | 
 | 6769 |      */ | 
 | 6770 |     @Override | 
 | 6771 |     public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6772 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6773 |         try { | 
 | 6774 |             Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); | 
 | 6775 |             if (phone == null) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6776 |                 phone = getDefaultPhone(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6777 |             } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6778 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6779 |             return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); | 
 | 6780 |         } finally { | 
 | 6781 |             Binder.restoreCallingIdentity(identity); | 
 | 6782 |         } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6783 |     } | 
 | 6784 |  | 
 | 6785 |     /** | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6786 |      * Sets the per-account voicemail ringtone. | 
 | 6787 |      * | 
 | 6788 |      * <p>Requires that the calling app is the default dialer, or has carrier privileges, or | 
 | 6789 |      * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. | 
 | 6790 |      * | 
 | 6791 |      * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the | 
 | 6792 |      * voicemail ringtone. | 
 | 6793 |      * @param uri The URI for the ringtone to play when receiving a voicemail from a specific | 
 | 6794 |      * PhoneAccount. | 
 | 6795 |      */ | 
 | 6796 |     @Override | 
 | 6797 |     public void setVoicemailRingtoneUri(String callingPackage, | 
 | 6798 |             PhoneAccountHandle phoneAccountHandle, Uri uri) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6799 |         final Phone defaultPhone = getDefaultPhone(); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6800 |         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6801 |         TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); | 
 | 6802 |         if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6803 |             TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 6804 |                     mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), | 
 | 6805 |                     "setVoicemailRingtoneUri"); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6806 |         } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6807 |  | 
 | 6808 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6809 |         try { | 
 | 6810 |             Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); | 
 | 6811 |             if (phone == null) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6812 |                 phone = defaultPhone; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6813 |             } | 
 | 6814 |             VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); | 
 | 6815 |         } finally { | 
 | 6816 |             Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6817 |         } | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6818 |     } | 
 | 6819 |  | 
 | 6820 |     /** | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6821 |      * Returns whether vibration is set for voicemail notification in Phone settings. | 
 | 6822 |      * | 
 | 6823 |      * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the | 
 | 6824 |      * voicemail vibration setting. | 
 | 6825 |      * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. | 
 | 6826 |      */ | 
 | 6827 |     @Override | 
 | 6828 |     public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6829 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6830 |         try { | 
 | 6831 |             Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); | 
 | 6832 |             if (phone == null) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6833 |                 phone = getDefaultPhone(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6834 |             } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6835 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6836 |             return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); | 
 | 6837 |         } finally { | 
 | 6838 |             Binder.restoreCallingIdentity(identity); | 
 | 6839 |         } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6840 |     } | 
 | 6841 |  | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6842 |     /** | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6843 |      * Sets the per-account voicemail vibration. | 
 | 6844 |      * | 
 | 6845 |      * <p>Requires that the calling app is the default dialer, or has carrier privileges, or | 
 | 6846 |      * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. | 
 | 6847 |      * | 
 | 6848 |      * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the | 
 | 6849 |      * voicemail vibration setting. | 
 | 6850 |      * @param enabled Whether to enable or disable vibration for voicemail notifications from a | 
 | 6851 |      * specific PhoneAccount. | 
 | 6852 |      */ | 
 | 6853 |     @Override | 
 | 6854 |     public void setVoicemailVibrationEnabled(String callingPackage, | 
 | 6855 |             PhoneAccountHandle phoneAccountHandle, boolean enabled) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6856 |         final Phone defaultPhone = getDefaultPhone(); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6857 |         mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6858 |         TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); | 
 | 6859 |         if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6860 |             TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 6861 |                     mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), | 
 | 6862 |                     "setVoicemailVibrationEnabled"); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6863 |         } | 
 | 6864 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6865 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6866 |         try { | 
 | 6867 |             Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); | 
 | 6868 |             if (phone == null) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6869 |                 phone = defaultPhone; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6870 |             } | 
 | 6871 |             VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); | 
 | 6872 |         } finally { | 
 | 6873 |             Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6874 |         } | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6875 |     } | 
 | 6876 |  | 
 | 6877 |     /** | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6878 |      * Make sure either called from same process as self (phone) or IPC caller has read privilege. | 
 | 6879 |      * | 
 | 6880 |      * @throws SecurityException if the caller does not have the required permission | 
 | 6881 |      */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6882 |     private void enforceReadPrivilegedPermission(String message) { | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6883 |         mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6884 |                 message); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6885 |     } | 
 | 6886 |  | 
 | 6887 |     /** | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6888 |      * Make sure either called from same process as self (phone) or IPC caller has send SMS | 
 | 6889 |      * permission. | 
 | 6890 |      * | 
 | 6891 |      * @throws SecurityException if the caller does not have the required permission | 
 | 6892 |      */ | 
 | 6893 |     private void enforceSendSmsPermission() { | 
 | 6894 |         mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); | 
 | 6895 |     } | 
 | 6896 |  | 
 | 6897 |     /** | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6898 |      * Make sure called from the package in charge of visual voicemail. | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6899 |      * | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6900 |      * @throws SecurityException if the caller is not the visual voicemail package. | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6901 |      */ | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6902 |     private void enforceVisualVoicemailPackage(String callingPackage, int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6903 |         final long identity = Binder.clearCallingIdentity(); | 
 | 6904 |         try { | 
 | 6905 |             ComponentName componentName = | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6906 |                     RemoteVvmTaskManager.getRemotePackage(mApp, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6907 |             if (componentName == null) { | 
 | 6908 |                 throw new SecurityException( | 
 | 6909 |                         "Caller not current active visual voicemail package[null]"); | 
 | 6910 |             } | 
 | 6911 |             String vvmPackage = componentName.getPackageName(); | 
 | 6912 |             if (!callingPackage.equals(vvmPackage)) { | 
 | 6913 |                 throw new SecurityException("Caller not current active visual voicemail package[" | 
 | 6914 |                         + vvmPackage + "]"); | 
 | 6915 |             } | 
 | 6916 |         } finally { | 
 | 6917 |             Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6918 |         } | 
 | 6919 |     } | 
 | 6920 |  | 
 | 6921 |     /** | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6922 |      * Return the application ID for the app type. | 
 | 6923 |      * | 
 | 6924 |      * @param subId the subscription ID that this request applies to. | 
 | 6925 |      * @param appType the uicc app type. | 
 | 6926 |      * @return Application ID for specificied app type, or null if no uicc. | 
 | 6927 |      */ | 
 | 6928 |     @Override | 
 | 6929 |     public String getAidForAppType(int subId, int appType) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6930 |         enforceReadPrivilegedPermission("getAidForAppType"); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6931 |         Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6932 |  | 
 | 6933 |         final long identity = Binder.clearCallingIdentity(); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6934 |         try { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6935 |             if (phone == null) { | 
 | 6936 |                 return null; | 
 | 6937 |             } | 
 | 6938 |             String aid = null; | 
 | 6939 |             try { | 
 | 6940 |                 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) | 
 | 6941 |                         .getApplicationByType(appType).getAid(); | 
 | 6942 |             } catch (Exception e) { | 
 | 6943 |                 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); | 
 | 6944 |             } | 
 | 6945 |             return aid; | 
 | 6946 |         } finally { | 
 | 6947 |             Binder.restoreCallingIdentity(identity); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6948 |         } | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6949 |     } | 
 | 6950 |  | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6951 |     /** | 
 | 6952 |      * Return the Electronic Serial Number. | 
 | 6953 |      * | 
 | 6954 |      * @param subId the subscription ID that this request applies to. | 
 | 6955 |      * @return ESN or null if error. | 
 | 6956 |      */ | 
 | 6957 |     @Override | 
 | 6958 |     public String getEsn(int subId) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6959 |         enforceReadPrivilegedPermission("getEsn"); | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6960 |         Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6961 |  | 
 | 6962 |         final long identity = Binder.clearCallingIdentity(); | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6963 |         try { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6964 |             if (phone == null) { | 
 | 6965 |                 return null; | 
 | 6966 |             } | 
 | 6967 |             String esn = null; | 
 | 6968 |             try { | 
 | 6969 |                 esn = phone.getEsn(); | 
 | 6970 |             } catch (Exception e) { | 
 | 6971 |                 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); | 
 | 6972 |             } | 
 | 6973 |             return esn; | 
 | 6974 |         } finally { | 
 | 6975 |             Binder.restoreCallingIdentity(identity); | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6976 |         } | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6977 |     } | 
 | 6978 |  | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6979 |     /** | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6980 |      * Return the Preferred Roaming List Version. | 
 | 6981 |      * | 
 | 6982 |      * @param subId the subscription ID that this request applies to. | 
 | 6983 |      * @return PRLVersion or null if error. | 
 | 6984 |      */ | 
 | 6985 |     @Override | 
 | 6986 |     public String getCdmaPrlVersion(int subId) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6987 |         enforceReadPrivilegedPermission("getCdmaPrlVersion"); | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6988 |         Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6989 |  | 
 | 6990 |         final long identity = Binder.clearCallingIdentity(); | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6991 |         try { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6992 |             if (phone == null) { | 
 | 6993 |                 return null; | 
 | 6994 |             } | 
 | 6995 |             String cdmaPrlVersion = null; | 
 | 6996 |             try { | 
 | 6997 |                 cdmaPrlVersion = phone.getCdmaPrlVersion(); | 
 | 6998 |             } catch (Exception e) { | 
 | 6999 |                 Log.e(LOG_TAG, "Not getting PRLVersion", e); | 
 | 7000 |             } | 
 | 7001 |             return cdmaPrlVersion; | 
 | 7002 |         } finally { | 
 | 7003 |             Binder.restoreCallingIdentity(identity); | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7004 |         } | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7005 |     } | 
 | 7006 |  | 
 | 7007 |     /** | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7008 |      * Get snapshot of Telephony histograms | 
 | 7009 |      * @return List of Telephony histograms | 
 | 7010 |      * @hide | 
 | 7011 |      */ | 
 | 7012 |     @Override | 
 | 7013 |     public List<TelephonyHistogram> getTelephonyHistograms() { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7014 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 7015 |                 mApp, getDefaultSubscription(), "getTelephonyHistograms"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7016 |  | 
 | 7017 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7018 |         try { | 
 | 7019 |             return RIL.getTelephonyRILTimingHistograms(); | 
 | 7020 |         } finally { | 
 | 7021 |             Binder.restoreCallingIdentity(identity); | 
 | 7022 |         } | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7023 |     } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7024 |  | 
 | 7025 |     /** | 
 | 7026 |      * {@hide} | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7027 |      * Set the allowed carrier list and the excluded carrier list, indicating the priority between | 
 | 7028 |      * the two lists. | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7029 |      * Require system privileges. In the future we may add this to carrier APIs. | 
 | 7030 |      * | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7031 |      * @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] | 7032 |      */ | 
 | 7033 |     @Override | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7034 |     @TelephonyManager.SetCarrierRestrictionResult | 
 | 7035 |     public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7036 |         enforceModifyPermission(); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7037 |         WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7038 |  | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7039 |         if (carrierRestrictionRules == null) { | 
 | 7040 |             throw new NullPointerException("carrier restriction cannot be null"); | 
| Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7041 |         } | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7042 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7043 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7044 |         try { | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7045 |             return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7046 |                     workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7047 |         } finally { | 
 | 7048 |             Binder.restoreCallingIdentity(identity); | 
 | 7049 |         } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7050 |     } | 
 | 7051 |  | 
 | 7052 |     /** | 
 | 7053 |      * {@hide} | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7054 |      * Get the allowed carrier list and the excluded carrier list, including the priority between | 
 | 7055 |      * the two lists. | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7056 |      * Require system privileges. In the future we may add this to carrier APIs. | 
 | 7057 |      * | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7058 |      * @return {@link android.telephony.CarrierRestrictionRules} | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7059 |      */ | 
 | 7060 |     @Override | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7061 |     public CarrierRestrictionRules getAllowedCarriers() { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7062 |         enforceReadPrivilegedPermission("getAllowedCarriers"); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7063 |         WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7064 |  | 
 | 7065 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7066 |         try { | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7067 |             Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); | 
 | 7068 |             if (response instanceof CarrierRestrictionRules) { | 
 | 7069 |                 return (CarrierRestrictionRules) response; | 
 | 7070 |             } | 
 | 7071 |             // Response is an Exception of some kind, | 
 | 7072 |             // which is signalled to the user as a NULL retval | 
 | 7073 |             return null; | 
 | 7074 |         } catch (Exception e) { | 
 | 7075 |             Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); | 
 | 7076 |             return null; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7077 |         } finally { | 
 | 7078 |             Binder.restoreCallingIdentity(identity); | 
 | 7079 |         } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7080 |     } | 
 | 7081 |  | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7082 |     /** | 
 | 7083 |      * Action set from carrier signalling broadcast receivers to enable/disable metered apns | 
 | 7084 |      * @param subId the subscription ID that this action applies to. | 
 | 7085 |      * @param enabled control enable or disable metered apns. | 
 | 7086 |      * {@hide} | 
 | 7087 |      */ | 
 | 7088 |     @Override | 
 | 7089 |     public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { | 
 | 7090 |         enforceModifyPermission(); | 
 | 7091 |         final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7092 |  | 
 | 7093 |         final long identity = Binder.clearCallingIdentity(); | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7094 |         if (phone == null) { | 
 | 7095 |             loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); | 
 | 7096 |             return; | 
 | 7097 |         } | 
 | 7098 |         try { | 
 | 7099 |             phone.carrierActionSetMeteredApnsEnabled(enabled); | 
 | 7100 |         } catch (Exception e) { | 
 | 7101 |             Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7102 |         } finally { | 
 | 7103 |             Binder.restoreCallingIdentity(identity); | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7104 |         } | 
 | 7105 |     } | 
 | 7106 |  | 
 | 7107 |     /** | 
 | 7108 |      * Action set from carrier signalling broadcast receivers to enable/disable radio | 
 | 7109 |      * @param subId the subscription ID that this action applies to. | 
 | 7110 |      * @param enabled control enable or disable radio. | 
 | 7111 |      * {@hide} | 
 | 7112 |      */ | 
 | 7113 |     @Override | 
 | 7114 |     public void carrierActionSetRadioEnabled(int subId, boolean enabled) { | 
 | 7115 |         enforceModifyPermission(); | 
 | 7116 |         final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7117 |  | 
 | 7118 |         final long identity = Binder.clearCallingIdentity(); | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7119 |         if (phone == null) { | 
 | 7120 |             loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); | 
 | 7121 |             return; | 
 | 7122 |         } | 
 | 7123 |         try { | 
 | 7124 |             phone.carrierActionSetRadioEnabled(enabled); | 
 | 7125 |         } catch (Exception e) { | 
 | 7126 |             Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7127 |         } finally { | 
 | 7128 |             Binder.restoreCallingIdentity(identity); | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7129 |         } | 
 | 7130 |     } | 
 | 7131 |  | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7132 |     /** | 
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7133 |      * Action set from carrier signalling broadcast receivers to start/stop reporting the default | 
 | 7134 |      * network status based on which carrier apps could apply actions accordingly, | 
 | 7135 |      * enable/disable default url handler for example. | 
 | 7136 |      * | 
 | 7137 |      * @param subId the subscription ID that this action applies to. | 
 | 7138 |      * @param report control start/stop reporting the default network status. | 
 | 7139 |      * {@hide} | 
 | 7140 |      */ | 
 | 7141 |     @Override | 
 | 7142 |     public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { | 
 | 7143 |         enforceModifyPermission(); | 
 | 7144 |         final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7145 |  | 
 | 7146 |         final long identity = Binder.clearCallingIdentity(); | 
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7147 |         if (phone == null) { | 
 | 7148 |             loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); | 
 | 7149 |             return; | 
 | 7150 |         } | 
 | 7151 |         try { | 
 | 7152 |             phone.carrierActionReportDefaultNetworkStatus(report); | 
 | 7153 |         } catch (Exception e) { | 
 | 7154 |             Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7155 |         } finally { | 
 | 7156 |             Binder.restoreCallingIdentity(identity); | 
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7157 |         } | 
 | 7158 |     } | 
 | 7159 |  | 
 | 7160 |     /** | 
| fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7161 |      * Action set from carrier signalling broadcast receivers to reset all carrier actions | 
 | 7162 |      * @param subId the subscription ID that this action applies to. | 
 | 7163 |      * {@hide} | 
 | 7164 |      */ | 
 | 7165 |     @Override | 
 | 7166 |     public void carrierActionResetAll(int subId) { | 
 | 7167 |         enforceModifyPermission(); | 
 | 7168 |         final Phone phone = getPhone(subId); | 
 | 7169 |         if (phone == null) { | 
 | 7170 |             loge("carrierAction: ResetAll fails with invalid sibId: " + subId); | 
 | 7171 |             return; | 
 | 7172 |         } | 
 | 7173 |         try { | 
 | 7174 |             phone.carrierActionResetAll(); | 
 | 7175 |         } catch (Exception e) { | 
 | 7176 |             Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); | 
 | 7177 |         } | 
 | 7178 |     } | 
 | 7179 |  | 
 | 7180 |     /** | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7181 |      * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a | 
 | 7182 |      * bug report is being generated. | 
 | 7183 |      */ | 
 | 7184 |     @Override | 
| Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7185 |     protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7186 |         if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) | 
 | 7187 |                 != PackageManager.PERMISSION_GRANTED) { | 
| dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7188 |             writer.println("Permission Denial: can't dump Phone from pid=" | 
 | 7189 |                     + Binder.getCallingPid() | 
 | 7190 |                     + ", uid=" + Binder.getCallingUid() | 
 | 7191 |                     + "without permission " | 
 | 7192 |                     + android.Manifest.permission.DUMP); | 
 | 7193 |             return; | 
 | 7194 |         } | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7195 |         DumpsysHandler.dump(mApp, fd, writer, args); | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7196 |     } | 
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7197 |  | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7198 |     @Override | 
| Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7199 |     public int handleShellCommand(@NonNull ParcelFileDescriptor in, | 
 | 7200 |             @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, | 
 | 7201 |             @NonNull String[] args) { | 
 | 7202 |         return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( | 
 | 7203 |                 this, in.getFileDescriptor(), out.getFileDescriptor(), | 
 | 7204 |                         err.getFileDescriptor(), args); | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7205 |     } | 
 | 7206 |  | 
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7207 |     /** | 
| Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7208 |      * Policy control of data connection. Usually used when data limit is passed. | 
 | 7209 |      * @param enabled True if enabling the data, otherwise disabling. | 
 | 7210 |      * @param subId Subscription index | 
 | 7211 |      * {@hide} | 
 | 7212 |      */ | 
 | 7213 |     @Override | 
 | 7214 |     public void setPolicyDataEnabled(boolean enabled, int subId) { | 
 | 7215 |         enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7216 |  | 
 | 7217 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7218 |         try { | 
 | 7219 |             Phone phone = getPhone(subId); | 
 | 7220 |             if (phone != null) { | 
| Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 7221 |                 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7222 |             } | 
 | 7223 |         } finally { | 
 | 7224 |             Binder.restoreCallingIdentity(identity); | 
| Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7225 |         } | 
 | 7226 |     } | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7227 |  | 
 | 7228 |     /** | 
 | 7229 |      * Get Client request stats | 
 | 7230 |      * @return List of Client Request Stats | 
 | 7231 |      * @hide | 
 | 7232 |      */ | 
 | 7233 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7234 |     public List<ClientRequestStats> getClientRequestStats(String callingPackage, | 
 | 7235 |             String callingFeatureId, int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7236 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7237 |                 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7238 |             return null; | 
 | 7239 |         } | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7240 |         Phone phone = getPhone(subId); | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7241 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7242 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7243 |         try { | 
 | 7244 |             if (phone != null) { | 
 | 7245 |                 return phone.getClientRequestStats(); | 
 | 7246 |             } | 
 | 7247 |  | 
 | 7248 |             return null; | 
 | 7249 |         } finally { | 
 | 7250 |             Binder.restoreCallingIdentity(identity); | 
 | 7251 |         } | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7252 |     } | 
 | 7253 |  | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7254 |     private WorkSource getWorkSource(int uid) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7255 |         String packageName = mApp.getPackageManager().getNameForUid(uid); | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7256 |         return new WorkSource(uid, packageName); | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7257 |     } | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7258 |  | 
 | 7259 |     /** | 
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7260 |      * Set SIM card power state. | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7261 |      * | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7262 |      * @param slotIndex SIM slot id. | 
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7263 |      * @param state  State of SIM (power down, power up, pass through) | 
 | 7264 |      * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} | 
 | 7265 |      * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} | 
 | 7266 |      * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7267 |      * | 
 | 7268 |      **/ | 
 | 7269 |     @Override | 
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7270 |     public void setSimPowerStateForSlot(int slotIndex, int state) { | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7271 |         enforceModifyPermission(); | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7272 |         Phone phone = PhoneFactory.getPhone(slotIndex); | 
 | 7273 |  | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7274 |         WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
 | 7275 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7276 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7277 |         try { | 
 | 7278 |             if (phone != null) { | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7279 |                 phone.setSimPowerState(state, workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7280 |             } | 
 | 7281 |         } finally { | 
 | 7282 |             Binder.restoreCallingIdentity(identity); | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7283 |         } | 
 | 7284 |     } | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7285 |  | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7286 |     private boolean isUssdApiAllowed(int subId) { | 
 | 7287 |         CarrierConfigManager configManager = | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7288 |                 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7289 |         if (configManager == null) { | 
 | 7290 |             return false; | 
 | 7291 |         } | 
 | 7292 |         PersistableBundle pb = configManager.getConfigForSubId(subId); | 
 | 7293 |         if (pb == null) { | 
 | 7294 |             return false; | 
 | 7295 |         } | 
 | 7296 |         return pb.getBoolean( | 
 | 7297 |                 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); | 
 | 7298 |     } | 
 | 7299 |  | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7300 |     /** | 
 | 7301 |      * Check if phone is in emergency callback mode | 
 | 7302 |      * @return true if phone is in emergency callback mode | 
 | 7303 |      * @param subId sub id | 
 | 7304 |      */ | 
| goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7305 |     @Override | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7306 |     public boolean getEmergencyCallbackMode(int subId) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7307 |         enforceReadPrivilegedPermission("getEmergencyCallbackMode"); | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7308 |         final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7309 |  | 
 | 7310 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7311 |         try { | 
 | 7312 |             if (phone != null) { | 
 | 7313 |                 return phone.isInEcm(); | 
 | 7314 |             } else { | 
 | 7315 |                 return false; | 
 | 7316 |             } | 
 | 7317 |         } finally { | 
 | 7318 |             Binder.restoreCallingIdentity(identity); | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7319 |         } | 
 | 7320 |     } | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7321 |  | 
 | 7322 |     /** | 
 | 7323 |      * Get the current signal strength information for the given subscription. | 
 | 7324 |      * Because this information is not updated when the device is in a low power state | 
 | 7325 |      * it should not be relied-upon to be current. | 
 | 7326 |      * @param subId Subscription index | 
 | 7327 |      * @return the most recent cached signal strength info from the modem | 
 | 7328 |      */ | 
 | 7329 |     @Override | 
 | 7330 |     public SignalStrength getSignalStrength(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7331 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7332 |         try { | 
 | 7333 |             Phone p = getPhone(subId); | 
 | 7334 |             if (p == null) { | 
 | 7335 |                 return null; | 
 | 7336 |             } | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7337 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7338 |             return p.getSignalStrength(); | 
 | 7339 |         } finally { | 
 | 7340 |             Binder.restoreCallingIdentity(identity); | 
 | 7341 |         } | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7342 |     } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7343 |  | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7344 |     /** | 
| Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7345 |      * Get the current modem radio state for the given slot. | 
 | 7346 |      * @param slotIndex slot index. | 
 | 7347 |      * @param callingPackage the name of the package making the call. | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7348 |      * @param callingFeatureId The feature in the package. | 
| Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7349 |      * @return the current radio power state from the modem | 
 | 7350 |      */ | 
 | 7351 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7352 |     public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { | 
| Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7353 |         Phone phone = PhoneFactory.getPhone(slotIndex); | 
 | 7354 |         if (phone != null) { | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7355 |             if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), | 
 | 7356 |                     callingPackage, callingFeatureId, "getRadioPowerState")) { | 
| Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7357 |                 return TelephonyManager.RADIO_POWER_UNAVAILABLE; | 
 | 7358 |             } | 
 | 7359 |  | 
 | 7360 |             final long identity = Binder.clearCallingIdentity(); | 
 | 7361 |             try { | 
 | 7362 |                 return phone.getRadioPowerState(); | 
 | 7363 |             } finally { | 
 | 7364 |                 Binder.restoreCallingIdentity(identity); | 
 | 7365 |             } | 
 | 7366 |         } | 
 | 7367 |         return TelephonyManager.RADIO_POWER_UNAVAILABLE; | 
 | 7368 |     } | 
 | 7369 |  | 
 | 7370 |     /** | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7371 |      * Checks if data roaming is enabled on the subscription with id {@code subId}. | 
 | 7372 |      * | 
 | 7373 |      * <p>Requires one of the following permissions: | 
 | 7374 |      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, | 
 | 7375 |      * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier | 
 | 7376 |      * privileges. | 
 | 7377 |      * | 
 | 7378 |      * @param subId subscription id | 
 | 7379 |      * @return {@code true} if data roaming is enabled on this subscription, otherwise return | 
 | 7380 |      * {@code false}. | 
 | 7381 |      */ | 
 | 7382 |     @Override | 
 | 7383 |     public boolean isDataRoamingEnabled(int subId) { | 
| Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7384 |         mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, | 
 | 7385 |                 null /* message */); | 
 | 7386 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7387 |         boolean isEnabled = false; | 
 | 7388 |         final long identity = Binder.clearCallingIdentity(); | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7389 |         try { | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7390 |             Phone phone = getPhone(subId); | 
 | 7391 |             isEnabled =  phone != null ? phone.getDataRoamingEnabled() : false; | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7392 |         } catch (Exception e) { | 
 | 7393 |             TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( | 
 | 7394 |                     mApp, subId, "isDataRoamingEnabled"); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7395 |         } finally { | 
 | 7396 |             Binder.restoreCallingIdentity(identity); | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7397 |         } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7398 |         return isEnabled; | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7399 |     } | 
 | 7400 |  | 
 | 7401 |  | 
 | 7402 |     /** | 
 | 7403 |      * Enables/Disables the data roaming on the subscription with id {@code subId}. | 
 | 7404 |      * | 
 | 7405 |      * <p> Requires permission: | 
 | 7406 |      * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier | 
 | 7407 |      * privileges. | 
 | 7408 |      * | 
 | 7409 |      * @param subId subscription id | 
 | 7410 |      * @param isEnabled {@code true} means enable, {@code false} means disable. | 
 | 7411 |      */ | 
 | 7412 |     @Override | 
 | 7413 |     public void setDataRoamingEnabled(int subId, boolean isEnabled) { | 
| Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7414 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 7415 |                 mApp, subId, "setDataRoamingEnabled"); | 
 | 7416 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7417 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7418 |         try { | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7419 |             Phone phone = getPhone(subId); | 
 | 7420 |             if (phone != null) { | 
 | 7421 |                 phone.setDataRoamingEnabled(isEnabled); | 
 | 7422 |             } | 
 | 7423 |         } finally { | 
 | 7424 |             Binder.restoreCallingIdentity(identity); | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7425 |         } | 
 | 7426 |     } | 
 | 7427 |  | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7428 |     @Override | 
| Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7429 |     public boolean isManualNetworkSelectionAllowed(int subId) { | 
| tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7430 |         TelephonyPermissions | 
 | 7431 |                 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
| Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7432 |                 mApp, subId, "isManualNetworkSelectionAllowed"); | 
 | 7433 |  | 
| Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7434 |         boolean isAllowed = true; | 
 | 7435 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7436 |         try { | 
| Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7437 |             Phone phone = getPhone(subId); | 
 | 7438 |             if (phone != null) { | 
 | 7439 |                 isAllowed = phone.isCspPlmnEnabled(); | 
 | 7440 |             } | 
 | 7441 |         } finally { | 
 | 7442 |             Binder.restoreCallingIdentity(identity); | 
 | 7443 |         } | 
 | 7444 |         return isAllowed; | 
 | 7445 |     } | 
 | 7446 |  | 
 | 7447 |     @Override | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7448 |     public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7449 |         boolean hasReadPermission = false; | 
| Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7450 |         try { | 
 | 7451 |             enforceReadPrivilegedPermission("getUiccCardsInfo"); | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7452 |             hasReadPermission = true; | 
| Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7453 |         } catch (SecurityException e) { | 
 | 7454 |             // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller | 
 | 7455 |             // has carrier privileges on an active UICC | 
 | 7456 |             if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) | 
 | 7457 |                         != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7458 |                 throw new SecurityException("Caller does not have permission."); | 
| Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7459 |             } | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7460 |         } | 
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7461 |  | 
 | 7462 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7463 |         try { | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7464 |             UiccController uiccController = UiccController.getInstance(); | 
 | 7465 |             ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7466 |             if (hasReadPermission) { | 
 | 7467 |                 return cardInfos; | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7468 |             } | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7469 |  | 
 | 7470 |             // Remove private info if the caller doesn't have access | 
 | 7471 |             ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); | 
 | 7472 |             for (UiccCardInfo cardInfo : cardInfos) { | 
 | 7473 |                 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo | 
 | 7474 |                 // is available | 
 | 7475 |                 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); | 
 | 7476 |                 if (card == null || card.getUiccProfile() == null) { | 
 | 7477 |                     // assume no access if the card or profile is unavailable | 
 | 7478 |                     filteredInfos.add(cardInfo.getUnprivileged()); | 
 | 7479 |                     continue; | 
 | 7480 |                 } | 
 | 7481 |                 UiccProfile profile = card.getUiccProfile(); | 
 | 7482 |                 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) | 
 | 7483 |                         == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
 | 7484 |                     filteredInfos.add(cardInfo); | 
 | 7485 |                 } else { | 
 | 7486 |                     filteredInfos.add(cardInfo.getUnprivileged()); | 
 | 7487 |                 } | 
 | 7488 |             } | 
 | 7489 |             return filteredInfos; | 
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7490 |         } finally { | 
 | 7491 |             Binder.restoreCallingIdentity(identity); | 
 | 7492 |         } | 
 | 7493 |     } | 
 | 7494 |  | 
 | 7495 |     @Override | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7496 |     public UiccSlotInfo[] getUiccSlotsInfo() { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7497 |         enforceReadPrivilegedPermission("getUiccSlotsInfo"); | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7498 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7499 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7500 |         try { | 
 | 7501 |             UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); | 
 | 7502 |             if (slots == null) { | 
 | 7503 |                 Rlog.i(LOG_TAG, "slots is null."); | 
 | 7504 |                 return null; | 
 | 7505 |             } | 
 | 7506 |  | 
 | 7507 |             UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; | 
 | 7508 |             for (int i = 0; i < slots.length; i++) { | 
 | 7509 |                 UiccSlot slot = slots[i]; | 
 | 7510 |                 if (slot == null) { | 
 | 7511 |                     continue; | 
 | 7512 |                 } | 
 | 7513 |  | 
| Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7514 |                 String cardId; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7515 |                 UiccCard card = slot.getUiccCard(); | 
 | 7516 |                 if (card != null) { | 
 | 7517 |                     cardId = card.getCardId(); | 
| Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7518 |                 } else { | 
| Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7519 |                     cardId = slot.getEid(); | 
 | 7520 |                     if (TextUtils.isEmpty(cardId)) { | 
 | 7521 |                         cardId = slot.getIccId(); | 
 | 7522 |                     } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7523 |                 } | 
 | 7524 |  | 
| Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7525 |                 if (cardId != null) { | 
 | 7526 |                     // if cardId is an ICCID, strip off trailing Fs before exposing to user | 
 | 7527 |                     // if cardId is an EID, it's all digits so this is fine | 
 | 7528 |                     cardId = IccUtils.stripTrailingFs(cardId); | 
 | 7529 |                 } | 
 | 7530 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7531 |                 int cardState = 0; | 
 | 7532 |                 switch (slot.getCardState()) { | 
 | 7533 |                     case CARDSTATE_ABSENT: | 
 | 7534 |                         cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; | 
 | 7535 |                         break; | 
 | 7536 |                     case CARDSTATE_PRESENT: | 
 | 7537 |                         cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; | 
 | 7538 |                         break; | 
 | 7539 |                     case CARDSTATE_ERROR: | 
 | 7540 |                         cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; | 
 | 7541 |                         break; | 
 | 7542 |                     case CARDSTATE_RESTRICTED: | 
 | 7543 |                         cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; | 
 | 7544 |                         break; | 
 | 7545 |                     default: | 
 | 7546 |                         break; | 
 | 7547 |  | 
 | 7548 |                 } | 
 | 7549 |  | 
 | 7550 |                 infos[i] = new UiccSlotInfo( | 
 | 7551 |                         slot.isActive(), | 
 | 7552 |                         slot.isEuicc(), | 
 | 7553 |                         cardId, | 
 | 7554 |                         cardState, | 
 | 7555 |                         slot.getPhoneId(), | 
| Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7556 |                         slot.isExtendedApduSupported(), | 
 | 7557 |                         slot.isRemovable()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7558 |             } | 
 | 7559 |             return infos; | 
 | 7560 |         } finally { | 
 | 7561 |             Binder.restoreCallingIdentity(identity); | 
| Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7562 |         } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7563 |     } | 
 | 7564 |  | 
 | 7565 |     @Override | 
 | 7566 |     public boolean switchSlots(int[] physicalSlots) { | 
 | 7567 |         enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7568 |  | 
 | 7569 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7570 |         try { | 
 | 7571 |             return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); | 
 | 7572 |         } finally { | 
 | 7573 |             Binder.restoreCallingIdentity(identity); | 
 | 7574 |         } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7575 |     } | 
| Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7576 |  | 
 | 7577 |     @Override | 
| Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7578 |     public int getCardIdForDefaultEuicc(int subId, String callingPackage) { | 
| Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7579 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7580 |         try { | 
 | 7581 |             return UiccController.getInstance().getCardIdForDefaultEuicc(); | 
 | 7582 |         } finally { | 
 | 7583 |             Binder.restoreCallingIdentity(identity); | 
 | 7584 |         } | 
 | 7585 |     } | 
 | 7586 |  | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7587 |     /** | 
| goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7588 |      * A test API to reload the UICC profile. | 
 | 7589 |      * | 
 | 7590 |      * <p>Requires that the calling app has permission | 
 | 7591 |      * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. | 
 | 7592 |      * @hide | 
 | 7593 |      */ | 
 | 7594 |     @Override | 
 | 7595 |     public void refreshUiccProfile(int subId) { | 
 | 7596 |         enforceModifyPermission(); | 
 | 7597 |  | 
 | 7598 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7599 |         try { | 
 | 7600 |             Phone phone = getPhone(subId); | 
 | 7601 |             if (phone == null) { | 
 | 7602 |                 return; | 
 | 7603 |             } | 
 | 7604 |             UiccCard uiccCard = phone.getUiccCard(); | 
 | 7605 |             if (uiccCard == null) { | 
 | 7606 |                 return; | 
 | 7607 |             } | 
 | 7608 |             UiccProfile uiccProfile = uiccCard.getUiccProfile(); | 
 | 7609 |             if (uiccProfile == null) { | 
 | 7610 |                 return; | 
 | 7611 |             } | 
 | 7612 |             uiccProfile.refresh(); | 
 | 7613 |         } finally { | 
 | 7614 |             Binder.restoreCallingIdentity(identity); | 
 | 7615 |         } | 
 | 7616 |     } | 
 | 7617 |  | 
 | 7618 |     /** | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7619 |      * Returns false if the mobile data is disabled by default, otherwise return true. | 
 | 7620 |      */ | 
 | 7621 |     private boolean getDefaultDataEnabled() { | 
| Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7622 |         return TelephonyProperties.mobile_data().orElse(true); | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7623 |     } | 
 | 7624 |  | 
 | 7625 |     /** | 
 | 7626 |      * Returns true if the data roaming is enabled by default, i.e the system property | 
 | 7627 |      * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of | 
 | 7628 |      * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. | 
 | 7629 |      */ | 
 | 7630 |     private boolean getDefaultDataRoamingEnabled(int subId) { | 
 | 7631 |         final CarrierConfigManager configMgr = (CarrierConfigManager) | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7632 |                 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7633 |         boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7634 |         isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( | 
 | 7635 |                 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); | 
 | 7636 |         return isDataRoamingEnabled; | 
 | 7637 |     } | 
 | 7638 |  | 
 | 7639 |     /** | 
 | 7640 |      * Returns the default network type for the given {@code subId}, if the default network type is | 
 | 7641 |      * not set, return {@link Phone#PREFERRED_NT_MODE}. | 
 | 7642 |      */ | 
 | 7643 |     private int getDefaultNetworkType(int subId) { | 
| Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7644 |         List<Integer> list = TelephonyProperties.default_network(); | 
 | 7645 |         int phoneId = mSubscriptionController.getPhoneId(subId); | 
 | 7646 |         if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { | 
 | 7647 |             return list.get(phoneId); | 
 | 7648 |         } | 
 | 7649 |         return Phone.PREFERRED_NT_MODE; | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7650 |     } | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7651 |  | 
 | 7652 |     @Override | 
 | 7653 |     public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String | 
| chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7654 |             gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7655 |         enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7656 |  | 
 | 7657 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7658 |         try { | 
 | 7659 |             final Phone phone = getPhone(subId); | 
 | 7660 |             if (phone == null) { | 
 | 7661 |                 loge("setCarrierTestOverride fails with invalid subId: " + subId); | 
 | 7662 |                 return; | 
 | 7663 |             } | 
| chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7664 |             phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, | 
 | 7665 |                     carrierPrivilegeRules, apn); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7666 |         } finally { | 
 | 7667 |             Binder.restoreCallingIdentity(identity); | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7668 |         } | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7669 |     } | 
 | 7670 |  | 
 | 7671 |     @Override | 
 | 7672 |     public int getCarrierIdListVersion(int subId) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7673 |         enforceReadPrivilegedPermission("getCarrierIdListVersion"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7674 |  | 
 | 7675 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7676 |         try { | 
 | 7677 |             final Phone phone = getPhone(subId); | 
 | 7678 |             if (phone == null) { | 
 | 7679 |                 loge("getCarrierIdListVersion fails with invalid subId: " + subId); | 
 | 7680 |                 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; | 
 | 7681 |             } | 
 | 7682 |             return phone.getCarrierIdListVersion(); | 
 | 7683 |         } finally { | 
 | 7684 |             Binder.restoreCallingIdentity(identity); | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7685 |         } | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7686 |     } | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7687 |  | 
 | 7688 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7689 |     public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, | 
 | 7690 |             String callingFeatureId) { | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7691 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7692 |                 mApp, subId, callingPackage, callingFeatureId, | 
 | 7693 |                 "getNumberOfModemsWithSimultaneousDataConnections")) { | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7694 |             return -1; | 
 | 7695 |         } | 
 | 7696 |  | 
 | 7697 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7698 |         try { | 
 | 7699 |             return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); | 
 | 7700 |         } finally { | 
 | 7701 |             Binder.restoreCallingIdentity(identity); | 
 | 7702 |         } | 
 | 7703 |     } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7704 |  | 
 | 7705 |     @Override | 
 | 7706 |     public int getCdmaRoamingMode(int subId) { | 
| zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 7707 |         TelephonyPermissions | 
 | 7708 |                 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7709 |                 mApp, subId, "getCdmaRoamingMode"); | 
 | 7710 |  | 
 | 7711 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7712 |         try { | 
 | 7713 |             return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); | 
 | 7714 |         } finally { | 
 | 7715 |             Binder.restoreCallingIdentity(identity); | 
 | 7716 |         } | 
 | 7717 |     } | 
 | 7718 |  | 
 | 7719 |     @Override | 
 | 7720 |     public boolean setCdmaRoamingMode(int subId, int mode) { | 
 | 7721 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 7722 |                 mApp, subId, "setCdmaRoamingMode"); | 
 | 7723 |  | 
 | 7724 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7725 |         try { | 
 | 7726 |             return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); | 
 | 7727 |         } finally { | 
 | 7728 |             Binder.restoreCallingIdentity(identity); | 
 | 7729 |         } | 
 | 7730 |     } | 
 | 7731 |  | 
 | 7732 |     @Override | 
 | 7733 |     public boolean setCdmaSubscriptionMode(int subId, int mode) { | 
 | 7734 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 7735 |                 mApp, subId, "setCdmaSubscriptionMode"); | 
 | 7736 |  | 
 | 7737 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7738 |         try { | 
 | 7739 |             return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); | 
 | 7740 |         } finally { | 
 | 7741 |             Binder.restoreCallingIdentity(identity); | 
 | 7742 |         } | 
 | 7743 |     } | 
| Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7744 |  | 
| sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7745 |     @Override | 
| sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7746 |     public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7747 |             String callingPackage, String callingFeatureId) { | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7748 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7749 |                 mApp, getDefaultSubscription(), callingPackage, callingFeatureId, | 
 | 7750 |                 "getEmergencyNumberList")) { | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7751 |             throw new SecurityException("Requires READ_PHONE_STATE permission."); | 
 | 7752 |         } | 
 | 7753 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7754 |         try { | 
| sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7755 |             Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); | 
 | 7756 |             for (Phone phone: PhoneFactory.getPhones()) { | 
 | 7757 |                 if (phone.getEmergencyNumberTracker() != null | 
 | 7758 |                         && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { | 
 | 7759 |                     emergencyNumberListInternal.put( | 
 | 7760 |                             phone.getSubId(), | 
 | 7761 |                             phone.getEmergencyNumberTracker().getEmergencyNumberList()); | 
 | 7762 |                 } | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7763 |             } | 
| sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7764 |             return emergencyNumberListInternal; | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7765 |         } finally { | 
 | 7766 |             Binder.restoreCallingIdentity(identity); | 
 | 7767 |         } | 
| sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7768 |     } | 
 | 7769 |  | 
 | 7770 |     @Override | 
| sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7771 |     public boolean isEmergencyNumber(String number, boolean exactMatch) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7772 |         final Phone defaultPhone = getDefaultPhone(); | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7773 |         if (!exactMatch) { | 
 | 7774 |             TelephonyPermissions | 
 | 7775 |                     .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
| sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7776 |                             mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7777 |         } | 
 | 7778 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7779 |         try { | 
| sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7780 |             for (Phone phone: PhoneFactory.getPhones()) { | 
 | 7781 |                 if (phone.getEmergencyNumberTracker() != null | 
 | 7782 |                         && phone.getEmergencyNumberTracker() != null) { | 
 | 7783 |                     if (phone.getEmergencyNumberTracker().isEmergencyNumber( | 
 | 7784 |                             number, exactMatch)) { | 
 | 7785 |                         return true; | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7786 |                     } | 
 | 7787 |                 } | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7788 |             } | 
 | 7789 |             return false; | 
 | 7790 |         } finally { | 
 | 7791 |             Binder.restoreCallingIdentity(identity); | 
 | 7792 |         } | 
 | 7793 |     } | 
 | 7794 |  | 
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7795 |     /** | 
 | 7796 |      * Update emergency number list for test mode. | 
 | 7797 |      */ | 
 | 7798 |     @Override | 
 | 7799 |     public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { | 
 | 7800 |         TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
 | 7801 |                 "updateEmergencyNumberListTestMode"); | 
 | 7802 |  | 
 | 7803 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7804 |         try { | 
 | 7805 |             for (Phone phone: PhoneFactory.getPhones()) { | 
 | 7806 |                 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
 | 7807 |                 if (tracker != null) { | 
 | 7808 |                     tracker.executeEmergencyNumberTestModeCommand(action, num); | 
 | 7809 |                 } | 
 | 7810 |             } | 
 | 7811 |         } finally { | 
 | 7812 |             Binder.restoreCallingIdentity(identity); | 
 | 7813 |         } | 
 | 7814 |     } | 
 | 7815 |  | 
 | 7816 |     /** | 
 | 7817 |      * Get the full emergency number list for test mode. | 
 | 7818 |      */ | 
 | 7819 |     @Override | 
 | 7820 |     public List<String> getEmergencyNumberListTestMode() { | 
 | 7821 |         TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
 | 7822 |                 "getEmergencyNumberListTestMode"); | 
 | 7823 |  | 
 | 7824 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7825 |         try { | 
 | 7826 |             Set<String> emergencyNumbers = new HashSet<>(); | 
 | 7827 |             for (Phone phone: PhoneFactory.getPhones()) { | 
 | 7828 |                 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
 | 7829 |                 if (tracker != null) { | 
 | 7830 |                     for (EmergencyNumber num : tracker.getEmergencyNumberList()) { | 
 | 7831 |                         emergencyNumbers.add(num.getNumber()); | 
 | 7832 |                     } | 
 | 7833 |                 } | 
 | 7834 |             } | 
 | 7835 |             return new ArrayList<>(emergencyNumbers); | 
 | 7836 |         } finally { | 
 | 7837 |             Binder.restoreCallingIdentity(identity); | 
 | 7838 |         } | 
 | 7839 |     } | 
 | 7840 |  | 
| chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7841 |     @Override | 
| Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7842 |     public int getEmergencyNumberDbVersion(int subId) { | 
 | 7843 |         enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); | 
 | 7844 |  | 
 | 7845 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7846 |         try { | 
 | 7847 |             final Phone phone = getPhone(subId); | 
 | 7848 |             if (phone == null) { | 
 | 7849 |                 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); | 
 | 7850 |                 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; | 
 | 7851 |             } | 
 | 7852 |             return phone.getEmergencyNumberDbVersion(); | 
 | 7853 |         } finally { | 
 | 7854 |             Binder.restoreCallingIdentity(identity); | 
 | 7855 |         } | 
 | 7856 |     } | 
 | 7857 |  | 
 | 7858 |     @Override | 
 | 7859 |     public void notifyOtaEmergencyNumberDbInstalled() { | 
 | 7860 |         enforceModifyPermission(); | 
 | 7861 |  | 
 | 7862 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7863 |         try { | 
 | 7864 |             for (Phone phone: PhoneFactory.getPhones()) { | 
 | 7865 |                 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
 | 7866 |                 if (tracker != null) { | 
 | 7867 |                     tracker.updateOtaEmergencyNumberDatabase(); | 
 | 7868 |                 } | 
 | 7869 |             } | 
 | 7870 |         } finally { | 
 | 7871 |             Binder.restoreCallingIdentity(identity); | 
 | 7872 |         } | 
 | 7873 |     } | 
 | 7874 |  | 
 | 7875 |     @Override | 
 | 7876 |     public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) { | 
 | 7877 |         enforceActiveEmergencySessionPermission(); | 
 | 7878 |  | 
 | 7879 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7880 |         try { | 
 | 7881 |             for (Phone phone: PhoneFactory.getPhones()) { | 
 | 7882 |                 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
 | 7883 |                 if (tracker != null) { | 
 | 7884 |                     tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath); | 
 | 7885 |                 } | 
 | 7886 |             } | 
 | 7887 |         } finally { | 
 | 7888 |             Binder.restoreCallingIdentity(identity); | 
 | 7889 |         } | 
 | 7890 |     } | 
 | 7891 |  | 
 | 7892 |     @Override | 
| chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7893 |     public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { | 
 | 7894 |         enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); | 
 | 7895 |         Phone phone = getPhone(subId); | 
 | 7896 |         if (phone == null) { | 
 | 7897 |             return null; | 
 | 7898 |         } | 
 | 7899 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7900 |         try { | 
 | 7901 |             UiccProfile profile = UiccController.getInstance() | 
 | 7902 |                     .getUiccProfileForPhone(phone.getPhoneId()); | 
 | 7903 |             if (profile != null) { | 
 | 7904 |                 return profile.getCertsFromCarrierPrivilegeAccessRules(); | 
 | 7905 |             } | 
 | 7906 |         } finally { | 
 | 7907 |             Binder.restoreCallingIdentity(identity); | 
 | 7908 |         } | 
 | 7909 |         return null; | 
 | 7910 |     } | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7911 |  | 
 | 7912 |     /** | 
 | 7913 |      * Enable or disable a modem stack. | 
 | 7914 |      */ | 
 | 7915 |     @Override | 
 | 7916 |     public boolean enableModemForSlot(int slotIndex, boolean enable) { | 
 | 7917 |         enforceModifyPermission(); | 
 | 7918 |  | 
 | 7919 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7920 |         try { | 
 | 7921 |             Phone phone = PhoneFactory.getPhone(slotIndex); | 
 | 7922 |             if (phone == null) { | 
 | 7923 |                 return false; | 
 | 7924 |             } else { | 
 | 7925 |                 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); | 
 | 7926 |             } | 
 | 7927 |         } finally { | 
 | 7928 |             Binder.restoreCallingIdentity(identity); | 
 | 7929 |         } | 
 | 7930 |     } | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7931 |  | 
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7932 |     /** | 
 | 7933 |      * Whether a modem stack is enabled or not. | 
 | 7934 |      */ | 
 | 7935 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7936 |     public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, | 
 | 7937 |             String callingFeatureId) { | 
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7938 |         Phone phone = PhoneFactory.getPhone(slotIndex); | 
 | 7939 |         if (phone == null) return false; | 
 | 7940 |  | 
 | 7941 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7942 |                 mApp, phone.getSubId(), callingPackage, callingFeatureId, | 
 | 7943 |                 "isModemEnabledForSlot")) { | 
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7944 |             throw new SecurityException("Requires READ_PHONE_STATE permission."); | 
 | 7945 |         } | 
 | 7946 |  | 
 | 7947 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7948 |         try { | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7949 |             try { | 
 | 7950 |                 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); | 
 | 7951 |             } catch (NoSuchElementException ex) { | 
 | 7952 |                 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); | 
 | 7953 |             } | 
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7954 |         } finally { | 
 | 7955 |             Binder.restoreCallingIdentity(identity); | 
 | 7956 |         } | 
 | 7957 |     } | 
 | 7958 |  | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7959 |     @Override | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7960 |     public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7961 |         enforceModifyPermission(); | 
 | 7962 |  | 
 | 7963 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7964 |         try { | 
 | 7965 |             mTelephonySharedPreferences.edit() | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7966 |                     .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7967 |                     .commit(); | 
 | 7968 |         } finally { | 
 | 7969 |             Binder.restoreCallingIdentity(identity); | 
 | 7970 |         } | 
 | 7971 |     } | 
 | 7972 |  | 
 | 7973 |     @Override | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7974 |     @TelephonyManager.IsMultiSimSupportedResult | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7975 |     public int isMultiSimSupported(String callingPackage, String callingFeatureId) { | 
| Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7976 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7977 |                 getDefaultPhone().getSubId(), callingPackage, callingFeatureId, | 
 | 7978 |                 "isMultiSimSupported")) { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7979 |             return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; | 
| Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7980 |         } | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7981 |  | 
 | 7982 |         final long identity = Binder.clearCallingIdentity(); | 
 | 7983 |         try { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7984 |             return isMultiSimSupportedInternal(); | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7985 |         } finally { | 
 | 7986 |             Binder.restoreCallingIdentity(identity); | 
 | 7987 |         } | 
 | 7988 |     } | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7989 |  | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7990 |     @TelephonyManager.IsMultiSimSupportedResult | 
 | 7991 |     private int isMultiSimSupportedInternal() { | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7992 |         // If the device has less than 2 SIM cards, indicate that multisim is restricted. | 
 | 7993 |         int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; | 
 | 7994 |         if (numPhysicalSlots < 2) { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7995 |             loge("isMultiSimSupportedInternal: requires at least 2 cards"); | 
 | 7996 |             return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7997 |         } | 
 | 7998 |         // Check if the hardware supports multisim functionality. If usage of multisim is not | 
 | 7999 |         // supported by the modem, indicate that it is restricted. | 
 | 8000 |         PhoneCapability staticCapability = | 
 | 8001 |                 mPhoneConfigurationManager.getStaticPhoneCapability(); | 
 | 8002 |         if (staticCapability == null) { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8003 |             loge("isMultiSimSupportedInternal: no static configuration available"); | 
 | 8004 |             return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8005 |         } | 
| Sarah Chin | 7caee49 | 2020-02-18 20:49:02 +0000 | [diff] [blame] | 8006 |         if (staticCapability.logicalModemList.size() < 2) { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8007 |             loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); | 
 | 8008 |             return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8009 |         } | 
 | 8010 |         // Check if support of multiple SIMs is restricted by carrier | 
 | 8011 |         if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8012 |             return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8013 |         } | 
 | 8014 |  | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8015 |         return TelephonyManager.MULTISIM_ALLOWED; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8016 |     } | 
 | 8017 |  | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8018 |     /** | 
 | 8019 |      * Switch configs to enable multi-sim or switch back to single-sim | 
| Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8020 |      * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE | 
 | 8021 |      * permission, but the other way around is possible with either MODIFY_PHONE_STATE | 
 | 8022 |      * or carrier privileges | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8023 |      * @param numOfSims number of active sims we want to switch to | 
 | 8024 |      */ | 
 | 8025 |     @Override | 
 | 8026 |     public void switchMultiSimConfig(int numOfSims) { | 
| Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8027 |         if (numOfSims == 1) { | 
 | 8028 |             enforceModifyPermission(); | 
 | 8029 |         } else { | 
 | 8030 |             TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 8031 |                     mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); | 
 | 8032 |         } | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8033 |         final long identity = Binder.clearCallingIdentity(); | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8034 |  | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8035 |         try { | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8036 |             //only proceed if multi-sim is not restricted | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8037 |             if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8038 |                 loge("switchMultiSimConfig not possible. It is restricted or not supported."); | 
 | 8039 |                 return; | 
 | 8040 |             } | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8041 |             mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); | 
 | 8042 |         } finally { | 
 | 8043 |             Binder.restoreCallingIdentity(identity); | 
 | 8044 |         } | 
 | 8045 |     } | 
 | 8046 |  | 
| Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8047 |     @Override | 
 | 8048 |     public boolean isApplicationOnUicc(int subId, int appType) { | 
 | 8049 |         enforceReadPrivilegedPermission("isApplicationOnUicc"); | 
 | 8050 |         Phone phone = getPhone(subId); | 
 | 8051 |         if (phone == null) { | 
 | 8052 |             return false; | 
 | 8053 |         } | 
 | 8054 |         final long identity = Binder.clearCallingIdentity(); | 
 | 8055 |         try { | 
 | 8056 |             UiccCard uiccCard = phone.getUiccCard(); | 
 | 8057 |             if (uiccCard == null) { | 
 | 8058 |                 return false; | 
 | 8059 |             } | 
 | 8060 |             UiccProfile uiccProfile = uiccCard.getUiccProfile(); | 
 | 8061 |             if (uiccProfile == null) { | 
 | 8062 |                 return false; | 
 | 8063 |             } | 
 | 8064 |             if (TelephonyManager.APPTYPE_SIM <= appType | 
 | 8065 |                     && appType <= TelephonyManager.APPTYPE_ISIM) { | 
 | 8066 |                 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); | 
 | 8067 |             } | 
 | 8068 |             return false; | 
 | 8069 |         } finally { | 
 | 8070 |             Binder.restoreCallingIdentity(identity); | 
 | 8071 |         } | 
 | 8072 |     } | 
 | 8073 |  | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8074 |     /** | 
| chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8075 |      * Get whether making changes to modem configurations will trigger reboot. | 
 | 8076 |      * Return value defaults to true. | 
| Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8077 |      */ | 
 | 8078 |     @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8079 |     public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, | 
 | 8080 |             String callingFeatureId) { | 
| chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8081 |         if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8082 |                 mApp, subId, callingPackage, callingFeatureId, | 
 | 8083 |                 "doesSwitchMultiSimConfigTriggerReboot")) { | 
| chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8084 |             return false; | 
 | 8085 |         } | 
| Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8086 |         final long identity = Binder.clearCallingIdentity(); | 
 | 8087 |         try { | 
 | 8088 |             return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); | 
 | 8089 |         } finally { | 
 | 8090 |             Binder.restoreCallingIdentity(identity); | 
 | 8091 |         } | 
 | 8092 |     } | 
 | 8093 |  | 
| Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8094 |     private void updateModemStateMetrics() { | 
 | 8095 |         TelephonyMetrics metrics = TelephonyMetrics.getInstance(); | 
 | 8096 |         // TODO: check the state for each modem if the api is ready. | 
 | 8097 |         metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); | 
 | 8098 |     } | 
 | 8099 |  | 
| Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8100 |     @Override | 
 | 8101 |     public int[] getSlotsMapping() { | 
 | 8102 |         enforceReadPrivilegedPermission("getSlotsMapping"); | 
 | 8103 |  | 
 | 8104 |         final long identity = Binder.clearCallingIdentity(); | 
 | 8105 |         try { | 
 | 8106 |             int phoneCount = TelephonyManager.getDefault().getPhoneCount(); | 
 | 8107 |             // All logical slots should have a mapping to a physical slot. | 
 | 8108 |             int[] logicalSlotsMapping = new int[phoneCount]; | 
 | 8109 |             UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); | 
 | 8110 |             for (int i = 0; i < slotInfos.length; i++) { | 
 | 8111 |                 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { | 
 | 8112 |                     logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; | 
 | 8113 |                 } | 
 | 8114 |             } | 
 | 8115 |             return logicalSlotsMapping; | 
 | 8116 |         } finally { | 
 | 8117 |             Binder.restoreCallingIdentity(identity); | 
 | 8118 |         } | 
 | 8119 |     } | 
| Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8120 |  | 
 | 8121 |     /** | 
 | 8122 |      * Get the IRadio HAL Version | 
 | 8123 |      */ | 
 | 8124 |     @Override | 
 | 8125 |     public int getRadioHalVersion() { | 
 | 8126 |         Phone phone = getDefaultPhone(); | 
 | 8127 |         if (phone == null) return -1; | 
 | 8128 |         HalVersion hv = phone.getHalVersion(); | 
 | 8129 |         if (hv.equals(HalVersion.UNKNOWN)) return -1; | 
 | 8130 |         return hv.major * 100 + hv.minor; | 
 | 8131 |     } | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8132 |  | 
 | 8133 |     /** | 
| Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8134 |      * Get the current calling package name. | 
 | 8135 |      * @return the current calling package name | 
 | 8136 |      */ | 
 | 8137 |     @Override | 
 | 8138 |     public String getCurrentPackageName() { | 
 | 8139 |         return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; | 
 | 8140 |     } | 
 | 8141 |  | 
 | 8142 |     /** | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8143 |      * Return whether data is enabled for certain APN type. This will tell if framework will accept | 
 | 8144 |      * corresponding network requests on a subId. | 
 | 8145 |      * | 
 | 8146 |      *  Data is enabled if: | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8147 |      *  1) user data is turned on, or | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8148 |      *  2) APN is un-metered for this subscription, or | 
 | 8149 |      *  3) APN type is whitelisted. E.g. MMS is whitelisted if | 
| changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8150 |      *  {@link TelephonyManager#setAlwaysAllowMmsData} is turned on. | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8151 |      * | 
 | 8152 |      * @return whether data is allowed for a apn type. | 
 | 8153 |      * | 
 | 8154 |      * @hide | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8155 |      */ | 
 | 8156 |     @Override | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8157 |     public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { | 
| Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8158 |         enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " | 
 | 8159 |                 + "isDataEnabledForApn"); | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8160 |  | 
 | 8161 |         // Now that all security checks passes, perform the operation as ourselves. | 
 | 8162 |         final long identity = Binder.clearCallingIdentity(); | 
 | 8163 |         try { | 
 | 8164 |             Phone phone = getPhone(subId); | 
 | 8165 |             if (phone == null) return false; | 
 | 8166 |  | 
| Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8167 |             boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8168 |             return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); | 
 | 8169 |         } finally { | 
 | 8170 |             Binder.restoreCallingIdentity(identity); | 
 | 8171 |         } | 
 | 8172 |     } | 
 | 8173 |  | 
 | 8174 |     @Override | 
| Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8175 |     public boolean isApnMetered(@ApnType int apnType, int subId) { | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8176 |         enforceReadPrivilegedPermission("isApnMetered"); | 
 | 8177 |  | 
 | 8178 |         // Now that all security checks passes, perform the operation as ourselves. | 
 | 8179 |         final long identity = Binder.clearCallingIdentity(); | 
 | 8180 |         try { | 
 | 8181 |             Phone phone = getPhone(subId); | 
 | 8182 |             if (phone == null) return true; // By default return true. | 
 | 8183 |  | 
| Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8184 |             return ApnSettingUtils.isMeteredApnType(apnType, phone); | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8185 |         } finally { | 
 | 8186 |             Binder.restoreCallingIdentity(identity); | 
 | 8187 |         } | 
 | 8188 |     } | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8189 |  | 
 | 8190 |     @Override | 
| Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8191 |     public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, | 
 | 8192 |             int subscriptionId, IBooleanConsumer resultCallback) { | 
 | 8193 |         enforceModifyPermission(); | 
 | 8194 |         long token = Binder.clearCallingIdentity(); | 
 | 8195 |         try { | 
 | 8196 |             Phone phone = getPhone(subscriptionId); | 
 | 8197 |             if (phone == null) { | 
 | 8198 |                 try { | 
 | 8199 |                     if (resultCallback != null) { | 
 | 8200 |                         resultCallback.accept(false); | 
 | 8201 |                     } | 
 | 8202 |                 } catch (RemoteException e) { | 
 | 8203 |                     // ignore | 
 | 8204 |                 } | 
 | 8205 |                 return; | 
 | 8206 |             } | 
 | 8207 |             Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = | 
 | 8208 |                     Pair.create(specifiers, (x) -> { | 
 | 8209 |                         try { | 
 | 8210 |                             if (resultCallback != null) { | 
 | 8211 |                                 resultCallback.accept(x); | 
 | 8212 |                             } | 
 | 8213 |                         } catch (RemoteException e) { | 
 | 8214 |                             // ignore | 
 | 8215 |                         } | 
 | 8216 |                     }); | 
 | 8217 |             sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); | 
 | 8218 |         } finally { | 
 | 8219 |             Binder.restoreCallingIdentity(token); | 
 | 8220 |         } | 
 | 8221 |     } | 
 | 8222 |  | 
 | 8223 |     @Override | 
| changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8224 |     public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { | 
| changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame^] | 8225 |         enforceReadPrivilegedPermission("isMvnoMatched"); | 
| changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8226 |         IccRecords iccRecords = UiccController.getInstance().getIccRecords( | 
 | 8227 |                 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); | 
 | 8228 |         if (iccRecords == null) { | 
 | 8229 |             Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); | 
 | 8230 |             return false; | 
 | 8231 |         } | 
 | 8232 |         return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); | 
 | 8233 |     } | 
 | 8234 |  | 
 | 8235 |     @Override | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8236 |     public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { | 
| Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8237 |         if (callingPackage == null) { | 
 | 8238 |             callingPackage = getCurrentPackageName(); | 
 | 8239 |         } | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8240 |         SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, | 
 | 8241 |                 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); | 
 | 8242 |         if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { | 
 | 8243 |             throw new SecurityException("Requires SEND_SMS permission to perform this operation"); | 
 | 8244 |         } | 
 | 8245 |         PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); | 
 | 8246 |         Intent intent = new Intent(); | 
 | 8247 |         intent.setClass(mApp, PickSmsSubscriptionActivity.class); | 
 | 8248 |         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 
 | 8249 |         // Bring up choose default SMS subscription dialog right now | 
 | 8250 |         intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, | 
 | 8251 |                 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); | 
 | 8252 |         mApp.startActivity(intent); | 
 | 8253 |     } | 
| chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8254 |  | 
 | 8255 |     @Override | 
 | 8256 |     public String getMmsUAProfUrl(int subId) { | 
 | 8257 |         //TODO investigate if this API should require proper permission check in R b/133791609 | 
 | 8258 |         final long identity = Binder.clearCallingIdentity(); | 
 | 8259 |         try { | 
| Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 8260 |             return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) | 
 | 8261 |                     .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); | 
| chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8262 |         } finally { | 
 | 8263 |             Binder.restoreCallingIdentity(identity); | 
 | 8264 |         } | 
 | 8265 |     } | 
 | 8266 |  | 
 | 8267 |     @Override | 
 | 8268 |     public String getMmsUserAgent(int subId) { | 
 | 8269 |         //TODO investigate if this API should require proper permission check in R b/133791609 | 
 | 8270 |         final long identity = Binder.clearCallingIdentity(); | 
 | 8271 |         try { | 
| Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 8272 |             return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) | 
 | 8273 |                     .getString(com.android.internal.R.string.config_mms_user_agent); | 
| chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8274 |         } finally { | 
 | 8275 |             Binder.restoreCallingIdentity(identity); | 
 | 8276 |         } | 
 | 8277 |     } | 
| Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8278 |  | 
 | 8279 |     @Override | 
 | 8280 |     public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { | 
 | 8281 |         enforceModifyPermission(); | 
 | 8282 |  | 
 | 8283 |         // Now that all security checks passes, perform the operation as ourselves. | 
 | 8284 |         final long identity = Binder.clearCallingIdentity(); | 
 | 8285 |         try { | 
 | 8286 |             Phone phone = getPhone(subId); | 
 | 8287 |             if (phone == null) return false; | 
 | 8288 |  | 
 | 8289 |             return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); | 
 | 8290 |         } finally { | 
 | 8291 |             Binder.restoreCallingIdentity(identity); | 
 | 8292 |         } | 
 | 8293 |     } | 
 | 8294 |  | 
 | 8295 |     @Override | 
 | 8296 |     public boolean isDataAllowedInVoiceCall(int subId) { | 
 | 8297 |         enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); | 
 | 8298 |  | 
 | 8299 |         // Now that all security checks passes, perform the operation as ourselves. | 
 | 8300 |         final long identity = Binder.clearCallingIdentity(); | 
 | 8301 |         try { | 
 | 8302 |             Phone phone = getPhone(subId); | 
 | 8303 |             if (phone == null) return false; | 
 | 8304 |  | 
 | 8305 |             return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); | 
 | 8306 |         } finally { | 
 | 8307 |             Binder.restoreCallingIdentity(identity); | 
 | 8308 |         } | 
 | 8309 |     } | 
| Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8310 |  | 
| changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8311 |     @Override | 
 | 8312 |     public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { | 
 | 8313 |         enforceModifyPermission(); | 
 | 8314 |  | 
 | 8315 |         // Now that all security checks passes, perform the operation as ourselves. | 
 | 8316 |         final long identity = Binder.clearCallingIdentity(); | 
 | 8317 |         try { | 
 | 8318 |             Phone phone = getPhone(subId); | 
 | 8319 |             if (phone == null) return false; | 
 | 8320 |  | 
 | 8321 |             return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow); | 
 | 8322 |         } finally { | 
 | 8323 |             Binder.restoreCallingIdentity(identity); | 
 | 8324 |         } | 
 | 8325 |     } | 
 | 8326 |  | 
| Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8327 |     /** | 
 | 8328 |      * Updates whether conference event pacakge handling is enabled. | 
 | 8329 |      * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} | 
 | 8330 |      *                                 otherwise. | 
 | 8331 |      */ | 
 | 8332 |     @Override | 
 | 8333 |     public void setCepEnabled(boolean isCepEnabled) { | 
 | 8334 |         TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); | 
 | 8335 |  | 
 | 8336 |         final long identity = Binder.clearCallingIdentity(); | 
 | 8337 |         try { | 
 | 8338 |             Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); | 
 | 8339 |             for (Phone phone : PhoneFactory.getPhones()) { | 
 | 8340 |                 Phone defaultPhone = phone.getImsPhone(); | 
 | 8341 |                 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { | 
 | 8342 |                     ImsPhone imsPhone = (ImsPhone) defaultPhone; | 
 | 8343 |                     ImsPhoneCallTracker imsPhoneCallTracker = | 
 | 8344 |                             (ImsPhoneCallTracker) imsPhone.getCallTracker(); | 
 | 8345 |                     imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); | 
 | 8346 |                     Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " | 
 | 8347 |                             + imsPhone.getMsisdn()); | 
 | 8348 |                 } | 
 | 8349 |             } | 
 | 8350 |         } finally { | 
 | 8351 |             Binder.restoreCallingIdentity(identity); | 
 | 8352 |         } | 
 | 8353 |     } | 
| allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8354 |  | 
 | 8355 |     /** | 
 | 8356 |      * Notify that an RCS autoconfiguration XML file has been received for provisioning. | 
 | 8357 |      * | 
 | 8358 |      * @param config       The XML file to be read. ASCII/UTF8 encoded text if not compressed. | 
 | 8359 |      * @param isCompressed The XML file is compressed in gzip format and must be decompressed | 
 | 8360 |      *                     before being read. | 
 | 8361 |      */ | 
 | 8362 |     @Override | 
 | 8363 |     public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean | 
 | 8364 |             isCompressed) { | 
 | 8365 |         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
 | 8366 |                 mApp, subId, "notifyRcsAutoConfigurationReceived"); | 
 | 8367 |         try { | 
 | 8368 |             IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); | 
 | 8369 |             if (configBinder == null) { | 
 | 8370 |                 Rlog.e(LOG_TAG, "null result for getImsConfig"); | 
 | 8371 |             } else { | 
 | 8372 |                 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); | 
 | 8373 |             } | 
 | 8374 |         } catch (RemoteException e) { | 
 | 8375 |             Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); | 
 | 8376 |         } | 
 | 8377 |     } | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8378 |  | 
 | 8379 |     @Override | 
 | 8380 |     public boolean isIccLockEnabled(int subId) { | 
 | 8381 |         enforceReadPrivilegedPermission("isIccLockEnabled"); | 
 | 8382 |  | 
 | 8383 |         // Now that all security checks passes, perform the operation as ourselves. | 
 | 8384 |         final long identity = Binder.clearCallingIdentity(); | 
 | 8385 |         try { | 
 | 8386 |             Phone phone = getPhone(subId); | 
 | 8387 |             if (phone != null && phone.getIccCard() != null) { | 
 | 8388 |                 return phone.getIccCard().getIccLockEnabled(); | 
 | 8389 |             } else { | 
 | 8390 |                 return false; | 
 | 8391 |             } | 
 | 8392 |         } finally { | 
 | 8393 |             Binder.restoreCallingIdentity(identity); | 
 | 8394 |         } | 
 | 8395 |     } | 
 | 8396 |  | 
 | 8397 |     /** | 
 | 8398 |      * Set the ICC pin lock enabled or disabled. | 
 | 8399 |      * | 
 | 8400 |      * @return an integer representing the status of IccLock enabled or disabled in the following | 
 | 8401 |      * three cases: | 
 | 8402 |      *   - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock | 
 | 8403 |      *   successfully. | 
 | 8404 |      *   - Positive number and zero for remaining password attempts. | 
 | 8405 |      *   - Negative number for other failure cases (such like enabling/disabling PIN failed). | 
 | 8406 |      * | 
 | 8407 |      */ | 
 | 8408 |     @Override | 
 | 8409 |     public int setIccLockEnabled(int subId, boolean enabled, String password) { | 
 | 8410 |         enforceModifyPermission(); | 
 | 8411 |  | 
 | 8412 |         Phone phone = getPhone(subId); | 
 | 8413 |         if (phone == null) { | 
 | 8414 |             return 0; | 
 | 8415 |         } | 
 | 8416 |         // Now that all security checks passes, perform the operation as ourselves. | 
 | 8417 |         final long identity = Binder.clearCallingIdentity(); | 
 | 8418 |         try { | 
 | 8419 |             int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, | 
 | 8420 |                     new Pair<Boolean, String>(enabled, password), phone, null); | 
 | 8421 |             return attemptsRemaining; | 
 | 8422 |  | 
 | 8423 |         } catch (Exception e) { | 
 | 8424 |             Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); | 
 | 8425 |         } finally { | 
 | 8426 |             Binder.restoreCallingIdentity(identity); | 
 | 8427 |         } | 
 | 8428 |         return 0; | 
 | 8429 |     } | 
 | 8430 |  | 
 | 8431 |     /** | 
 | 8432 |      * Change the ICC password used in ICC pin lock. | 
 | 8433 |      * | 
 | 8434 |      * @return an integer representing the status of IccLock changed in the following three cases: | 
 | 8435 |      *   - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. | 
 | 8436 |      *   - Positive number and zero for remaining password attempts. | 
 | 8437 |      *   - Negative number for other failure cases (such like enabling/disabling PIN failed). | 
 | 8438 |      * | 
 | 8439 |      */ | 
 | 8440 |     @Override | 
 | 8441 |     public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { | 
 | 8442 |         enforceModifyPermission(); | 
 | 8443 |  | 
 | 8444 |         Phone phone = getPhone(subId); | 
 | 8445 |         if (phone == null) { | 
 | 8446 |             return 0; | 
 | 8447 |         } | 
 | 8448 |         // Now that all security checks passes, perform the operation as ourselves. | 
 | 8449 |         final long identity = Binder.clearCallingIdentity(); | 
 | 8450 |         try { | 
 | 8451 |             int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, | 
 | 8452 |                     new Pair<String, String>(oldPassword, newPassword), phone, null); | 
 | 8453 |             return attemptsRemaining; | 
 | 8454 |  | 
 | 8455 |         } catch (Exception e) { | 
 | 8456 |             Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); | 
 | 8457 |         } finally { | 
 | 8458 |             Binder.restoreCallingIdentity(identity); | 
 | 8459 |         } | 
 | 8460 |         return 0; | 
 | 8461 |     } | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 8462 |  | 
 | 8463 |     /** | 
 | 8464 |      * Request for receiving user activity notification | 
 | 8465 |      */ | 
 | 8466 |     @Override | 
 | 8467 |     public void requestUserActivityNotification() { | 
 | 8468 |         if (!mNotifyUserActivity.get() | 
 | 8469 |                 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { | 
 | 8470 |             mNotifyUserActivity.set(true); | 
 | 8471 |         } | 
 | 8472 |     } | 
 | 8473 |  | 
 | 8474 |     /** | 
 | 8475 |      * Called when userActivity is signalled in the power manager. | 
 | 8476 |      * This is safe to call from any thread, with any window manager locks held or not. | 
 | 8477 |      */ | 
 | 8478 |     @Override | 
 | 8479 |     public void userActivity() { | 
 | 8480 |         // *************************************** | 
 | 8481 |         // *  Inherited from PhoneWindowManager  * | 
 | 8482 |         // *************************************** | 
 | 8483 |         // THIS IS CALLED FROM DEEP IN THE POWER MANAGER | 
 | 8484 |         // WITH ITS LOCKS HELD. | 
 | 8485 |         // | 
 | 8486 |         // This code must be VERY careful about the locks | 
 | 8487 |         // it acquires. | 
 | 8488 |         // In fact, the current code acquires way too many, | 
 | 8489 |         // and probably has lurking deadlocks. | 
 | 8490 |  | 
 | 8491 |         if (Binder.getCallingUid() != Process.SYSTEM_UID) { | 
 | 8492 |             throw new SecurityException("Only the OS may call notifyUserActivity()"); | 
 | 8493 |         } | 
 | 8494 |  | 
 | 8495 |         if (mNotifyUserActivity.getAndSet(false)) { | 
 | 8496 |             mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, | 
 | 8497 |                     USER_ACTIVITY_NOTIFICATION_DELAY); | 
 | 8498 |         } | 
 | 8499 |     } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8500 | } |