| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2006 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | package com.android.phone; | 
|  | 18 |  | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; | 
|  | 20 |  | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; | 
|  | 22 |  | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 23 | import android.Manifest.permission; | 
| Tyler Gunn | 327a972 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 24 | import android.annotation.Nullable; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 25 | import android.app.AppOpsManager; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 26 | import android.app.PendingIntent; | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 27 | import android.content.ComponentName; | 
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 28 | import android.content.ContentResolver; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 29 | import android.content.Context; | 
|  | 30 | import android.content.Intent; | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 31 | import android.content.SharedPreferences; | 
| Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 32 | import android.content.pm.ApplicationInfo; | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 33 | import android.content.pm.ComponentInfo; | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 34 | import android.content.pm.PackageInfo; | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 35 | import android.content.pm.PackageManager; | 
| Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 36 | import android.net.NetworkStats; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 37 | import android.net.Uri; | 
|  | 38 | import android.os.AsyncResult; | 
|  | 39 | import android.os.Binder; | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 40 | import android.os.Build; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.os.Bundle; | 
|  | 42 | import android.os.Handler; | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 43 | import android.os.IBinder; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.os.Looper; | 
|  | 45 | import android.os.Message; | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 46 | import android.os.Messenger; | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 47 | import android.os.PersistableBundle; | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 48 | import android.os.RemoteException; | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 49 | import android.os.ResultReceiver; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | import android.os.ServiceManager; | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 51 | import android.os.ShellCallback; | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 52 | import android.os.SystemProperties; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.os.UserHandle; | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 54 | import android.os.UserManager; | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 55 | import android.os.WorkSource; | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 56 | import android.preference.PreferenceManager; | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 57 | import android.provider.Settings; | 
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 58 | import android.provider.Telephony; | 
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 59 | import android.telecom.PhoneAccount; | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 60 | import android.telecom.PhoneAccountHandle; | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 61 | import android.telecom.TelecomManager; | 
| Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 62 | import android.telephony.CarrierConfigManager; | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 63 | import android.telephony.CarrierRestrictionRules; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 64 | import android.telephony.CellInfo; | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 65 | import android.telephony.CellInfoGsm; | 
|  | 66 | import android.telephony.CellInfoWcdma; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 67 | import android.telephony.CellLocation; | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 68 | import android.telephony.ClientRequestStats; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 69 | import android.telephony.ICellInfoCallback; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 70 | import android.telephony.IccOpenLogicalChannelResponse; | 
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 71 | import android.telephony.LocationAccessPolicy; | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 72 | import android.telephony.ModemActivityInfo; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 73 | import android.telephony.NeighboringCellInfo; | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 74 | import android.telephony.NetworkScanRequest; | 
| Michele | bcb01bc | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 75 | import android.telephony.PhoneCapability; | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 76 | import android.telephony.PhoneNumberRange; | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 77 | import android.telephony.RadioAccessFamily; | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 78 | import android.telephony.RadioAccessSpecifier; | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 79 | import android.telephony.Rlog; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 80 | import android.telephony.ServiceState; | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 81 | import android.telephony.SignalStrength; | 
| Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 82 | import android.telephony.SmsManager; | 
| Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 83 | import android.telephony.SubscriptionInfo; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 84 | import android.telephony.SubscriptionManager; | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 85 | import android.telephony.TelephonyHistogram; | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 86 | import android.telephony.TelephonyManager; | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 87 | import android.telephony.TelephonyScanManager; | 
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 88 | import android.telephony.UiccCardInfo; | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 89 | import android.telephony.UiccSlotInfo; | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 90 | import android.telephony.UssdResponse; | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 91 | import android.telephony.VisualVoicemailSmsFilterSettings; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 92 | import android.telephony.cdma.CdmaCellLocation; | 
| Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 93 | import android.telephony.data.ApnSetting; | 
| Jack Yu | 40306fc | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 94 | import android.telephony.data.ApnSetting.ApnType; | 
| calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 95 | import android.telephony.emergency.EmergencyNumber; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 96 | import android.telephony.gsm.GsmCellLocation; | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 97 | import android.telephony.ims.ProvisioningManager; | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 98 | import android.telephony.ims.aidl.IImsCapabilityCallback; | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 99 | import android.telephony.ims.aidl.IImsConfig; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 100 | import android.telephony.ims.aidl.IImsConfigCallback; | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 101 | import android.telephony.ims.aidl.IImsMmTelFeature; | 
|  | 102 | import android.telephony.ims.aidl.IImsRcsFeature; | 
|  | 103 | import android.telephony.ims.aidl.IImsRegistration; | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 104 | import android.telephony.ims.aidl.IImsRegistrationCallback; | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 105 | import android.telephony.ims.feature.MmTelFeature; | 
|  | 106 | import android.telephony.ims.stub.ImsConfigImplBase; | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 107 | import android.telephony.ims.stub.ImsRegistrationImplBase; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 108 | import android.text.TextUtils; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 109 | import android.util.ArraySet; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 110 | import android.util.Log; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 111 | import android.util.Pair; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 112 | import android.util.Slog; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 113 |  | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 114 | import com.android.ims.ImsException; | 
| Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 115 | import com.android.ims.ImsManager; | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 116 | import com.android.ims.internal.IImsServiceFeatureCallback; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 117 | import com.android.internal.telephony.CallManager; | 
| Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 118 | import com.android.internal.telephony.CallStateException; | 
| pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 119 | import com.android.internal.telephony.CarrierInfoManager; | 
| chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 120 | import com.android.internal.telephony.CarrierResolver; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 121 | import com.android.internal.telephony.CellNetworkScanResult; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 122 | import com.android.internal.telephony.CommandException; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.DefaultPhoneNotifier; | 
| Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 124 | import com.android.internal.telephony.HalVersion; | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 125 | import com.android.internal.telephony.INumberVerificationCallback; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.ITelephony; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 127 | import com.android.internal.telephony.IccCard; | 
| Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.LocaleTracker; | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 129 | import com.android.internal.telephony.MccTable; | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.NetworkScanRequestTracker; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.OperatorInfo; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.Phone; | 
| Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.PhoneConfigurationManager; | 
| Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.PhoneConstantConversions; | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.PhoneConstants; | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.PhoneFactory; | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.ProxyController; | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.RIL; | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.RILConstants; | 
| Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.ServiceStateTracker; | 
| sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 141 | import com.android.internal.telephony.SmsApplication; | 
|  | 142 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.SubscriptionController; | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 144 | import com.android.internal.telephony.TelephonyPermissions; | 
| Malcolm Chen | 460810d | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; | 
| sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 146 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.euicc.EuiccConnector; | 
| Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.ims.ImsResolver; | 
| Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.metrics.TelephonyMetrics; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.uicc.IccIoResult; | 
|  | 151 | import com.android.internal.telephony.uicc.IccUtils; | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.uicc.SIMRecords; | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.uicc.UiccCard; | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.uicc.UiccCardApplication; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.uicc.UiccController; | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.uicc.UiccProfile; | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 157 | import com.android.internal.telephony.uicc.UiccSlot; | 
| fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 159 | import com.android.internal.util.HexDump; | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 160 | import com.android.phone.vvm.PhoneAccountHandleConverter; | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 161 | import com.android.phone.vvm.RemoteVvmTaskManager; | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 162 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; | 
| Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 163 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 164 |  | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 165 | import java.io.FileDescriptor; | 
|  | 166 | import java.io.PrintWriter; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 167 | import java.nio.charset.StandardCharsets; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 168 | import java.util.ArrayList; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 169 | import java.util.Arrays; | 
| sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 170 | import java.util.Collection; | 
| sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 171 | import java.util.HashMap; | 
| sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 172 | import java.util.HashSet; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 173 | import java.util.List; | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 174 | import java.util.Locale; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 175 | import java.util.Map; | 
| Nazanin Bakhshi | 1f78d7d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 176 | import java.util.NoSuchElementException; | 
| sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 177 | import java.util.Set; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 178 |  | 
|  | 179 | /** | 
|  | 180 | * Implementation of the ITelephony interface. | 
|  | 181 | */ | 
| Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 182 | public class PhoneInterfaceManager extends ITelephony.Stub { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 183 | private static final String LOG_TAG = "PhoneInterfaceManager"; | 
|  | 184 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); | 
|  | 185 | private static final boolean DBG_LOC = false; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 186 | private static final boolean DBG_MERGE = false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 187 |  | 
|  | 188 | // Message codes used with mMainThreadHandler | 
|  | 189 | private static final int CMD_HANDLE_PIN_MMI = 1; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 190 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; | 
|  | 191 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 192 | private static final int CMD_OPEN_CHANNEL = 9; | 
|  | 193 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; | 
|  | 194 | private static final int CMD_CLOSE_CHANNEL = 11; | 
|  | 195 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 196 | private static final int CMD_NV_READ_ITEM = 13; | 
|  | 197 | private static final int EVENT_NV_READ_ITEM_DONE = 14; | 
|  | 198 | private static final int CMD_NV_WRITE_ITEM = 15; | 
|  | 199 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; | 
|  | 200 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; | 
|  | 201 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 202 | private static final int CMD_RESET_MODEM_CONFIG = 19; | 
|  | 203 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 204 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; | 
|  | 205 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; | 
|  | 206 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; | 
|  | 207 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; | 
| Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 208 | private static final int CMD_SEND_ENVELOPE = 25; | 
|  | 209 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 210 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; | 
|  | 211 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; | 
| Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 212 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; | 
|  | 213 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; | 
|  | 214 | private static final int CMD_EXCHANGE_SIM_IO = 31; | 
|  | 215 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 216 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; | 
|  | 217 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 218 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; | 
|  | 219 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 220 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; | 
|  | 221 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 222 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; | 
|  | 223 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; | 
|  | 224 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; | 
|  | 225 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 226 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; | 
|  | 227 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; | 
|  | 228 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; | 
|  | 229 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 230 | private static final int CMD_HANDLE_USSD_REQUEST = 47; | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 231 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; | 
|  | 232 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 233 | private static final int CMD_SWITCH_SLOTS = 50; | 
|  | 234 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 235 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; | 
|  | 236 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; | 
|  | 237 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; | 
|  | 238 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; | 
|  | 239 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; | 
|  | 240 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; | 
|  | 241 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; | 
|  | 242 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 243 | private static final int CMD_GET_ALL_CELL_INFO = 60; | 
|  | 244 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; | 
|  | 245 | private static final int CMD_GET_CELL_LOCATION = 62; | 
|  | 246 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 247 | private static final int CMD_MODEM_REBOOT = 64; | 
|  | 248 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 249 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; | 
|  | 250 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; | 
| Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 251 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; | 
|  | 252 | private static final int EVENT_ENABLE_MODEM_DONE = 69; | 
| Nazanin Bakhshi | 1f78d7d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 253 | private static final int CMD_GET_MODEM_STATUS = 70; | 
|  | 254 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 255 |  | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 256 | // Parameters of select command. | 
|  | 257 | private static final int SELECT_COMMAND = 0xA4; | 
|  | 258 | private static final int SELECT_P1 = 0x04; | 
|  | 259 | private static final int SELECT_P2 = 0; | 
|  | 260 | private static final int SELECT_P3 = 0x10; | 
|  | 261 |  | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 262 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; | 
|  | 263 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; | 
|  | 264 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; | 
|  | 265 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 266 | /** The singleton instance. */ | 
|  | 267 | private static PhoneInterfaceManager sInstance; | 
|  | 268 |  | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 269 | private PhoneGlobals mApp; | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 270 | private CallManager mCM; | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 271 | private UserManager mUserManager; | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 272 | private AppOpsManager mAppOps; | 
|  | 273 | private MainThreadHandler mMainThreadHandler; | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 274 | private SubscriptionController mSubscriptionController; | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 275 | private SharedPreferences mTelephonySharedPreferences; | 
| Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 276 | private PhoneConfigurationManager mPhoneConfigurationManager; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 277 |  | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 278 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; | 
|  | 279 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 280 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 281 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; | 
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 282 |  | 
| Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 283 | // String to store multi SIM allowed | 
|  | 284 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; | 
|  | 285 |  | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 286 | // The AID of ISD-R. | 
|  | 287 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; | 
|  | 288 |  | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 289 | private NetworkScanRequestTracker mNetworkScanRequestTracker; | 
|  | 290 |  | 
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 291 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; | 
|  | 292 | private static final int MANUFACTURER_CODE_LENGTH = 8; | 
|  | 293 |  | 
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 294 | /** | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 295 | * A request object to use for transmitting data to an ICC. | 
|  | 296 | */ | 
|  | 297 | private static final class IccAPDUArgument { | 
|  | 298 | public int channel, cla, command, p1, p2, p3; | 
|  | 299 | public String data; | 
|  | 300 |  | 
|  | 301 | public IccAPDUArgument(int channel, int cla, int command, | 
|  | 302 | int p1, int p2, int p3, String data) { | 
|  | 303 | this.channel = channel; | 
|  | 304 | this.cla = cla; | 
|  | 305 | this.command = command; | 
|  | 306 | this.p1 = p1; | 
|  | 307 | this.p2 = p2; | 
|  | 308 | this.p3 = p3; | 
|  | 309 | this.data = data; | 
|  | 310 | } | 
|  | 311 | } | 
|  | 312 |  | 
|  | 313 | /** | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 314 | * A request object to use for transmitting data to an ICC. | 
|  | 315 | */ | 
|  | 316 | private static final class ManualNetworkSelectionArgument { | 
|  | 317 | public OperatorInfo operatorInfo; | 
|  | 318 | public boolean persistSelection; | 
|  | 319 |  | 
|  | 320 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { | 
|  | 321 | this.operatorInfo = operatorInfo; | 
|  | 322 | this.persistSelection = persistSelection; | 
|  | 323 | } | 
|  | 324 | } | 
|  | 325 |  | 
|  | 326 | /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 327 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the | 
|  | 328 | * request after sending. The main thread will notify the request when it is complete. | 
|  | 329 | */ | 
|  | 330 | private static final class MainThreadRequest { | 
|  | 331 | /** The argument to use for the request */ | 
|  | 332 | public Object argument; | 
|  | 333 | /** The result of the request that is run on the main thread */ | 
|  | 334 | public Object result; | 
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 335 | // The subscriber id that this request applies to. Defaults to | 
|  | 336 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID | 
|  | 337 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 338 |  | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 339 | // In cases where subId is unavailable, the caller needs to specify the phone. | 
|  | 340 | public Phone phone; | 
|  | 341 |  | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 342 | public WorkSource workSource; | 
|  | 343 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 344 | public MainThreadRequest(Object argument) { | 
|  | 345 | this.argument = argument; | 
|  | 346 | } | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 347 |  | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 348 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { | 
|  | 349 | this.argument = argument; | 
|  | 350 | if (phone != null) { | 
|  | 351 | this.phone = phone; | 
|  | 352 | } | 
|  | 353 | this.workSource = workSource; | 
|  | 354 | } | 
|  | 355 |  | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 356 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 357 | this.argument = argument; | 
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 358 | if (subId != null) { | 
|  | 359 | this.subId = subId; | 
|  | 360 | } | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 361 | this.workSource = workSource; | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 362 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 363 | } | 
|  | 364 |  | 
| Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 365 | private static final class IncomingThirdPartyCallArgs { | 
|  | 366 | public final ComponentName component; | 
|  | 367 | public final String callId; | 
|  | 368 | public final String callerDisplayName; | 
|  | 369 |  | 
|  | 370 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, | 
|  | 371 | String callerDisplayName) { | 
|  | 372 | this.component = component; | 
|  | 373 | this.callId = callId; | 
|  | 374 | this.callerDisplayName = callerDisplayName; | 
|  | 375 | } | 
|  | 376 | } | 
|  | 377 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 378 | /** | 
|  | 379 | * A handler that processes messages on the main thread in the phone process. Since many | 
|  | 380 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the | 
|  | 381 | * inbound binder threads to the main thread in the phone process.  The Binder thread | 
|  | 382 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting | 
|  | 383 | * on, which will be notified when the operation completes and will contain the result of the | 
|  | 384 | * request. | 
|  | 385 | * | 
|  | 386 | * <p>If a MainThreadRequest object is provided in the msg.obj field, | 
|  | 387 | * note that request.result must be set to something non-null for the calling thread to | 
|  | 388 | * unblock. | 
|  | 389 | */ | 
|  | 390 | private final class MainThreadHandler extends Handler { | 
|  | 391 | @Override | 
|  | 392 | public void handleMessage(Message msg) { | 
|  | 393 | MainThreadRequest request; | 
|  | 394 | Message onCompleted; | 
|  | 395 | AsyncResult ar; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 396 | UiccCard uiccCard; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 397 | IccAPDUArgument iccArgument; | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 398 | final Phone defaultPhone = getDefaultPhone(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 399 |  | 
|  | 400 | switch (msg.what) { | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 401 | case CMD_HANDLE_USSD_REQUEST: { | 
|  | 402 | request = (MainThreadRequest) msg.obj; | 
|  | 403 | final Phone phone = getPhoneFromRequest(request); | 
|  | 404 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; | 
|  | 405 | String ussdRequest =  ussdObject.first; | 
|  | 406 | ResultReceiver wrappedCallback = ussdObject.second; | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 407 |  | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 408 | if (!isUssdApiAllowed(request.subId)) { | 
|  | 409 | // Carrier does not support use of this API, return failure. | 
|  | 410 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); | 
|  | 411 | UssdResponse response = new UssdResponse(ussdRequest, null); | 
|  | 412 | Bundle returnData = new Bundle(); | 
|  | 413 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); | 
|  | 414 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 415 |  | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 416 | request.result = true; | 
|  | 417 | notifyRequester(request); | 
|  | 418 | return; | 
|  | 419 | } | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 420 |  | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 421 | try { | 
|  | 422 | request.result = phone != null | 
|  | 423 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; | 
|  | 424 | } catch (CallStateException cse) { | 
|  | 425 | request.result = false; | 
|  | 426 | } | 
|  | 427 | // Wake up the requesting thread | 
|  | 428 | notifyRequester(request); | 
|  | 429 | break; | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 430 | } | 
|  | 431 |  | 
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 432 | case CMD_HANDLE_PIN_MMI: { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 433 | request = (MainThreadRequest) msg.obj; | 
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 434 | final Phone phone = getPhoneFromRequest(request); | 
|  | 435 | request.result = phone != null ? | 
|  | 436 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) | 
|  | 437 | : false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 438 | // Wake up the requesting thread | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 439 | notifyRequester(request); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 440 | break; | 
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 441 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 442 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 443 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 444 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 445 | iccArgument = (IccAPDUArgument) request.argument; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 446 | uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 447 | if (uiccCard == null) { | 
|  | 448 | loge("iccTransmitApduLogicalChannel: No UICC"); | 
|  | 449 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 450 | notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 451 | } else { | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 452 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, | 
|  | 453 | request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 454 | uiccCard.iccTransmitApduLogicalChannel( | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 455 | iccArgument.channel, iccArgument.cla, iccArgument.command, | 
|  | 456 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 457 | onCompleted); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 458 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 459 | break; | 
|  | 460 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 461 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 462 | ar = (AsyncResult) msg.obj; | 
|  | 463 | request = (MainThreadRequest) ar.userObj; | 
|  | 464 | if (ar.exception == null && ar.result != null) { | 
|  | 465 | request.result = ar.result; | 
|  | 466 | } else { | 
|  | 467 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
|  | 468 | if (ar.result == null) { | 
|  | 469 | loge("iccTransmitApduLogicalChannel: Empty response"); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 470 | } else if (ar.exception instanceof CommandException) { | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 471 | loge("iccTransmitApduLogicalChannel: CommandException: " + | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 472 | ar.exception); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 473 | } else { | 
|  | 474 | loge("iccTransmitApduLogicalChannel: Unknown exception"); | 
|  | 475 | } | 
|  | 476 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 477 | notifyRequester(request); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 478 | break; | 
|  | 479 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 480 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: | 
|  | 481 | request = (MainThreadRequest) msg.obj; | 
|  | 482 | iccArgument = (IccAPDUArgument) request.argument; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 483 | uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 484 | if (uiccCard == null) { | 
|  | 485 | loge("iccTransmitApduBasicChannel: No UICC"); | 
|  | 486 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 487 | notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 488 | } else { | 
|  | 489 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, | 
|  | 490 | request); | 
|  | 491 | uiccCard.iccTransmitApduBasicChannel( | 
|  | 492 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, | 
|  | 493 | iccArgument.p3, iccArgument.data, onCompleted); | 
|  | 494 | } | 
|  | 495 | break; | 
|  | 496 |  | 
|  | 497 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: | 
|  | 498 | ar = (AsyncResult) msg.obj; | 
|  | 499 | request = (MainThreadRequest) ar.userObj; | 
|  | 500 | if (ar.exception == null && ar.result != null) { | 
|  | 501 | request.result = ar.result; | 
|  | 502 | } else { | 
|  | 503 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
|  | 504 | if (ar.result == null) { | 
|  | 505 | loge("iccTransmitApduBasicChannel: Empty response"); | 
|  | 506 | } else if (ar.exception instanceof CommandException) { | 
|  | 507 | loge("iccTransmitApduBasicChannel: CommandException: " + | 
|  | 508 | ar.exception); | 
|  | 509 | } else { | 
|  | 510 | loge("iccTransmitApduBasicChannel: Unknown exception"); | 
|  | 511 | } | 
|  | 512 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 513 | notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 514 | break; | 
|  | 515 |  | 
|  | 516 | case CMD_EXCHANGE_SIM_IO: | 
|  | 517 | request = (MainThreadRequest) msg.obj; | 
|  | 518 | iccArgument = (IccAPDUArgument) request.argument; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 519 | uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 520 | if (uiccCard == null) { | 
|  | 521 | loge("iccExchangeSimIO: No UICC"); | 
|  | 522 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 523 | notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 524 | } else { | 
|  | 525 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, | 
|  | 526 | request); | 
|  | 527 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ | 
|  | 528 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, | 
|  | 529 | iccArgument.data, onCompleted); | 
|  | 530 | } | 
|  | 531 | break; | 
|  | 532 |  | 
|  | 533 | case EVENT_EXCHANGE_SIM_IO_DONE: | 
|  | 534 | ar = (AsyncResult) msg.obj; | 
|  | 535 | request = (MainThreadRequest) ar.userObj; | 
|  | 536 | if (ar.exception == null && ar.result != null) { | 
|  | 537 | request.result = ar.result; | 
|  | 538 | } else { | 
|  | 539 | request.result = new IccIoResult(0x6f, 0, (byte[])null); | 
|  | 540 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 541 | notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 542 | break; | 
|  | 543 |  | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 544 | case CMD_SEND_ENVELOPE: | 
|  | 545 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 546 | uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 547 | if (uiccCard == null) { | 
|  | 548 | loge("sendEnvelopeWithStatus: No UICC"); | 
|  | 549 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 550 | notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 551 | } else { | 
|  | 552 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); | 
|  | 553 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); | 
|  | 554 | } | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 555 | break; | 
|  | 556 |  | 
|  | 557 | case EVENT_SEND_ENVELOPE_DONE: | 
|  | 558 | ar = (AsyncResult) msg.obj; | 
|  | 559 | request = (MainThreadRequest) ar.userObj; | 
| Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 560 | if (ar.exception == null && ar.result != null) { | 
|  | 561 | request.result = ar.result; | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 562 | } else { | 
| Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 563 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
|  | 564 | if (ar.result == null) { | 
|  | 565 | loge("sendEnvelopeWithStatus: Empty response"); | 
|  | 566 | } else if (ar.exception instanceof CommandException) { | 
|  | 567 | loge("sendEnvelopeWithStatus: CommandException: " + | 
|  | 568 | ar.exception); | 
|  | 569 | } else { | 
|  | 570 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); | 
|  | 571 | } | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 572 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 573 | notifyRequester(request); | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 574 | break; | 
|  | 575 |  | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 576 | case CMD_OPEN_CHANNEL: | 
|  | 577 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 578 | uiccCard = getUiccCardFromRequest(request); | 
| Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 579 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 580 | if (uiccCard == null) { | 
|  | 581 | loge("iccOpenLogicalChannel: No UICC"); | 
| Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 582 | request.result = new IccOpenLogicalChannelResponse(-1, | 
|  | 583 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 584 | notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 585 | } else { | 
|  | 586 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); | 
| Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 587 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, | 
|  | 588 | openChannelArgs.second, onCompleted); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 589 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 590 | break; | 
|  | 591 |  | 
|  | 592 | case EVENT_OPEN_CHANNEL_DONE: | 
|  | 593 | ar = (AsyncResult) msg.obj; | 
|  | 594 | request = (MainThreadRequest) ar.userObj; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 595 | IccOpenLogicalChannelResponse openChannelResp; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 596 | if (ar.exception == null && ar.result != null) { | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 597 | int[] result = (int[]) ar.result; | 
|  | 598 | int channelId = result[0]; | 
|  | 599 | byte[] selectResponse = null; | 
|  | 600 | if (result.length > 1) { | 
|  | 601 | selectResponse = new byte[result.length - 1]; | 
|  | 602 | for (int i = 1; i < result.length; ++i) { | 
|  | 603 | selectResponse[i - 1] = (byte) result[i]; | 
|  | 604 | } | 
|  | 605 | } | 
|  | 606 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 607 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 608 | } else { | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 609 | if (ar.result == null) { | 
|  | 610 | loge("iccOpenLogicalChannel: Empty response"); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 611 | } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 612 | if (ar.exception != null) { | 
|  | 613 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); | 
|  | 614 | } | 
|  | 615 |  | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 616 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; | 
| Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 617 | if (ar.exception instanceof CommandException) { | 
|  | 618 | CommandException.Error error = | 
|  | 619 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 620 | if (error == CommandException.Error.MISSING_RESOURCE) { | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 621 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; | 
| Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 622 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 623 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 624 | } | 
|  | 625 | } | 
|  | 626 | openChannelResp = new IccOpenLogicalChannelResponse( | 
|  | 627 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 628 | } | 
| Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 629 | request.result = openChannelResp; | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 630 | notifyRequester(request); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 631 | break; | 
|  | 632 |  | 
|  | 633 | case CMD_CLOSE_CHANNEL: | 
|  | 634 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 635 | uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 636 | if (uiccCard == null) { | 
|  | 637 | loge("iccCloseLogicalChannel: No UICC"); | 
| Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 638 | request.result = false; | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 639 | notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 640 | } else { | 
|  | 641 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); | 
|  | 642 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); | 
|  | 643 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 644 | break; | 
|  | 645 |  | 
|  | 646 | case EVENT_CLOSE_CHANNEL_DONE: | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 647 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); | 
|  | 648 | break; | 
|  | 649 |  | 
|  | 650 | case CMD_NV_READ_ITEM: | 
|  | 651 | request = (MainThreadRequest) msg.obj; | 
|  | 652 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 653 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, | 
|  | 654 | request.workSource); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 655 | break; | 
|  | 656 |  | 
|  | 657 | case EVENT_NV_READ_ITEM_DONE: | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 658 | ar = (AsyncResult) msg.obj; | 
|  | 659 | request = (MainThreadRequest) ar.userObj; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 660 | if (ar.exception == null && ar.result != null) { | 
|  | 661 | request.result = ar.result;     // String | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 662 | } else { | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 663 | request.result = ""; | 
|  | 664 | if (ar.result == null) { | 
|  | 665 | loge("nvReadItem: Empty response"); | 
|  | 666 | } else if (ar.exception instanceof CommandException) { | 
|  | 667 | loge("nvReadItem: CommandException: " + | 
|  | 668 | ar.exception); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 669 | } else { | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 670 | loge("nvReadItem: Unknown exception"); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 671 | } | 
|  | 672 | } | 
| Pengquan Meng | 0c05b50 | 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 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 676 | case CMD_NV_WRITE_ITEM: | 
|  | 677 | request = (MainThreadRequest) msg.obj; | 
|  | 678 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); | 
|  | 679 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 680 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 681 | request.workSource); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 682 | break; | 
|  | 683 |  | 
|  | 684 | case EVENT_NV_WRITE_ITEM_DONE: | 
|  | 685 | handleNullReturnEvent(msg, "nvWriteItem"); | 
|  | 686 | break; | 
|  | 687 |  | 
|  | 688 | case CMD_NV_WRITE_CDMA_PRL: | 
|  | 689 | request = (MainThreadRequest) msg.obj; | 
|  | 690 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 691 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 692 | break; | 
|  | 693 |  | 
|  | 694 | case EVENT_NV_WRITE_CDMA_PRL_DONE: | 
|  | 695 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); | 
|  | 696 | break; | 
|  | 697 |  | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 698 | case CMD_RESET_MODEM_CONFIG: | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 699 | request = (MainThreadRequest) msg.obj; | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 700 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 701 | defaultPhone.resetModemConfig(onCompleted); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 702 | break; | 
|  | 703 |  | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 704 | case EVENT_RESET_MODEM_CONFIG_DONE: | 
|  | 705 | handleNullReturnEvent(msg, "resetModemConfig"); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 706 | break; | 
|  | 707 |  | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 708 | case CMD_GET_PREFERRED_NETWORK_TYPE: | 
|  | 709 | request = (MainThreadRequest) msg.obj; | 
|  | 710 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 711 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 712 | break; | 
|  | 713 |  | 
|  | 714 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: | 
|  | 715 | ar = (AsyncResult) msg.obj; | 
|  | 716 | request = (MainThreadRequest) ar.userObj; | 
|  | 717 | if (ar.exception == null && ar.result != null) { | 
|  | 718 | request.result = ar.result;     // Integer | 
|  | 719 | } else { | 
| Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 720 | request.result = null; | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 721 | if (ar.result == null) { | 
|  | 722 | loge("getPreferredNetworkType: Empty response"); | 
|  | 723 | } else if (ar.exception instanceof CommandException) { | 
|  | 724 | loge("getPreferredNetworkType: CommandException: " + | 
|  | 725 | ar.exception); | 
|  | 726 | } else { | 
|  | 727 | loge("getPreferredNetworkType: Unknown exception"); | 
|  | 728 | } | 
|  | 729 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 730 | notifyRequester(request); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 731 | break; | 
|  | 732 |  | 
|  | 733 | case CMD_SET_PREFERRED_NETWORK_TYPE: | 
|  | 734 | request = (MainThreadRequest) msg.obj; | 
|  | 735 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); | 
|  | 736 | int networkType = (Integer) request.argument; | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 737 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 738 | break; | 
|  | 739 |  | 
|  | 740 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: | 
|  | 741 | handleNullReturnEvent(msg, "setPreferredNetworkType"); | 
|  | 742 | break; | 
|  | 743 |  | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 744 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: | 
|  | 745 | request = (MainThreadRequest)msg.obj; | 
|  | 746 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 747 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 748 | break; | 
|  | 749 |  | 
|  | 750 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: | 
|  | 751 | ar = (AsyncResult)msg.obj; | 
|  | 752 | request = (MainThreadRequest)ar.userObj; | 
|  | 753 | request.result = ar; | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 754 | notifyRequester(request); | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 755 | break; | 
|  | 756 |  | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 757 | case CMD_SET_VOICEMAIL_NUMBER: | 
|  | 758 | request = (MainThreadRequest) msg.obj; | 
|  | 759 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); | 
|  | 760 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 761 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, | 
|  | 762 | onCompleted); | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 763 | break; | 
|  | 764 |  | 
|  | 765 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: | 
|  | 766 | handleNullReturnEvent(msg, "setVoicemailNumber"); | 
|  | 767 | break; | 
|  | 768 |  | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 769 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: | 
|  | 770 | request = (MainThreadRequest) msg.obj; | 
|  | 771 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, | 
|  | 772 | request); | 
|  | 773 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); | 
|  | 774 | break; | 
|  | 775 |  | 
|  | 776 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: | 
|  | 777 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); | 
|  | 778 | break; | 
|  | 779 |  | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 780 | case CMD_PERFORM_NETWORK_SCAN: | 
|  | 781 | request = (MainThreadRequest) msg.obj; | 
|  | 782 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); | 
|  | 783 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); | 
|  | 784 | break; | 
|  | 785 |  | 
|  | 786 | case EVENT_PERFORM_NETWORK_SCAN_DONE: | 
|  | 787 | ar = (AsyncResult) msg.obj; | 
|  | 788 | request = (MainThreadRequest) ar.userObj; | 
|  | 789 | CellNetworkScanResult cellScanResult; | 
|  | 790 | if (ar.exception == null && ar.result != null) { | 
|  | 791 | cellScanResult = new CellNetworkScanResult( | 
|  | 792 | CellNetworkScanResult.STATUS_SUCCESS, | 
|  | 793 | (List<OperatorInfo>) ar.result); | 
|  | 794 | } else { | 
|  | 795 | if (ar.result == null) { | 
|  | 796 | loge("getCellNetworkScanResults: Empty response"); | 
|  | 797 | } | 
|  | 798 | if (ar.exception != null) { | 
|  | 799 | loge("getCellNetworkScanResults: Exception: " + ar.exception); | 
|  | 800 | } | 
|  | 801 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; | 
|  | 802 | if (ar.exception instanceof CommandException) { | 
|  | 803 | CommandException.Error error = | 
|  | 804 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 805 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { | 
|  | 806 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; | 
|  | 807 | } else if (error == CommandException.Error.GENERIC_FAILURE) { | 
|  | 808 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; | 
|  | 809 | } | 
|  | 810 | } | 
|  | 811 | cellScanResult = new CellNetworkScanResult(errorCode, null); | 
|  | 812 | } | 
|  | 813 | request.result = cellScanResult; | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 814 | notifyRequester(request); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 815 | break; | 
|  | 816 |  | 
|  | 817 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: | 
|  | 818 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 819 | ManualNetworkSelectionArgument selArg = | 
|  | 820 | (ManualNetworkSelectionArgument) request.argument; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 821 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, | 
|  | 822 | request); | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 823 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, | 
|  | 824 | selArg.persistSelection, onCompleted); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 825 | break; | 
|  | 826 |  | 
|  | 827 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: | 
| Pengquan Meng | dd9ac82 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 828 | ar = (AsyncResult) msg.obj; | 
|  | 829 | request = (MainThreadRequest) ar.userObj; | 
|  | 830 | if (ar.exception == null) { | 
|  | 831 | request.result = true; | 
|  | 832 | } else { | 
|  | 833 | request.result = false; | 
|  | 834 | loge("setNetworkSelectionModeManual " + ar.exception); | 
|  | 835 | } | 
|  | 836 | notifyRequester(request); | 
|  | 837 | mApp.onNetworkSelectionChanged(request.subId); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 838 | break; | 
|  | 839 |  | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 840 | case CMD_GET_MODEM_ACTIVITY_INFO: | 
|  | 841 | request = (MainThreadRequest) msg.obj; | 
|  | 842 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); | 
| James Mattis | c56281c | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 843 | if (defaultPhone != null) { | 
|  | 844 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); | 
|  | 845 | } | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 846 | break; | 
|  | 847 |  | 
|  | 848 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: | 
|  | 849 | ar = (AsyncResult) msg.obj; | 
|  | 850 | request = (MainThreadRequest) ar.userObj; | 
|  | 851 | if (ar.exception == null && ar.result != null) { | 
|  | 852 | request.result = ar.result; | 
|  | 853 | } else { | 
|  | 854 | if (ar.result == null) { | 
|  | 855 | loge("queryModemActivityInfo: Empty response"); | 
|  | 856 | } else if (ar.exception instanceof CommandException) { | 
|  | 857 | loge("queryModemActivityInfo: CommandException: " + | 
|  | 858 | ar.exception); | 
|  | 859 | } else { | 
|  | 860 | loge("queryModemActivityInfo: Unknown exception"); | 
|  | 861 | } | 
|  | 862 | } | 
| Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 863 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. | 
|  | 864 | if (request.result == null) { | 
|  | 865 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); | 
|  | 866 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 867 | notifyRequester(request); | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 868 | break; | 
|  | 869 |  | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 870 | case CMD_SET_ALLOWED_CARRIERS: | 
|  | 871 | request = (MainThreadRequest) msg.obj; | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 872 | CarrierRestrictionRules argument = | 
|  | 873 | (CarrierRestrictionRules) request.argument; | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 874 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 875 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 876 | break; | 
|  | 877 |  | 
|  | 878 | case EVENT_SET_ALLOWED_CARRIERS_DONE: | 
|  | 879 | ar = (AsyncResult) msg.obj; | 
|  | 880 | request = (MainThreadRequest) ar.userObj; | 
|  | 881 | if (ar.exception == null && ar.result != null) { | 
|  | 882 | request.result = ar.result; | 
|  | 883 | } else { | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 884 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; | 
|  | 885 | if (ar.exception instanceof CommandException) { | 
|  | 886 | loge("setAllowedCarriers: CommandException: " + ar.exception); | 
|  | 887 | CommandException.Error error = | 
|  | 888 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 889 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
|  | 890 | request.result = | 
|  | 891 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; | 
|  | 892 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 893 | } else { | 
|  | 894 | loge("setAllowedCarriers: Unknown exception"); | 
|  | 895 | } | 
|  | 896 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 897 | notifyRequester(request); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 898 | break; | 
|  | 899 |  | 
|  | 900 | case CMD_GET_ALLOWED_CARRIERS: | 
|  | 901 | request = (MainThreadRequest) msg.obj; | 
|  | 902 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 903 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 904 | break; | 
|  | 905 |  | 
|  | 906 | case EVENT_GET_ALLOWED_CARRIERS_DONE: | 
|  | 907 | ar = (AsyncResult) msg.obj; | 
|  | 908 | request = (MainThreadRequest) ar.userObj; | 
|  | 909 | if (ar.exception == null && ar.result != null) { | 
|  | 910 | request.result = ar.result; | 
|  | 911 | } else { | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 912 | request.result = new IllegalStateException( | 
|  | 913 | "Failed to get carrier restrictions"); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 914 | if (ar.result == null) { | 
|  | 915 | loge("getAllowedCarriers: Empty response"); | 
|  | 916 | } else if (ar.exception instanceof CommandException) { | 
|  | 917 | loge("getAllowedCarriers: CommandException: " + | 
|  | 918 | ar.exception); | 
|  | 919 | } else { | 
|  | 920 | loge("getAllowedCarriers: Unknown exception"); | 
|  | 921 | } | 
|  | 922 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 923 | notifyRequester(request); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 924 | break; | 
|  | 925 |  | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 926 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: | 
|  | 927 | ar = (AsyncResult) msg.obj; | 
|  | 928 | request = (MainThreadRequest) ar.userObj; | 
|  | 929 | if (ar.exception == null && ar.result != null) { | 
|  | 930 | request.result = ar.result; | 
|  | 931 | } else { | 
|  | 932 | request.result = new IllegalArgumentException( | 
|  | 933 | "Failed to retrieve Forbidden Plmns"); | 
|  | 934 | if (ar.result == null) { | 
|  | 935 | loge("getForbiddenPlmns: Empty response"); | 
|  | 936 | } else { | 
|  | 937 | loge("getForbiddenPlmns: Unknown exception"); | 
|  | 938 | } | 
|  | 939 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 940 | notifyRequester(request); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 941 | break; | 
|  | 942 |  | 
|  | 943 | case CMD_GET_FORBIDDEN_PLMNS: | 
|  | 944 | request = (MainThreadRequest) msg.obj; | 
|  | 945 | uiccCard = getUiccCardFromRequest(request); | 
|  | 946 | if (uiccCard == null) { | 
|  | 947 | loge("getForbiddenPlmns() UiccCard is null"); | 
|  | 948 | request.result = new IllegalArgumentException( | 
|  | 949 | "getForbiddenPlmns() UiccCard is null"); | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 950 | notifyRequester(request); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 951 | break; | 
|  | 952 | } | 
|  | 953 | Integer appType = (Integer) request.argument; | 
|  | 954 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); | 
|  | 955 | if (uiccApp == null) { | 
|  | 956 | loge("getForbiddenPlmns() no app with specified type -- " | 
|  | 957 | + appType); | 
|  | 958 | request.result = new IllegalArgumentException("Failed to get UICC App"); | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 959 | notifyRequester(request); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 960 | break; | 
|  | 961 | } else { | 
|  | 962 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() | 
|  | 963 | + " specified type -- " + appType); | 
|  | 964 | } | 
|  | 965 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); | 
|  | 966 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( | 
|  | 967 | onCompleted); | 
|  | 968 | break; | 
|  | 969 |  | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 970 | case CMD_SWITCH_SLOTS: | 
|  | 971 | request = (MainThreadRequest) msg.obj; | 
|  | 972 | int[] physicalSlots = (int[]) request.argument; | 
|  | 973 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); | 
|  | 974 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); | 
|  | 975 | break; | 
|  | 976 |  | 
|  | 977 | case EVENT_SWITCH_SLOTS_DONE: | 
|  | 978 | ar = (AsyncResult) msg.obj; | 
|  | 979 | request = (MainThreadRequest) ar.userObj; | 
|  | 980 | request.result = (ar.exception == null); | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 981 | notifyRequester(request); | 
|  | 982 | break; | 
|  | 983 | case CMD_GET_NETWORK_SELECTION_MODE: | 
|  | 984 | request = (MainThreadRequest) msg.obj; | 
|  | 985 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); | 
|  | 986 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); | 
|  | 987 | break; | 
|  | 988 |  | 
|  | 989 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: | 
|  | 990 | ar = (AsyncResult) msg.obj; | 
|  | 991 | request = (MainThreadRequest) ar.userObj; | 
|  | 992 | if (ar.exception != null) { | 
|  | 993 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; | 
|  | 994 | } else { | 
|  | 995 | int mode = ((int[]) ar.result)[0]; | 
|  | 996 | if (mode == 0) { | 
|  | 997 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; | 
|  | 998 | } else { | 
|  | 999 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; | 
|  | 1000 | } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1001 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1002 | notifyRequester(request); | 
|  | 1003 | break; | 
|  | 1004 | case CMD_GET_CDMA_ROAMING_MODE: | 
|  | 1005 | request = (MainThreadRequest) msg.obj; | 
|  | 1006 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); | 
|  | 1007 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); | 
|  | 1008 | break; | 
|  | 1009 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: | 
|  | 1010 | ar = (AsyncResult) msg.obj; | 
|  | 1011 | request = (MainThreadRequest) ar.userObj; | 
|  | 1012 | if (ar.exception != null) { | 
|  | 1013 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; | 
|  | 1014 | } else { | 
|  | 1015 | request.result = ((int[]) ar.result)[0]; | 
|  | 1016 | } | 
|  | 1017 | notifyRequester(request); | 
|  | 1018 | break; | 
|  | 1019 | case CMD_SET_CDMA_ROAMING_MODE: | 
|  | 1020 | request = (MainThreadRequest) msg.obj; | 
|  | 1021 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); | 
|  | 1022 | int mode = (int) request.argument; | 
|  | 1023 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); | 
|  | 1024 | break; | 
|  | 1025 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: | 
|  | 1026 | ar = (AsyncResult) msg.obj; | 
|  | 1027 | request = (MainThreadRequest) ar.userObj; | 
|  | 1028 | request.result = ar.exception == null; | 
|  | 1029 | notifyRequester(request); | 
|  | 1030 | break; | 
|  | 1031 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: | 
|  | 1032 | request = (MainThreadRequest) msg.obj; | 
|  | 1033 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); | 
|  | 1034 | int subscriptionMode = (int) request.argument; | 
|  | 1035 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); | 
|  | 1036 | break; | 
|  | 1037 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: | 
|  | 1038 | ar = (AsyncResult) msg.obj; | 
|  | 1039 | request = (MainThreadRequest) ar.userObj; | 
|  | 1040 | request.result = ar.exception == null; | 
|  | 1041 | notifyRequester(request); | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1042 | break; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1043 | case CMD_GET_ALL_CELL_INFO: | 
|  | 1044 | request = (MainThreadRequest) msg.obj; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1045 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1046 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1047 | break; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1048 | case EVENT_GET_ALL_CELL_INFO_DONE: | 
|  | 1049 | ar = (AsyncResult) msg.obj; | 
|  | 1050 | request = (MainThreadRequest) ar.userObj; | 
| Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1051 | // If a timeout occurs, the response will be null | 
|  | 1052 | request.result = (ar.exception == null && ar.result != null) | 
|  | 1053 | ? ar.result : new ArrayList<CellInfo>(); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1054 | synchronized (request) { | 
|  | 1055 | request.notifyAll(); | 
|  | 1056 | } | 
|  | 1057 | break; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1058 | case CMD_REQUEST_CELL_INFO_UPDATE: | 
|  | 1059 | request = (MainThreadRequest) msg.obj; | 
|  | 1060 | request.phone.requestCellInfoUpdate(request.workSource, | 
|  | 1061 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); | 
|  | 1062 | break; | 
|  | 1063 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: | 
|  | 1064 | ar = (AsyncResult) msg.obj; | 
|  | 1065 | request = (MainThreadRequest) ar.userObj; | 
|  | 1066 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; | 
|  | 1067 | try { | 
|  | 1068 | if (ar.exception != null) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1069 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); | 
| Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1070 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, | 
|  | 1071 | new android.os.ParcelableException(ar.exception)); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1072 | } else if (ar.result == null) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1073 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); | 
| Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1074 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1075 | } else { | 
|  | 1076 | // use the result as returned | 
|  | 1077 | cb.onCellInfo((List<CellInfo>) ar.result); | 
|  | 1078 | } | 
|  | 1079 | } catch (RemoteException re) { | 
|  | 1080 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); | 
|  | 1081 | } | 
|  | 1082 | break; | 
|  | 1083 | case CMD_GET_CELL_LOCATION: | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1084 | request = (MainThreadRequest) msg.obj; | 
|  | 1085 | WorkSource ws = (WorkSource) request.argument; | 
|  | 1086 | Phone phone = getPhoneFromRequest(request); | 
|  | 1087 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); | 
|  | 1088 | break; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1089 | case EVENT_GET_CELL_LOCATION_DONE: | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1090 | ar = (AsyncResult) msg.obj; | 
|  | 1091 | request = (MainThreadRequest) ar.userObj; | 
|  | 1092 | if (ar.exception == null) { | 
|  | 1093 | request.result = ar.result; | 
|  | 1094 | } else { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1095 | phone = getPhoneFromRequest(request); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1096 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) | 
|  | 1097 | ? new CdmaCellLocation() : new GsmCellLocation(); | 
|  | 1098 | } | 
|  | 1099 |  | 
|  | 1100 | synchronized (request) { | 
|  | 1101 | request.notifyAll(); | 
|  | 1102 | } | 
|  | 1103 | break; | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1104 | case CMD_MODEM_REBOOT: | 
|  | 1105 | request = (MainThreadRequest) msg.obj; | 
|  | 1106 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1107 | defaultPhone.rebootModem(onCompleted); | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1108 | break; | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1109 | case EVENT_CMD_MODEM_REBOOT_DONE: | 
|  | 1110 | handleNullReturnEvent(msg, "rebootModem"); | 
|  | 1111 | break; | 
| Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1112 | case CMD_REQUEST_ENABLE_MODEM: | 
|  | 1113 | request = (MainThreadRequest) msg.obj; | 
|  | 1114 | boolean enable = (boolean) request.argument; | 
|  | 1115 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); | 
| Nazanin Bakhshi | 9b37957 | 2019-03-01 17:27:47 -0800 | [diff] [blame] | 1116 | onCompleted.arg1 = enable ? 1 : 0; | 
| Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1117 | PhoneConfigurationManager.getInstance() | 
|  | 1118 | .enablePhone(request.phone, enable, onCompleted); | 
|  | 1119 | break; | 
|  | 1120 | case EVENT_ENABLE_MODEM_DONE: | 
|  | 1121 | ar = (AsyncResult) msg.obj; | 
|  | 1122 | request = (MainThreadRequest) ar.userObj; | 
|  | 1123 | request.result = (ar.exception == null); | 
| Nazanin Bakhshi | 1f78d7d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1124 | int phoneId = request.phone.getPhoneId(); | 
| Nazanin Bakhshi | 9b37957 | 2019-03-01 17:27:47 -0800 | [diff] [blame] | 1125 | //update the cache as modem status has changed | 
| Nazanin Bakhshi | 1f78d7d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1126 | if ((boolean) request.result) { | 
|  | 1127 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); | 
|  | 1128 | updateModemStateMetrics(); | 
|  | 1129 | } else { | 
|  | 1130 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." | 
|  | 1131 | + ar.exception); | 
|  | 1132 | } | 
|  | 1133 | notifyRequester(request); | 
|  | 1134 | break; | 
|  | 1135 | case CMD_GET_MODEM_STATUS: | 
|  | 1136 | request = (MainThreadRequest) msg.obj; | 
|  | 1137 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); | 
|  | 1138 | PhoneConfigurationManager.getInstance() | 
|  | 1139 | .getPhoneStatusFromModem(request.phone, onCompleted); | 
|  | 1140 | break; | 
|  | 1141 | case EVENT_GET_MODEM_STATUS_DONE: | 
|  | 1142 | ar = (AsyncResult) msg.obj; | 
|  | 1143 | request = (MainThreadRequest) ar.userObj; | 
|  | 1144 | int id = request.phone.getPhoneId(); | 
|  | 1145 | if (ar.exception == null && ar.result != null) { | 
|  | 1146 | request.result = ar.result; | 
|  | 1147 | //update the cache as modem status has changed | 
|  | 1148 | mPhoneConfigurationManager.addToPhoneStatusCache(id, | 
|  | 1149 | (boolean) request.result); | 
|  | 1150 | } else { | 
|  | 1151 | // Return true if modem status cannot be retrieved. For most cases, | 
|  | 1152 | // modem status is on. And for older version modems, GET_MODEM_STATUS | 
|  | 1153 | // and disable modem are not supported. Modem is always on. | 
|  | 1154 | // TODO: this should be fixed in R to support a third | 
|  | 1155 | // status UNKNOWN b/131631629 | 
|  | 1156 | request.result = true; | 
|  | 1157 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." | 
|  | 1158 | + ar.exception); | 
|  | 1159 | } | 
| Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1160 | notifyRequester(request); | 
|  | 1161 | break; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1162 | default: | 
|  | 1163 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); | 
|  | 1164 | break; | 
|  | 1165 | } | 
|  | 1166 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1167 |  | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1168 | private void notifyRequester(MainThreadRequest request) { | 
|  | 1169 | synchronized (request) { | 
|  | 1170 | request.notifyAll(); | 
|  | 1171 | } | 
|  | 1172 | } | 
|  | 1173 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1174 | private void handleNullReturnEvent(Message msg, String command) { | 
|  | 1175 | AsyncResult ar = (AsyncResult) msg.obj; | 
|  | 1176 | MainThreadRequest request = (MainThreadRequest) ar.userObj; | 
|  | 1177 | if (ar.exception == null) { | 
|  | 1178 | request.result = true; | 
|  | 1179 | } else { | 
|  | 1180 | request.result = false; | 
|  | 1181 | if (ar.exception instanceof CommandException) { | 
|  | 1182 | loge(command + ": CommandException: " + ar.exception); | 
|  | 1183 | } else { | 
|  | 1184 | loge(command + ": Unknown exception"); | 
|  | 1185 | } | 
|  | 1186 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1187 | notifyRequester(request); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1188 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1189 | } | 
|  | 1190 |  | 
|  | 1191 | /** | 
|  | 1192 | * Posts the specified command to be executed on the main thread, | 
|  | 1193 | * waits for the request to complete, and returns the result. | 
|  | 1194 | * @see #sendRequestAsync | 
|  | 1195 | */ | 
|  | 1196 | private Object sendRequest(int command, Object argument) { | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1197 | return sendRequest( | 
|  | 1198 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1199 | } | 
|  | 1200 |  | 
|  | 1201 | /** | 
|  | 1202 | * Posts the specified command to be executed on the main thread, | 
|  | 1203 | * waits for the request to complete, and returns the result. | 
|  | 1204 | * @see #sendRequestAsync | 
|  | 1205 | */ | 
|  | 1206 | private Object sendRequest(int command, Object argument, WorkSource workSource) { | 
|  | 1207 | return sendRequest(command, argument,  SubscriptionManager.INVALID_SUBSCRIPTION_ID, | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1208 | null, workSource); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1209 | } | 
|  | 1210 |  | 
|  | 1211 | /** | 
|  | 1212 | * Posts the specified command to be executed on the main thread, | 
|  | 1213 | * waits for the request to complete, and returns the result. | 
|  | 1214 | * @see #sendRequestAsync | 
|  | 1215 | */ | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1216 | private Object sendRequest(int command, Object argument, Integer subId) { | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1217 | return sendRequest(command, argument, subId, null, null); | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1218 | } | 
|  | 1219 |  | 
|  | 1220 | /** | 
|  | 1221 | * Posts the specified command to be executed on the main thread, | 
|  | 1222 | * waits for the request to complete, and returns the result. | 
|  | 1223 | * @see #sendRequestAsync | 
|  | 1224 | */ | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1225 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { | 
|  | 1226 | return sendRequest(command, argument, subId, null, workSource); | 
|  | 1227 | } | 
|  | 1228 |  | 
|  | 1229 | /** | 
|  | 1230 | * Posts the specified command to be executed on the main thread, | 
|  | 1231 | * waits for the request to complete, and returns the result. | 
|  | 1232 | * @see #sendRequestAsync | 
|  | 1233 | */ | 
|  | 1234 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { | 
|  | 1235 | return sendRequest( | 
|  | 1236 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); | 
|  | 1237 | } | 
|  | 1238 |  | 
|  | 1239 | /** | 
|  | 1240 | * Posts the specified command to be executed on the main thread, | 
|  | 1241 | * waits for the request to complete, and returns the result. | 
|  | 1242 | * @see #sendRequestAsync | 
|  | 1243 | */ | 
|  | 1244 | private Object sendRequest( | 
|  | 1245 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1246 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { | 
|  | 1247 | throw new RuntimeException("This method will deadlock if called from the main thread."); | 
|  | 1248 | } | 
|  | 1249 |  | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1250 | MainThreadRequest request = null; | 
|  | 1251 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { | 
|  | 1252 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); | 
|  | 1253 | } else if (phone != null) { | 
|  | 1254 | request = new MainThreadRequest(argument, phone, workSource); | 
|  | 1255 | } else { | 
|  | 1256 | request = new MainThreadRequest(argument, subId, workSource); | 
|  | 1257 | } | 
|  | 1258 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1259 | Message msg = mMainThreadHandler.obtainMessage(command, request); | 
|  | 1260 | msg.sendToTarget(); | 
|  | 1261 |  | 
|  | 1262 | // Wait for the request to complete | 
|  | 1263 | synchronized (request) { | 
|  | 1264 | while (request.result == null) { | 
|  | 1265 | try { | 
|  | 1266 | request.wait(); | 
|  | 1267 | } catch (InterruptedException e) { | 
|  | 1268 | // Do nothing, go back and wait until the request is complete | 
|  | 1269 | } | 
|  | 1270 | } | 
|  | 1271 | } | 
|  | 1272 | return request.result; | 
|  | 1273 | } | 
|  | 1274 |  | 
|  | 1275 | /** | 
|  | 1276 | * Asynchronous ("fire and forget") version of sendRequest(): | 
|  | 1277 | * Posts the specified command to be executed on the main thread, and | 
|  | 1278 | * returns immediately. | 
|  | 1279 | * @see #sendRequest | 
|  | 1280 | */ | 
|  | 1281 | private void sendRequestAsync(int command) { | 
|  | 1282 | mMainThreadHandler.sendEmptyMessage(command); | 
|  | 1283 | } | 
|  | 1284 |  | 
|  | 1285 | /** | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1286 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1287 | * @see {@link #sendRequest(int)} | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1288 | */ | 
|  | 1289 | private void sendRequestAsync(int command, Object argument) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1290 | sendRequestAsync(command, argument, null, null); | 
|  | 1291 | } | 
|  | 1292 |  | 
|  | 1293 | /** | 
|  | 1294 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. | 
|  | 1295 | * @see {@link #sendRequest(int,Object)} | 
|  | 1296 | */ | 
|  | 1297 | private void sendRequestAsync( | 
|  | 1298 | int command, Object argument, Phone phone, WorkSource workSource) { | 
|  | 1299 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1300 | Message msg = mMainThreadHandler.obtainMessage(command, request); | 
|  | 1301 | msg.sendToTarget(); | 
|  | 1302 | } | 
|  | 1303 |  | 
|  | 1304 | /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1305 | * Initialize the singleton PhoneInterfaceManager instance. | 
|  | 1306 | * This is only done once, at startup, from PhoneApp.onCreate(). | 
|  | 1307 | */ | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1308 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1309 | synchronized (PhoneInterfaceManager.class) { | 
|  | 1310 | if (sInstance == null) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1311 | sInstance = new PhoneInterfaceManager(app); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1312 | } else { | 
|  | 1313 | Log.wtf(LOG_TAG, "init() called multiple times!  sInstance = " + sInstance); | 
|  | 1314 | } | 
|  | 1315 | return sInstance; | 
|  | 1316 | } | 
|  | 1317 | } | 
|  | 1318 |  | 
|  | 1319 | /** Private constructor; @see init() */ | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1320 | private PhoneInterfaceManager(PhoneGlobals app) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1321 | mApp = app; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1322 | mCM = PhoneGlobals.getInstance().mCM; | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1323 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1324 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); | 
|  | 1325 | mMainThreadHandler = new MainThreadHandler(); | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1326 | mSubscriptionController = SubscriptionController.getInstance(); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1327 | mTelephonySharedPreferences = | 
|  | 1328 | PreferenceManager.getDefaultSharedPreferences(mApp); | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1329 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); | 
| Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1330 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1331 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1332 | publish(); | 
|  | 1333 | } | 
|  | 1334 |  | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1335 | private Phone getDefaultPhone() { | 
|  | 1336 | Phone thePhone = getPhone(getDefaultSubscription()); | 
|  | 1337 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); | 
|  | 1338 | } | 
|  | 1339 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1340 | private void publish() { | 
|  | 1341 | if (DBG) log("publish: " + this); | 
|  | 1342 |  | 
|  | 1343 | ServiceManager.addService("phone", this); | 
|  | 1344 | } | 
|  | 1345 |  | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1346 | private Phone getPhoneFromRequest(MainThreadRequest request) { | 
| Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1347 | if (request.phone != null) { | 
|  | 1348 | return request.phone; | 
|  | 1349 | } else { | 
|  | 1350 | return getPhoneFromSubId(request.subId); | 
|  | 1351 | } | 
|  | 1352 | } | 
|  | 1353 |  | 
|  | 1354 | private Phone getPhoneFromSubId(int subId) { | 
|  | 1355 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) | 
|  | 1356 | ? getDefaultPhone() : getPhone(subId); | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1357 | } | 
|  | 1358 |  | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1359 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { | 
|  | 1360 | Phone phone = getPhoneFromRequest(request); | 
|  | 1361 | return phone == null ? null : | 
|  | 1362 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); | 
|  | 1363 | } | 
|  | 1364 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1365 | // returns phone associated with the subId. | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1366 | private Phone getPhone(int subId) { | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1367 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1368 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1369 |  | 
|  | 1370 | public void dial(String number) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1371 | dialForSubscriber(getPreferredVoiceSubscription(), number); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1372 | } | 
|  | 1373 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1374 | public void dialForSubscriber(int subId, String number) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1375 | if (DBG) log("dial: " + number); | 
|  | 1376 | // No permission check needed here: This is just a wrapper around the | 
|  | 1377 | // ACTION_DIAL intent, which is available to any app since it puts up | 
|  | 1378 | // the UI before it does anything. | 
|  | 1379 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1380 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1381 | try { | 
|  | 1382 | String url = createTelUrl(number); | 
|  | 1383 | if (url == null) { | 
|  | 1384 | return; | 
|  | 1385 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1386 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1387 | // PENDING: should we just silently fail if phone is offhook or ringing? | 
|  | 1388 | PhoneConstants.State state = mCM.getState(subId); | 
|  | 1389 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { | 
|  | 1390 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); | 
|  | 1391 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 
|  | 1392 | mApp.startActivity(intent); | 
|  | 1393 | } | 
|  | 1394 | } finally { | 
|  | 1395 | Binder.restoreCallingIdentity(identity); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1396 | } | 
|  | 1397 | } | 
|  | 1398 |  | 
|  | 1399 | public void call(String callingPackage, String number) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1400 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1401 | } | 
|  | 1402 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1403 | public void callForSubscriber(int subId, String callingPackage, String number) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1404 | if (DBG) log("call: " + number); | 
|  | 1405 |  | 
|  | 1406 | // This is just a wrapper around the ACTION_CALL intent, but we still | 
|  | 1407 | // need to do a permission check since we're calling startActivity() | 
|  | 1408 | // from the context of the phone app. | 
|  | 1409 | enforceCallPermission(); | 
|  | 1410 |  | 
|  | 1411 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) | 
|  | 1412 | != AppOpsManager.MODE_ALLOWED) { | 
|  | 1413 | return; | 
|  | 1414 | } | 
|  | 1415 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1416 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1417 | try { | 
|  | 1418 | String url = createTelUrl(number); | 
|  | 1419 | if (url == null) { | 
|  | 1420 | return; | 
|  | 1421 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1422 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1423 | boolean isValid = false; | 
|  | 1424 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); | 
|  | 1425 | if (slist != null) { | 
|  | 1426 | for (SubscriptionInfo subInfoRecord : slist) { | 
|  | 1427 | if (subInfoRecord.getSubscriptionId() == subId) { | 
|  | 1428 | isValid = true; | 
|  | 1429 | break; | 
|  | 1430 | } | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1431 | } | 
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1432 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1433 | if (!isValid) { | 
|  | 1434 | return; | 
|  | 1435 | } | 
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1436 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1437 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); | 
|  | 1438 | intent.putExtra(SUBSCRIPTION_KEY, subId); | 
|  | 1439 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 
|  | 1440 | mApp.startActivity(intent); | 
|  | 1441 | } finally { | 
|  | 1442 | Binder.restoreCallingIdentity(identity); | 
|  | 1443 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1444 | } | 
|  | 1445 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1446 | public boolean supplyPin(String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1447 | return supplyPinForSubscriber(getDefaultSubscription(), pin); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1448 | } | 
|  | 1449 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1450 | public boolean supplyPinForSubscriber(int subId, String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1451 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1452 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; | 
|  | 1453 | } | 
|  | 1454 |  | 
|  | 1455 | public boolean supplyPuk(String puk, String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1456 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1457 | } | 
|  | 1458 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1459 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1460 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1461 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; | 
|  | 1462 | } | 
|  | 1463 |  | 
|  | 1464 | /** {@hide} */ | 
|  | 1465 | public int[] supplyPinReportResult(String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1466 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1467 | } | 
|  | 1468 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1469 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1470 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1471 |  | 
|  | 1472 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1473 | try { | 
|  | 1474 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); | 
|  | 1475 | checkSimPin.start(); | 
|  | 1476 | return checkSimPin.unlockSim(null, pin); | 
|  | 1477 | } finally { | 
|  | 1478 | Binder.restoreCallingIdentity(identity); | 
|  | 1479 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1480 | } | 
|  | 1481 |  | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1482 | /** {@hide} */ | 
|  | 1483 | public int[] supplyPukReportResult(String puk, String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1484 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1485 | } | 
|  | 1486 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1487 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1488 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1489 |  | 
|  | 1490 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1491 | try { | 
|  | 1492 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); | 
|  | 1493 | checkSimPuk.start(); | 
|  | 1494 | return checkSimPuk.unlockSim(puk, pin); | 
|  | 1495 | } finally { | 
|  | 1496 | Binder.restoreCallingIdentity(identity); | 
|  | 1497 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1498 | } | 
|  | 1499 |  | 
|  | 1500 | /** | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1501 | * Helper thread to turn async call to SimCard#supplyPin into | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1502 | * a synchronous one. | 
|  | 1503 | */ | 
|  | 1504 | private static class UnlockSim extends Thread { | 
|  | 1505 |  | 
|  | 1506 | private final IccCard mSimCard; | 
|  | 1507 |  | 
|  | 1508 | private boolean mDone = false; | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1509 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; | 
|  | 1510 | private int mRetryCount = -1; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1511 |  | 
|  | 1512 | // For replies from SimCard interface | 
|  | 1513 | private Handler mHandler; | 
|  | 1514 |  | 
|  | 1515 | // For async handler to identify request type | 
|  | 1516 | private static final int SUPPLY_PIN_COMPLETE = 100; | 
|  | 1517 |  | 
|  | 1518 | public UnlockSim(IccCard simCard) { | 
|  | 1519 | mSimCard = simCard; | 
|  | 1520 | } | 
|  | 1521 |  | 
|  | 1522 | @Override | 
|  | 1523 | public void run() { | 
|  | 1524 | Looper.prepare(); | 
|  | 1525 | synchronized (UnlockSim.this) { | 
|  | 1526 | mHandler = new Handler() { | 
|  | 1527 | @Override | 
|  | 1528 | public void handleMessage(Message msg) { | 
|  | 1529 | AsyncResult ar = (AsyncResult) msg.obj; | 
|  | 1530 | switch (msg.what) { | 
|  | 1531 | case SUPPLY_PIN_COMPLETE: | 
|  | 1532 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); | 
|  | 1533 | synchronized (UnlockSim.this) { | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1534 | mRetryCount = msg.arg1; | 
|  | 1535 | if (ar.exception != null) { | 
|  | 1536 | if (ar.exception instanceof CommandException && | 
|  | 1537 | ((CommandException)(ar.exception)).getCommandError() | 
|  | 1538 | == CommandException.Error.PASSWORD_INCORRECT) { | 
|  | 1539 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; | 
|  | 1540 | } else { | 
|  | 1541 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; | 
|  | 1542 | } | 
|  | 1543 | } else { | 
|  | 1544 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; | 
|  | 1545 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1546 | mDone = true; | 
|  | 1547 | UnlockSim.this.notifyAll(); | 
|  | 1548 | } | 
|  | 1549 | break; | 
|  | 1550 | } | 
|  | 1551 | } | 
|  | 1552 | }; | 
|  | 1553 | UnlockSim.this.notifyAll(); | 
|  | 1554 | } | 
|  | 1555 | Looper.loop(); | 
|  | 1556 | } | 
|  | 1557 |  | 
|  | 1558 | /* | 
|  | 1559 | * Use PIN or PUK to unlock SIM card | 
|  | 1560 | * | 
|  | 1561 | * If PUK is null, unlock SIM card with PIN | 
|  | 1562 | * | 
|  | 1563 | * If PUK is not null, unlock SIM card with PUK and set PIN code | 
|  | 1564 | */ | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1565 | synchronized int[] unlockSim(String puk, String pin) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1566 |  | 
|  | 1567 | while (mHandler == null) { | 
|  | 1568 | try { | 
|  | 1569 | wait(); | 
|  | 1570 | } catch (InterruptedException e) { | 
|  | 1571 | Thread.currentThread().interrupt(); | 
|  | 1572 | } | 
|  | 1573 | } | 
|  | 1574 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); | 
|  | 1575 |  | 
|  | 1576 | if (puk == null) { | 
|  | 1577 | mSimCard.supplyPin(pin, callback); | 
|  | 1578 | } else { | 
|  | 1579 | mSimCard.supplyPuk(puk, pin, callback); | 
|  | 1580 | } | 
|  | 1581 |  | 
|  | 1582 | while (!mDone) { | 
|  | 1583 | try { | 
|  | 1584 | Log.d(LOG_TAG, "wait for done"); | 
|  | 1585 | wait(); | 
|  | 1586 | } catch (InterruptedException e) { | 
|  | 1587 | // Restore the interrupted status | 
|  | 1588 | Thread.currentThread().interrupt(); | 
|  | 1589 | } | 
|  | 1590 | } | 
|  | 1591 | Log.d(LOG_TAG, "done"); | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1592 | int[] resultArray = new int[2]; | 
|  | 1593 | resultArray[0] = mResult; | 
|  | 1594 | resultArray[1] = mRetryCount; | 
|  | 1595 | return resultArray; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1596 | } | 
|  | 1597 | } | 
|  | 1598 |  | 
|  | 1599 | public void updateServiceLocation() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1600 | updateServiceLocationForSubscriber(getDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1601 |  | 
|  | 1602 | } | 
|  | 1603 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1604 | public void updateServiceLocationForSubscriber(int subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1605 | // No permission check needed here: this call is harmless, and it's | 
|  | 1606 | // needed for the ServiceState.requestStateUpdate() call (which is | 
|  | 1607 | // already intentionally exposed to 3rd parties.) | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1608 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1609 | try { | 
|  | 1610 | final Phone phone = getPhone(subId); | 
|  | 1611 | if (phone != null) { | 
|  | 1612 | phone.updateServiceLocation(); | 
|  | 1613 | } | 
|  | 1614 | } finally { | 
|  | 1615 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1616 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1617 | } | 
|  | 1618 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1619 | @Override | 
|  | 1620 | public boolean isRadioOn(String callingPackage) { | 
|  | 1621 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1622 | } | 
|  | 1623 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1624 | @Override | 
|  | 1625 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1626 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1627 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1628 | return false; | 
|  | 1629 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1630 |  | 
|  | 1631 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1632 | try { | 
|  | 1633 | return isRadioOnForSubscriber(subId); | 
|  | 1634 | } finally { | 
|  | 1635 | Binder.restoreCallingIdentity(identity); | 
|  | 1636 | } | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1637 | } | 
|  | 1638 |  | 
|  | 1639 | private boolean isRadioOnForSubscriber(int subId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1640 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1641 | try { | 
|  | 1642 | final Phone phone = getPhone(subId); | 
|  | 1643 | if (phone != null) { | 
|  | 1644 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; | 
|  | 1645 | } else { | 
|  | 1646 | return false; | 
|  | 1647 | } | 
|  | 1648 | } finally { | 
|  | 1649 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1650 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1651 | } | 
|  | 1652 |  | 
|  | 1653 | public void toggleRadioOnOff() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1654 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1655 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1656 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1657 | public void toggleRadioOnOffForSubscriber(int subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1658 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1659 |  | 
|  | 1660 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1661 | try { | 
|  | 1662 | final Phone phone = getPhone(subId); | 
|  | 1663 | if (phone != null) { | 
|  | 1664 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); | 
|  | 1665 | } | 
|  | 1666 | } finally { | 
|  | 1667 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1668 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1669 | } | 
|  | 1670 |  | 
|  | 1671 | public boolean setRadio(boolean turnOn) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1672 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1673 | } | 
|  | 1674 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1675 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1676 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1677 |  | 
|  | 1678 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1679 | try { | 
|  | 1680 | final Phone phone = getPhone(subId); | 
|  | 1681 | if (phone == null) { | 
|  | 1682 | return false; | 
|  | 1683 | } | 
|  | 1684 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { | 
|  | 1685 | toggleRadioOnOffForSubscriber(subId); | 
|  | 1686 | } | 
|  | 1687 | return true; | 
|  | 1688 | } finally { | 
|  | 1689 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1690 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1691 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1692 |  | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1693 | public boolean needMobileRadioShutdown() { | 
|  | 1694 | /* | 
|  | 1695 | * If any of the Radios are available, it will need to be | 
|  | 1696 | * shutdown. So return true if any Radio is available. | 
|  | 1697 | */ | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1698 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1699 | try { | 
|  | 1700 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
|  | 1701 | Phone phone = PhoneFactory.getPhone(i); | 
|  | 1702 | if (phone != null && phone.isRadioAvailable()) return true; | 
|  | 1703 | } | 
|  | 1704 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); | 
|  | 1705 | return false; | 
|  | 1706 | } finally { | 
|  | 1707 | Binder.restoreCallingIdentity(identity); | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1708 | } | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1709 | } | 
|  | 1710 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1711 | @Override | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1712 | public void shutdownMobileRadios() { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1713 | enforceModifyPermission(); | 
|  | 1714 |  | 
|  | 1715 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1716 | try { | 
|  | 1717 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
|  | 1718 | logv("Shutting down Phone " + i); | 
|  | 1719 | shutdownRadioUsingPhoneId(i); | 
|  | 1720 | } | 
|  | 1721 | } finally { | 
|  | 1722 | Binder.restoreCallingIdentity(identity); | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1723 | } | 
|  | 1724 | } | 
|  | 1725 |  | 
|  | 1726 | private void shutdownRadioUsingPhoneId(int phoneId) { | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1727 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 1728 | if (phone != null && phone.isRadioAvailable()) { | 
|  | 1729 | phone.shutdownRadio(); | 
|  | 1730 | } | 
|  | 1731 | } | 
|  | 1732 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1733 | public boolean setRadioPower(boolean turnOn) { | 
| Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1734 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1735 |  | 
|  | 1736 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1737 | try { | 
|  | 1738 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); | 
|  | 1739 | if (defaultPhone != null) { | 
|  | 1740 | defaultPhone.setRadioPower(turnOn); | 
|  | 1741 | return true; | 
|  | 1742 | } else { | 
|  | 1743 | loge("There's no default phone."); | 
|  | 1744 | return false; | 
|  | 1745 | } | 
|  | 1746 | } finally { | 
|  | 1747 | Binder.restoreCallingIdentity(identity); | 
| Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1748 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1749 | } | 
|  | 1750 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1751 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1752 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1753 |  | 
|  | 1754 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1755 | try { | 
|  | 1756 | final Phone phone = getPhone(subId); | 
|  | 1757 | if (phone != null) { | 
|  | 1758 | phone.setRadioPower(turnOn); | 
|  | 1759 | return true; | 
|  | 1760 | } else { | 
|  | 1761 | return false; | 
|  | 1762 | } | 
|  | 1763 | } finally { | 
|  | 1764 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1765 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1766 | } | 
|  | 1767 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1768 | // FIXME: subId version needed | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1769 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1770 | public boolean enableDataConnectivity() { | 
|  | 1771 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1772 |  | 
|  | 1773 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1774 | try { | 
|  | 1775 | int subId = mSubscriptionController.getDefaultDataSubId(); | 
|  | 1776 | final Phone phone = getPhone(subId); | 
|  | 1777 | if (phone != null) { | 
| Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1778 | phone.getDataEnabledSettings().setUserDataEnabled(true); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1779 | return true; | 
|  | 1780 | } else { | 
|  | 1781 | return false; | 
|  | 1782 | } | 
|  | 1783 | } finally { | 
|  | 1784 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1785 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1786 | } | 
|  | 1787 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1788 | // FIXME: subId version needed | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1789 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1790 | public boolean disableDataConnectivity() { | 
|  | 1791 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1792 |  | 
|  | 1793 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1794 | try { | 
|  | 1795 | int subId = mSubscriptionController.getDefaultDataSubId(); | 
|  | 1796 | final Phone phone = getPhone(subId); | 
|  | 1797 | if (phone != null) { | 
| Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1798 | phone.getDataEnabledSettings().setUserDataEnabled(false); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1799 | return true; | 
|  | 1800 | } else { | 
|  | 1801 | return false; | 
|  | 1802 | } | 
|  | 1803 | } finally { | 
|  | 1804 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1805 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1806 | } | 
|  | 1807 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1808 | @Override | 
| Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1809 | public boolean isDataConnectivityPossible(int subId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1810 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1811 | try { | 
|  | 1812 | final Phone phone = getPhone(subId); | 
|  | 1813 | if (phone != null) { | 
| Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1814 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1815 | } else { | 
|  | 1816 | return false; | 
|  | 1817 | } | 
|  | 1818 | } finally { | 
|  | 1819 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1820 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1821 | } | 
|  | 1822 |  | 
|  | 1823 | public boolean handlePinMmi(String dialString) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1824 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1825 | } | 
|  | 1826 |  | 
| pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1827 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1828 | enforceCallPermission(); | 
|  | 1829 |  | 
|  | 1830 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1831 | try { | 
|  | 1832 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 1833 | return; | 
|  | 1834 | } | 
|  | 1835 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); | 
|  | 1836 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); | 
|  | 1837 | } finally { | 
|  | 1838 | Binder.restoreCallingIdentity(identity); | 
|  | 1839 | } | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1840 | }; | 
|  | 1841 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1842 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1843 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1844 |  | 
|  | 1845 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1846 | try { | 
|  | 1847 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 1848 | return false; | 
|  | 1849 | } | 
|  | 1850 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); | 
|  | 1851 | } finally { | 
|  | 1852 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1853 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1854 | } | 
|  | 1855 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1856 | public int getCallState() { | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1857 | return getCallStateForSlot(getSlotForDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1858 | } | 
|  | 1859 |  | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1860 | public int getCallStateForSlot(int slotIndex) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1861 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1862 | try { | 
|  | 1863 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 1864 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : | 
|  | 1865 | PhoneConstantConversions.convertCallState(phone.getState()); | 
|  | 1866 | } finally { | 
|  | 1867 | Binder.restoreCallingIdentity(identity); | 
|  | 1868 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1869 | } | 
|  | 1870 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1871 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1872 | public int getDataState() { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1873 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1874 | try { | 
|  | 1875 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); | 
|  | 1876 | if (phone != null) { | 
|  | 1877 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); | 
|  | 1878 | } else { | 
|  | 1879 | return PhoneConstantConversions.convertDataState( | 
|  | 1880 | PhoneConstants.DataState.DISCONNECTED); | 
|  | 1881 | } | 
|  | 1882 | } finally { | 
|  | 1883 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1884 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1885 | } | 
|  | 1886 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1887 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1888 | public int getDataActivity() { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1889 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1890 | try { | 
|  | 1891 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); | 
|  | 1892 | if (phone != null) { | 
|  | 1893 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); | 
|  | 1894 | } else { | 
|  | 1895 | return TelephonyManager.DATA_ACTIVITY_NONE; | 
|  | 1896 | } | 
|  | 1897 | } finally { | 
|  | 1898 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1899 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1900 | } | 
|  | 1901 |  | 
|  | 1902 | @Override | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1903 | public Bundle getCellLocation(String callingPackage) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1904 | mApp.getSystemService(AppOpsManager.class) | 
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1905 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1906 |  | 
|  | 1907 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 1908 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 1909 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 1910 | .setCallingPackage(callingPackage) | 
|  | 1911 | .setCallingPid(Binder.getCallingPid()) | 
|  | 1912 | .setCallingUid(Binder.getCallingUid()) | 
|  | 1913 | .setMethod("getCellLocation") | 
|  | 1914 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 1915 | .build()); | 
|  | 1916 | switch (locationResult) { | 
|  | 1917 | case DENIED_HARD: | 
|  | 1918 | throw new SecurityException("Not allowed to access cell location"); | 
|  | 1919 | case DENIED_SOFT: | 
|  | 1920 | return new Bundle(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1921 | } | 
|  | 1922 |  | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1923 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1924 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1925 | try { | 
|  | 1926 | if (DBG_LOC) log("getCellLocation: is active user"); | 
|  | 1927 | Bundle data = new Bundle(); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1928 | int subId = mSubscriptionController.getDefaultDataSubId(); | 
|  | 1929 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); | 
|  | 1930 | cl.fillInNotifierBundle(data); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1931 | return data; | 
|  | 1932 | } finally { | 
|  | 1933 | Binder.restoreCallingIdentity(identity); | 
|  | 1934 | } | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1935 | } | 
|  | 1936 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1937 | @Override | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1938 | public String getNetworkCountryIsoForPhone(int phoneId) { | 
|  | 1939 | // Reporting the correct network country is ambiguous when IWLAN could conflict with | 
|  | 1940 | // registered cell info, so return a NULL country instead. | 
|  | 1941 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1942 | try { | 
| Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1943 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { | 
|  | 1944 | // Get default phone in this case. | 
|  | 1945 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; | 
|  | 1946 | } | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1947 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); | 
| Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1948 | // Todo: fix this when we can get the actual cellular network info when the device | 
|  | 1949 | // is on IWLAN. | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1950 | if (TelephonyManager.NETWORK_TYPE_IWLAN | 
|  | 1951 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { | 
|  | 1952 | return ""; | 
|  | 1953 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1954 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 1955 | if (phone != null) { | 
|  | 1956 | ServiceStateTracker sst = phone.getServiceStateTracker(); | 
|  | 1957 | if (sst != null) { | 
|  | 1958 | LocaleTracker lt = sst.getLocaleTracker(); | 
|  | 1959 | if (lt != null) { | 
|  | 1960 | return lt.getCurrentCountry(); | 
|  | 1961 | } | 
|  | 1962 | } | 
|  | 1963 | } | 
|  | 1964 | return ""; | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1965 | } finally { | 
|  | 1966 | Binder.restoreCallingIdentity(identity); | 
|  | 1967 | } | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1968 | } | 
|  | 1969 |  | 
|  | 1970 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1971 | public void enableLocationUpdates() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1972 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1973 | } | 
|  | 1974 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1975 | @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1976 | public void enableLocationUpdatesForSubscriber(int subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1977 | mApp.enforceCallingOrSelfPermission( | 
|  | 1978 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1979 |  | 
|  | 1980 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1981 | try { | 
|  | 1982 | final Phone phone = getPhone(subId); | 
|  | 1983 | if (phone != null) { | 
|  | 1984 | phone.enableLocationUpdates(); | 
|  | 1985 | } | 
|  | 1986 | } finally { | 
|  | 1987 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1988 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1989 | } | 
|  | 1990 |  | 
|  | 1991 | @Override | 
|  | 1992 | public void disableLocationUpdates() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1993 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1994 | } | 
|  | 1995 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1996 | @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1997 | public void disableLocationUpdatesForSubscriber(int subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1998 | mApp.enforceCallingOrSelfPermission( | 
|  | 1999 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2000 |  | 
|  | 2001 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2002 | try { | 
|  | 2003 | final Phone phone = getPhone(subId); | 
|  | 2004 | if (phone != null) { | 
|  | 2005 | phone.disableLocationUpdates(); | 
|  | 2006 | } | 
|  | 2007 | } finally { | 
|  | 2008 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2009 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2010 | } | 
|  | 2011 |  | 
| Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2012 | /** | 
|  | 2013 | * Returns the target SDK version number for a given package name. | 
|  | 2014 | * | 
|  | 2015 | * @return target SDK if the package is found or INT_MAX. | 
|  | 2016 | */ | 
|  | 2017 | private int getTargetSdk(String packageName) { | 
|  | 2018 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2019 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo( | 
|  | 2020 | packageName, 0); | 
| Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2021 | if (ai != null) return ai.targetSdkVersion; | 
|  | 2022 | } catch (PackageManager.NameNotFoundException unexpected) { | 
|  | 2023 | } | 
|  | 2024 | return Integer.MAX_VALUE; | 
|  | 2025 | } | 
|  | 2026 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2027 | @Override | 
|  | 2028 | @SuppressWarnings("unchecked") | 
| Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2029 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { | 
|  | 2030 | final int targetSdk = getTargetSdk(callingPackage); | 
| Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2031 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { | 
|  | 2032 | throw new SecurityException( | 
|  | 2033 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); | 
|  | 2034 | } | 
| Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2035 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2036 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), | 
|  | 2037 | callingPackage) != AppOpsManager.MODE_ALLOWED) { | 
|  | 2038 | return null; | 
|  | 2039 | } | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2040 |  | 
| Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2041 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2042 |  | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2043 | List<CellInfo> info = getAllCellInfo(callingPackage); | 
|  | 2044 | if (info == null) return null; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2045 |  | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2046 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); | 
|  | 2047 | for (CellInfo ci : info) { | 
|  | 2048 | if (ci instanceof CellInfoGsm) { | 
|  | 2049 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); | 
|  | 2050 | } else if (ci instanceof CellInfoWcdma) { | 
|  | 2051 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); | 
|  | 2052 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2053 | } | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2054 | return (neighbors.size()) > 0 ? neighbors : null; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2055 | } | 
|  | 2056 |  | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2057 | private List<CellInfo> getCachedCellInfo() { | 
|  | 2058 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); | 
|  | 2059 | for (Phone phone : PhoneFactory.getPhones()) { | 
|  | 2060 | List<CellInfo> info = phone.getAllCellInfo(); | 
|  | 2061 | if (info != null) cellInfos.addAll(info); | 
|  | 2062 | } | 
|  | 2063 | return cellInfos; | 
|  | 2064 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2065 |  | 
|  | 2066 | @Override | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2067 | public List<CellInfo> getAllCellInfo(String callingPackage) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2068 | mApp.getSystemService(AppOpsManager.class) | 
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2069 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2070 |  | 
|  | 2071 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 2072 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 2073 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 2074 | .setCallingPackage(callingPackage) | 
|  | 2075 | .setCallingPid(Binder.getCallingPid()) | 
|  | 2076 | .setCallingUid(Binder.getCallingUid()) | 
|  | 2077 | .setMethod("getAllCellInfo") | 
| Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2078 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2079 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 2080 | .build()); | 
|  | 2081 | switch (locationResult) { | 
|  | 2082 | case DENIED_HARD: | 
|  | 2083 | throw new SecurityException("Not allowed to access cell info"); | 
|  | 2084 | case DENIED_SOFT: | 
|  | 2085 | return new ArrayList<>(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2086 | } | 
|  | 2087 |  | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2088 | final int targetSdk = getTargetSdk(callingPackage); | 
|  | 2089 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { | 
|  | 2090 | return getCachedCellInfo(); | 
|  | 2091 | } | 
|  | 2092 |  | 
| Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2093 | if (DBG_LOC) log("getAllCellInfo: is active user"); | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2094 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2095 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2096 | try { | 
|  | 2097 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); | 
|  | 2098 | for (Phone phone : PhoneFactory.getPhones()) { | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2099 | final List<CellInfo> info = (List<CellInfo>) sendRequest( | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2100 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2101 | if (info != null) cellInfos.addAll(info); | 
|  | 2102 | } | 
|  | 2103 | return cellInfos; | 
|  | 2104 | } finally { | 
|  | 2105 | Binder.restoreCallingIdentity(identity); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2106 | } | 
|  | 2107 | } | 
|  | 2108 |  | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2109 | @Override | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2110 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { | 
|  | 2111 | requestCellInfoUpdateInternal( | 
|  | 2112 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); | 
|  | 2113 | } | 
|  | 2114 |  | 
|  | 2115 | @Override | 
|  | 2116 | public void requestCellInfoUpdateWithWorkSource( | 
|  | 2117 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { | 
|  | 2118 | enforceModifyPermission(); | 
|  | 2119 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); | 
|  | 2120 | } | 
|  | 2121 |  | 
|  | 2122 | private void requestCellInfoUpdateInternal( | 
|  | 2123 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2124 | mApp.getSystemService(AppOpsManager.class) | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2125 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2126 |  | 
|  | 2127 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 2128 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 2129 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 2130 | .setCallingPackage(callingPackage) | 
|  | 2131 | .setCallingPid(Binder.getCallingPid()) | 
|  | 2132 | .setCallingUid(Binder.getCallingUid()) | 
|  | 2133 | .setMethod("requestCellInfoUpdate") | 
|  | 2134 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 2135 | .build()); | 
|  | 2136 | switch (locationResult) { | 
|  | 2137 | case DENIED_HARD: | 
|  | 2138 | throw new SecurityException("Not allowed to access cell info"); | 
|  | 2139 | case DENIED_SOFT: | 
| Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2140 | try { | 
|  | 2141 | cb.onCellInfo(new ArrayList<CellInfo>()); | 
|  | 2142 | } catch (RemoteException re) { | 
|  | 2143 | // Drop without consequences | 
|  | 2144 | } | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2145 | return; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2146 | } | 
|  | 2147 |  | 
| Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2148 |  | 
|  | 2149 | final Phone phone = getPhoneFromSubId(subId); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2150 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); | 
|  | 2151 |  | 
|  | 2152 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); | 
|  | 2153 | } | 
|  | 2154 |  | 
|  | 2155 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2156 | public void setCellInfoListRate(int rateInMillis) { | 
| Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2157 | enforceModifyPermission(); | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2158 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2159 |  | 
|  | 2160 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2161 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2162 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2163 | } finally { | 
|  | 2164 | Binder.restoreCallingIdentity(identity); | 
|  | 2165 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2166 | } | 
|  | 2167 |  | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2168 | @Override | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2169 | public String getImeiForSlot(int slotIndex, String callingPackage) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2170 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2171 | if (phone == null) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2172 | return null; | 
|  | 2173 | } | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2174 | int subId = phone.getSubId(); | 
|  | 2175 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 2176 | mApp, subId, callingPackage, "getImeiForSlot")) { | 
|  | 2177 | return null; | 
|  | 2178 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2179 |  | 
|  | 2180 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2181 | try { | 
|  | 2182 | return phone.getImei(); | 
|  | 2183 | } finally { | 
|  | 2184 | Binder.restoreCallingIdentity(identity); | 
|  | 2185 | } | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2186 | } | 
|  | 2187 |  | 
|  | 2188 | @Override | 
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2189 | public String getTypeAllocationCodeForSlot(int slotIndex) { | 
|  | 2190 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2191 | String tac = null; | 
|  | 2192 | if (phone != null) { | 
|  | 2193 | String imei = phone.getImei(); | 
|  | 2194 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); | 
|  | 2195 | } | 
|  | 2196 | return tac; | 
|  | 2197 | } | 
|  | 2198 |  | 
|  | 2199 | @Override | 
| Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2200 | public String getMeidForSlot(int slotIndex, String callingPackage) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2201 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2202 | if (phone == null) { | 
| Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2203 | return null; | 
|  | 2204 | } | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2205 |  | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2206 | int subId = phone.getSubId(); | 
|  | 2207 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 2208 | mApp, subId, callingPackage, "getMeidForSlot")) { | 
|  | 2209 | return null; | 
|  | 2210 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2211 |  | 
|  | 2212 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2213 | try { | 
|  | 2214 | return phone.getMeid(); | 
|  | 2215 | } finally { | 
|  | 2216 | Binder.restoreCallingIdentity(identity); | 
|  | 2217 | } | 
| Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2218 | } | 
|  | 2219 |  | 
|  | 2220 | @Override | 
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2221 | public String getManufacturerCodeForSlot(int slotIndex) { | 
|  | 2222 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2223 | String manufacturerCode = null; | 
|  | 2224 | if (phone != null) { | 
|  | 2225 | String meid = phone.getMeid(); | 
|  | 2226 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); | 
|  | 2227 | } | 
|  | 2228 | return manufacturerCode; | 
|  | 2229 | } | 
|  | 2230 |  | 
|  | 2231 | @Override | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2232 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2233 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2234 | if (phone == null) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2235 | return null; | 
|  | 2236 | } | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2237 | int subId = phone.getSubId(); | 
|  | 2238 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 2239 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { | 
|  | 2240 | return null; | 
|  | 2241 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2242 |  | 
|  | 2243 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2244 | try { | 
|  | 2245 | return phone.getDeviceSvn(); | 
|  | 2246 | } finally { | 
|  | 2247 | Binder.restoreCallingIdentity(identity); | 
|  | 2248 | } | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2249 | } | 
|  | 2250 |  | 
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2251 | @Override | 
|  | 2252 | public int getSubscriptionCarrierId(int subId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2253 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2254 | try { | 
|  | 2255 | final Phone phone = getPhone(subId); | 
|  | 2256 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); | 
|  | 2257 | } finally { | 
|  | 2258 | Binder.restoreCallingIdentity(identity); | 
|  | 2259 | } | 
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2260 | } | 
|  | 2261 |  | 
|  | 2262 | @Override | 
|  | 2263 | public String getSubscriptionCarrierName(int subId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2264 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2265 | try { | 
|  | 2266 | final Phone phone = getPhone(subId); | 
|  | 2267 | return phone == null ? null : phone.getCarrierName(); | 
|  | 2268 | } finally { | 
|  | 2269 | Binder.restoreCallingIdentity(identity); | 
|  | 2270 | } | 
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2271 | } | 
|  | 2272 |  | 
| calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2273 | @Override | 
| chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2274 | public int getSubscriptionSpecificCarrierId(int subId) { | 
| chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2275 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2276 | try { | 
|  | 2277 | final Phone phone = getPhone(subId); | 
|  | 2278 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID | 
| chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2279 | : phone.getSpecificCarrierId(); | 
| chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2280 | } finally { | 
|  | 2281 | Binder.restoreCallingIdentity(identity); | 
|  | 2282 | } | 
|  | 2283 | } | 
|  | 2284 |  | 
|  | 2285 | @Override | 
| chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2286 | public String getSubscriptionSpecificCarrierName(int subId) { | 
| chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2287 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2288 | try { | 
|  | 2289 | final Phone phone = getPhone(subId); | 
| chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2290 | return phone == null ? null : phone.getSpecificCarrierName(); | 
| chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2291 | } finally { | 
|  | 2292 | Binder.restoreCallingIdentity(identity); | 
|  | 2293 | } | 
|  | 2294 | } | 
|  | 2295 |  | 
| chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2296 | @Override | 
| chen xu | 4ca4e69 | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2297 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { | 
|  | 2298 | if (!isSubscriptionMccMnc) { | 
|  | 2299 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); | 
|  | 2300 | } | 
| chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2301 | final Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2302 | if (phone == null) { | 
|  | 2303 | return TelephonyManager.UNKNOWN_CARRIER_ID; | 
|  | 2304 | } | 
|  | 2305 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2306 | try { | 
|  | 2307 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); | 
|  | 2308 | } finally { | 
|  | 2309 | Binder.restoreCallingIdentity(identity); | 
|  | 2310 | } | 
|  | 2311 | } | 
|  | 2312 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2313 | // | 
|  | 2314 | // Internal helper methods. | 
|  | 2315 | // | 
|  | 2316 |  | 
| Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2317 | /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2318 | * Make sure the caller has the MODIFY_PHONE_STATE permission. | 
|  | 2319 | * | 
|  | 2320 | * @throws SecurityException if the caller does not have the required permission | 
|  | 2321 | */ | 
|  | 2322 | private void enforceModifyPermission() { | 
|  | 2323 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); | 
|  | 2324 | } | 
|  | 2325 |  | 
|  | 2326 | /** | 
|  | 2327 | * Make sure the caller has the CALL_PHONE permission. | 
|  | 2328 | * | 
|  | 2329 | * @throws SecurityException if the caller does not have the required permission | 
|  | 2330 | */ | 
|  | 2331 | private void enforceCallPermission() { | 
|  | 2332 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); | 
|  | 2333 | } | 
|  | 2334 |  | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2335 | private void enforceConnectivityInternalPermission() { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2336 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2337 | "ConnectivityService"); | 
|  | 2338 | } | 
|  | 2339 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2340 | private String createTelUrl(String number) { | 
|  | 2341 | if (TextUtils.isEmpty(number)) { | 
|  | 2342 | return null; | 
|  | 2343 | } | 
|  | 2344 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2345 | return "tel:" + number; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2346 | } | 
|  | 2347 |  | 
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2348 | private static void log(String msg) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2349 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); | 
|  | 2350 | } | 
|  | 2351 |  | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2352 | private static void logv(String msg) { | 
|  | 2353 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); | 
|  | 2354 | } | 
|  | 2355 |  | 
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2356 | private static void loge(String msg) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2357 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); | 
|  | 2358 | } | 
|  | 2359 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2360 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2361 | public int getActivePhoneType() { | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2362 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2363 | } | 
|  | 2364 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2365 | @Override | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2366 | public int getActivePhoneTypeForSlot(int slotIndex) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2367 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2368 | try { | 
|  | 2369 | final Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2370 | if (phone == null) { | 
|  | 2371 | return PhoneConstants.PHONE_TYPE_NONE; | 
|  | 2372 | } else { | 
|  | 2373 | return phone.getPhoneType(); | 
|  | 2374 | } | 
|  | 2375 | } finally { | 
|  | 2376 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2377 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2378 | } | 
|  | 2379 |  | 
|  | 2380 | /** | 
|  | 2381 | * Returns the CDMA ERI icon index to display | 
|  | 2382 | */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2383 | @Override | 
|  | 2384 | public int getCdmaEriIconIndex(String callingPackage) { | 
|  | 2385 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2386 | } | 
|  | 2387 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2388 | @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2389 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2390 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2391 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2392 | return -1; | 
|  | 2393 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2394 |  | 
|  | 2395 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2396 | try { | 
|  | 2397 | final Phone phone = getPhone(subId); | 
|  | 2398 | if (phone != null) { | 
|  | 2399 | return phone.getCdmaEriIconIndex(); | 
|  | 2400 | } else { | 
|  | 2401 | return -1; | 
|  | 2402 | } | 
|  | 2403 | } finally { | 
|  | 2404 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2405 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2406 | } | 
|  | 2407 |  | 
|  | 2408 | /** | 
|  | 2409 | * Returns the CDMA ERI icon mode, | 
|  | 2410 | * 0 - ON | 
|  | 2411 | * 1 - FLASHING | 
|  | 2412 | */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2413 | @Override | 
|  | 2414 | public int getCdmaEriIconMode(String callingPackage) { | 
|  | 2415 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2416 | } | 
|  | 2417 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2418 | @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2419 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2420 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2421 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2422 | return -1; | 
|  | 2423 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2424 |  | 
|  | 2425 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2426 | try { | 
|  | 2427 | final Phone phone = getPhone(subId); | 
|  | 2428 | if (phone != null) { | 
|  | 2429 | return phone.getCdmaEriIconMode(); | 
|  | 2430 | } else { | 
|  | 2431 | return -1; | 
|  | 2432 | } | 
|  | 2433 | } finally { | 
|  | 2434 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2435 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2436 | } | 
|  | 2437 |  | 
|  | 2438 | /** | 
|  | 2439 | * Returns the CDMA ERI text, | 
|  | 2440 | */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2441 | @Override | 
|  | 2442 | public String getCdmaEriText(String callingPackage) { | 
|  | 2443 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2444 | } | 
|  | 2445 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2446 | @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2447 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2448 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2449 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2450 | return null; | 
|  | 2451 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2452 |  | 
|  | 2453 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2454 | try { | 
|  | 2455 | final Phone phone = getPhone(subId); | 
|  | 2456 | if (phone != null) { | 
|  | 2457 | return phone.getCdmaEriText(); | 
|  | 2458 | } else { | 
|  | 2459 | return null; | 
|  | 2460 | } | 
|  | 2461 | } finally { | 
|  | 2462 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2463 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2464 | } | 
|  | 2465 |  | 
|  | 2466 | /** | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2467 | * Returns the CDMA MDN. | 
|  | 2468 | */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2469 | @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2470 | public String getCdmaMdn(int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2471 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 2472 | mApp, subId, "getCdmaMdn"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2473 |  | 
|  | 2474 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2475 | try { | 
|  | 2476 | final Phone phone = getPhone(subId); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2477 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2478 | return phone.getLine1Number(); | 
|  | 2479 | } else { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2480 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2481 | return null; | 
|  | 2482 | } | 
|  | 2483 | } finally { | 
|  | 2484 | Binder.restoreCallingIdentity(identity); | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2485 | } | 
|  | 2486 | } | 
|  | 2487 |  | 
|  | 2488 | /** | 
|  | 2489 | * Returns the CDMA MIN. | 
|  | 2490 | */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2491 | @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2492 | public String getCdmaMin(int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2493 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 2494 | mApp, subId, "getCdmaMin"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2495 |  | 
|  | 2496 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2497 | try { | 
|  | 2498 | final Phone phone = getPhone(subId); | 
|  | 2499 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { | 
|  | 2500 | return phone.getCdmaMin(); | 
|  | 2501 | } else { | 
|  | 2502 | return null; | 
|  | 2503 | } | 
|  | 2504 | } finally { | 
|  | 2505 | Binder.restoreCallingIdentity(identity); | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2506 | } | 
|  | 2507 | } | 
|  | 2508 |  | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2509 | @Override | 
|  | 2510 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, | 
|  | 2511 | INumberVerificationCallback callback, String callingPackage) { | 
|  | 2512 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) | 
|  | 2513 | != PERMISSION_GRANTED) { | 
|  | 2514 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); | 
|  | 2515 | } | 
|  | 2516 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 2517 |  | 
|  | 2518 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); | 
|  | 2519 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { | 
|  | 2520 | throw new SecurityException("Calling package must be configured in the device config"); | 
|  | 2521 | } | 
|  | 2522 |  | 
|  | 2523 | if (range == null) { | 
|  | 2524 | throw new NullPointerException("Range must be non-null"); | 
|  | 2525 | } | 
|  | 2526 |  | 
|  | 2527 | timeoutMillis = Math.min(timeoutMillis, | 
| Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2528 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2529 |  | 
|  | 2530 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); | 
|  | 2531 | } | 
|  | 2532 |  | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2533 | /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2534 | * Returns true if CDMA provisioning needs to run. | 
|  | 2535 | */ | 
|  | 2536 | public boolean needsOtaServiceProvisioning() { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2537 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2538 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2539 | return getDefaultPhone().needsOtaServiceProvisioning(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2540 | } finally { | 
|  | 2541 | Binder.restoreCallingIdentity(identity); | 
|  | 2542 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2543 | } | 
|  | 2544 |  | 
|  | 2545 | /** | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2546 | * Sets the voice mail number of a given subId. | 
|  | 2547 | */ | 
|  | 2548 | @Override | 
|  | 2549 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2550 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2551 |  | 
|  | 2552 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2553 | try { | 
|  | 2554 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, | 
|  | 2555 | new Pair<String, String>(alphaTag, number), new Integer(subId)); | 
|  | 2556 | return success; | 
|  | 2557 | } finally { | 
|  | 2558 | Binder.restoreCallingIdentity(identity); | 
|  | 2559 | } | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2560 | } | 
|  | 2561 |  | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2562 | @Override | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2563 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { | 
|  | 2564 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2565 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2566 | if (!TextUtils.equals(callingPackage, systemDialer)) { | 
|  | 2567 | throw new SecurityException("caller must be system dialer"); | 
|  | 2568 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2569 |  | 
|  | 2570 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2571 | try { | 
|  | 2572 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); | 
|  | 2573 | if (phoneAccountHandle == null) { | 
|  | 2574 | return null; | 
|  | 2575 | } | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2576 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2577 | } finally { | 
|  | 2578 | Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2579 | } | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2580 | } | 
|  | 2581 |  | 
|  | 2582 | @Override | 
| Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2583 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { | 
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2584 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2585 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2586 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { | 
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2587 | return null; | 
|  | 2588 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2589 |  | 
| Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2590 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2591 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2592 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); | 
| Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2593 | } finally { | 
|  | 2594 | Binder.restoreCallingIdentity(identity); | 
|  | 2595 | } | 
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2596 | } | 
|  | 2597 |  | 
|  | 2598 | @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2599 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, | 
|  | 2600 | VisualVoicemailSmsFilterSettings settings) { | 
|  | 2601 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2602 |  | 
|  | 2603 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2604 | try { | 
|  | 2605 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2606 | mApp, callingPackage, subId, settings); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2607 | } finally { | 
|  | 2608 | Binder.restoreCallingIdentity(identity); | 
|  | 2609 | } | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2610 | } | 
|  | 2611 |  | 
|  | 2612 | @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2613 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { | 
|  | 2614 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2615 |  | 
|  | 2616 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2617 | try { | 
|  | 2618 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2619 | mApp, callingPackage, subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2620 | } finally { | 
|  | 2621 | Binder.restoreCallingIdentity(identity); | 
|  | 2622 | } | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2623 | } | 
|  | 2624 |  | 
|  | 2625 | @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2626 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( | 
|  | 2627 | String callingPackage, int subId) { | 
|  | 2628 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2629 |  | 
|  | 2630 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2631 | try { | 
|  | 2632 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2633 | mApp, callingPackage, subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2634 | } finally { | 
|  | 2635 | Binder.restoreCallingIdentity(identity); | 
|  | 2636 | } | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2637 | } | 
|  | 2638 |  | 
|  | 2639 | @Override | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2640 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2641 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2642 |  | 
|  | 2643 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2644 | try { | 
|  | 2645 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2646 | mApp, subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2647 | } finally { | 
|  | 2648 | Binder.restoreCallingIdentity(identity); | 
|  | 2649 | } | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2650 | } | 
|  | 2651 |  | 
|  | 2652 | @Override | 
|  | 2653 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, | 
|  | 2654 | String number, int port, String text, PendingIntent sentIntent) { | 
|  | 2655 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2656 | enforceVisualVoicemailPackage(callingPackage, subId); | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2657 | enforceSendSmsPermission(); | 
|  | 2658 | // Make the calls as the phone process. | 
|  | 2659 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2660 | try { | 
|  | 2661 | SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); | 
|  | 2662 | if (port == 0) { | 
|  | 2663 | smsManager.sendTextMessageWithSelfPermissions(number, null, text, | 
|  | 2664 | sentIntent, null, false); | 
|  | 2665 | } else { | 
|  | 2666 | byte[] data = text.getBytes(StandardCharsets.UTF_8); | 
|  | 2667 | smsManager.sendDataMessageWithSelfPermissions(number, null, | 
|  | 2668 | (short) port, data, sentIntent, null); | 
|  | 2669 | } | 
|  | 2670 | } finally { | 
|  | 2671 | Binder.restoreCallingIdentity(identity); | 
|  | 2672 | } | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2673 | } | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2674 | /** | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2675 | * Sets the voice activation state of a given subId. | 
|  | 2676 | */ | 
|  | 2677 | @Override | 
|  | 2678 | public void setVoiceActivationState(int subId, int activationState) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2679 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 2680 | mApp, subId, "setVoiceActivationState"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2681 |  | 
|  | 2682 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2683 | try { | 
|  | 2684 | final Phone phone = getPhone(subId); | 
|  | 2685 | if (phone != null) { | 
|  | 2686 | phone.setVoiceActivationState(activationState); | 
|  | 2687 | } else { | 
|  | 2688 | loge("setVoiceActivationState fails with invalid subId: " + subId); | 
|  | 2689 | } | 
|  | 2690 | } finally { | 
|  | 2691 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2692 | } | 
|  | 2693 | } | 
|  | 2694 |  | 
|  | 2695 | /** | 
|  | 2696 | * Sets the data activation state of a given subId. | 
|  | 2697 | */ | 
|  | 2698 | @Override | 
|  | 2699 | public void setDataActivationState(int subId, int activationState) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2700 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 2701 | mApp, subId, "setDataActivationState"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2702 |  | 
|  | 2703 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2704 | try { | 
|  | 2705 | final Phone phone = getPhone(subId); | 
|  | 2706 | if (phone != null) { | 
|  | 2707 | phone.setDataActivationState(activationState); | 
|  | 2708 | } else { | 
|  | 2709 | loge("setVoiceActivationState fails with invalid subId: " + subId); | 
|  | 2710 | } | 
|  | 2711 | } finally { | 
|  | 2712 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2713 | } | 
|  | 2714 | } | 
|  | 2715 |  | 
|  | 2716 | /** | 
|  | 2717 | * Returns the voice activation state of a given subId. | 
|  | 2718 | */ | 
|  | 2719 | @Override | 
|  | 2720 | public int getVoiceActivationState(int subId, String callingPackage) { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2721 | enforceReadPrivilegedPermission("getVoiceActivationState"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2722 |  | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2723 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2724 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2725 | try { | 
|  | 2726 | if (phone != null) { | 
|  | 2727 | return phone.getVoiceActivationState(); | 
|  | 2728 | } else { | 
|  | 2729 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; | 
|  | 2730 | } | 
|  | 2731 | } finally { | 
|  | 2732 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2733 | } | 
|  | 2734 | } | 
|  | 2735 |  | 
|  | 2736 | /** | 
|  | 2737 | * Returns the data activation state of a given subId. | 
|  | 2738 | */ | 
|  | 2739 | @Override | 
|  | 2740 | public int getDataActivationState(int subId, String callingPackage) { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2741 | enforceReadPrivilegedPermission("getDataActivationState"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2742 |  | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2743 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2744 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2745 | try { | 
|  | 2746 | if (phone != null) { | 
|  | 2747 | return phone.getDataActivationState(); | 
|  | 2748 | } else { | 
|  | 2749 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; | 
|  | 2750 | } | 
|  | 2751 | } finally { | 
|  | 2752 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2753 | } | 
|  | 2754 | } | 
|  | 2755 |  | 
|  | 2756 | /** | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2757 | * Returns the unread count of voicemails for a subId | 
|  | 2758 | */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2759 | @Override | 
| Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2760 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { | 
|  | 2761 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 2762 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { | 
|  | 2763 | return 0; | 
|  | 2764 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2765 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2766 | try { | 
|  | 2767 | final Phone phone = getPhone(subId); | 
|  | 2768 | if (phone != null) { | 
|  | 2769 | return phone.getVoiceMessageCount(); | 
|  | 2770 | } else { | 
|  | 2771 | return 0; | 
|  | 2772 | } | 
|  | 2773 | } finally { | 
|  | 2774 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2775 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2776 | } | 
|  | 2777 |  | 
|  | 2778 | /** | 
| pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2779 | * returns true, if the device is in a state where both voice and data | 
|  | 2780 | * are supported simultaneously. This can change based on location or network condition. | 
|  | 2781 | */ | 
|  | 2782 | @Override | 
|  | 2783 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2784 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2785 | try { | 
|  | 2786 | final Phone phone = getPhone(subId); | 
|  | 2787 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); | 
|  | 2788 | } finally { | 
|  | 2789 | Binder.restoreCallingIdentity(identity); | 
|  | 2790 | } | 
| pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2791 | } | 
|  | 2792 |  | 
|  | 2793 | /** | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2794 | * Send the dialer code if called from the current default dialer or the caller has | 
|  | 2795 | * carrier privilege. | 
|  | 2796 | * @param inputCode The dialer code to send | 
|  | 2797 | */ | 
|  | 2798 | @Override | 
|  | 2799 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2800 | final Phone defaultPhone = getDefaultPhone(); | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2801 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2802 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) | 
|  | 2803 | .getDefaultDialerPackage(); | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2804 | if (!TextUtils.equals(callingPackage, defaultDialer)) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2805 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( | 
|  | 2806 | getDefaultSubscription(), "sendDialerSpecialCode"); | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2807 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2808 |  | 
|  | 2809 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2810 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2811 | defaultPhone.sendDialerSpecialCode(inputCode); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2812 | } finally { | 
|  | 2813 | Binder.restoreCallingIdentity(identity); | 
|  | 2814 | } | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2815 | } | 
|  | 2816 |  | 
|  | 2817 | /** | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2818 | * Returns the data network type. | 
|  | 2819 | * Legacy call, permission-free. | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2820 | * | 
|  | 2821 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. | 
|  | 2822 | */ | 
|  | 2823 | @Override | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2824 | public int getNetworkType() { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2825 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2826 | try { | 
|  | 2827 | final Phone phone = getPhone(getDefaultSubscription()); | 
|  | 2828 | if (phone != null) { | 
|  | 2829 | return phone.getServiceState().getDataNetworkType(); | 
|  | 2830 | } else { | 
|  | 2831 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 2832 | } | 
|  | 2833 | } finally { | 
|  | 2834 | Binder.restoreCallingIdentity(identity); | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2835 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2836 | } | 
|  | 2837 |  | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2838 | @Override | 
|  | 2839 | public int getNetworkSelectionMode(int subId) { | 
| Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2840 | if (!isActiveSubscription(subId)) { | 
|  | 2841 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; | 
|  | 2842 | } | 
|  | 2843 |  | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2844 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); | 
|  | 2845 | } | 
|  | 2846 |  | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2847 | @Override | 
| Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2848 | public boolean isInEmergencySmsMode() { | 
|  | 2849 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); | 
|  | 2850 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2851 | try { | 
|  | 2852 | for (Phone phone : PhoneFactory.getPhones()) { | 
|  | 2853 | if (phone.isInEmergencySmsMode()) { | 
|  | 2854 | return true; | 
|  | 2855 | } | 
|  | 2856 | } | 
|  | 2857 | } finally { | 
|  | 2858 | Binder.restoreCallingIdentity(identity); | 
|  | 2859 | } | 
|  | 2860 | return false; | 
|  | 2861 | } | 
|  | 2862 |  | 
|  | 2863 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2864 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) | 
|  | 2865 | throws RemoteException { | 
|  | 2866 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2867 | final long token = Binder.clearCallingIdentity(); | 
|  | 2868 | try { | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2869 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2870 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2871 | .addRegistrationCallbackForSubscription(c, subId); | 
|  | 2872 | } finally { | 
|  | 2873 | Binder.restoreCallingIdentity(token); | 
|  | 2874 | } | 
|  | 2875 | } | 
|  | 2876 |  | 
|  | 2877 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2878 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { | 
|  | 2879 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2880 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 2881 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 2882 | } | 
|  | 2883 | Binder.withCleanCallingIdentity(() -> { | 
|  | 2884 | try { | 
|  | 2885 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2886 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2887 | .removeRegistrationCallbackForSubscription(c, subId); | 
|  | 2888 | } catch (IllegalArgumentException e) { | 
|  | 2889 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId | 
|  | 2890 | + "is inactive, ignoring unregister."); | 
|  | 2891 | // If the subscription is no longer active, just return, since the callback | 
|  | 2892 | // will already have been removed internally. | 
|  | 2893 | } | 
|  | 2894 | }); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2895 | } | 
|  | 2896 |  | 
|  | 2897 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2898 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) | 
|  | 2899 | throws RemoteException { | 
|  | 2900 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2901 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 2902 | final long token = Binder.clearCallingIdentity(); | 
|  | 2903 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2904 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2905 | .addCapabilitiesCallbackForSubscription(c, subId); | 
|  | 2906 | } finally { | 
|  | 2907 | Binder.restoreCallingIdentity(token); | 
|  | 2908 | } | 
|  | 2909 | } | 
|  | 2910 |  | 
|  | 2911 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2912 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { | 
|  | 2913 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2914 |  | 
|  | 2915 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 2916 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 2917 | } | 
|  | 2918 | Binder.withCleanCallingIdentity(() -> { | 
|  | 2919 | try { | 
|  | 2920 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2921 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2922 | .removeCapabilitiesCallbackForSubscription(c, subId); | 
|  | 2923 | } catch (IllegalArgumentException e) { | 
|  | 2924 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId | 
|  | 2925 | + "is inactive, ignoring unregister."); | 
|  | 2926 | // If the subscription is no longer active, just return, since the callback | 
|  | 2927 | // will already have been removed internally. | 
|  | 2928 | } | 
|  | 2929 | }); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2930 | } | 
|  | 2931 |  | 
|  | 2932 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2933 | public boolean isCapable(int subId, int capability, int regTech) { | 
|  | 2934 | enforceReadPrivilegedPermission("isCapable"); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2935 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 2936 | final long token = Binder.clearCallingIdentity(); | 
|  | 2937 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2938 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2939 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); | 
|  | 2940 | } catch (ImsException e) { | 
|  | 2941 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); | 
|  | 2942 | return false; | 
| Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2943 | } catch (IllegalArgumentException e) { | 
|  | 2944 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); | 
|  | 2945 | return false; | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2946 | } finally { | 
|  | 2947 | Binder.restoreCallingIdentity(token); | 
|  | 2948 | } | 
|  | 2949 | } | 
|  | 2950 |  | 
|  | 2951 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2952 | public boolean isAvailable(int subId, int capability, int regTech) { | 
|  | 2953 | enforceReadPrivilegedPermission("isAvailable"); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2954 | final long token = Binder.clearCallingIdentity(); | 
|  | 2955 | try { | 
|  | 2956 | Phone phone = getPhone(subId); | 
|  | 2957 | if (phone == null) return false; | 
|  | 2958 | return phone.isImsCapabilityAvailable(capability, regTech); | 
|  | 2959 | } finally { | 
|  | 2960 | Binder.restoreCallingIdentity(token); | 
|  | 2961 | } | 
|  | 2962 | } | 
|  | 2963 |  | 
|  | 2964 | @Override | 
|  | 2965 | public boolean isAdvancedCallingSettingEnabled(int subId) { | 
|  | 2966 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); | 
|  | 2967 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 2968 | final long token = Binder.clearCallingIdentity(); | 
|  | 2969 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2970 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2971 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); | 
|  | 2972 | } finally { | 
|  | 2973 | Binder.restoreCallingIdentity(token); | 
|  | 2974 | } | 
|  | 2975 | } | 
|  | 2976 |  | 
|  | 2977 | @Override | 
| Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2978 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2979 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
| Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2980 | "setAdvancedCallingSettingEnabled"); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2981 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2982 | try { | 
|  | 2983 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2984 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2985 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); | 
|  | 2986 | } finally { | 
|  | 2987 | Binder.restoreCallingIdentity(identity); | 
|  | 2988 | } | 
|  | 2989 | } | 
|  | 2990 |  | 
|  | 2991 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2992 | public boolean isVtSettingEnabled(int subId) { | 
|  | 2993 | enforceReadPrivilegedPermission("isVtSettingEnabled"); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2994 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2995 | try { | 
|  | 2996 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2997 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2998 | getSlotIndexOrException(subId)).isVtEnabledByUser(); | 
|  | 2999 | } finally { | 
|  | 3000 | Binder.restoreCallingIdentity(identity); | 
|  | 3001 | } | 
|  | 3002 | } | 
|  | 3003 |  | 
|  | 3004 | @Override | 
| Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3005 | public void setVtSettingEnabled(int subId, boolean isEnabled) { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3006 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
| Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3007 | "setVtSettingEnabled"); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3008 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3009 | try { | 
|  | 3010 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3011 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3012 | } finally { | 
|  | 3013 | Binder.restoreCallingIdentity(identity); | 
|  | 3014 | } | 
|  | 3015 | } | 
|  | 3016 |  | 
|  | 3017 | @Override | 
|  | 3018 | public boolean isVoWiFiSettingEnabled(int subId) { | 
|  | 3019 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); | 
|  | 3020 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3021 | try { | 
|  | 3022 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3023 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3024 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); | 
|  | 3025 | } finally { | 
|  | 3026 | Binder.restoreCallingIdentity(identity); | 
|  | 3027 | } | 
|  | 3028 | } | 
|  | 3029 |  | 
|  | 3030 | @Override | 
| Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3031 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3032 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
| Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3033 | "setVoWiFiSettingEnabled"); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3034 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3035 | try { | 
|  | 3036 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3037 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3038 | } finally { | 
|  | 3039 | Binder.restoreCallingIdentity(identity); | 
|  | 3040 | } | 
|  | 3041 | } | 
|  | 3042 |  | 
|  | 3043 | @Override | 
|  | 3044 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { | 
|  | 3045 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); | 
|  | 3046 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3047 | try { | 
|  | 3048 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3049 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3050 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); | 
|  | 3051 | } finally { | 
|  | 3052 | Binder.restoreCallingIdentity(identity); | 
|  | 3053 | } | 
|  | 3054 | } | 
|  | 3055 |  | 
|  | 3056 | @Override | 
| Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3057 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3058 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
| Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3059 | "setVoWiFiRoamingSettingEnabled"); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3060 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3061 | try { | 
|  | 3062 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3063 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3064 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); | 
|  | 3065 | } finally { | 
|  | 3066 | Binder.restoreCallingIdentity(identity); | 
|  | 3067 | } | 
|  | 3068 | } | 
|  | 3069 |  | 
|  | 3070 | @Override | 
|  | 3071 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { | 
|  | 3072 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 3073 | "setVoWiFiNonPersistent"); | 
|  | 3074 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3075 | try { | 
|  | 3076 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3077 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 2bc9570 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3078 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3079 | } finally { | 
|  | 3080 | Binder.restoreCallingIdentity(identity); | 
|  | 3081 | } | 
|  | 3082 | } | 
|  | 3083 |  | 
|  | 3084 | @Override | 
|  | 3085 | public int getVoWiFiModeSetting(int subId) { | 
|  | 3086 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); | 
|  | 3087 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3088 | try { | 
|  | 3089 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3090 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3091 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); | 
|  | 3092 | } finally { | 
|  | 3093 | Binder.restoreCallingIdentity(identity); | 
|  | 3094 | } | 
|  | 3095 | } | 
|  | 3096 |  | 
|  | 3097 | @Override | 
|  | 3098 | public void setVoWiFiModeSetting(int subId, int mode) { | 
|  | 3099 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 3100 | "setVoWiFiModeSetting"); | 
|  | 3101 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3102 | try { | 
|  | 3103 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3104 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3105 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); | 
|  | 3106 | } finally { | 
|  | 3107 | Binder.restoreCallingIdentity(identity); | 
|  | 3108 | } | 
|  | 3109 | } | 
|  | 3110 |  | 
|  | 3111 | @Override | 
|  | 3112 | public int getVoWiFiRoamingModeSetting(int subId) { | 
|  | 3113 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); | 
|  | 3114 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3115 | try { | 
|  | 3116 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3117 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3118 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); | 
|  | 3119 | } finally { | 
|  | 3120 | Binder.restoreCallingIdentity(identity); | 
|  | 3121 | } | 
|  | 3122 | } | 
|  | 3123 |  | 
|  | 3124 | @Override | 
|  | 3125 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { | 
|  | 3126 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 3127 | "setVoWiFiRoamingModeSetting"); | 
|  | 3128 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3129 | try { | 
|  | 3130 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3131 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3132 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); | 
|  | 3133 | } finally { | 
|  | 3134 | Binder.restoreCallingIdentity(identity); | 
|  | 3135 | } | 
|  | 3136 | } | 
|  | 3137 |  | 
|  | 3138 | @Override | 
|  | 3139 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { | 
|  | 3140 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 3141 | "setRttCapabilityEnabled"); | 
|  | 3142 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3143 | try { | 
|  | 3144 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3145 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3146 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); | 
|  | 3147 | } finally { | 
|  | 3148 | Binder.restoreCallingIdentity(identity); | 
|  | 3149 | } | 
|  | 3150 | } | 
|  | 3151 |  | 
|  | 3152 | @Override | 
|  | 3153 | public boolean isTtyOverVolteEnabled(int subId) { | 
|  | 3154 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); | 
|  | 3155 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3156 | try { | 
|  | 3157 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3158 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3159 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); | 
|  | 3160 | } finally { | 
|  | 3161 | Binder.restoreCallingIdentity(identity); | 
|  | 3162 | } | 
|  | 3163 | } | 
|  | 3164 |  | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3165 | @Override | 
|  | 3166 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { | 
|  | 3167 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); | 
|  | 3168 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3169 | try { | 
|  | 3170 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3171 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3172 | .addProvisioningCallbackForSubscription(callback, subId); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3173 | } finally { | 
|  | 3174 | Binder.restoreCallingIdentity(identity); | 
|  | 3175 | } | 
|  | 3176 | } | 
|  | 3177 |  | 
|  | 3178 | @Override | 
|  | 3179 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { | 
|  | 3180 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); | 
|  | 3181 | final long identity = Binder.clearCallingIdentity(); | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3182 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 3183 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 3184 | } | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3185 | try { | 
|  | 3186 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3187 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3188 | .removeProvisioningCallbackForSubscription(callback, subId); | 
|  | 3189 | } catch (IllegalArgumentException e) { | 
|  | 3190 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId | 
|  | 3191 | + "is inactive, ignoring unregister."); | 
|  | 3192 | // If the subscription is no longer active, just return, since the callback will already | 
|  | 3193 | // have been removed internally. | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3194 | } finally { | 
|  | 3195 | Binder.restoreCallingIdentity(identity); | 
|  | 3196 | } | 
|  | 3197 | } | 
|  | 3198 |  | 
|  | 3199 | @Override | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3200 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, | 
|  | 3201 | boolean isProvisioned) { | 
|  | 3202 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN | 
|  | 3203 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 3204 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); | 
|  | 3205 | } | 
|  | 3206 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 3207 | "setProvisioningStatusForCapability"); | 
|  | 3208 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3209 | try { | 
|  | 3210 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 3211 | Phone phone = getPhone(subId); | 
|  | 3212 | if (phone == null) { | 
|  | 3213 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " | 
|  | 3214 | + subId); | 
|  | 3215 | return; | 
|  | 3216 | } | 
|  | 3217 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { | 
|  | 3218 | return; | 
|  | 3219 | } | 
|  | 3220 |  | 
|  | 3221 | // this capability requires provisioning, route to the correct API. | 
|  | 3222 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); | 
|  | 3223 | switch (capability) { | 
|  | 3224 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { | 
|  | 3225 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 3226 | ims.setVolteProvisioned(isProvisioned); | 
|  | 3227 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { | 
|  | 3228 | ims.setWfcProvisioned(isProvisioned); | 
|  | 3229 | } | 
|  | 3230 | break; | 
|  | 3231 | } | 
|  | 3232 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { | 
|  | 3233 | // There is currently no difference in VT provisioning type. | 
|  | 3234 | ims.setVtProvisioned(isProvisioned); | 
|  | 3235 | break; | 
|  | 3236 | } | 
|  | 3237 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { | 
|  | 3238 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so | 
|  | 3239 | // change the capability of the feature instead if needed. | 
|  | 3240 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) | 
|  | 3241 | == isProvisioned) { | 
|  | 3242 | // No change in provisioning. | 
|  | 3243 | return; | 
|  | 3244 | } | 
|  | 3245 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); | 
|  | 3246 | try { | 
|  | 3247 | ims.changeMmTelCapability(capability, tech, isProvisioned); | 
|  | 3248 | } catch (ImsException e) { | 
|  | 3249 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" | 
|  | 3250 | + ", Exception" + e.getMessage()); | 
|  | 3251 | } | 
|  | 3252 | break; | 
|  | 3253 | } | 
|  | 3254 | default: { | 
|  | 3255 | throw new IllegalArgumentException("Tried to set provisioning for capability '" | 
|  | 3256 | + capability + "', which does not require provisioning."); | 
|  | 3257 | } | 
|  | 3258 | } | 
|  | 3259 |  | 
|  | 3260 | } finally { | 
|  | 3261 | Binder.restoreCallingIdentity(identity); | 
|  | 3262 | } | 
|  | 3263 | } | 
|  | 3264 |  | 
|  | 3265 | @Override | 
|  | 3266 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { | 
|  | 3267 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN | 
|  | 3268 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 3269 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); | 
|  | 3270 | } | 
|  | 3271 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); | 
|  | 3272 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3273 | try { | 
|  | 3274 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 3275 | Phone phone = getPhone(subId); | 
|  | 3276 | if (phone == null) { | 
|  | 3277 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " | 
|  | 3278 | + subId); | 
|  | 3279 | // We will fail with "true" as the provisioning status because this is the default | 
|  | 3280 | // if we do not require provisioning. | 
|  | 3281 | return true; | 
|  | 3282 | } | 
|  | 3283 |  | 
|  | 3284 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { | 
|  | 3285 | return true; | 
|  | 3286 | } | 
|  | 3287 |  | 
|  | 3288 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); | 
|  | 3289 | switch (capability) { | 
|  | 3290 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { | 
|  | 3291 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 3292 | return ims.isVolteProvisionedOnDevice(); | 
|  | 3293 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { | 
|  | 3294 | return ims.isWfcProvisionedOnDevice(); | 
|  | 3295 | } | 
|  | 3296 | // This should never happen, since we are checking tech above to make sure it | 
|  | 3297 | // is either LTE or IWLAN. | 
|  | 3298 | throw new IllegalArgumentException("Invalid radio technology for voice " | 
|  | 3299 | + "capability."); | 
|  | 3300 | } | 
|  | 3301 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { | 
|  | 3302 | // There is currently no difference in VT provisioning type. | 
|  | 3303 | return ims.isVtProvisionedOnDevice(); | 
|  | 3304 | } | 
|  | 3305 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { | 
|  | 3306 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. | 
|  | 3307 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); | 
|  | 3308 | } | 
|  | 3309 | default: { | 
|  | 3310 | throw new IllegalArgumentException("Tried to get provisioning for capability '" | 
|  | 3311 | + capability + "', which does not require provisioning."); | 
|  | 3312 | } | 
|  | 3313 | } | 
|  | 3314 |  | 
|  | 3315 | } finally { | 
|  | 3316 | Binder.restoreCallingIdentity(identity); | 
|  | 3317 | } | 
|  | 3318 | } | 
|  | 3319 |  | 
|  | 3320 | @Override | 
|  | 3321 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { | 
|  | 3322 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN | 
|  | 3323 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 3324 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); | 
|  | 3325 | } | 
|  | 3326 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); | 
|  | 3327 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); | 
|  | 3328 | return (provisionedBits & capability) > 0; | 
|  | 3329 | } | 
|  | 3330 |  | 
|  | 3331 | @Override | 
|  | 3332 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, | 
|  | 3333 | boolean isProvisioned) { | 
|  | 3334 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN | 
|  | 3335 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 3336 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); | 
|  | 3337 | } | 
|  | 3338 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 3339 | "setProvisioningStatusForCapability"); | 
|  | 3340 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); | 
|  | 3341 | // If the current provisioning status for capability already matches isProvisioned, | 
|  | 3342 | // do nothing. | 
|  | 3343 | if (((provisionedBits & capability) > 0) == isProvisioned) { | 
|  | 3344 | return; | 
|  | 3345 | } | 
|  | 3346 | if (isProvisioned) { | 
|  | 3347 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); | 
|  | 3348 | } else { | 
|  | 3349 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); | 
|  | 3350 | } | 
|  | 3351 | } | 
|  | 3352 |  | 
|  | 3353 | /** | 
|  | 3354 | * @return the bitfield containing the MmTel provisioning for the provided subscription and | 
|  | 3355 | * technology. The bitfield should mirror the bitfield defined by | 
|  | 3356 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. | 
|  | 3357 | */ | 
|  | 3358 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { | 
|  | 3359 | String key = getMmTelProvisioningKey(subId, tech); | 
|  | 3360 | // Default is no capabilities are provisioned. | 
|  | 3361 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); | 
|  | 3362 | } | 
|  | 3363 |  | 
|  | 3364 | /** | 
|  | 3365 | * Sets the MmTel capability provisioning bitfield (defined by | 
|  | 3366 | *     {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and | 
|  | 3367 | *     technology specified. | 
|  | 3368 | * | 
|  | 3369 | * Note: This is a synchronous command and should not be called on UI thread. | 
|  | 3370 | */ | 
|  | 3371 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { | 
|  | 3372 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); | 
|  | 3373 | String key = getMmTelProvisioningKey(subId, tech); | 
|  | 3374 | editor.putInt(key, newField); | 
|  | 3375 | editor.commit(); | 
|  | 3376 | } | 
|  | 3377 |  | 
|  | 3378 | private static String getMmTelProvisioningKey(int subId, int tech) { | 
|  | 3379 | // resulting key is provision_ims_mmtel_{subId}_{tech} | 
|  | 3380 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; | 
|  | 3381 | } | 
|  | 3382 |  | 
|  | 3383 | /** | 
|  | 3384 | * Query CarrierConfig to see if the specified capability requires provisioning for the | 
|  | 3385 | * carrier associated with the subscription id. | 
|  | 3386 | */ | 
|  | 3387 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, | 
|  | 3388 | int capability) { | 
|  | 3389 | CarrierConfigManager configManager = new CarrierConfigManager(context); | 
|  | 3390 | PersistableBundle c = configManager.getConfigForSubId(subId); | 
|  | 3391 | boolean requireUtProvisioning = c.getBoolean( | 
| Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 3392 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3393 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, | 
|  | 3394 | false); | 
|  | 3395 | boolean requireVoiceVtProvisioning = c.getBoolean( | 
|  | 3396 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); | 
|  | 3397 |  | 
|  | 3398 | // First check to make sure that the capability requires provisioning. | 
|  | 3399 | switch (capability) { | 
|  | 3400 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: | 
|  | 3401 | // intentional fallthrough | 
|  | 3402 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { | 
|  | 3403 | if (requireVoiceVtProvisioning) { | 
|  | 3404 | // Voice and Video requires provisioning | 
|  | 3405 | return true; | 
|  | 3406 | } | 
|  | 3407 | break; | 
|  | 3408 | } | 
|  | 3409 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { | 
|  | 3410 | if (requireUtProvisioning) { | 
|  | 3411 | // UT requires provisioning | 
|  | 3412 | return true; | 
|  | 3413 | } | 
|  | 3414 | break; | 
|  | 3415 | } | 
|  | 3416 | } | 
|  | 3417 | return false; | 
|  | 3418 | } | 
|  | 3419 |  | 
|  | 3420 | @Override | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3421 | public int getImsProvisioningInt(int subId, int key) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3422 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 3423 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
|  | 3424 | } | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3425 | enforceReadPrivilegedPermission("getImsProvisioningInt"); | 
|  | 3426 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3427 | try { | 
|  | 3428 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3429 | int slotId = getSlotIndex(subId); | 
|  | 3430 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 3431 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" | 
|  | 3432 | + subId + "' for key:" + key); | 
|  | 3433 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; | 
|  | 3434 | } | 
|  | 3435 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3436 | } catch (ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3437 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" | 
|  | 3438 | + subId + "' for key:" + key); | 
|  | 3439 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3440 | } finally { | 
|  | 3441 | Binder.restoreCallingIdentity(identity); | 
|  | 3442 | } | 
|  | 3443 | } | 
|  | 3444 |  | 
|  | 3445 | @Override | 
|  | 3446 | public String getImsProvisioningString(int subId, int key) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3447 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 3448 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
|  | 3449 | } | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3450 | enforceReadPrivilegedPermission("getImsProvisioningString"); | 
|  | 3451 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3452 | try { | 
|  | 3453 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3454 | int slotId = getSlotIndex(subId); | 
|  | 3455 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 3456 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" | 
|  | 3457 | + subId + "' for key:" + key); | 
|  | 3458 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; | 
|  | 3459 | } | 
|  | 3460 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3461 | } catch (ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3462 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" | 
|  | 3463 | + subId + "' for key:" + key); | 
|  | 3464 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3465 | } finally { | 
|  | 3466 | Binder.restoreCallingIdentity(identity); | 
|  | 3467 | } | 
|  | 3468 | } | 
|  | 3469 |  | 
|  | 3470 | @Override | 
|  | 3471 | public int setImsProvisioningInt(int subId, int key, int value) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3472 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 3473 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
|  | 3474 | } | 
| Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3475 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 3476 | "setImsProvisioningInt"); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3477 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3478 | try { | 
|  | 3479 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3480 | int slotId = getSlotIndex(subId); | 
|  | 3481 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 3482 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" | 
|  | 3483 | + subId + "' for key:" + key); | 
|  | 3484 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
|  | 3485 | } | 
|  | 3486 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3487 | } catch (ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3488 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId | 
|  | 3489 | + "' for key:" + key); | 
|  | 3490 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3491 | } finally { | 
|  | 3492 | Binder.restoreCallingIdentity(identity); | 
|  | 3493 | } | 
|  | 3494 | } | 
|  | 3495 |  | 
|  | 3496 | @Override | 
|  | 3497 | public int setImsProvisioningString(int subId, int key, String value) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3498 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 3499 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
|  | 3500 | } | 
| Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3501 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 3502 | "setImsProvisioningString"); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3503 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3504 | try { | 
|  | 3505 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3506 | int slotId = getSlotIndex(subId); | 
|  | 3507 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 3508 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" | 
|  | 3509 | + subId + "' for key:" + key); | 
|  | 3510 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
|  | 3511 | } | 
|  | 3512 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3513 | } catch (ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3514 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId | 
|  | 3515 | + "' for key:" + key); | 
|  | 3516 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3517 | } finally { | 
|  | 3518 | Binder.restoreCallingIdentity(identity); | 
|  | 3519 | } | 
|  | 3520 | } | 
|  | 3521 |  | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3522 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { | 
|  | 3523 | int slotId = SubscriptionManager.getSlotIndex(subId); | 
|  | 3524 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { | 
| Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3525 | throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3526 | } | 
|  | 3527 | return slotId; | 
|  | 3528 | } | 
|  | 3529 |  | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3530 | private int getSlotIndex(int subId) { | 
|  | 3531 | int slotId = SubscriptionManager.getSlotIndex(subId); | 
|  | 3532 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { | 
|  | 3533 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; | 
|  | 3534 | } | 
|  | 3535 | return slotId; | 
|  | 3536 | } | 
|  | 3537 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3538 | /** | 
|  | 3539 | * Returns the network type for a subId | 
|  | 3540 | */ | 
|  | 3541 | @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3542 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3543 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3544 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3545 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 3546 | } | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3547 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3548 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3549 | try { | 
|  | 3550 | final Phone phone = getPhone(subId); | 
|  | 3551 | if (phone != null) { | 
|  | 3552 | return phone.getServiceState().getDataNetworkType(); | 
|  | 3553 | } else { | 
|  | 3554 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 3555 | } | 
|  | 3556 | } finally { | 
|  | 3557 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3558 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3559 | } | 
|  | 3560 |  | 
|  | 3561 | /** | 
|  | 3562 | * Returns the data network type | 
|  | 3563 | */ | 
|  | 3564 | @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3565 | public int getDataNetworkType(String callingPackage) { | 
|  | 3566 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3567 | } | 
|  | 3568 |  | 
|  | 3569 | /** | 
|  | 3570 | * Returns the data network type for a subId | 
|  | 3571 | */ | 
|  | 3572 | @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3573 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3574 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3575 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3576 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 3577 | } | 
|  | 3578 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3579 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3580 | try { | 
|  | 3581 | final Phone phone = getPhone(subId); | 
|  | 3582 | if (phone != null) { | 
|  | 3583 | return phone.getServiceState().getDataNetworkType(); | 
|  | 3584 | } else { | 
|  | 3585 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 3586 | } | 
|  | 3587 | } finally { | 
|  | 3588 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3589 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3590 | } | 
|  | 3591 |  | 
|  | 3592 | /** | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3593 | * Returns the Voice network type for a subId | 
|  | 3594 | */ | 
|  | 3595 | @Override | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3596 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3597 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3598 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3599 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 3600 | } | 
|  | 3601 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3602 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3603 | try { | 
|  | 3604 | final Phone phone = getPhone(subId); | 
|  | 3605 | if (phone != null) { | 
|  | 3606 | return phone.getServiceState().getVoiceNetworkType(); | 
|  | 3607 | } else { | 
|  | 3608 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 3609 | } | 
|  | 3610 | } finally { | 
|  | 3611 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3612 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3613 | } | 
|  | 3614 |  | 
|  | 3615 | /** | 
|  | 3616 | * @return true if a ICC card is present | 
|  | 3617 | */ | 
|  | 3618 | public boolean hasIccCard() { | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3619 | // FIXME Make changes to pass defaultSimId of type int | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3620 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( | 
|  | 3621 | getDefaultSubscription())); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3622 | } | 
|  | 3623 |  | 
|  | 3624 | /** | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3625 | * @return true if a ICC card is present for a slotIndex | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3626 | */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3627 | @Override | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3628 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3629 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3630 | try { | 
|  | 3631 | final Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 3632 | if (phone != null) { | 
|  | 3633 | return phone.getIccCard().hasIccCard(); | 
|  | 3634 | } else { | 
|  | 3635 | return false; | 
|  | 3636 | } | 
|  | 3637 | } finally { | 
|  | 3638 | Binder.restoreCallingIdentity(identity); | 
| Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3639 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3640 | } | 
|  | 3641 |  | 
|  | 3642 | /** | 
|  | 3643 | * Return if the current radio is LTE on CDMA. This | 
|  | 3644 | * is a tri-state return value as for a period of time | 
|  | 3645 | * the mode may be unknown. | 
|  | 3646 | * | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3647 | * @param callingPackage the name of the package making the call. | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3648 | * @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] | 3649 | * or {@link Phone#LTE_ON_CDMA_TRUE} | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3650 | */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3651 | @Override | 
|  | 3652 | public int getLteOnCdmaMode(String callingPackage) { | 
|  | 3653 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3654 | } | 
|  | 3655 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3656 | @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3657 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3658 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3659 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3660 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; | 
|  | 3661 | } | 
|  | 3662 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3663 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3664 | try { | 
|  | 3665 | final Phone phone = getPhone(subId); | 
|  | 3666 | if (phone == null) { | 
|  | 3667 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; | 
|  | 3668 | } else { | 
|  | 3669 | return phone.getLteOnCdmaMode(); | 
|  | 3670 | } | 
|  | 3671 | } finally { | 
|  | 3672 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3673 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3674 | } | 
|  | 3675 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3676 | /** | 
|  | 3677 | * {@hide} | 
|  | 3678 | * Returns Default subId, 0 in the case of single standby. | 
|  | 3679 | */ | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3680 | private int getDefaultSubscription() { | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3681 | return mSubscriptionController.getDefaultSubId(); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3682 | } | 
|  | 3683 |  | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3684 | private int getSlotForDefaultSubscription() { | 
|  | 3685 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); | 
|  | 3686 | } | 
|  | 3687 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3688 | private int getPreferredVoiceSubscription() { | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3689 | return mSubscriptionController.getDefaultVoiceSubId(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3690 | } | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3691 |  | 
| Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3692 | private boolean isActiveSubscription(int subId) { | 
|  | 3693 | return mSubscriptionController.isActiveSubId(subId); | 
|  | 3694 | } | 
|  | 3695 |  | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3696 | /** | 
|  | 3697 | * @see android.telephony.TelephonyManager.WifiCallingChoices | 
|  | 3698 | */ | 
|  | 3699 | public int getWhenToMakeWifiCalls() { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3700 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3701 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3702 | return Settings.System.getInt(mApp.getContentResolver(), | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3703 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, | 
|  | 3704 | getWhenToMakeWifiCallsDefaultPreference()); | 
|  | 3705 | } finally { | 
|  | 3706 | Binder.restoreCallingIdentity(identity); | 
|  | 3707 | } | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3708 | } | 
|  | 3709 |  | 
|  | 3710 | /** | 
|  | 3711 | * @see android.telephony.TelephonyManager.WifiCallingChoices | 
|  | 3712 | */ | 
|  | 3713 | public void setWhenToMakeWifiCalls(int preference) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3714 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3715 | try { | 
|  | 3716 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3717 | Settings.System.putInt(mApp.getContentResolver(), | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3718 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); | 
|  | 3719 | } finally { | 
|  | 3720 | Binder.restoreCallingIdentity(identity); | 
|  | 3721 | } | 
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3722 | } | 
|  | 3723 |  | 
| Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3724 | private static int getWhenToMakeWifiCallsDefaultPreference() { | 
| Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3725 | // TODO: Use a build property to choose this value. | 
| Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3726 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3727 | } | 
| Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3728 |  | 
| Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3729 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { | 
|  | 3730 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); | 
|  | 3731 | if (phoneId == -1) { | 
|  | 3732 | throw new IllegalArgumentException("Given slot index: " + slotIndex | 
|  | 3733 | + " does not correspond to an active phone"); | 
|  | 3734 | } | 
|  | 3735 | return PhoneFactory.getPhone(phoneId); | 
|  | 3736 | } | 
|  | 3737 |  | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3738 | @Override | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3739 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( | 
|  | 3740 | int subId, String callingPackage, String aid, int p2) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3741 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3742 | mApp, subId, "iccOpenLogicalChannel"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3743 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3744 | if (DBG) { | 
|  | 3745 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); | 
|  | 3746 | } | 
|  | 3747 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, | 
|  | 3748 | p2); | 
|  | 3749 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3750 |  | 
| Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3751 |  | 
|  | 3752 | @Override | 
|  | 3753 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( | 
|  | 3754 | int slotIndex, String callingPackage, String aid, int p2) { | 
|  | 3755 | enforceModifyPermission(); | 
|  | 3756 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 3757 | if (DBG) { | 
|  | 3758 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); | 
|  | 3759 | } | 
|  | 3760 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), | 
|  | 3761 | callingPackage, aid, p2); | 
|  | 3762 | } | 
|  | 3763 |  | 
|  | 3764 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, | 
|  | 3765 | String callingPackage, String aid, int p2) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3766 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3767 | try { | 
|  | 3768 | if (TextUtils.equals(ISDR_AID, aid)) { | 
|  | 3769 | // Only allows LPA to open logical channel to ISD-R. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3770 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() | 
|  | 3771 | .getContext().getPackageManager()); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3772 | if (bestComponent == null | 
|  | 3773 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { | 
|  | 3774 | loge("The calling package is not allowed to access ISD-R."); | 
|  | 3775 | throw new SecurityException( | 
|  | 3776 | "The calling package is not allowed to access ISD-R."); | 
|  | 3777 | } | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3778 | } | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3779 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3780 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( | 
| Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3781 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, | 
|  | 3782 | null /* workSource */); | 
|  | 3783 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3784 | return response; | 
|  | 3785 | } finally { | 
|  | 3786 | Binder.restoreCallingIdentity(identity); | 
|  | 3787 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3788 | } | 
|  | 3789 |  | 
|  | 3790 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3791 | public boolean iccCloseLogicalChannel(int subId, int channel) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3792 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3793 | mApp, subId, "iccCloseLogicalChannel"); | 
| Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3794 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); | 
|  | 3795 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); | 
|  | 3796 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3797 |  | 
| Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3798 | @Override | 
|  | 3799 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { | 
|  | 3800 | enforceModifyPermission(); | 
|  | 3801 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); | 
|  | 3802 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), | 
|  | 3803 | channel); | 
|  | 3804 | } | 
|  | 3805 |  | 
|  | 3806 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3807 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3808 | try { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3809 | if (channel < 0) { | 
|  | 3810 | return false; | 
|  | 3811 | } | 
| Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3812 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, | 
|  | 3813 | null /* workSource */); | 
|  | 3814 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3815 | return success; | 
|  | 3816 | } finally { | 
|  | 3817 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3818 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3819 | } | 
|  | 3820 |  | 
|  | 3821 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3822 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3823 | int command, int p1, int p2, int p3, String data) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3824 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3825 | mApp, subId, "iccTransmitApduLogicalChannel"); | 
| Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3826 | if (DBG) { | 
|  | 3827 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel | 
|  | 3828 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" | 
|  | 3829 | + p3 + " data=" + data); | 
|  | 3830 | } | 
|  | 3831 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, | 
|  | 3832 | command, p1, p2, p3, data); | 
|  | 3833 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3834 |  | 
| Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3835 | @Override | 
|  | 3836 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, | 
|  | 3837 | int command, int p1, int p2, int p3, String data) { | 
|  | 3838 | enforceModifyPermission(); | 
|  | 3839 | if (DBG) { | 
|  | 3840 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel | 
|  | 3841 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" | 
|  | 3842 | + p3 + " data=" + data); | 
|  | 3843 | } | 
|  | 3844 | return iccTransmitApduLogicalChannelWithPermission( | 
|  | 3845 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, | 
|  | 3846 | data); | 
|  | 3847 | } | 
|  | 3848 |  | 
|  | 3849 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, | 
|  | 3850 | int command, int p1, int p2, int p3, String data) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3851 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3852 | try { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3853 | if (channel < 0) { | 
|  | 3854 | return ""; | 
|  | 3855 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3856 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3857 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, | 
| Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3858 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, | 
|  | 3859 | null /* workSource */); | 
|  | 3860 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3861 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3862 | // Append the returned status code to the end of the response payload. | 
|  | 3863 | String s = Integer.toHexString( | 
|  | 3864 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); | 
|  | 3865 | if (response.payload != null) { | 
|  | 3866 | s = IccUtils.bytesToHexString(response.payload) + s; | 
|  | 3867 | } | 
|  | 3868 | return s; | 
|  | 3869 | } finally { | 
|  | 3870 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3871 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3872 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3873 |  | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3874 | @Override | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3875 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, | 
|  | 3876 | int command, int p1, int p2, int p3, String data) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3877 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3878 | mApp, subId, "iccTransmitApduBasicChannel"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3879 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3880 | if (DBG) { | 
|  | 3881 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" | 
|  | 3882 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); | 
|  | 3883 | } | 
|  | 3884 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, | 
|  | 3885 | cla, command, p1, p2, p3, data); | 
|  | 3886 | } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3887 |  | 
| Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3888 | @Override | 
|  | 3889 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, | 
|  | 3890 | int command, int p1, int p2, int p3, String data) { | 
|  | 3891 | enforceModifyPermission(); | 
|  | 3892 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 3893 | if (DBG) { | 
|  | 3894 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla | 
|  | 3895 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 | 
|  | 3896 | + " data=" + data); | 
|  | 3897 | } | 
|  | 3898 |  | 
|  | 3899 | return iccTransmitApduBasicChannelWithPermission( | 
|  | 3900 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, | 
|  | 3901 | p2, p3, data); | 
|  | 3902 | } | 
|  | 3903 |  | 
|  | 3904 | // open APDU basic channel assuming the caller has sufficient permissions | 
|  | 3905 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, | 
|  | 3906 | int cla, int command, int p1, int p2, int p3, String data) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3907 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3908 | try { | 
|  | 3909 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 | 
|  | 3910 | && TextUtils.equals(ISDR_AID, data)) { | 
|  | 3911 | // Only allows LPA to select ISD-R. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3912 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() | 
|  | 3913 | .getContext().getPackageManager()); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3914 | if (bestComponent == null | 
|  | 3915 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { | 
|  | 3916 | loge("The calling package is not allowed to select ISD-R."); | 
|  | 3917 | throw new SecurityException( | 
|  | 3918 | "The calling package is not allowed to select ISD-R."); | 
|  | 3919 | } | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3920 | } | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3921 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3922 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, | 
| Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3923 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, | 
|  | 3924 | null /* workSource */); | 
|  | 3925 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3926 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3927 | // Append the returned status code to the end of the response payload. | 
|  | 3928 | String s = Integer.toHexString( | 
|  | 3929 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); | 
|  | 3930 | if (response.payload != null) { | 
|  | 3931 | s = IccUtils.bytesToHexString(response.payload) + s; | 
|  | 3932 | } | 
|  | 3933 | return s; | 
|  | 3934 | } finally { | 
|  | 3935 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3936 | } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3937 | } | 
|  | 3938 |  | 
|  | 3939 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3940 | 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] | 3941 | String filePath) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3942 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3943 | mApp, subId, "iccExchangeSimIO"); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3944 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3945 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3946 | try { | 
|  | 3947 | if (DBG) { | 
|  | 3948 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " | 
|  | 3949 | + p1 + " " + p2 + " " + p3 + ":" + filePath); | 
|  | 3950 | } | 
|  | 3951 |  | 
|  | 3952 | IccIoResult response = | 
|  | 3953 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, | 
|  | 3954 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), | 
|  | 3955 | subId); | 
|  | 3956 |  | 
|  | 3957 | if (DBG) { | 
|  | 3958 | log("Exchange SIM_IO [R]" + response); | 
|  | 3959 | } | 
|  | 3960 |  | 
|  | 3961 | byte[] result = null; | 
|  | 3962 | int length = 2; | 
|  | 3963 | if (response.payload != null) { | 
|  | 3964 | length = 2 + response.payload.length; | 
|  | 3965 | result = new byte[length]; | 
|  | 3966 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); | 
|  | 3967 | } else { | 
|  | 3968 | result = new byte[length]; | 
|  | 3969 | } | 
|  | 3970 |  | 
|  | 3971 | result[length - 1] = (byte) response.sw2; | 
|  | 3972 | result[length - 2] = (byte) response.sw1; | 
|  | 3973 | return result; | 
|  | 3974 | } finally { | 
|  | 3975 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3976 | } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3977 | } | 
|  | 3978 |  | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3979 | /** | 
|  | 3980 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) | 
|  | 3981 | * on a particular subscription | 
|  | 3982 | */ | 
| sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3983 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { | 
|  | 3984 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 3985 | mApp, subId, callingPackage, "getForbiddenPlmns")) { | 
|  | 3986 | return null; | 
|  | 3987 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3988 |  | 
|  | 3989 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3990 | try { | 
|  | 3991 | if (appType != TelephonyManager.APPTYPE_USIM | 
|  | 3992 | && appType != TelephonyManager.APPTYPE_SIM) { | 
|  | 3993 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); | 
|  | 3994 | return null; | 
|  | 3995 | } | 
|  | 3996 | Object response = sendRequest( | 
|  | 3997 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); | 
|  | 3998 | if (response instanceof String[]) { | 
|  | 3999 | return (String[]) response; | 
|  | 4000 | } | 
|  | 4001 | // Response is an Exception of some kind, | 
|  | 4002 | // which is signalled to the user as a NULL retval | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4003 | return null; | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4004 | } finally { | 
|  | 4005 | Binder.restoreCallingIdentity(identity); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4006 | } | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4007 | } | 
|  | 4008 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4009 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4010 | public String sendEnvelopeWithStatus(int subId, String content) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4011 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4012 | mApp, subId, "sendEnvelopeWithStatus"); | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4013 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4014 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4015 | try { | 
|  | 4016 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); | 
|  | 4017 | if (response.payload == null) { | 
|  | 4018 | return ""; | 
|  | 4019 | } | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4020 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4021 | // Append the returned status code to the end of the response payload. | 
|  | 4022 | String s = Integer.toHexString( | 
|  | 4023 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); | 
|  | 4024 | s = IccUtils.bytesToHexString(response.payload) + s; | 
|  | 4025 | return s; | 
|  | 4026 | } finally { | 
|  | 4027 | Binder.restoreCallingIdentity(identity); | 
|  | 4028 | } | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4029 | } | 
|  | 4030 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4031 | /** | 
|  | 4032 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} | 
|  | 4033 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. | 
|  | 4034 | * | 
|  | 4035 | * @param itemID the ID of the item to read | 
|  | 4036 | * @return the NV item as a String, or null on error. | 
|  | 4037 | */ | 
|  | 4038 | @Override | 
|  | 4039 | public String nvReadItem(int itemID) { | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4040 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4041 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4042 | mApp, getDefaultSubscription(), "nvReadItem"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4043 |  | 
|  | 4044 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4045 | try { | 
|  | 4046 | if (DBG) log("nvReadItem: item " + itemID); | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4047 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4048 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); | 
|  | 4049 | return value; | 
|  | 4050 | } finally { | 
|  | 4051 | Binder.restoreCallingIdentity(identity); | 
|  | 4052 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4053 | } | 
|  | 4054 |  | 
|  | 4055 | /** | 
|  | 4056 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} | 
|  | 4057 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. | 
|  | 4058 | * | 
|  | 4059 | * @param itemID the ID of the item to read | 
|  | 4060 | * @param itemValue the value to write, as a String | 
|  | 4061 | * @return true on success; false on any failure | 
|  | 4062 | */ | 
|  | 4063 | @Override | 
|  | 4064 | public boolean nvWriteItem(int itemID, String itemValue) { | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4065 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4066 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4067 | mApp, getDefaultSubscription(), "nvWriteItem"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4068 |  | 
|  | 4069 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4070 | try { | 
|  | 4071 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); | 
|  | 4072 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4073 | new Pair<Integer, String>(itemID, itemValue), workSource); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4074 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); | 
|  | 4075 | return success; | 
|  | 4076 | } finally { | 
|  | 4077 | Binder.restoreCallingIdentity(identity); | 
|  | 4078 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4079 | } | 
|  | 4080 |  | 
|  | 4081 | /** | 
|  | 4082 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. | 
|  | 4083 | * Used for device configuration by some CDMA operators. | 
|  | 4084 | * | 
|  | 4085 | * @param preferredRoamingList byte array containing the new PRL | 
|  | 4086 | * @return true on success; false on any failure | 
|  | 4087 | */ | 
|  | 4088 | @Override | 
|  | 4089 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4090 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4091 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4092 |  | 
|  | 4093 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4094 | try { | 
|  | 4095 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); | 
|  | 4096 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); | 
|  | 4097 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); | 
|  | 4098 | return success; | 
|  | 4099 | } finally { | 
|  | 4100 | Binder.restoreCallingIdentity(identity); | 
|  | 4101 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4102 | } | 
|  | 4103 |  | 
|  | 4104 | /** | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4105 | * 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] | 4106 | * Used for device configuration by some CDMA operators. | 
|  | 4107 | * | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4108 | * @param slotIndex - device slot. | 
|  | 4109 | * | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4110 | * @return true on success; false on any failure | 
|  | 4111 | */ | 
|  | 4112 | @Override | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4113 | public boolean resetModemConfig(int slotIndex) { | 
|  | 4114 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 4115 | if (phone != null) { | 
|  | 4116 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4117 | mApp, phone.getSubId(), "resetModemConfig"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4118 |  | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4119 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4120 | try { | 
|  | 4121 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); | 
|  | 4122 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); | 
|  | 4123 | return success; | 
|  | 4124 | } finally { | 
|  | 4125 | Binder.restoreCallingIdentity(identity); | 
|  | 4126 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4127 | } | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4128 | return false; | 
|  | 4129 | } | 
|  | 4130 |  | 
|  | 4131 | /** | 
|  | 4132 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. | 
|  | 4133 | * | 
|  | 4134 | * @param slotIndex - device slot. | 
|  | 4135 | * | 
|  | 4136 | * @return true on success; false on any failure | 
|  | 4137 | */ | 
|  | 4138 | @Override | 
|  | 4139 | public boolean rebootModem(int slotIndex) { | 
|  | 4140 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 4141 | if (phone != null) { | 
|  | 4142 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4143 | mApp, phone.getSubId(), "rebootModem"); | 
|  | 4144 |  | 
|  | 4145 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4146 | try { | 
|  | 4147 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); | 
|  | 4148 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); | 
|  | 4149 | return success; | 
|  | 4150 | } finally { | 
|  | 4151 | Binder.restoreCallingIdentity(identity); | 
|  | 4152 | } | 
|  | 4153 | } | 
|  | 4154 | return false; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4155 | } | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4156 |  | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4157 | public String[] getPcscfAddress(String apnType, String callingPackage) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4158 | final Phone defaultPhone = getDefaultPhone(); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4159 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4160 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4161 | return new String[0]; | 
|  | 4162 | } | 
|  | 4163 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4164 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4165 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4166 | return defaultPhone.getPcscfAddress(apnType); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4167 | } finally { | 
|  | 4168 | Binder.restoreCallingIdentity(identity); | 
|  | 4169 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4170 | } | 
|  | 4171 |  | 
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4172 | /** | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4173 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability | 
|  | 4174 | * status updates, if not already enabled. | 
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4175 | */ | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4176 | public void enableIms(int slotId) { | 
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4177 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4178 |  | 
|  | 4179 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4180 | try { | 
| Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4181 | ImsResolver resolver = PhoneFactory.getImsResolver(); | 
|  | 4182 | if (resolver == null) { | 
|  | 4183 | // may happen if the device does not support IMS. | 
|  | 4184 | return; | 
|  | 4185 | } | 
|  | 4186 | resolver.enableIms(slotId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4187 | } finally { | 
|  | 4188 | Binder.restoreCallingIdentity(identity); | 
|  | 4189 | } | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4190 | } | 
|  | 4191 |  | 
|  | 4192 | /** | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4193 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature | 
|  | 4194 | * status updates to disabled. | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4195 | */ | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4196 | public void disableIms(int slotId) { | 
|  | 4197 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4198 |  | 
|  | 4199 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4200 | try { | 
| Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4201 | ImsResolver resolver = PhoneFactory.getImsResolver(); | 
|  | 4202 | if (resolver == null) { | 
|  | 4203 | // may happen if the device does not support IMS. | 
|  | 4204 | return; | 
|  | 4205 | } | 
|  | 4206 | resolver.disableIms(slotId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4207 | } finally { | 
|  | 4208 | Binder.restoreCallingIdentity(identity); | 
|  | 4209 | } | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4210 | } | 
|  | 4211 |  | 
|  | 4212 | /** | 
|  | 4213 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel | 
|  | 4214 | * feature or {@link null} if the service is not available. If the feature is available, the | 
|  | 4215 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. | 
|  | 4216 | */ | 
|  | 4217 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4218 | IImsServiceFeatureCallback callback) { | 
|  | 4219 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4220 |  | 
|  | 4221 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4222 | try { | 
| Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4223 | ImsResolver resolver = PhoneFactory.getImsResolver(); | 
|  | 4224 | if (resolver == null) { | 
|  | 4225 | // may happen if the device does not support IMS. | 
|  | 4226 | return null; | 
|  | 4227 | } | 
|  | 4228 | return resolver.getMmTelFeatureAndListen(slotId, callback); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4229 | } finally { | 
|  | 4230 | Binder.restoreCallingIdentity(identity); | 
|  | 4231 | } | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4232 | } | 
|  | 4233 |  | 
|  | 4234 | /** | 
|  | 4235 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS | 
|  | 4236 | * feature during emergency calling or {@link null} if the service is not available. If the | 
|  | 4237 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a | 
|  | 4238 | * listener for feature updates. | 
|  | 4239 | */ | 
|  | 4240 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { | 
|  | 4241 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4242 |  | 
|  | 4243 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4244 | try { | 
| Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4245 | ImsResolver resolver = PhoneFactory.getImsResolver(); | 
|  | 4246 | if (resolver == null) { | 
|  | 4247 | // may happen if the device does not support IMS. | 
|  | 4248 | return null; | 
|  | 4249 | } | 
|  | 4250 | return resolver.getRcsFeatureAndListen(slotId, callback); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4251 | } finally { | 
|  | 4252 | Binder.restoreCallingIdentity(identity); | 
|  | 4253 | } | 
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4254 | } | 
|  | 4255 |  | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4256 | /** | 
|  | 4257 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature | 
| Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4258 | * specified or null if IMS is not supported on the slot specified. | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4259 | */ | 
|  | 4260 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { | 
|  | 4261 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4262 |  | 
|  | 4263 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4264 | try { | 
| Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4265 | ImsResolver resolver = PhoneFactory.getImsResolver(); | 
|  | 4266 | if (resolver == null) { | 
|  | 4267 | // may happen if the device does not support IMS. | 
|  | 4268 | return null; | 
|  | 4269 | } | 
|  | 4270 | return resolver.getImsRegistration(slotId, feature); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4271 | } finally { | 
|  | 4272 | Binder.restoreCallingIdentity(identity); | 
|  | 4273 | } | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4274 | } | 
|  | 4275 |  | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4276 | /** | 
|  | 4277 | * Returns the {@link IImsConfig} structure associated with the slotId and feature | 
| Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4278 | * specified or null if IMS is not supported on the slot specified. | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4279 | */ | 
|  | 4280 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { | 
|  | 4281 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4282 |  | 
|  | 4283 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4284 | try { | 
| Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4285 | ImsResolver resolver = PhoneFactory.getImsResolver(); | 
|  | 4286 | if (resolver == null) { | 
|  | 4287 | // may happen if the device does not support IMS. | 
|  | 4288 | return null; | 
|  | 4289 | } | 
|  | 4290 | return resolver.getImsConfig(slotId, feature); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4291 | } finally { | 
|  | 4292 | Binder.restoreCallingIdentity(identity); | 
|  | 4293 | } | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4294 | } | 
|  | 4295 |  | 
| Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4296 | /** | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4297 | * Sets the ImsService Package Name that Telephony will bind to. | 
|  | 4298 | * | 
|  | 4299 | * @param slotId the slot ID that the ImsService should bind for. | 
|  | 4300 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the | 
|  | 4301 | *         ImsService is the device default ImsService. | 
|  | 4302 | * @param packageName The package name of the application that contains the ImsService to bind | 
|  | 4303 | *         to. | 
|  | 4304 | * @return true if setting the ImsService to bind to succeeded, false if it did not. | 
|  | 4305 | * @hide | 
|  | 4306 | */ | 
|  | 4307 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { | 
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4308 | int[] subIds = SubscriptionManager.getSubId(slotId); | 
|  | 4309 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, | 
|  | 4310 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), | 
|  | 4311 | "setImsService"); | 
|  | 4312 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4313 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4314 | try { | 
| Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4315 | ImsResolver resolver = PhoneFactory.getImsResolver(); | 
|  | 4316 | if (resolver == null) { | 
|  | 4317 | // may happen if the device does not support IMS. | 
|  | 4318 | return false; | 
|  | 4319 | } | 
|  | 4320 | return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService, | 
|  | 4321 | packageName); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4322 | } finally { | 
|  | 4323 | Binder.restoreCallingIdentity(identity); | 
|  | 4324 | } | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4325 | } | 
|  | 4326 |  | 
|  | 4327 | /** | 
|  | 4328 | * Return the ImsService configuration. | 
|  | 4329 | * | 
|  | 4330 | * @param slotId The slot that the ImsService is associated with. | 
|  | 4331 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is | 
|  | 4332 | *         the device default. | 
|  | 4333 | * @return the package name of the ImsService configuration. | 
|  | 4334 | */ | 
|  | 4335 | public String getImsService(int slotId, boolean isCarrierImsService) { | 
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4336 | int[] subIds = SubscriptionManager.getSubId(slotId); | 
|  | 4337 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, | 
|  | 4338 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), | 
|  | 4339 | "getImsService"); | 
|  | 4340 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4341 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4342 | try { | 
| Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4343 | ImsResolver resolver = PhoneFactory.getImsResolver(); | 
|  | 4344 | if (resolver == null) { | 
|  | 4345 | // may happen if the device does not support IMS. | 
|  | 4346 | return ""; | 
|  | 4347 | } | 
|  | 4348 | return resolver.getImsServiceConfiguration(slotId, isCarrierImsService); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4349 | } finally { | 
|  | 4350 | Binder.restoreCallingIdentity(identity); | 
|  | 4351 | } | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4352 | } | 
|  | 4353 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4354 | public void setImsRegistrationState(boolean registered) { | 
|  | 4355 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4356 |  | 
|  | 4357 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4358 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4359 | getDefaultPhone().setImsRegistrationState(registered); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4360 | } finally { | 
|  | 4361 | Binder.restoreCallingIdentity(identity); | 
|  | 4362 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4363 | } | 
|  | 4364 |  | 
|  | 4365 | /** | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4366 | * Set the network selection mode to automatic. | 
|  | 4367 | * | 
|  | 4368 | */ | 
|  | 4369 | @Override | 
|  | 4370 | public void setNetworkSelectionModeAutomatic(int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4371 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4372 | mApp, subId, "setNetworkSelectionModeAutomatic"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4373 |  | 
| Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4374 | if (!isActiveSubscription(subId)) { | 
|  | 4375 | return; | 
|  | 4376 | } | 
|  | 4377 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4378 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4379 | try { | 
|  | 4380 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); | 
|  | 4381 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); | 
|  | 4382 | } finally { | 
|  | 4383 | Binder.restoreCallingIdentity(identity); | 
|  | 4384 | } | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4385 | } | 
|  | 4386 |  | 
| Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4387 | /** | 
|  | 4388 | * Ask the radio to connect to the input network and change selection mode to manual. | 
|  | 4389 | * | 
|  | 4390 | * @param subId the id of the subscription. | 
|  | 4391 | * @param operatorInfo the operator information, included the PLMN, long name and short name of | 
|  | 4392 | * the operator to attach to. | 
|  | 4393 | * @param persistSelection whether the selection will persist until reboot. If true, only allows | 
|  | 4394 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume | 
|  | 4395 | * normal network selection next time. | 
|  | 4396 | * @return {@code true} on success; {@code true} on any failure. | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4397 | */ | 
|  | 4398 | @Override | 
| Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4399 | public boolean setNetworkSelectionModeManual( | 
|  | 4400 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4401 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4402 | mApp, subId, "setNetworkSelectionModeManual"); | 
| Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4403 |  | 
|  | 4404 | if (!isActiveSubscription(subId)) { | 
|  | 4405 | return false; | 
|  | 4406 | } | 
|  | 4407 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4408 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4409 | try { | 
| Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4410 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4411 | persistSelection); | 
| Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4412 | if (DBG) { | 
|  | 4413 | log("setNetworkSelectionModeManual: subId: " + subId | 
|  | 4414 | + " operator: " + operatorInfo); | 
|  | 4415 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4416 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); | 
|  | 4417 | } finally { | 
|  | 4418 | Binder.restoreCallingIdentity(identity); | 
|  | 4419 | } | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4420 | } | 
|  | 4421 |  | 
|  | 4422 | /** | 
|  | 4423 | * Scans for available networks. | 
|  | 4424 | */ | 
|  | 4425 | @Override | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4426 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4427 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4428 | mApp, subId, "getCellNetworkScanResults"); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4429 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 4430 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 4431 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 4432 | .setCallingPackage(callingPackage) | 
|  | 4433 | .setCallingPid(Binder.getCallingPid()) | 
|  | 4434 | .setCallingUid(Binder.getCallingUid()) | 
|  | 4435 | .setMethod("getCellNetworkScanResults") | 
|  | 4436 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 4437 | .build()); | 
|  | 4438 | switch (locationResult) { | 
|  | 4439 | case DENIED_HARD: | 
|  | 4440 | throw new SecurityException("Not allowed to access scan results -- location"); | 
|  | 4441 | case DENIED_SOFT: | 
|  | 4442 | return null; | 
|  | 4443 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4444 |  | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4445 | long identity = Binder.clearCallingIdentity(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4446 | try { | 
|  | 4447 | if (DBG) log("getCellNetworkScanResults: subId " + subId); | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4448 | return (CellNetworkScanResult) sendRequest( | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4449 | CMD_PERFORM_NETWORK_SCAN, null, subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4450 | } finally { | 
|  | 4451 | Binder.restoreCallingIdentity(identity); | 
|  | 4452 | } | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4453 | } | 
|  | 4454 |  | 
|  | 4455 | /** | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4456 | * Starts a new network scan and returns the id of this scan. | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4457 | * | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4458 | * @param subId id of the subscription | 
|  | 4459 | * @param request contains the radio access networks with bands/channels to scan | 
|  | 4460 | * @param messenger callback messenger for scan results or errors | 
|  | 4461 | * @param binder for the purpose of auto clean when the user thread crashes | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4462 | * @return the id of the requested scan which can be used to stop the scan. | 
|  | 4463 | */ | 
|  | 4464 | @Override | 
|  | 4465 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4466 | IBinder binder, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4467 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4468 | mApp, subId, "requestNetworkScan"); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4469 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 4470 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 4471 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 4472 | .setCallingPackage(callingPackage) | 
|  | 4473 | .setCallingPid(Binder.getCallingPid()) | 
|  | 4474 | .setCallingUid(Binder.getCallingUid()) | 
|  | 4475 | .setMethod("requestNetworkScan") | 
|  | 4476 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 4477 | .build()); | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4478 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { | 
|  | 4479 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request); | 
|  | 4480 | if (e != null) { | 
|  | 4481 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { | 
|  | 4482 | throw e; | 
|  | 4483 | } else { | 
| Hall Liu | 46dd96a | 2019-04-03 12:50:44 -0700 | [diff] [blame] | 4484 | loge(e.getMessage()); | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4485 | return TelephonyScanManager.INVALID_SCAN_ID; | 
|  | 4486 | } | 
|  | 4487 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4488 | } | 
| Hall Liu | bac7d48 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4489 | int callingUid = Binder.getCallingUid(); | 
|  | 4490 | int callingPid = Binder.getCallingPid(); | 
| yinxu | 612a819 | 2019-04-18 10:38:27 -0700 | [diff] [blame] | 4491 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4492 | try { | 
|  | 4493 | return mNetworkScanRequestTracker.startNetworkScan( | 
|  | 4494 | request, messenger, binder, getPhone(subId), | 
| Hall Liu | bac7d48 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4495 | callingUid, callingPid, callingPackage); | 
| yinxu | 612a819 | 2019-04-18 10:38:27 -0700 | [diff] [blame] | 4496 | } finally { | 
|  | 4497 | Binder.restoreCallingIdentity(identity); | 
|  | 4498 | } | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4499 | } | 
|  | 4500 |  | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4501 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( | 
|  | 4502 | NetworkScanRequest request) { | 
|  | 4503 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) | 
|  | 4504 | != PERMISSION_GRANTED) { | 
|  | 4505 | return new SecurityException("permission.NETWORK_SCAN is needed for network scans" | 
|  | 4506 | + " without location access."); | 
|  | 4507 | } | 
|  | 4508 |  | 
|  | 4509 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { | 
|  | 4510 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4511 | if (ras.getChannels() != null && ras.getChannels().length > 0) { | 
|  | 4512 | return new SecurityException("Specific channels must not be" | 
|  | 4513 | + " scanned without location access."); | 
|  | 4514 | } | 
|  | 4515 | } | 
|  | 4516 | } | 
|  | 4517 |  | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4518 | return null; | 
|  | 4519 | } | 
|  | 4520 |  | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4521 | /** | 
|  | 4522 | * Stops an existing network scan with the given scanId. | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4523 | * | 
|  | 4524 | * @param subId id of the subscription | 
|  | 4525 | * @param scanId id of the scan that needs to be stopped | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4526 | */ | 
|  | 4527 | @Override | 
|  | 4528 | public void stopNetworkScan(int subId, int scanId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4529 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4530 | mApp, subId, "stopNetworkScan"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4531 |  | 
| Hall Liu | bac7d48 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4532 | int callingUid = Binder.getCallingUid(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4533 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4534 | try { | 
| Hall Liu | bac7d48 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4535 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4536 | } finally { | 
|  | 4537 | Binder.restoreCallingIdentity(identity); | 
|  | 4538 | } | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4539 | } | 
|  | 4540 |  | 
|  | 4541 | /** | 
| Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4542 | * Get the calculated preferred network type. | 
|  | 4543 | * Used for debugging incorrect network type. | 
|  | 4544 | * | 
|  | 4545 | * @return the preferred network type, defined in RILConstants.java. | 
|  | 4546 | */ | 
|  | 4547 | @Override | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4548 | public int getCalculatedPreferredNetworkType(String callingPackage) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4549 | final Phone defaultPhone = getDefaultPhone(); | 
|  | 4550 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), | 
|  | 4551 | callingPackage, "getCalculatedPreferredNetworkType")) { | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4552 | return RILConstants.PREFERRED_NETWORK_MODE; | 
|  | 4553 | } | 
|  | 4554 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4555 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4556 | try { | 
|  | 4557 | // FIXME: need to get SubId from somewhere. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4558 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4559 | } finally { | 
|  | 4560 | Binder.restoreCallingIdentity(identity); | 
|  | 4561 | } | 
| Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4562 | } | 
|  | 4563 |  | 
|  | 4564 | /** | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4565 | * Get the preferred network type. | 
|  | 4566 | * Used for device configuration by some CDMA operators. | 
|  | 4567 | * | 
|  | 4568 | * @return the preferred network type, defined in RILConstants.java. | 
|  | 4569 | */ | 
|  | 4570 | @Override | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4571 | public int getPreferredNetworkType(int subId) { | 
| Pengquan Meng | 4848cd0 | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4572 | TelephonyPermissions | 
|  | 4573 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 4574 | mApp, subId, "getPreferredNetworkType"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4575 |  | 
|  | 4576 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4577 | try { | 
|  | 4578 | if (DBG) log("getPreferredNetworkType"); | 
|  | 4579 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); | 
|  | 4580 | int networkType = (result != null ? result[0] : -1); | 
|  | 4581 | if (DBG) log("getPreferredNetworkType: " + networkType); | 
|  | 4582 | return networkType; | 
|  | 4583 | } finally { | 
|  | 4584 | Binder.restoreCallingIdentity(identity); | 
|  | 4585 | } | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4586 | } | 
|  | 4587 |  | 
|  | 4588 | /** | 
|  | 4589 | * Set the preferred network type. | 
|  | 4590 | * Used for device configuration by some CDMA operators. | 
|  | 4591 | * | 
|  | 4592 | * @param networkType the preferred network type, defined in RILConstants.java. | 
|  | 4593 | * @return true on success; false on any failure. | 
|  | 4594 | */ | 
|  | 4595 | @Override | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4596 | public boolean setPreferredNetworkType(int subId, int networkType) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4597 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4598 | mApp, subId, "setPreferredNetworkType"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4599 |  | 
|  | 4600 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4601 | try { | 
|  | 4602 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); | 
|  | 4603 | Boolean success = (Boolean) sendRequest( | 
|  | 4604 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); | 
|  | 4605 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); | 
|  | 4606 | if (success) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4607 | Settings.Global.putInt(mApp.getContentResolver(), | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4608 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); | 
|  | 4609 | } | 
|  | 4610 | return success; | 
|  | 4611 | } finally { | 
|  | 4612 | Binder.restoreCallingIdentity(identity); | 
| Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4613 | } | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4614 | } | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4615 |  | 
|  | 4616 | /** | 
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4617 | * Check whether DUN APN is required for tethering with subId. | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4618 | * | 
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4619 | * @param subId the id of the subscription to require tethering. | 
| Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4620 | * @return {@code true} if DUN APN is required for tethering. | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4621 | * @hide | 
|  | 4622 | */ | 
|  | 4623 | @Override | 
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4624 | public boolean getTetherApnRequiredForSubscriber(int subId) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4625 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4626 | final long identity = Binder.clearCallingIdentity(); | 
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4627 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4628 | try { | 
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4629 | if (phone != null) { | 
|  | 4630 | return phone.hasMatchedTetherApnSetting(); | 
|  | 4631 | } else { | 
|  | 4632 | return false; | 
|  | 4633 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4634 | } finally { | 
|  | 4635 | Binder.restoreCallingIdentity(identity); | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4636 | } | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4637 | } | 
|  | 4638 |  | 
|  | 4639 | /** | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4640 | * Set mobile data enabled | 
|  | 4641 | * Used by the user through settings etc to turn on/off mobile data | 
|  | 4642 | * | 
|  | 4643 | * @param enable {@code true} turn turn data on, else {@code false} | 
|  | 4644 | */ | 
|  | 4645 | @Override | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4646 | public void setUserDataEnabled(int subId, boolean enable) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4647 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4648 | mApp, subId, "setUserDataEnabled"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4649 |  | 
|  | 4650 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4651 | try { | 
|  | 4652 | int phoneId = mSubscriptionController.getPhoneId(subId); | 
|  | 4653 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); | 
|  | 4654 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 4655 | if (phone != null) { | 
|  | 4656 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); | 
| Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4657 | phone.getDataEnabledSettings().setUserDataEnabled(enable); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4658 | } else { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4659 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4660 | } | 
|  | 4661 | } finally { | 
|  | 4662 | Binder.restoreCallingIdentity(identity); | 
| Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4663 | } | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4664 | } | 
|  | 4665 |  | 
|  | 4666 | /** | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4667 | * Get the user enabled state of Mobile Data. | 
|  | 4668 | * | 
|  | 4669 | * TODO: remove and use isUserDataEnabled. | 
|  | 4670 | * This can't be removed now because some vendor codes | 
|  | 4671 | * calls through ITelephony directly while they should | 
|  | 4672 | * use TelephonyManager. | 
|  | 4673 | * | 
|  | 4674 | * @return true on enabled | 
|  | 4675 | */ | 
|  | 4676 | @Override | 
|  | 4677 | public boolean getDataEnabled(int subId) { | 
|  | 4678 | return isUserDataEnabled(subId); | 
|  | 4679 | } | 
|  | 4680 |  | 
|  | 4681 | /** | 
|  | 4682 | * Get whether mobile data is enabled per user setting. | 
|  | 4683 | * | 
|  | 4684 | * There are other factors deciding whether mobile data is actually enabled, but they are | 
|  | 4685 | * not considered here. See {@link #isDataEnabled(int)} for more details. | 
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4686 | * | 
| Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4687 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4688 | * | 
|  | 4689 | * @return {@code true} if data is enabled else {@code false} | 
|  | 4690 | */ | 
|  | 4691 | @Override | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4692 | public boolean isUserDataEnabled(int subId) { | 
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4693 | try { | 
|  | 4694 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, | 
|  | 4695 | null); | 
|  | 4696 | } catch (Exception e) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4697 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4698 | mApp, subId, "isUserDataEnabled"); | 
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4699 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4700 |  | 
|  | 4701 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4702 | try { | 
|  | 4703 | int phoneId = mSubscriptionController.getPhoneId(subId); | 
|  | 4704 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); | 
|  | 4705 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 4706 | if (phone != null) { | 
|  | 4707 | boolean retVal = phone.isUserDataEnabled(); | 
|  | 4708 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); | 
|  | 4709 | return retVal; | 
|  | 4710 | } else { | 
|  | 4711 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); | 
|  | 4712 | return false; | 
|  | 4713 | } | 
|  | 4714 | } finally { | 
|  | 4715 | Binder.restoreCallingIdentity(identity); | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4716 | } | 
|  | 4717 | } | 
|  | 4718 |  | 
|  | 4719 | /** | 
|  | 4720 | * Get whether mobile data is enabled. | 
|  | 4721 | * | 
|  | 4722 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding | 
|  | 4723 | * whether mobile data is actually enabled. | 
|  | 4724 | * | 
|  | 4725 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. | 
|  | 4726 | * | 
|  | 4727 | * @return {@code true} if data is enabled else {@code false} | 
|  | 4728 | */ | 
|  | 4729 | @Override | 
|  | 4730 | public boolean isDataEnabled(int subId) { | 
|  | 4731 | try { | 
|  | 4732 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, | 
|  | 4733 | null); | 
|  | 4734 | } catch (Exception e) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4735 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4736 | mApp, subId, "isDataEnabled"); | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4737 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4738 |  | 
|  | 4739 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4740 | try { | 
|  | 4741 | int phoneId = mSubscriptionController.getPhoneId(subId); | 
|  | 4742 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); | 
|  | 4743 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 4744 | if (phone != null) { | 
| Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4745 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4746 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); | 
|  | 4747 | return retVal; | 
|  | 4748 | } else { | 
|  | 4749 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); | 
|  | 4750 | return false; | 
|  | 4751 | } | 
|  | 4752 | } finally { | 
|  | 4753 | Binder.restoreCallingIdentity(identity); | 
| Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4754 | } | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4755 | } | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4756 |  | 
|  | 4757 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4758 | public int getCarrierPrivilegeStatus(int subId) { | 
|  | 4759 | final Phone phone = getPhone(subId); | 
|  | 4760 | if (phone == null) { | 
|  | 4761 | loge("getCarrierPrivilegeStatus: Invalid subId"); | 
|  | 4762 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
|  | 4763 | } | 
|  | 4764 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4765 | if (card == null) { | 
| Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4766 | loge("getCarrierPrivilegeStatus: No UICC"); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4767 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
|  | 4768 | } | 
|  | 4769 | return card.getCarrierPrivilegeStatusForCurrentTransaction( | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4770 | phone.getContext().getPackageManager()); | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4771 | } | 
| Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4772 |  | 
|  | 4773 | @Override | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4774 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { | 
|  | 4775 | final Phone phone = getPhone(subId); | 
|  | 4776 | if (phone == null) { | 
|  | 4777 | loge("getCarrierPrivilegeStatus: Invalid subId"); | 
|  | 4778 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
|  | 4779 | } | 
|  | 4780 | UiccProfile profile = | 
|  | 4781 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); | 
|  | 4782 | if (profile == null) { | 
|  | 4783 | loge("getCarrierPrivilegeStatus: No UICC"); | 
|  | 4784 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
|  | 4785 | } | 
|  | 4786 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); | 
|  | 4787 | } | 
|  | 4788 |  | 
|  | 4789 | @Override | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4790 | public int checkCarrierPrivilegesForPackage(String pkgName) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4791 | final Phone defaultPhone = getDefaultPhone(); | 
| Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4792 | if (TextUtils.isEmpty(pkgName)) | 
|  | 4793 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4794 | UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId()); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4795 | if (card == null) { | 
|  | 4796 | loge("checkCarrierPrivilegesForPackage: No UICC"); | 
|  | 4797 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
|  | 4798 | } | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4799 | return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(), | 
|  | 4800 | pkgName); | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4801 | } | 
|  | 4802 |  | 
|  | 4803 | @Override | 
|  | 4804 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { | 
| Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4805 | if (TextUtils.isEmpty(pkgName)) | 
|  | 4806 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4807 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
|  | 4808 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
|  | 4809 | UiccCard card = UiccController.getInstance().getUiccCard(i); | 
|  | 4810 | if (card == null) { | 
| Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4811 | // No UICC in that slot. | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4812 | continue; | 
|  | 4813 | } | 
|  | 4814 |  | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4815 | result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4816 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
|  | 4817 | break; | 
|  | 4818 | } | 
|  | 4819 | } | 
|  | 4820 |  | 
|  | 4821 | return result; | 
| Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4822 | } | 
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4823 |  | 
|  | 4824 | @Override | 
| Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4825 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { | 
|  | 4826 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { | 
|  | 4827 | loge("phoneId " + phoneId + " is not valid."); | 
|  | 4828 | return null; | 
|  | 4829 | } | 
|  | 4830 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4831 | if (card == null) { | 
| Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4832 | loge("getCarrierPackageNamesForIntent: No UICC"); | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4833 | return null ; | 
|  | 4834 | } | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4835 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4836 | } | 
|  | 4837 |  | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4838 | @Override | 
|  | 4839 | public List<String> getPackagesWithCarrierPrivileges() { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4840 | PackageManager pm = mApp.getPackageManager(); | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4841 | List<String> privilegedPackages = new ArrayList<>(); | 
|  | 4842 | List<PackageInfo> packages = null; | 
|  | 4843 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
|  | 4844 | UiccCard card = UiccController.getInstance().getUiccCard(i); | 
|  | 4845 | if (card == null) { | 
|  | 4846 | // No UICC in that slot. | 
|  | 4847 | continue; | 
|  | 4848 | } | 
|  | 4849 | if (card.hasCarrierPrivilegeRules()) { | 
|  | 4850 | if (packages == null) { | 
|  | 4851 | // Only check packages in user 0 for now | 
|  | 4852 | packages = pm.getInstalledPackagesAsUser( | 
|  | 4853 | PackageManager.MATCH_DISABLED_COMPONENTS | 
|  | 4854 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS | 
|  | 4855 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); | 
|  | 4856 | } | 
|  | 4857 | for (int p = packages.size() - 1; p >= 0; p--) { | 
|  | 4858 | PackageInfo pkgInfo = packages.get(p); | 
|  | 4859 | if (pkgInfo != null && pkgInfo.packageName != null | 
|  | 4860 | && card.getCarrierPrivilegeStatus(pkgInfo) | 
|  | 4861 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
|  | 4862 | privilegedPackages.add(pkgInfo.packageName); | 
|  | 4863 | } | 
|  | 4864 | } | 
|  | 4865 | } | 
|  | 4866 | } | 
|  | 4867 | return privilegedPackages; | 
|  | 4868 | } | 
|  | 4869 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4870 | private String getIccId(int subId) { | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4871 | final Phone phone = getPhone(subId); | 
|  | 4872 | UiccCard card = phone == null ? null : phone.getUiccCard(); | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4873 | if (card == null) { | 
|  | 4874 | loge("getIccId: No UICC"); | 
|  | 4875 | return null; | 
|  | 4876 | } | 
|  | 4877 | String iccId = card.getIccId(); | 
|  | 4878 | if (TextUtils.isEmpty(iccId)) { | 
|  | 4879 | loge("getIccId: ICC ID is null or empty."); | 
|  | 4880 | return null; | 
|  | 4881 | } | 
|  | 4882 | return iccId; | 
|  | 4883 | } | 
|  | 4884 |  | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4885 | @Override | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4886 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, | 
|  | 4887 | String number) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4888 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( | 
|  | 4889 | subId, "setLine1NumberForDisplayForSubscriber"); | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4890 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4891 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4892 | try { | 
|  | 4893 | final String iccId = getIccId(subId); | 
|  | 4894 | final Phone phone = getPhone(subId); | 
|  | 4895 | if (phone == null) { | 
|  | 4896 | return false; | 
|  | 4897 | } | 
|  | 4898 | final String subscriberId = phone.getSubscriberId(); | 
|  | 4899 |  | 
|  | 4900 | if (DBG_MERGE) { | 
|  | 4901 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" | 
|  | 4902 | + subscriberId + " to " + number); | 
|  | 4903 | } | 
|  | 4904 |  | 
|  | 4905 | if (TextUtils.isEmpty(iccId)) { | 
|  | 4906 | return false; | 
|  | 4907 | } | 
|  | 4908 |  | 
|  | 4909 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); | 
|  | 4910 |  | 
|  | 4911 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; | 
|  | 4912 | if (alphaTag == null) { | 
|  | 4913 | editor.remove(alphaTagPrefKey); | 
|  | 4914 | } else { | 
|  | 4915 | editor.putString(alphaTagPrefKey, alphaTag); | 
|  | 4916 | } | 
|  | 4917 |  | 
|  | 4918 | // Record both the line number and IMSI for this ICCID, since we need to | 
|  | 4919 | // track all merged IMSIs based on line number | 
|  | 4920 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; | 
|  | 4921 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; | 
|  | 4922 | if (number == null) { | 
|  | 4923 | editor.remove(numberPrefKey); | 
|  | 4924 | editor.remove(subscriberPrefKey); | 
|  | 4925 | } else { | 
|  | 4926 | editor.putString(numberPrefKey, number); | 
|  | 4927 | editor.putString(subscriberPrefKey, subscriberId); | 
|  | 4928 | } | 
|  | 4929 |  | 
|  | 4930 | editor.commit(); | 
|  | 4931 | return true; | 
|  | 4932 | } finally { | 
|  | 4933 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4934 | } | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4935 | } | 
|  | 4936 |  | 
|  | 4937 | @Override | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4938 | public String getLine1NumberForDisplay(int subId, String callingPackage) { | 
| Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4939 | // This is open to apps with WRITE_SMS. | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4940 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4941 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { | 
| Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4942 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4943 | return null; | 
|  | 4944 | } | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4945 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4946 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4947 | try { | 
|  | 4948 | String iccId = getIccId(subId); | 
|  | 4949 | if (iccId != null) { | 
|  | 4950 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; | 
|  | 4951 | if (DBG_MERGE) { | 
|  | 4952 | log("getLine1NumberForDisplay returning " | 
|  | 4953 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); | 
|  | 4954 | } | 
|  | 4955 | return mTelephonySharedPreferences.getString(numberPrefKey, null); | 
| Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4956 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4957 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); | 
|  | 4958 | return null; | 
|  | 4959 | } finally { | 
|  | 4960 | Binder.restoreCallingIdentity(identity); | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4961 | } | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4962 | } | 
|  | 4963 |  | 
|  | 4964 | @Override | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4965 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4966 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4967 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4968 | return null; | 
|  | 4969 | } | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4970 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4971 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4972 | try { | 
|  | 4973 | String iccId = getIccId(subId); | 
|  | 4974 | if (iccId != null) { | 
|  | 4975 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; | 
|  | 4976 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); | 
|  | 4977 | } | 
|  | 4978 | return null; | 
|  | 4979 | } finally { | 
|  | 4980 | Binder.restoreCallingIdentity(identity); | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4981 | } | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4982 | } | 
| Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4983 |  | 
|  | 4984 | @Override | 
| Jordan Liu | 9775d4b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 4985 | public String[] getMergedSubscriberIds(int subId, String callingPackage) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4986 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried | 
|  | 4987 | // about carrier-privileged callers not having access. | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4988 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4989 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, | 
|  | 4990 | "getMergedSubscriberIds")) { | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4991 | return null; | 
|  | 4992 | } | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4993 |  | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4994 | final long identity  = Binder.clearCallingIdentity(); | 
|  | 4995 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4996 | final Context context = mApp; | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4997 | final TelephonyManager tele = TelephonyManager.from(context); | 
|  | 4998 | final SubscriptionManager sub = SubscriptionManager.from(context); | 
|  | 4999 |  | 
|  | 5000 | // Figure out what subscribers are currently active | 
|  | 5001 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); | 
|  | 5002 | // Clear calling identity, when calling TelephonyManager, because callerUid must be | 
|  | 5003 | // the process, where TelephonyManager was instantiated. | 
|  | 5004 | // Otherwise AppOps check will fail. | 
|  | 5005 |  | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5006 | final int[] subIds = sub.getActiveSubscriptionIdList(); | 
| Jordan Liu | 9775d4b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5007 | for (int id : subIds) { | 
|  | 5008 | // Only consider subs which match the current subId | 
|  | 5009 | // This logic can be simplified. See b/131189269 for progress. | 
|  | 5010 | if (subId != id) { | 
|  | 5011 | continue; | 
|  | 5012 | } | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5013 | activeSubscriberIds.add(tele.getSubscriberId(subId)); | 
|  | 5014 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5015 |  | 
|  | 5016 | // First pass, find a number override for an active subscriber | 
|  | 5017 | String mergeNumber = null; | 
|  | 5018 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); | 
|  | 5019 | for (String key : prefs.keySet()) { | 
|  | 5020 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { | 
|  | 5021 | final String subscriberId = (String) prefs.get(key); | 
|  | 5022 | if (activeSubscriberIds.contains(subscriberId)) { | 
|  | 5023 | final String iccId = key.substring( | 
|  | 5024 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); | 
|  | 5025 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; | 
|  | 5026 | mergeNumber = (String) prefs.get(numberKey); | 
|  | 5027 | if (DBG_MERGE) { | 
|  | 5028 | Slog.d(LOG_TAG, "Found line number " + mergeNumber | 
|  | 5029 | + " for active subscriber " + subscriberId); | 
|  | 5030 | } | 
|  | 5031 | if (!TextUtils.isEmpty(mergeNumber)) { | 
|  | 5032 | break; | 
|  | 5033 | } | 
|  | 5034 | } | 
|  | 5035 | } | 
|  | 5036 | } | 
|  | 5037 |  | 
|  | 5038 | // Shortcut when no active merged subscribers | 
|  | 5039 | if (TextUtils.isEmpty(mergeNumber)) { | 
|  | 5040 | return null; | 
|  | 5041 | } | 
|  | 5042 |  | 
|  | 5043 | // Second pass, find all subscribers under that line override | 
|  | 5044 | final ArraySet<String> result = new ArraySet<>(); | 
|  | 5045 | for (String key : prefs.keySet()) { | 
|  | 5046 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { | 
|  | 5047 | final String number = (String) prefs.get(key); | 
|  | 5048 | if (mergeNumber.equals(number)) { | 
|  | 5049 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); | 
|  | 5050 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; | 
|  | 5051 | final String subscriberId = (String) prefs.get(subscriberKey); | 
|  | 5052 | if (!TextUtils.isEmpty(subscriberId)) { | 
|  | 5053 | result.add(subscriberId); | 
|  | 5054 | } | 
|  | 5055 | } | 
|  | 5056 | } | 
|  | 5057 | } | 
|  | 5058 |  | 
|  | 5059 | final String[] resultArray = result.toArray(new String[result.size()]); | 
|  | 5060 | Arrays.sort(resultArray); | 
|  | 5061 | if (DBG_MERGE) { | 
|  | 5062 | Slog.d(LOG_TAG, | 
|  | 5063 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); | 
|  | 5064 | } | 
|  | 5065 | return resultArray; | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5066 | } finally { | 
|  | 5067 | Binder.restoreCallingIdentity(identity); | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5068 | } | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5069 | } | 
|  | 5070 |  | 
|  | 5071 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5072 | public boolean setOperatorBrandOverride(int subId, String brand) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5073 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( | 
|  | 5074 | subId, "setOperatorBrandOverride"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5075 |  | 
|  | 5076 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5077 | try { | 
|  | 5078 | final Phone phone = getPhone(subId); | 
|  | 5079 | return phone == null ? false : phone.setOperatorBrandOverride(brand); | 
|  | 5080 | } finally { | 
|  | 5081 | Binder.restoreCallingIdentity(identity); | 
|  | 5082 | } | 
| Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5083 | } | 
| Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5084 |  | 
|  | 5085 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5086 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, | 
| Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5087 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, | 
|  | 5088 | List<String> cdmaNonRoamingList) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5089 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5090 |  | 
|  | 5091 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5092 | try { | 
|  | 5093 | final Phone phone = getPhone(subId); | 
|  | 5094 | if (phone == null) { | 
|  | 5095 | return false; | 
|  | 5096 | } | 
|  | 5097 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, | 
|  | 5098 | cdmaNonRoamingList); | 
|  | 5099 | } finally { | 
|  | 5100 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5101 | } | 
| Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5102 | } | 
|  | 5103 |  | 
|  | 5104 | @Override | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5105 | @Deprecated | 
|  | 5106 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { | 
|  | 5107 | enforceModifyPermission(); | 
|  | 5108 |  | 
|  | 5109 | int returnValue = 0; | 
|  | 5110 | try { | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5111 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5112 | if(result.exception == null) { | 
|  | 5113 | if (result.result != null) { | 
|  | 5114 | byte[] responseData = (byte[])(result.result); | 
|  | 5115 | if(responseData.length > oemResp.length) { | 
|  | 5116 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + | 
|  | 5117 | responseData.length +  "bytes. Buffer Size is " + | 
|  | 5118 | oemResp.length + "bytes."); | 
|  | 5119 | } | 
|  | 5120 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); | 
|  | 5121 | returnValue = responseData.length; | 
|  | 5122 | } | 
|  | 5123 | } else { | 
|  | 5124 | CommandException ex = (CommandException) result.exception; | 
|  | 5125 | returnValue = ex.getCommandError().ordinal(); | 
|  | 5126 | if(returnValue > 0) returnValue *= -1; | 
|  | 5127 | } | 
|  | 5128 | } catch (RuntimeException e) { | 
|  | 5129 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); | 
|  | 5130 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); | 
|  | 5131 | if(returnValue > 0) returnValue *= -1; | 
|  | 5132 | } | 
|  | 5133 |  | 
|  | 5134 | return returnValue; | 
|  | 5135 | } | 
|  | 5136 |  | 
|  | 5137 | @Override | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5138 | public void setRadioCapability(RadioAccessFamily[] rafs) { | 
|  | 5139 | try { | 
|  | 5140 | ProxyController.getInstance().setRadioCapability(rafs); | 
|  | 5141 | } catch (RuntimeException e) { | 
|  | 5142 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); | 
|  | 5143 | } | 
|  | 5144 | } | 
|  | 5145 |  | 
|  | 5146 | @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5147 | public int getRadioAccessFamily(int phoneId, String callingPackage) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5148 | Phone phone = PhoneFactory.getPhone(phoneId); | 
| chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5149 | int raf = RadioAccessFamily.RAF_UNKNOWN; | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5150 | if (phone == null) { | 
| chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5151 | return raf; | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5152 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5153 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5154 | try { | 
| chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5155 | TelephonyPermissions | 
|  | 5156 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 5157 | mApp, phone.getSubId(), "getRadioAccessFamily"); | 
|  | 5158 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5159 | } finally { | 
|  | 5160 | Binder.restoreCallingIdentity(identity); | 
|  | 5161 | } | 
| chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5162 | return raf; | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5163 | } | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5164 |  | 
|  | 5165 | @Override | 
|  | 5166 | public void enableVideoCalling(boolean enable) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5167 | final Phone defaultPhone = getDefaultPhone(); | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5168 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5169 |  | 
|  | 5170 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5171 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5172 | ImsManager.getInstance(defaultPhone.getContext(), | 
|  | 5173 | defaultPhone.getPhoneId()).setVtSetting(enable); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5174 | } finally { | 
|  | 5175 | Binder.restoreCallingIdentity(identity); | 
|  | 5176 | } | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5177 | } | 
|  | 5178 |  | 
|  | 5179 | @Override | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5180 | public boolean isVideoCallingEnabled(String callingPackage) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5181 | final Phone defaultPhone = getDefaultPhone(); | 
| Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5182 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5183 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { | 
| Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5184 | return false; | 
|  | 5185 | } | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5186 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5187 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5188 | try { | 
|  | 5189 | // Check the user preference and the  system-level IMS setting. Even if the user has | 
|  | 5190 | // enabled video calling, if IMS is disabled we aren't able to support video calling. | 
|  | 5191 | // In the long run, we may instead need to check if there exists a connection service | 
|  | 5192 | // which can support video calling. | 
|  | 5193 | ImsManager imsManager = | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5194 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5195 | return imsManager.isVtEnabledByPlatform() | 
|  | 5196 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() | 
|  | 5197 | && imsManager.isVtEnabledByUser(); | 
|  | 5198 | } finally { | 
|  | 5199 | Binder.restoreCallingIdentity(identity); | 
|  | 5200 | } | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5201 | } | 
| Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5202 |  | 
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5203 | @Override | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5204 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { | 
|  | 5205 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 5206 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { | 
|  | 5207 | return false; | 
|  | 5208 | } | 
|  | 5209 |  | 
|  | 5210 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5211 | try { | 
|  | 5212 | CarrierConfigManager configManager = | 
|  | 5213 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5214 | return configManager.getConfigForSubId(subId) | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5215 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); | 
|  | 5216 | } finally { | 
|  | 5217 | Binder.restoreCallingIdentity(identity); | 
|  | 5218 | } | 
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5219 | } | 
|  | 5220 |  | 
|  | 5221 | @Override | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5222 | public boolean isWorldPhone(int subId, String callingPackage) { | 
|  | 5223 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 5224 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { | 
|  | 5225 | return false; | 
|  | 5226 | } | 
|  | 5227 |  | 
|  | 5228 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5229 | try { | 
|  | 5230 | CarrierConfigManager configManager = | 
|  | 5231 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5232 | return configManager.getConfigForSubId(subId) | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5233 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); | 
|  | 5234 | } finally { | 
|  | 5235 | Binder.restoreCallingIdentity(identity); | 
|  | 5236 | } | 
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5237 | } | 
|  | 5238 |  | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5239 | @Override | 
|  | 5240 | public boolean isTtyModeSupported() { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5241 | TelecomManager telecomManager = TelecomManager.from(mApp); | 
| Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5242 | return telecomManager.isTtySupported(); | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5243 | } | 
|  | 5244 |  | 
|  | 5245 | @Override | 
|  | 5246 | public boolean isHearingAidCompatibilitySupported() { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5247 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5248 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5249 | return mApp.getResources().getBoolean(R.bool.hac_enabled); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5250 | } finally { | 
|  | 5251 | Binder.restoreCallingIdentity(identity); | 
|  | 5252 | } | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5253 | } | 
|  | 5254 |  | 
| Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5255 | /** | 
|  | 5256 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier | 
|  | 5257 | * support for the feature and device firmware support. | 
|  | 5258 | * | 
|  | 5259 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. | 
|  | 5260 | */ | 
|  | 5261 | @Override | 
|  | 5262 | public boolean isRttSupported(int subscriptionId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5263 | final long identity = Binder.clearCallingIdentity(); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5264 | final Phone phone = getPhone(subscriptionId); | 
|  | 5265 | if (phone == null) { | 
|  | 5266 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); | 
|  | 5267 | return false; | 
|  | 5268 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5269 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5270 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5271 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); | 
|  | 5272 | boolean isDeviceSupported = | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5273 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5274 | return isCarrierSupported && isDeviceSupported; | 
|  | 5275 | } finally { | 
|  | 5276 | Binder.restoreCallingIdentity(identity); | 
|  | 5277 | } | 
| Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5278 | } | 
|  | 5279 |  | 
| Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5280 | /** | 
|  | 5281 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier | 
|  | 5282 | * both also support RTT. | 
|  | 5283 | */ | 
|  | 5284 | public boolean isRttEnabled(int subscriptionId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5285 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5286 | try { | 
| Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5287 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5288 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5289 | } finally { | 
|  | 5290 | Binder.restoreCallingIdentity(identity); | 
|  | 5291 | } | 
| Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5292 | } | 
|  | 5293 |  | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5294 | /** | 
|  | 5295 | * Returns the unique device ID of phone, for example, the IMEI for | 
|  | 5296 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. | 
|  | 5297 | * | 
|  | 5298 | * <p>Requires Permission: | 
|  | 5299 | *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} | 
|  | 5300 | */ | 
|  | 5301 | @Override | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5302 | public String getDeviceId(String callingPackage) { | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5303 | final Phone phone = PhoneFactory.getPhone(0); | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5304 | if (phone == null) { | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5305 | return null; | 
|  | 5306 | } | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5307 | int subId = phone.getSubId(); | 
|  | 5308 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 5309 | mApp, subId, callingPackage, "getDeviceId")) { | 
|  | 5310 | return null; | 
|  | 5311 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5312 |  | 
|  | 5313 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5314 | try { | 
|  | 5315 | return phone.getDeviceId(); | 
|  | 5316 | } finally { | 
|  | 5317 | Binder.restoreCallingIdentity(identity); | 
|  | 5318 | } | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5319 | } | 
|  | 5320 |  | 
| Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5321 | /** | 
|  | 5322 | * {@hide} | 
|  | 5323 | * Returns the IMS Registration Status on a particular subid | 
|  | 5324 | * | 
|  | 5325 | * @param subId | 
|  | 5326 | */ | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5327 | public boolean isImsRegistered(int subId) { | 
| Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5328 | Phone phone = getPhone(subId); | 
|  | 5329 | if (phone != null) { | 
|  | 5330 | return phone.isImsRegistered(); | 
|  | 5331 | } else { | 
|  | 5332 | return false; | 
|  | 5333 | } | 
|  | 5334 | } | 
|  | 5335 |  | 
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5336 | @Override | 
|  | 5337 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5338 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5339 | try { | 
|  | 5340 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); | 
|  | 5341 | } finally { | 
|  | 5342 | Binder.restoreCallingIdentity(identity); | 
|  | 5343 | } | 
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5344 | } | 
| Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5345 |  | 
| Tyler Gunn | 327a972 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5346 | @Override | 
|  | 5347 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { | 
|  | 5348 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5349 | try { | 
|  | 5350 | Phone phone = getPhone(subscriptionId); | 
|  | 5351 | if (phone == null) { | 
|  | 5352 | return null; | 
|  | 5353 | } | 
|  | 5354 | return PhoneUtils.makePstnPhoneAccountHandle(phone); | 
|  | 5355 | } finally { | 
|  | 5356 | Binder.restoreCallingIdentity(identity); | 
|  | 5357 | } | 
|  | 5358 | } | 
|  | 5359 |  | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5360 | /** | 
|  | 5361 | * @return the VoWiFi calling availability. | 
| Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5362 | */ | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5363 | public boolean isWifiCallingAvailable(int subId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5364 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5365 | try { | 
|  | 5366 | Phone phone = getPhone(subId); | 
|  | 5367 | if (phone != null) { | 
|  | 5368 | return phone.isWifiCallingEnabled(); | 
|  | 5369 | } else { | 
|  | 5370 | return false; | 
|  | 5371 | } | 
|  | 5372 | } finally { | 
|  | 5373 | Binder.restoreCallingIdentity(identity); | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5374 | } | 
| Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5375 | } | 
|  | 5376 |  | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5377 | /** | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5378 | * @return the VT calling availability. | 
| Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5379 | */ | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5380 | public boolean isVideoTelephonyAvailable(int subId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5381 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5382 | try { | 
|  | 5383 | Phone phone = getPhone(subId); | 
|  | 5384 | if (phone != null) { | 
|  | 5385 | return phone.isVideoEnabled(); | 
|  | 5386 | } else { | 
|  | 5387 | return false; | 
|  | 5388 | } | 
|  | 5389 | } finally { | 
|  | 5390 | Binder.restoreCallingIdentity(identity); | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5391 | } | 
|  | 5392 | } | 
|  | 5393 |  | 
|  | 5394 | /** | 
|  | 5395 | * @return the IMS registration technology for the MMTEL feature. Valid return values are | 
|  | 5396 | * defined in {@link ImsRegistrationImplBase}. | 
|  | 5397 | */ | 
|  | 5398 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5399 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5400 | try { | 
|  | 5401 | Phone phone = getPhone(subId); | 
|  | 5402 | if (phone != null) { | 
|  | 5403 | return phone.getImsRegistrationTech(); | 
|  | 5404 | } else { | 
|  | 5405 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; | 
|  | 5406 | } | 
|  | 5407 | } finally { | 
|  | 5408 | Binder.restoreCallingIdentity(identity); | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5409 | } | 
| Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5410 | } | 
|  | 5411 |  | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5412 | @Override | 
|  | 5413 | public void factoryReset(int subId) { | 
|  | 5414 | enforceConnectivityInternalPermission(); | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5415 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { | 
|  | 5416 | return; | 
|  | 5417 | } | 
|  | 5418 |  | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5419 | final long identity = Binder.clearCallingIdentity(); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5420 |  | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5421 | try { | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5422 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( | 
|  | 5423 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5424 | setUserDataEnabled(subId, getDefaultDataEnabled()); | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5425 | setNetworkSelectionModeAutomatic(subId); | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5426 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5427 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); | 
|  | 5428 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5429 | } | 
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5430 | // There has been issues when Sms raw table somehow stores orphan | 
|  | 5431 | // fragments. They lead to garbled message when new fragments come | 
|  | 5432 | // in and combined with those stale ones. In case this happens again, | 
|  | 5433 | // user can reset all network settings which will clean up this table. | 
|  | 5434 | cleanUpSmsRawTable(getDefaultPhone().getContext()); | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5435 | } finally { | 
|  | 5436 | Binder.restoreCallingIdentity(identity); | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5437 | } | 
|  | 5438 | } | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5439 |  | 
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5440 | private void cleanUpSmsRawTable(Context context) { | 
|  | 5441 | ContentResolver resolver = context.getContentResolver(); | 
|  | 5442 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); | 
|  | 5443 | resolver.delete(uri, null, null); | 
|  | 5444 | } | 
|  | 5445 |  | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5446 | @Override | 
| chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5447 | public String getSimLocaleForSubscriber(int subId) { | 
|  | 5448 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); | 
|  | 5449 | final Phone phone = getPhone(subId); | 
|  | 5450 | if (phone == null) { | 
|  | 5451 | log("getSimLocaleForSubscriber, invalid subId"); | 
| Pengquan Meng | 9c29148 | 2019-01-28 16:26:29 -0800 | [diff] [blame] | 5452 | return null; | 
| chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5453 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5454 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5455 | try { | 
| chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5456 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, | 
|  | 5457 | phone.getContext().getOpPackageName()); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5458 | // Try and fetch the locale from the carrier properties or from the SIM language | 
|  | 5459 | // preferences (EF-PL and EF-LI)... | 
|  | 5460 | final int mcc = info.getMcc(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5461 | String simLanguage = null; | 
| chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5462 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); | 
|  | 5463 | if (localeFromDefaultSim != null) { | 
|  | 5464 | if (!localeFromDefaultSim.getCountry().isEmpty()) { | 
|  | 5465 | if (DBG) log("Using locale from subId: " + subId + " locale: " | 
|  | 5466 | + localeFromDefaultSim); | 
|  | 5467 | return localeFromDefaultSim.toLanguageTag(); | 
|  | 5468 | } else { | 
|  | 5469 | simLanguage = localeFromDefaultSim.getLanguage(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5470 | } | 
|  | 5471 | } | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5472 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5473 | // The SIM language preferences only store a language (e.g. fr = French), not an | 
|  | 5474 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from | 
|  | 5475 | // the SIM and carrier preferences does not include a country we add the country | 
|  | 5476 | // determined from the SIM MCC to provide an exact locale. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5477 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5478 | if (mccLocale != null) { | 
| chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5479 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5480 | return mccLocale.toLanguageTag(); | 
|  | 5481 | } | 
|  | 5482 |  | 
|  | 5483 | if (DBG) log("No locale found - returning null"); | 
|  | 5484 | return null; | 
|  | 5485 | } finally { | 
|  | 5486 | Binder.restoreCallingIdentity(identity); | 
|  | 5487 | } | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5488 | } | 
|  | 5489 |  | 
|  | 5490 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5491 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5492 | } | 
|  | 5493 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5494 | /** | 
|  | 5495 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. | 
|  | 5496 | */ | 
|  | 5497 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5498 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5499 | } | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5500 |  | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5501 | private final ModemActivityInfo mLastModemActivityInfo = | 
|  | 5502 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); | 
|  | 5503 |  | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5504 | /** | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5505 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object | 
|  | 5506 | * representing the state of the modem. | 
|  | 5507 | * | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5508 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one | 
|  | 5509 | * caller to it. Everyone should call this class to get cumulative data. | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5510 | * @hide | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5511 | */ | 
|  | 5512 | @Override | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5513 | public void requestModemActivityInfo(ResultReceiver result) { | 
|  | 5514 | enforceModifyPermission(); | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5515 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5516 |  | 
|  | 5517 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5518 | try { | 
|  | 5519 | ModemActivityInfo ret = null; | 
|  | 5520 | synchronized (mLastModemActivityInfo) { | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5521 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( | 
|  | 5522 | CMD_GET_MODEM_ACTIVITY_INFO, | 
|  | 5523 | null, workSource); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5524 | if (isModemActivityInfoValid(info)) { | 
|  | 5525 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; | 
|  | 5526 | for (int i = 0; i < mergedTxTimeMs.length; i++) { | 
|  | 5527 | mergedTxTimeMs[i] = | 
|  | 5528 | info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i]; | 
|  | 5529 | } | 
|  | 5530 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); | 
|  | 5531 | mLastModemActivityInfo.setSleepTimeMillis( | 
|  | 5532 | info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis()); | 
|  | 5533 | mLastModemActivityInfo.setIdleTimeMillis( | 
|  | 5534 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); | 
|  | 5535 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); | 
|  | 5536 | mLastModemActivityInfo.setRxTimeMillis( | 
|  | 5537 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); | 
|  | 5538 | mLastModemActivityInfo.setEnergyUsed( | 
|  | 5539 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5540 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5541 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), | 
|  | 5542 | mLastModemActivityInfo.getSleepTimeMillis(), | 
|  | 5543 | mLastModemActivityInfo.getIdleTimeMillis(), | 
|  | 5544 | mLastModemActivityInfo.getTxTimeMillis(), | 
|  | 5545 | mLastModemActivityInfo.getRxTimeMillis(), | 
|  | 5546 | mLastModemActivityInfo.getEnergyUsed()); | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5547 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5548 | Bundle bundle = new Bundle(); | 
|  | 5549 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); | 
|  | 5550 | result.send(0, bundle); | 
|  | 5551 | } finally { | 
|  | 5552 | Binder.restoreCallingIdentity(identity); | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5553 | } | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5554 | } | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5555 |  | 
| Siddharth Ray | f5d2955 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5556 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be | 
|  | 5557 | // less than total activity duration. | 
|  | 5558 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { | 
|  | 5559 | if (info == null) { | 
|  | 5560 | return false; | 
|  | 5561 | } | 
|  | 5562 | int activityDurationMs = | 
|  | 5563 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); | 
|  | 5564 | int totalTxTimeMs = 0; | 
|  | 5565 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { | 
|  | 5566 | totalTxTimeMs += info.getTxTimeMillis()[i]; | 
|  | 5567 | } | 
|  | 5568 | return (info.isValid() | 
|  | 5569 | && (info.getSleepTimeMillis() <= activityDurationMs) | 
|  | 5570 | && (info.getIdleTimeMillis() <= activityDurationMs) | 
|  | 5571 | && (info.getRxTimeMillis() <= activityDurationMs) | 
|  | 5572 | && (totalTxTimeMs <= activityDurationMs)); | 
|  | 5573 | } | 
|  | 5574 |  | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5575 | /** | 
|  | 5576 | * {@hide} | 
|  | 5577 | * Returns the service state information on specified subscription. | 
|  | 5578 | */ | 
|  | 5579 | @Override | 
|  | 5580 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5581 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5582 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5583 | return null; | 
|  | 5584 | } | 
|  | 5585 |  | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5586 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = | 
|  | 5587 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 5588 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 5589 | .setCallingPackage(callingPackage) | 
|  | 5590 | .setCallingPid(Binder.getCallingPid()) | 
|  | 5591 | .setCallingUid(Binder.getCallingUid()) | 
|  | 5592 | .setMethod("getServiceStateForSubscriber") | 
| Hall Liu | 8b0cba2 | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5593 | .setLogAsInfo(true) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5594 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 5595 | .build()); | 
|  | 5596 |  | 
|  | 5597 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = | 
|  | 5598 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 5599 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 5600 | .setCallingPackage(callingPackage) | 
|  | 5601 | .setCallingPid(Binder.getCallingPid()) | 
|  | 5602 | .setCallingUid(Binder.getCallingUid()) | 
|  | 5603 | .setMethod("getServiceStateForSubscriber") | 
| Hall Liu | 8b0cba2 | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5604 | .setLogAsInfo(true) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5605 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) | 
|  | 5606 | .build()); | 
|  | 5607 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. | 
|  | 5608 | boolean hasFinePermission = | 
|  | 5609 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; | 
|  | 5610 | boolean hasCoarsePermission = | 
|  | 5611 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; | 
|  | 5612 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5613 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5614 | try { | 
|  | 5615 | final Phone phone = getPhone(subId); | 
|  | 5616 | if (phone == null) { | 
|  | 5617 | return null; | 
|  | 5618 | } | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5619 |  | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5620 | ServiceState ss = phone.getServiceState(); | 
|  | 5621 |  | 
|  | 5622 | // Scrub out the location info in ServiceState depending on what level of access | 
|  | 5623 | // the caller has. | 
|  | 5624 | if (hasFinePermission) return ss; | 
|  | 5625 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); | 
|  | 5626 | return ss.sanitizeLocationInfo(true); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5627 | } finally { | 
|  | 5628 | Binder.restoreCallingIdentity(identity); | 
|  | 5629 | } | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5630 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5631 |  | 
|  | 5632 | /** | 
|  | 5633 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. | 
|  | 5634 | * | 
|  | 5635 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the | 
|  | 5636 | * voicemail ringtone. | 
|  | 5637 | * @return The URI for the ringtone to play when receiving a voicemail from a specific | 
|  | 5638 | * PhoneAccount. | 
|  | 5639 | */ | 
|  | 5640 | @Override | 
|  | 5641 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5642 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5643 | try { | 
|  | 5644 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); | 
|  | 5645 | if (phone == null) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5646 | phone = getDefaultPhone(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5647 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5648 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5649 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); | 
|  | 5650 | } finally { | 
|  | 5651 | Binder.restoreCallingIdentity(identity); | 
|  | 5652 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5653 | } | 
|  | 5654 |  | 
|  | 5655 | /** | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5656 | * Sets the per-account voicemail ringtone. | 
|  | 5657 | * | 
|  | 5658 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or | 
|  | 5659 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. | 
|  | 5660 | * | 
|  | 5661 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the | 
|  | 5662 | * voicemail ringtone. | 
|  | 5663 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific | 
|  | 5664 | * PhoneAccount. | 
|  | 5665 | */ | 
|  | 5666 | @Override | 
|  | 5667 | public void setVoicemailRingtoneUri(String callingPackage, | 
|  | 5668 | PhoneAccountHandle phoneAccountHandle, Uri uri) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5669 | final Phone defaultPhone = getDefaultPhone(); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5670 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 5671 | if (!TextUtils.equals(callingPackage, | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5672 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5673 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5674 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), | 
|  | 5675 | "setVoicemailRingtoneUri"); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5676 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5677 |  | 
|  | 5678 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5679 | try { | 
|  | 5680 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); | 
|  | 5681 | if (phone == null) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5682 | phone = defaultPhone; | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5683 | } | 
|  | 5684 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); | 
|  | 5685 | } finally { | 
|  | 5686 | Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5687 | } | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5688 | } | 
|  | 5689 |  | 
|  | 5690 | /** | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5691 | * Returns whether vibration is set for voicemail notification in Phone settings. | 
|  | 5692 | * | 
|  | 5693 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the | 
|  | 5694 | * voicemail vibration setting. | 
|  | 5695 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. | 
|  | 5696 | */ | 
|  | 5697 | @Override | 
|  | 5698 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5699 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5700 | try { | 
|  | 5701 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); | 
|  | 5702 | if (phone == null) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5703 | phone = getDefaultPhone(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5704 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5705 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5706 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); | 
|  | 5707 | } finally { | 
|  | 5708 | Binder.restoreCallingIdentity(identity); | 
|  | 5709 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5710 | } | 
|  | 5711 |  | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5712 | /** | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5713 | * Sets the per-account voicemail vibration. | 
|  | 5714 | * | 
|  | 5715 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or | 
|  | 5716 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. | 
|  | 5717 | * | 
|  | 5718 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the | 
|  | 5719 | * voicemail vibration setting. | 
|  | 5720 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a | 
|  | 5721 | * specific PhoneAccount. | 
|  | 5722 | */ | 
|  | 5723 | @Override | 
|  | 5724 | public void setVoicemailVibrationEnabled(String callingPackage, | 
|  | 5725 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5726 | final Phone defaultPhone = getDefaultPhone(); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5727 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 5728 | if (!TextUtils.equals(callingPackage, | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5729 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5730 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5731 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), | 
|  | 5732 | "setVoicemailVibrationEnabled"); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5733 | } | 
|  | 5734 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5735 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5736 | try { | 
|  | 5737 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); | 
|  | 5738 | if (phone == null) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5739 | phone = defaultPhone; | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5740 | } | 
|  | 5741 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); | 
|  | 5742 | } finally { | 
|  | 5743 | Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5744 | } | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5745 | } | 
|  | 5746 |  | 
|  | 5747 | /** | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5748 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. | 
|  | 5749 | * | 
|  | 5750 | * @throws SecurityException if the caller does not have the required permission | 
|  | 5751 | */ | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5752 | private void enforceReadPrivilegedPermission(String message) { | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5753 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5754 | message); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5755 | } | 
|  | 5756 |  | 
|  | 5757 | /** | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5758 | * Make sure either called from same process as self (phone) or IPC caller has send SMS | 
|  | 5759 | * permission. | 
|  | 5760 | * | 
|  | 5761 | * @throws SecurityException if the caller does not have the required permission | 
|  | 5762 | */ | 
|  | 5763 | private void enforceSendSmsPermission() { | 
|  | 5764 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); | 
|  | 5765 | } | 
|  | 5766 |  | 
|  | 5767 | /** | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5768 | * Make sure called from the package in charge of visual voicemail. | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5769 | * | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5770 | * @throws SecurityException if the caller is not the visual voicemail package. | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5771 | */ | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5772 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5773 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5774 | try { | 
|  | 5775 | ComponentName componentName = | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5776 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5777 | if (componentName == null) { | 
|  | 5778 | throw new SecurityException( | 
|  | 5779 | "Caller not current active visual voicemail package[null]"); | 
|  | 5780 | } | 
|  | 5781 | String vvmPackage = componentName.getPackageName(); | 
|  | 5782 | if (!callingPackage.equals(vvmPackage)) { | 
|  | 5783 | throw new SecurityException("Caller not current active visual voicemail package[" | 
|  | 5784 | + vvmPackage + "]"); | 
|  | 5785 | } | 
|  | 5786 | } finally { | 
|  | 5787 | Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5788 | } | 
|  | 5789 | } | 
|  | 5790 |  | 
|  | 5791 | /** | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5792 | * Return the application ID for the app type. | 
|  | 5793 | * | 
|  | 5794 | * @param subId the subscription ID that this request applies to. | 
|  | 5795 | * @param appType the uicc app type. | 
|  | 5796 | * @return Application ID for specificied app type, or null if no uicc. | 
|  | 5797 | */ | 
|  | 5798 | @Override | 
|  | 5799 | public String getAidForAppType(int subId, int appType) { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5800 | enforceReadPrivilegedPermission("getAidForAppType"); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5801 | Phone phone = getPhone(subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5802 |  | 
|  | 5803 | final long identity = Binder.clearCallingIdentity(); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5804 | try { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5805 | if (phone == null) { | 
|  | 5806 | return null; | 
|  | 5807 | } | 
|  | 5808 | String aid = null; | 
|  | 5809 | try { | 
|  | 5810 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) | 
|  | 5811 | .getApplicationByType(appType).getAid(); | 
|  | 5812 | } catch (Exception e) { | 
|  | 5813 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); | 
|  | 5814 | } | 
|  | 5815 | return aid; | 
|  | 5816 | } finally { | 
|  | 5817 | Binder.restoreCallingIdentity(identity); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5818 | } | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5819 | } | 
|  | 5820 |  | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5821 | /** | 
|  | 5822 | * Return the Electronic Serial Number. | 
|  | 5823 | * | 
|  | 5824 | * @param subId the subscription ID that this request applies to. | 
|  | 5825 | * @return ESN or null if error. | 
|  | 5826 | */ | 
|  | 5827 | @Override | 
|  | 5828 | public String getEsn(int subId) { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5829 | enforceReadPrivilegedPermission("getEsn"); | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5830 | Phone phone = getPhone(subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5831 |  | 
|  | 5832 | final long identity = Binder.clearCallingIdentity(); | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5833 | try { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5834 | if (phone == null) { | 
|  | 5835 | return null; | 
|  | 5836 | } | 
|  | 5837 | String esn = null; | 
|  | 5838 | try { | 
|  | 5839 | esn = phone.getEsn(); | 
|  | 5840 | } catch (Exception e) { | 
|  | 5841 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); | 
|  | 5842 | } | 
|  | 5843 | return esn; | 
|  | 5844 | } finally { | 
|  | 5845 | Binder.restoreCallingIdentity(identity); | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5846 | } | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5847 | } | 
|  | 5848 |  | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5849 | /** | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5850 | * Return the Preferred Roaming List Version. | 
|  | 5851 | * | 
|  | 5852 | * @param subId the subscription ID that this request applies to. | 
|  | 5853 | * @return PRLVersion or null if error. | 
|  | 5854 | */ | 
|  | 5855 | @Override | 
|  | 5856 | public String getCdmaPrlVersion(int subId) { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5857 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5858 | Phone phone = getPhone(subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5859 |  | 
|  | 5860 | final long identity = Binder.clearCallingIdentity(); | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5861 | try { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5862 | if (phone == null) { | 
|  | 5863 | return null; | 
|  | 5864 | } | 
|  | 5865 | String cdmaPrlVersion = null; | 
|  | 5866 | try { | 
|  | 5867 | cdmaPrlVersion = phone.getCdmaPrlVersion(); | 
|  | 5868 | } catch (Exception e) { | 
|  | 5869 | Log.e(LOG_TAG, "Not getting PRLVersion", e); | 
|  | 5870 | } | 
|  | 5871 | return cdmaPrlVersion; | 
|  | 5872 | } finally { | 
|  | 5873 | Binder.restoreCallingIdentity(identity); | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5874 | } | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5875 | } | 
|  | 5876 |  | 
|  | 5877 | /** | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5878 | * Get snapshot of Telephony histograms | 
|  | 5879 | * @return List of Telephony histograms | 
|  | 5880 | * @hide | 
|  | 5881 | */ | 
|  | 5882 | @Override | 
|  | 5883 | public List<TelephonyHistogram> getTelephonyHistograms() { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5884 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5885 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5886 |  | 
|  | 5887 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5888 | try { | 
|  | 5889 | return RIL.getTelephonyRILTimingHistograms(); | 
|  | 5890 | } finally { | 
|  | 5891 | Binder.restoreCallingIdentity(identity); | 
|  | 5892 | } | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5893 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5894 |  | 
|  | 5895 | /** | 
|  | 5896 | * {@hide} | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5897 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between | 
|  | 5898 | * the two lists. | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5899 | * Require system privileges. In the future we may add this to carrier APIs. | 
|  | 5900 | * | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5901 | * @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] | 5902 | */ | 
|  | 5903 | @Override | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5904 | @TelephonyManager.SetCarrierRestrictionResult | 
|  | 5905 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5906 | enforceModifyPermission(); | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5907 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5908 |  | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5909 | if (carrierRestrictionRules == null) { | 
|  | 5910 | throw new NullPointerException("carrier restriction cannot be null"); | 
| Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5911 | } | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5912 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5913 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5914 | try { | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5915 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5916 | workSource); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5917 | } finally { | 
|  | 5918 | Binder.restoreCallingIdentity(identity); | 
|  | 5919 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5920 | } | 
|  | 5921 |  | 
|  | 5922 | /** | 
|  | 5923 | * {@hide} | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5924 | * Get the allowed carrier list and the excluded carrier list, including the priority between | 
|  | 5925 | * the two lists. | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5926 | * Require system privileges. In the future we may add this to carrier APIs. | 
|  | 5927 | * | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5928 | * @return {@link android.telephony.CarrierRestrictionRules} | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5929 | */ | 
|  | 5930 | @Override | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5931 | public CarrierRestrictionRules getAllowedCarriers() { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5932 | enforceReadPrivilegedPermission("getAllowedCarriers"); | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5933 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5934 |  | 
|  | 5935 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5936 | try { | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5937 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); | 
|  | 5938 | if (response instanceof CarrierRestrictionRules) { | 
|  | 5939 | return (CarrierRestrictionRules) response; | 
|  | 5940 | } | 
|  | 5941 | // Response is an Exception of some kind, | 
|  | 5942 | // which is signalled to the user as a NULL retval | 
|  | 5943 | return null; | 
|  | 5944 | } catch (Exception e) { | 
|  | 5945 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); | 
|  | 5946 | return null; | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5947 | } finally { | 
|  | 5948 | Binder.restoreCallingIdentity(identity); | 
|  | 5949 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5950 | } | 
|  | 5951 |  | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5952 | /** | 
|  | 5953 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns | 
|  | 5954 | * @param subId the subscription ID that this action applies to. | 
|  | 5955 | * @param enabled control enable or disable metered apns. | 
|  | 5956 | * {@hide} | 
|  | 5957 | */ | 
|  | 5958 | @Override | 
|  | 5959 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { | 
|  | 5960 | enforceModifyPermission(); | 
|  | 5961 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5962 |  | 
|  | 5963 | final long identity = Binder.clearCallingIdentity(); | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5964 | if (phone == null) { | 
|  | 5965 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); | 
|  | 5966 | return; | 
|  | 5967 | } | 
|  | 5968 | try { | 
|  | 5969 | phone.carrierActionSetMeteredApnsEnabled(enabled); | 
|  | 5970 | } catch (Exception e) { | 
|  | 5971 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5972 | } finally { | 
|  | 5973 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5974 | } | 
|  | 5975 | } | 
|  | 5976 |  | 
|  | 5977 | /** | 
|  | 5978 | * Action set from carrier signalling broadcast receivers to enable/disable radio | 
|  | 5979 | * @param subId the subscription ID that this action applies to. | 
|  | 5980 | * @param enabled control enable or disable radio. | 
|  | 5981 | * {@hide} | 
|  | 5982 | */ | 
|  | 5983 | @Override | 
|  | 5984 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { | 
|  | 5985 | enforceModifyPermission(); | 
|  | 5986 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5987 |  | 
|  | 5988 | final long identity = Binder.clearCallingIdentity(); | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5989 | if (phone == null) { | 
|  | 5990 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); | 
|  | 5991 | return; | 
|  | 5992 | } | 
|  | 5993 | try { | 
|  | 5994 | phone.carrierActionSetRadioEnabled(enabled); | 
|  | 5995 | } catch (Exception e) { | 
|  | 5996 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5997 | } finally { | 
|  | 5998 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5999 | } | 
|  | 6000 | } | 
|  | 6001 |  | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6002 | /** | 
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6003 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default | 
|  | 6004 | * network status based on which carrier apps could apply actions accordingly, | 
|  | 6005 | * enable/disable default url handler for example. | 
|  | 6006 | * | 
|  | 6007 | * @param subId the subscription ID that this action applies to. | 
|  | 6008 | * @param report control start/stop reporting the default network status. | 
|  | 6009 | * {@hide} | 
|  | 6010 | */ | 
|  | 6011 | @Override | 
|  | 6012 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { | 
|  | 6013 | enforceModifyPermission(); | 
|  | 6014 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6015 |  | 
|  | 6016 | final long identity = Binder.clearCallingIdentity(); | 
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6017 | if (phone == null) { | 
|  | 6018 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); | 
|  | 6019 | return; | 
|  | 6020 | } | 
|  | 6021 | try { | 
|  | 6022 | phone.carrierActionReportDefaultNetworkStatus(report); | 
|  | 6023 | } catch (Exception e) { | 
|  | 6024 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6025 | } finally { | 
|  | 6026 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6027 | } | 
|  | 6028 | } | 
|  | 6029 |  | 
|  | 6030 | /** | 
| fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 6031 | * Action set from carrier signalling broadcast receivers to reset all carrier actions | 
|  | 6032 | * @param subId the subscription ID that this action applies to. | 
|  | 6033 | * {@hide} | 
|  | 6034 | */ | 
|  | 6035 | @Override | 
|  | 6036 | public void carrierActionResetAll(int subId) { | 
|  | 6037 | enforceModifyPermission(); | 
|  | 6038 | final Phone phone = getPhone(subId); | 
|  | 6039 | if (phone == null) { | 
|  | 6040 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); | 
|  | 6041 | return; | 
|  | 6042 | } | 
|  | 6043 | try { | 
|  | 6044 | phone.carrierActionResetAll(); | 
|  | 6045 | } catch (Exception e) { | 
|  | 6046 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); | 
|  | 6047 | } | 
|  | 6048 | } | 
|  | 6049 |  | 
|  | 6050 | /** | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6051 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a | 
|  | 6052 | * bug report is being generated. | 
|  | 6053 | */ | 
|  | 6054 | @Override | 
| Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 6055 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6056 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) | 
|  | 6057 | != PackageManager.PERMISSION_GRANTED) { | 
| dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 6058 | writer.println("Permission Denial: can't dump Phone from pid=" | 
|  | 6059 | + Binder.getCallingPid() | 
|  | 6060 | + ", uid=" + Binder.getCallingUid() | 
|  | 6061 | + "without permission " | 
|  | 6062 | + android.Manifest.permission.DUMP); | 
|  | 6063 | return; | 
|  | 6064 | } | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6065 | DumpsysHandler.dump(mApp, fd, writer, args); | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6066 | } | 
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6067 |  | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6068 | @Override | 
|  | 6069 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, | 
|  | 6070 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) | 
|  | 6071 | throws RemoteException { | 
|  | 6072 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); | 
|  | 6073 | } | 
|  | 6074 |  | 
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6075 | /** | 
| Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6076 | * Get aggregated video call data usage since boot. | 
|  | 6077 | * | 
|  | 6078 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. | 
|  | 6079 | * @return Snapshot of video call data usage | 
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6080 | * {@hide} | 
|  | 6081 | */ | 
|  | 6082 | @Override | 
| Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6083 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { | 
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6084 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, | 
|  | 6085 | null); | 
|  | 6086 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6087 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6088 | try { | 
|  | 6089 | // NetworkStatsService keeps tracking the active network interface and identity. It | 
|  | 6090 | // records the delta with the corresponding network identity. | 
|  | 6091 | // We just return the total video call data usage snapshot since boot. | 
|  | 6092 | Phone phone = getPhone(subId); | 
|  | 6093 | if (phone != null) { | 
|  | 6094 | return phone.getVtDataUsage(perUidStats); | 
|  | 6095 | } | 
|  | 6096 | return null; | 
|  | 6097 | } finally { | 
|  | 6098 | Binder.restoreCallingIdentity(identity); | 
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6099 | } | 
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6100 | } | 
| Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6101 |  | 
|  | 6102 | /** | 
|  | 6103 | * Policy control of data connection. Usually used when data limit is passed. | 
|  | 6104 | * @param enabled True if enabling the data, otherwise disabling. | 
|  | 6105 | * @param subId Subscription index | 
|  | 6106 | * {@hide} | 
|  | 6107 | */ | 
|  | 6108 | @Override | 
|  | 6109 | public void setPolicyDataEnabled(boolean enabled, int subId) { | 
|  | 6110 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6111 |  | 
|  | 6112 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6113 | try { | 
|  | 6114 | Phone phone = getPhone(subId); | 
|  | 6115 | if (phone != null) { | 
| Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6116 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6117 | } | 
|  | 6118 | } finally { | 
|  | 6119 | Binder.restoreCallingIdentity(identity); | 
| Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6120 | } | 
|  | 6121 | } | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6122 |  | 
|  | 6123 | /** | 
|  | 6124 | * Get Client request stats | 
|  | 6125 | * @return List of Client Request Stats | 
|  | 6126 | * @hide | 
|  | 6127 | */ | 
|  | 6128 | @Override | 
|  | 6129 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6130 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6131 | mApp, subId, callingPackage, "getClientRequestStats")) { | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6132 | return null; | 
|  | 6133 | } | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6134 | Phone phone = getPhone(subId); | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6135 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6136 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6137 | try { | 
|  | 6138 | if (phone != null) { | 
|  | 6139 | return phone.getClientRequestStats(); | 
|  | 6140 | } | 
|  | 6141 |  | 
|  | 6142 | return null; | 
|  | 6143 | } finally { | 
|  | 6144 | Binder.restoreCallingIdentity(identity); | 
|  | 6145 | } | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6146 | } | 
|  | 6147 |  | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6148 | private WorkSource getWorkSource(int uid) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6149 | String packageName = mApp.getPackageManager().getNameForUid(uid); | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6150 | return new WorkSource(uid, packageName); | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6151 | } | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6152 |  | 
|  | 6153 | /** | 
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6154 | * Set SIM card power state. | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6155 | * | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6156 | * @param slotIndex SIM slot id. | 
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6157 | * @param state  State of SIM (power down, power up, pass through) | 
|  | 6158 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} | 
|  | 6159 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} | 
|  | 6160 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6161 | * | 
|  | 6162 | **/ | 
|  | 6163 | @Override | 
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6164 | public void setSimPowerStateForSlot(int slotIndex, int state) { | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6165 | enforceModifyPermission(); | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6166 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 6167 |  | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6168 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 6169 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6170 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6171 | try { | 
|  | 6172 | if (phone != null) { | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6173 | phone.setSimPowerState(state, workSource); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6174 | } | 
|  | 6175 | } finally { | 
|  | 6176 | Binder.restoreCallingIdentity(identity); | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6177 | } | 
|  | 6178 | } | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6179 |  | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6180 | private boolean isUssdApiAllowed(int subId) { | 
|  | 6181 | CarrierConfigManager configManager = | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6182 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6183 | if (configManager == null) { | 
|  | 6184 | return false; | 
|  | 6185 | } | 
|  | 6186 | PersistableBundle pb = configManager.getConfigForSubId(subId); | 
|  | 6187 | if (pb == null) { | 
|  | 6188 | return false; | 
|  | 6189 | } | 
|  | 6190 | return pb.getBoolean( | 
|  | 6191 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); | 
|  | 6192 | } | 
|  | 6193 |  | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6194 | /** | 
|  | 6195 | * Check if phone is in emergency callback mode | 
|  | 6196 | * @return true if phone is in emergency callback mode | 
|  | 6197 | * @param subId sub id | 
|  | 6198 | */ | 
| goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6199 | @Override | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6200 | public boolean getEmergencyCallbackMode(int subId) { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6201 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6202 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6203 |  | 
|  | 6204 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6205 | try { | 
|  | 6206 | if (phone != null) { | 
|  | 6207 | return phone.isInEcm(); | 
|  | 6208 | } else { | 
|  | 6209 | return false; | 
|  | 6210 | } | 
|  | 6211 | } finally { | 
|  | 6212 | Binder.restoreCallingIdentity(identity); | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6213 | } | 
|  | 6214 | } | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6215 |  | 
|  | 6216 | /** | 
|  | 6217 | * Get the current signal strength information for the given subscription. | 
|  | 6218 | * Because this information is not updated when the device is in a low power state | 
|  | 6219 | * it should not be relied-upon to be current. | 
|  | 6220 | * @param subId Subscription index | 
|  | 6221 | * @return the most recent cached signal strength info from the modem | 
|  | 6222 | */ | 
|  | 6223 | @Override | 
|  | 6224 | public SignalStrength getSignalStrength(int subId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6225 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6226 | try { | 
|  | 6227 | Phone p = getPhone(subId); | 
|  | 6228 | if (p == null) { | 
|  | 6229 | return null; | 
|  | 6230 | } | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6231 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6232 | return p.getSignalStrength(); | 
|  | 6233 | } finally { | 
|  | 6234 | Binder.restoreCallingIdentity(identity); | 
|  | 6235 | } | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6236 | } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6237 |  | 
| Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6238 | /** | 
| chen xu | 907e5a2 | 2018-10-11 13:21:04 -0700 | [diff] [blame] | 6239 | * Get the current modem radio state for the given slot. | 
|  | 6240 | * @param slotIndex slot index. | 
|  | 6241 | * @param callingPackage the name of the package making the call. | 
|  | 6242 | * @return the current radio power state from the modem | 
|  | 6243 | */ | 
|  | 6244 | @Override | 
|  | 6245 | public int getRadioPowerState(int slotIndex, String callingPackage) { | 
|  | 6246 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 6247 | if (phone != null) { | 
|  | 6248 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 6249 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { | 
|  | 6250 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; | 
|  | 6251 | } | 
|  | 6252 |  | 
|  | 6253 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6254 | try { | 
|  | 6255 | return phone.getRadioPowerState(); | 
|  | 6256 | } finally { | 
|  | 6257 | Binder.restoreCallingIdentity(identity); | 
|  | 6258 | } | 
|  | 6259 | } | 
|  | 6260 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; | 
|  | 6261 | } | 
|  | 6262 |  | 
|  | 6263 | /** | 
| Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6264 | * Checks if data roaming is enabled on the subscription with id {@code subId}. | 
|  | 6265 | * | 
|  | 6266 | * <p>Requires one of the following permissions: | 
|  | 6267 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, | 
|  | 6268 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier | 
|  | 6269 | * privileges. | 
|  | 6270 | * | 
|  | 6271 | * @param subId subscription id | 
|  | 6272 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return | 
|  | 6273 | * {@code false}. | 
|  | 6274 | */ | 
|  | 6275 | @Override | 
|  | 6276 | public boolean isDataRoamingEnabled(int subId) { | 
| Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6277 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, | 
|  | 6278 | null /* message */); | 
|  | 6279 |  | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6280 | boolean isEnabled = false; | 
|  | 6281 | final long identity = Binder.clearCallingIdentity(); | 
| Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6282 | try { | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6283 | Phone phone = getPhone(subId); | 
|  | 6284 | isEnabled =  phone != null ? phone.getDataRoamingEnabled() : false; | 
| Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6285 | } catch (Exception e) { | 
|  | 6286 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( | 
|  | 6287 | mApp, subId, "isDataRoamingEnabled"); | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6288 | } finally { | 
|  | 6289 | Binder.restoreCallingIdentity(identity); | 
| Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6290 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6291 | return isEnabled; | 
| Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6292 | } | 
|  | 6293 |  | 
|  | 6294 |  | 
|  | 6295 | /** | 
|  | 6296 | * Enables/Disables the data roaming on the subscription with id {@code subId}. | 
|  | 6297 | * | 
|  | 6298 | * <p> Requires permission: | 
|  | 6299 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier | 
|  | 6300 | * privileges. | 
|  | 6301 | * | 
|  | 6302 | * @param subId subscription id | 
|  | 6303 | * @param isEnabled {@code true} means enable, {@code false} means disable. | 
|  | 6304 | */ | 
|  | 6305 | @Override | 
|  | 6306 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { | 
| Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6307 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6308 | mApp, subId, "setDataRoamingEnabled"); | 
|  | 6309 |  | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6310 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6311 | try { | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6312 | Phone phone = getPhone(subId); | 
|  | 6313 | if (phone != null) { | 
|  | 6314 | phone.setDataRoamingEnabled(isEnabled); | 
|  | 6315 | } | 
|  | 6316 | } finally { | 
|  | 6317 | Binder.restoreCallingIdentity(identity); | 
| Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6318 | } | 
|  | 6319 | } | 
|  | 6320 |  | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6321 | @Override | 
| Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6322 | public boolean isManualNetworkSelectionAllowed(int subId) { | 
| Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6323 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( | 
|  | 6324 | mApp, subId, "isManualNetworkSelectionAllowed"); | 
|  | 6325 |  | 
| Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6326 | boolean isAllowed = true; | 
|  | 6327 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6328 | try { | 
| Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6329 | Phone phone = getPhone(subId); | 
|  | 6330 | if (phone != null) { | 
|  | 6331 | isAllowed = phone.isCspPlmnEnabled(); | 
|  | 6332 | } | 
|  | 6333 | } finally { | 
|  | 6334 | Binder.restoreCallingIdentity(identity); | 
|  | 6335 | } | 
|  | 6336 | return isAllowed; | 
|  | 6337 | } | 
|  | 6338 |  | 
|  | 6339 | @Override | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6340 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { | 
| Jordan Liu | 6799795 | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6341 | boolean hasReadPermission = false; | 
| Jordan Liu | 53fdb78 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6342 | try { | 
|  | 6343 | enforceReadPrivilegedPermission("getUiccCardsInfo"); | 
| Jordan Liu | 6799795 | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6344 | hasReadPermission = true; | 
| Jordan Liu | 53fdb78 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6345 | } catch (SecurityException e) { | 
|  | 6346 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller | 
|  | 6347 | // has carrier privileges on an active UICC | 
|  | 6348 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) | 
|  | 6349 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
| Jordan Liu | 6799795 | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6350 | throw new SecurityException("Caller does not have permission."); | 
| Jordan Liu | 53fdb78 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6351 | } | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6352 | } | 
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6353 |  | 
|  | 6354 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6355 | try { | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6356 | UiccController uiccController = UiccController.getInstance(); | 
|  | 6357 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); | 
| Jordan Liu | 6799795 | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6358 | if (hasReadPermission) { | 
|  | 6359 | return cardInfos; | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6360 | } | 
| Jordan Liu | 6799795 | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6361 |  | 
|  | 6362 | // Remove private info if the caller doesn't have access | 
|  | 6363 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); | 
|  | 6364 | for (UiccCardInfo cardInfo : cardInfos) { | 
|  | 6365 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo | 
|  | 6366 | // is available | 
|  | 6367 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); | 
|  | 6368 | if (card == null || card.getUiccProfile() == null) { | 
|  | 6369 | // assume no access if the card or profile is unavailable | 
|  | 6370 | filteredInfos.add(cardInfo.getUnprivileged()); | 
|  | 6371 | continue; | 
|  | 6372 | } | 
|  | 6373 | UiccProfile profile = card.getUiccProfile(); | 
|  | 6374 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) | 
|  | 6375 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
|  | 6376 | filteredInfos.add(cardInfo); | 
|  | 6377 | } else { | 
|  | 6378 | filteredInfos.add(cardInfo.getUnprivileged()); | 
|  | 6379 | } | 
|  | 6380 | } | 
|  | 6381 | return filteredInfos; | 
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6382 | } finally { | 
|  | 6383 | Binder.restoreCallingIdentity(identity); | 
|  | 6384 | } | 
|  | 6385 | } | 
|  | 6386 |  | 
|  | 6387 | @Override | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6388 | public UiccSlotInfo[] getUiccSlotsInfo() { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6389 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6390 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6391 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6392 | try { | 
|  | 6393 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); | 
|  | 6394 | if (slots == null) { | 
|  | 6395 | Rlog.i(LOG_TAG, "slots is null."); | 
|  | 6396 | return null; | 
|  | 6397 | } | 
|  | 6398 |  | 
|  | 6399 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; | 
|  | 6400 | for (int i = 0; i < slots.length; i++) { | 
|  | 6401 | UiccSlot slot = slots[i]; | 
|  | 6402 | if (slot == null) { | 
|  | 6403 | continue; | 
|  | 6404 | } | 
|  | 6405 |  | 
|  | 6406 | String cardId; | 
|  | 6407 | UiccCard card = slot.getUiccCard(); | 
|  | 6408 | if (card != null) { | 
|  | 6409 | cardId = card.getCardId(); | 
|  | 6410 | } else { | 
|  | 6411 | cardId = slot.getIccId(); | 
|  | 6412 | } | 
|  | 6413 |  | 
| Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 6414 | if (cardId != null) { | 
|  | 6415 | // if cardId is an ICCID, strip off trailing Fs before exposing to user | 
|  | 6416 | // if cardId is an EID, it's all digits so this is fine | 
|  | 6417 | cardId = IccUtils.stripTrailingFs(cardId); | 
|  | 6418 | } | 
|  | 6419 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6420 | int cardState = 0; | 
|  | 6421 | switch (slot.getCardState()) { | 
|  | 6422 | case CARDSTATE_ABSENT: | 
|  | 6423 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; | 
|  | 6424 | break; | 
|  | 6425 | case CARDSTATE_PRESENT: | 
|  | 6426 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; | 
|  | 6427 | break; | 
|  | 6428 | case CARDSTATE_ERROR: | 
|  | 6429 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; | 
|  | 6430 | break; | 
|  | 6431 | case CARDSTATE_RESTRICTED: | 
|  | 6432 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; | 
|  | 6433 | break; | 
|  | 6434 | default: | 
|  | 6435 | break; | 
|  | 6436 |  | 
|  | 6437 | } | 
|  | 6438 |  | 
|  | 6439 | infos[i] = new UiccSlotInfo( | 
|  | 6440 | slot.isActive(), | 
|  | 6441 | slot.isEuicc(), | 
|  | 6442 | cardId, | 
|  | 6443 | cardState, | 
|  | 6444 | slot.getPhoneId(), | 
| Jordan Liu | ef65d87 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6445 | slot.isExtendedApduSupported(), | 
|  | 6446 | slot.isRemovable()); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6447 | } | 
|  | 6448 | return infos; | 
|  | 6449 | } finally { | 
|  | 6450 | Binder.restoreCallingIdentity(identity); | 
| Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6451 | } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6452 | } | 
|  | 6453 |  | 
|  | 6454 | @Override | 
|  | 6455 | public boolean switchSlots(int[] physicalSlots) { | 
|  | 6456 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6457 |  | 
|  | 6458 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6459 | try { | 
|  | 6460 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); | 
|  | 6461 | } finally { | 
|  | 6462 | Binder.restoreCallingIdentity(identity); | 
|  | 6463 | } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6464 | } | 
| Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6465 |  | 
|  | 6466 | @Override | 
| Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6467 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { | 
| Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6468 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6469 | try { | 
|  | 6470 | return UiccController.getInstance().getCardIdForDefaultEuicc(); | 
|  | 6471 | } finally { | 
|  | 6472 | Binder.restoreCallingIdentity(identity); | 
|  | 6473 | } | 
|  | 6474 | } | 
|  | 6475 |  | 
|  | 6476 | @Override | 
| Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6477 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { | 
|  | 6478 | enforceModifyPermission(); | 
|  | 6479 | final Phone phone = getPhone(subId); | 
|  | 6480 | if (phone == null) { | 
|  | 6481 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); | 
|  | 6482 | return; | 
|  | 6483 | } | 
|  | 6484 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6485 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6486 | try { | 
|  | 6487 | phone.setRadioIndicationUpdateMode(filters, mode); | 
|  | 6488 | } finally { | 
|  | 6489 | Binder.restoreCallingIdentity(identity); | 
|  | 6490 | } | 
| Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6491 | } | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6492 |  | 
|  | 6493 | /** | 
| goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6494 | * A test API to reload the UICC profile. | 
|  | 6495 | * | 
|  | 6496 | * <p>Requires that the calling app has permission | 
|  | 6497 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. | 
|  | 6498 | * @hide | 
|  | 6499 | */ | 
|  | 6500 | @Override | 
|  | 6501 | public void refreshUiccProfile(int subId) { | 
|  | 6502 | enforceModifyPermission(); | 
|  | 6503 |  | 
|  | 6504 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6505 | try { | 
|  | 6506 | Phone phone = getPhone(subId); | 
|  | 6507 | if (phone == null) { | 
|  | 6508 | return; | 
|  | 6509 | } | 
|  | 6510 | UiccCard uiccCard = phone.getUiccCard(); | 
|  | 6511 | if (uiccCard == null) { | 
|  | 6512 | return; | 
|  | 6513 | } | 
|  | 6514 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); | 
|  | 6515 | if (uiccProfile == null) { | 
|  | 6516 | return; | 
|  | 6517 | } | 
|  | 6518 | uiccProfile.refresh(); | 
|  | 6519 | } finally { | 
|  | 6520 | Binder.restoreCallingIdentity(identity); | 
|  | 6521 | } | 
|  | 6522 | } | 
|  | 6523 |  | 
|  | 6524 | /** | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6525 | * Returns false if the mobile data is disabled by default, otherwise return true. | 
|  | 6526 | */ | 
|  | 6527 | private boolean getDefaultDataEnabled() { | 
|  | 6528 | return "true".equalsIgnoreCase( | 
|  | 6529 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); | 
|  | 6530 | } | 
|  | 6531 |  | 
|  | 6532 | /** | 
|  | 6533 | * Returns true if the data roaming is enabled by default, i.e the system property | 
|  | 6534 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of | 
|  | 6535 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. | 
|  | 6536 | */ | 
|  | 6537 | private boolean getDefaultDataRoamingEnabled(int subId) { | 
|  | 6538 | final CarrierConfigManager configMgr = (CarrierConfigManager) | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6539 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6540 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( | 
|  | 6541 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); | 
|  | 6542 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( | 
|  | 6543 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); | 
|  | 6544 | return isDataRoamingEnabled; | 
|  | 6545 | } | 
|  | 6546 |  | 
|  | 6547 | /** | 
|  | 6548 | * Returns the default network type for the given {@code subId}, if the default network type is | 
|  | 6549 | * not set, return {@link Phone#PREFERRED_NT_MODE}. | 
|  | 6550 | */ | 
|  | 6551 | private int getDefaultNetworkType(int subId) { | 
|  | 6552 | return Integer.parseInt( | 
|  | 6553 | TelephonyManager.getTelephonyProperty( | 
|  | 6554 | mSubscriptionController.getPhoneId(subId), | 
|  | 6555 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, | 
|  | 6556 | String.valueOf(Phone.PREFERRED_NT_MODE))); | 
|  | 6557 | } | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6558 |  | 
|  | 6559 | @Override | 
|  | 6560 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String | 
|  | 6561 | gid1, String gid2, String plmn, String spn) { | 
|  | 6562 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6563 |  | 
|  | 6564 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6565 | try { | 
|  | 6566 | final Phone phone = getPhone(subId); | 
|  | 6567 | if (phone == null) { | 
|  | 6568 | loge("setCarrierTestOverride fails with invalid subId: " + subId); | 
|  | 6569 | return; | 
|  | 6570 | } | 
|  | 6571 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn); | 
|  | 6572 | } finally { | 
|  | 6573 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6574 | } | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6575 | } | 
|  | 6576 |  | 
|  | 6577 | @Override | 
|  | 6578 | public int getCarrierIdListVersion(int subId) { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6579 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6580 |  | 
|  | 6581 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6582 | try { | 
|  | 6583 | final Phone phone = getPhone(subId); | 
|  | 6584 | if (phone == null) { | 
|  | 6585 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); | 
|  | 6586 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; | 
|  | 6587 | } | 
|  | 6588 | return phone.getCarrierIdListVersion(); | 
|  | 6589 | } finally { | 
|  | 6590 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6591 | } | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6592 | } | 
| Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6593 |  | 
|  | 6594 | @Override | 
|  | 6595 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { | 
|  | 6596 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 6597 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { | 
|  | 6598 | return -1; | 
|  | 6599 | } | 
|  | 6600 |  | 
|  | 6601 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6602 | try { | 
|  | 6603 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); | 
|  | 6604 | } finally { | 
|  | 6605 | Binder.restoreCallingIdentity(identity); | 
|  | 6606 | } | 
|  | 6607 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6608 |  | 
|  | 6609 | @Override | 
|  | 6610 | public int getCdmaRoamingMode(int subId) { | 
|  | 6611 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6612 | mApp, subId, "getCdmaRoamingMode"); | 
|  | 6613 |  | 
|  | 6614 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6615 | try { | 
|  | 6616 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); | 
|  | 6617 | } finally { | 
|  | 6618 | Binder.restoreCallingIdentity(identity); | 
|  | 6619 | } | 
|  | 6620 | } | 
|  | 6621 |  | 
|  | 6622 | @Override | 
|  | 6623 | public boolean setCdmaRoamingMode(int subId, int mode) { | 
|  | 6624 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6625 | mApp, subId, "setCdmaRoamingMode"); | 
|  | 6626 |  | 
|  | 6627 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6628 | try { | 
|  | 6629 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); | 
|  | 6630 | } finally { | 
|  | 6631 | Binder.restoreCallingIdentity(identity); | 
|  | 6632 | } | 
|  | 6633 | } | 
|  | 6634 |  | 
|  | 6635 | @Override | 
|  | 6636 | public boolean setCdmaSubscriptionMode(int subId, int mode) { | 
|  | 6637 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6638 | mApp, subId, "setCdmaSubscriptionMode"); | 
|  | 6639 |  | 
|  | 6640 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6641 | try { | 
|  | 6642 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); | 
|  | 6643 | } finally { | 
|  | 6644 | Binder.restoreCallingIdentity(identity); | 
|  | 6645 | } | 
|  | 6646 | } | 
| chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6647 |  | 
| sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 6648 | private void ensureUserRunning(int userId) { | 
|  | 6649 | if (!mUserManager.isUserRunning(userId)) { | 
|  | 6650 | throw new IllegalStateException("User " + userId + " does not exist or not running"); | 
|  | 6651 | } | 
|  | 6652 | } | 
|  | 6653 |  | 
|  | 6654 | /** | 
|  | 6655 | * Returns a list of SMS apps on a given user. | 
|  | 6656 | * | 
|  | 6657 | * Only the shell user (UID 2000 or 0) can call it. | 
|  | 6658 | * Target user must be running. | 
|  | 6659 | */ | 
|  | 6660 | @Override | 
|  | 6661 | public String[] getSmsApps(int userId) { | 
|  | 6662 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); | 
|  | 6663 | ensureUserRunning(userId); | 
|  | 6664 |  | 
|  | 6665 | final Collection<SmsApplicationData> apps = | 
|  | 6666 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); | 
|  | 6667 |  | 
|  | 6668 | String[] ret = new String[apps.size()]; | 
|  | 6669 | int i = 0; | 
|  | 6670 | for (SmsApplicationData app : apps) { | 
|  | 6671 | ret[i++] = app.mPackageName; | 
|  | 6672 | } | 
|  | 6673 | return ret; | 
|  | 6674 | } | 
|  | 6675 |  | 
|  | 6676 | /** | 
|  | 6677 | * Returns the default SMS app package name on a given user. | 
|  | 6678 | * | 
|  | 6679 | * Only the shell user (UID 2000 or 0) can call it. | 
|  | 6680 | * Target user must be running. | 
|  | 6681 | */ | 
|  | 6682 | @Override | 
|  | 6683 | public String getDefaultSmsApp(int userId) { | 
|  | 6684 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); | 
|  | 6685 | ensureUserRunning(userId); | 
|  | 6686 |  | 
|  | 6687 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, | 
|  | 6688 | /* updateIfNeeded= */ true, userId); | 
|  | 6689 | return cn == null ? null : cn.getPackageName(); | 
|  | 6690 | } | 
|  | 6691 |  | 
|  | 6692 | /** | 
|  | 6693 | * Set a package as the default SMS app on a given user. | 
|  | 6694 | * | 
|  | 6695 | * Only the shell user (UID 2000 or 0) can call it. | 
|  | 6696 | * Target user must be running. | 
|  | 6697 | */ | 
|  | 6698 | @Override | 
|  | 6699 | public void setDefaultSmsApp(int userId, String packageName) { | 
|  | 6700 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); | 
|  | 6701 | ensureUserRunning(userId); | 
|  | 6702 |  | 
|  | 6703 | boolean found = false; | 
|  | 6704 | for (String pkg : getSmsApps(userId)) { | 
|  | 6705 | if (TextUtils.equals(packageName, pkg)) { | 
|  | 6706 | found = true; | 
|  | 6707 | break; | 
|  | 6708 | } | 
|  | 6709 | } | 
|  | 6710 | if (!found) { | 
|  | 6711 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); | 
|  | 6712 | } | 
|  | 6713 |  | 
|  | 6714 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); | 
|  | 6715 | } | 
|  | 6716 |  | 
| chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6717 | @Override | 
| sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6718 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( | 
| sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6719 | String callingPackage) { | 
| sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6720 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6721 | mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) { | 
| sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6722 | throw new SecurityException("Requires READ_PHONE_STATE permission."); | 
|  | 6723 | } | 
|  | 6724 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6725 | try { | 
| sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6726 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); | 
|  | 6727 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 6728 | if (phone.getEmergencyNumberTracker() != null | 
|  | 6729 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { | 
|  | 6730 | emergencyNumberListInternal.put( | 
|  | 6731 | phone.getSubId(), | 
|  | 6732 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); | 
|  | 6733 | } | 
| sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6734 | } | 
| sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6735 | return emergencyNumberListInternal; | 
| sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6736 | } finally { | 
|  | 6737 | Binder.restoreCallingIdentity(identity); | 
|  | 6738 | } | 
| sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6739 | } | 
|  | 6740 |  | 
|  | 6741 | @Override | 
| sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6742 | public boolean isEmergencyNumber(String number, boolean exactMatch) { | 
| sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6743 | final Phone defaultPhone = getDefaultPhone(); | 
|  | 6744 | if (!exactMatch) { | 
|  | 6745 | TelephonyPermissions | 
|  | 6746 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
| sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6747 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); | 
| sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6748 | } | 
|  | 6749 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6750 | try { | 
| sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6751 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 6752 | if (phone.getEmergencyNumberTracker() != null | 
|  | 6753 | && phone.getEmergencyNumberTracker() != null) { | 
|  | 6754 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( | 
|  | 6755 | number, exactMatch)) { | 
|  | 6756 | return true; | 
| sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6757 | } | 
|  | 6758 | } | 
| sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6759 | } | 
|  | 6760 | return false; | 
|  | 6761 | } finally { | 
|  | 6762 | Binder.restoreCallingIdentity(identity); | 
|  | 6763 | } | 
|  | 6764 | } | 
|  | 6765 |  | 
| sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6766 | /** | 
|  | 6767 | * Update emergency number list for test mode. | 
|  | 6768 | */ | 
|  | 6769 | @Override | 
|  | 6770 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { | 
|  | 6771 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 6772 | "updateEmergencyNumberListTestMode"); | 
|  | 6773 |  | 
|  | 6774 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6775 | try { | 
|  | 6776 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 6777 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
|  | 6778 | if (tracker != null) { | 
|  | 6779 | tracker.executeEmergencyNumberTestModeCommand(action, num); | 
|  | 6780 | } | 
|  | 6781 | } | 
|  | 6782 | } finally { | 
|  | 6783 | Binder.restoreCallingIdentity(identity); | 
|  | 6784 | } | 
|  | 6785 | } | 
|  | 6786 |  | 
|  | 6787 | /** | 
|  | 6788 | * Get the full emergency number list for test mode. | 
|  | 6789 | */ | 
|  | 6790 | @Override | 
|  | 6791 | public List<String> getEmergencyNumberListTestMode() { | 
|  | 6792 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 6793 | "getEmergencyNumberListTestMode"); | 
|  | 6794 |  | 
|  | 6795 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6796 | try { | 
|  | 6797 | Set<String> emergencyNumbers = new HashSet<>(); | 
|  | 6798 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 6799 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
|  | 6800 | if (tracker != null) { | 
|  | 6801 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { | 
|  | 6802 | emergencyNumbers.add(num.getNumber()); | 
|  | 6803 | } | 
|  | 6804 | } | 
|  | 6805 | } | 
|  | 6806 | return new ArrayList<>(emergencyNumbers); | 
|  | 6807 | } finally { | 
|  | 6808 | Binder.restoreCallingIdentity(identity); | 
|  | 6809 | } | 
|  | 6810 | } | 
|  | 6811 |  | 
| sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6812 | @Override | 
| chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6813 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { | 
|  | 6814 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); | 
|  | 6815 | Phone phone = getPhone(subId); | 
|  | 6816 | if (phone == null) { | 
|  | 6817 | return null; | 
|  | 6818 | } | 
|  | 6819 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6820 | try { | 
|  | 6821 | UiccProfile profile = UiccController.getInstance() | 
|  | 6822 | .getUiccProfileForPhone(phone.getPhoneId()); | 
|  | 6823 | if (profile != null) { | 
|  | 6824 | return profile.getCertsFromCarrierPrivilegeAccessRules(); | 
|  | 6825 | } | 
|  | 6826 | } finally { | 
|  | 6827 | Binder.restoreCallingIdentity(identity); | 
|  | 6828 | } | 
|  | 6829 | return null; | 
|  | 6830 | } | 
| Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6831 |  | 
|  | 6832 | /** | 
|  | 6833 | * Enable or disable a modem stack. | 
|  | 6834 | */ | 
|  | 6835 | @Override | 
|  | 6836 | public boolean enableModemForSlot(int slotIndex, boolean enable) { | 
|  | 6837 | enforceModifyPermission(); | 
|  | 6838 |  | 
|  | 6839 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6840 | try { | 
|  | 6841 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 6842 | if (phone == null) { | 
|  | 6843 | return false; | 
|  | 6844 | } else { | 
|  | 6845 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); | 
|  | 6846 | } | 
|  | 6847 | } finally { | 
|  | 6848 | Binder.restoreCallingIdentity(identity); | 
|  | 6849 | } | 
|  | 6850 | } | 
| Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6851 |  | 
| Malcolm Chen | 33f55e1 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 6852 | /** | 
|  | 6853 | * Whether a modem stack is enabled or not. | 
|  | 6854 | */ | 
|  | 6855 | @Override | 
|  | 6856 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) { | 
|  | 6857 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 6858 | if (phone == null) return false; | 
|  | 6859 |  | 
|  | 6860 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 6861 | mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) { | 
|  | 6862 | throw new SecurityException("Requires READ_PHONE_STATE permission."); | 
|  | 6863 | } | 
|  | 6864 |  | 
|  | 6865 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6866 | try { | 
| Nazanin Bakhshi | 1f78d7d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 6867 | try { | 
|  | 6868 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); | 
|  | 6869 | } catch (NoSuchElementException ex) { | 
|  | 6870 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); | 
|  | 6871 | } | 
| Malcolm Chen | 33f55e1 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 6872 | } finally { | 
|  | 6873 | Binder.restoreCallingIdentity(identity); | 
|  | 6874 | } | 
|  | 6875 | } | 
|  | 6876 |  | 
| Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6877 | @Override | 
| Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6878 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { | 
| Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6879 | enforceModifyPermission(); | 
|  | 6880 |  | 
|  | 6881 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6882 | try { | 
|  | 6883 | mTelephonySharedPreferences.edit() | 
| Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6884 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) | 
| Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6885 | .commit(); | 
|  | 6886 | } finally { | 
|  | 6887 | Binder.restoreCallingIdentity(identity); | 
|  | 6888 | } | 
|  | 6889 | } | 
|  | 6890 |  | 
|  | 6891 | @Override | 
| Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6892 | @TelephonyManager.IsMultiSimSupportedResult | 
|  | 6893 | public int isMultiSimSupported(String callingPackage) { | 
| Michele | bcb01bc | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6894 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, | 
| Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6895 | getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) { | 
|  | 6896 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; | 
| Michele | bcb01bc | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6897 | } | 
| Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6898 |  | 
|  | 6899 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6900 | try { | 
| Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6901 | return isMultiSimSupportedInternal(); | 
| Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6902 | } finally { | 
|  | 6903 | Binder.restoreCallingIdentity(identity); | 
|  | 6904 | } | 
|  | 6905 | } | 
| Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6906 |  | 
| Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6907 | @TelephonyManager.IsMultiSimSupportedResult | 
|  | 6908 | private int isMultiSimSupportedInternal() { | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6909 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. | 
|  | 6910 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; | 
|  | 6911 | if (numPhysicalSlots < 2) { | 
| Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6912 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); | 
|  | 6913 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6914 | } | 
|  | 6915 | // Check if the hardware supports multisim functionality. If usage of multisim is not | 
|  | 6916 | // supported by the modem, indicate that it is restricted. | 
|  | 6917 | PhoneCapability staticCapability = | 
|  | 6918 | mPhoneConfigurationManager.getStaticPhoneCapability(); | 
|  | 6919 | if (staticCapability == null) { | 
| Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6920 | loge("isMultiSimSupportedInternal: no static configuration available"); | 
|  | 6921 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6922 | } | 
|  | 6923 | if (staticCapability.logicalModemList.size() < 2) { | 
| Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6924 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); | 
|  | 6925 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6926 | } | 
|  | 6927 | // Check if support of multiple SIMs is restricted by carrier | 
|  | 6928 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { | 
| Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6929 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6930 | } | 
|  | 6931 |  | 
| Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6932 | return TelephonyManager.MULTISIM_ALLOWED; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6933 | } | 
|  | 6934 |  | 
| Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6935 | /** | 
|  | 6936 | * Switch configs to enable multi-sim or switch back to single-sim | 
| Nazanin Bakhshi | 814dc22 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6937 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE | 
|  | 6938 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE | 
|  | 6939 | * or carrier privileges | 
| Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6940 | * @param numOfSims number of active sims we want to switch to | 
|  | 6941 | */ | 
|  | 6942 | @Override | 
|  | 6943 | public void switchMultiSimConfig(int numOfSims) { | 
| Nazanin Bakhshi | 814dc22 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6944 | if (numOfSims == 1) { | 
|  | 6945 | enforceModifyPermission(); | 
|  | 6946 | } else { | 
|  | 6947 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6948 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); | 
|  | 6949 | } | 
| Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6950 | final long identity = Binder.clearCallingIdentity(); | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6951 |  | 
| Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6952 | try { | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6953 | //only proceed if multi-sim is not restricted | 
| Michele | 2fb0f22 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6954 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6955 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); | 
|  | 6956 | return; | 
|  | 6957 | } | 
| Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6958 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); | 
|  | 6959 | } finally { | 
|  | 6960 | Binder.restoreCallingIdentity(identity); | 
|  | 6961 | } | 
|  | 6962 | } | 
|  | 6963 |  | 
|  | 6964 | /** | 
| Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6965 | * Get whether reboot is required or not after making changes to modem configurations. | 
| Nazanin Bakhshi | 4a68f5f | 2019-02-08 14:31:19 -0800 | [diff] [blame] | 6966 | * Return value defaults to true | 
| Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6967 | */ | 
|  | 6968 | @Override | 
|  | 6969 | public boolean isRebootRequiredForModemConfigChange() { | 
|  | 6970 | enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange"); | 
|  | 6971 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6972 | try { | 
|  | 6973 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); | 
|  | 6974 | } finally { | 
|  | 6975 | Binder.restoreCallingIdentity(identity); | 
|  | 6976 | } | 
|  | 6977 | } | 
|  | 6978 |  | 
| Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 6979 | private void updateModemStateMetrics() { | 
|  | 6980 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); | 
|  | 6981 | // TODO: check the state for each modem if the api is ready. | 
|  | 6982 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); | 
|  | 6983 | } | 
|  | 6984 |  | 
| Pengquan Meng | 3aceaec | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 6985 | @Override | 
|  | 6986 | public int[] getSlotsMapping() { | 
|  | 6987 | enforceReadPrivilegedPermission("getSlotsMapping"); | 
|  | 6988 |  | 
|  | 6989 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6990 | try { | 
|  | 6991 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); | 
|  | 6992 | // All logical slots should have a mapping to a physical slot. | 
|  | 6993 | int[] logicalSlotsMapping = new int[phoneCount]; | 
|  | 6994 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); | 
|  | 6995 | for (int i = 0; i < slotInfos.length; i++) { | 
|  | 6996 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { | 
|  | 6997 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; | 
|  | 6998 | } | 
|  | 6999 | } | 
|  | 7000 | return logicalSlotsMapping; | 
|  | 7001 | } finally { | 
|  | 7002 | Binder.restoreCallingIdentity(identity); | 
|  | 7003 | } | 
|  | 7004 | } | 
| Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 7005 |  | 
|  | 7006 | /** | 
|  | 7007 | * Get the IRadio HAL Version | 
|  | 7008 | */ | 
|  | 7009 | @Override | 
|  | 7010 | public int getRadioHalVersion() { | 
|  | 7011 | Phone phone = getDefaultPhone(); | 
|  | 7012 | if (phone == null) return -1; | 
|  | 7013 | HalVersion hv = phone.getHalVersion(); | 
|  | 7014 | if (hv.equals(HalVersion.UNKNOWN)) return -1; | 
|  | 7015 | return hv.major * 100 + hv.minor; | 
|  | 7016 | } | 
| Malcolm Chen | 460810d | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7017 |  | 
|  | 7018 | /** | 
| Malcolm Chen | 2973969 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7019 | * Return whether data is enabled for certain APN type. This will tell if framework will accept | 
|  | 7020 | * corresponding network requests on a subId. | 
|  | 7021 | * | 
|  | 7022 | *  Data is enabled if: | 
| Malcolm Chen | 460810d | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7023 | *  1) user data is turned on, or | 
| Malcolm Chen | 2973969 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7024 | *  2) APN is un-metered for this subscription, or | 
|  | 7025 | *  3) APN type is whitelisted. E.g. MMS is whitelisted if | 
|  | 7026 | *  {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. | 
|  | 7027 | * | 
|  | 7028 | * @return whether data is allowed for a apn type. | 
|  | 7029 | * | 
|  | 7030 | * @hide | 
| Malcolm Chen | 460810d | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7031 | */ | 
|  | 7032 | @Override | 
| Malcolm Chen | 2973969 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7033 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { | 
| Malcolm Chen | 460810d | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7034 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Malcolm Chen | 2973969 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7035 | mApp, subId, callingPackage, "isDataEnabledForApn")) { | 
|  | 7036 | throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn"); | 
| Malcolm Chen | 460810d | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7037 | } | 
|  | 7038 |  | 
|  | 7039 | // Now that all security checks passes, perform the operation as ourselves. | 
|  | 7040 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7041 | try { | 
|  | 7042 | Phone phone = getPhone(subId); | 
|  | 7043 | if (phone == null) return false; | 
|  | 7044 |  | 
| Jack Yu | 40306fc | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7045 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); | 
| Malcolm Chen | 2973969 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7046 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); | 
|  | 7047 | } finally { | 
|  | 7048 | Binder.restoreCallingIdentity(identity); | 
|  | 7049 | } | 
|  | 7050 | } | 
|  | 7051 |  | 
|  | 7052 | @Override | 
| Jack Yu | 40306fc | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7053 | public boolean isApnMetered(@ApnType int apnType, int subId) { | 
| Malcolm Chen | 2973969 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7054 | enforceReadPrivilegedPermission("isApnMetered"); | 
|  | 7055 |  | 
|  | 7056 | // Now that all security checks passes, perform the operation as ourselves. | 
|  | 7057 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7058 | try { | 
|  | 7059 | Phone phone = getPhone(subId); | 
|  | 7060 | if (phone == null) return true; // By default return true. | 
|  | 7061 |  | 
| Jack Yu | 40306fc | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7062 | return ApnSettingUtils.isMeteredApnType(apnType, phone); | 
| Malcolm Chen | 460810d | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7063 | } finally { | 
|  | 7064 | Binder.restoreCallingIdentity(identity); | 
|  | 7065 | } | 
|  | 7066 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 7067 | } |