| 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; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 24 | import android.app.AppOpsManager; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 25 | import android.app.PendingIntent; | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 26 | import android.content.ComponentName; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.content.Context; | 
|  | 28 | import android.content.Intent; | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 29 | import android.content.SharedPreferences; | 
| Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 30 | import android.content.pm.ApplicationInfo; | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 31 | import android.content.pm.ComponentInfo; | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 32 | import android.content.pm.PackageInfo; | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 33 | import android.content.pm.PackageManager; | 
| Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 34 | import android.net.NetworkStats; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 35 | import android.net.Uri; | 
|  | 36 | import android.os.AsyncResult; | 
|  | 37 | import android.os.Binder; | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 38 | import android.os.Build; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 39 | import android.os.Bundle; | 
|  | 40 | import android.os.Handler; | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 41 | import android.os.IBinder; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Looper; | 
|  | 43 | import android.os.Message; | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.Messenger; | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 45 | import android.os.PersistableBundle; | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 46 | import android.os.RemoteException; | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 47 | import android.os.ResultReceiver; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 48 | import android.os.ServiceManager; | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 49 | import android.os.ShellCallback; | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 50 | import android.os.SystemProperties; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 51 | import android.os.UserHandle; | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 52 | import android.os.UserManager; | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 53 | import android.os.WorkSource; | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 54 | import android.preference.PreferenceManager; | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 55 | import android.provider.Settings; | 
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 56 | import android.telecom.PhoneAccount; | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 57 | import android.telecom.PhoneAccountHandle; | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 58 | import android.telecom.TelecomManager; | 
| Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 59 | import android.telephony.CarrierConfigManager; | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 60 | import android.telephony.CarrierRestrictionRules; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 61 | import android.telephony.CellInfo; | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 62 | import android.telephony.CellInfoGsm; | 
|  | 63 | import android.telephony.CellInfoWcdma; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 64 | import android.telephony.CellLocation; | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 65 | import android.telephony.ClientRequestStats; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 66 | import android.telephony.ICellInfoCallback; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 67 | import android.telephony.IccOpenLogicalChannelResponse; | 
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 68 | import android.telephony.LocationAccessPolicy; | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 69 | import android.telephony.ModemActivityInfo; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 70 | import android.telephony.NeighboringCellInfo; | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 71 | import android.telephony.NetworkScanRequest; | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 72 | import android.telephony.PhoneNumberRange; | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 73 | import android.telephony.RadioAccessFamily; | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 74 | import android.telephony.Rlog; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 75 | import android.telephony.ServiceState; | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 76 | import android.telephony.SignalStrength; | 
| Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 77 | import android.telephony.SmsManager; | 
| Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 78 | import android.telephony.SubscriptionInfo; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 79 | import android.telephony.SubscriptionManager; | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 80 | import android.telephony.TelephonyHistogram; | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 81 | import android.telephony.TelephonyManager; | 
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 82 | import android.telephony.UiccCardInfo; | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 83 | import android.telephony.UiccSlotInfo; | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 84 | import android.telephony.UssdResponse; | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 85 | import android.telephony.VisualVoicemailSmsFilterSettings; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 86 | import android.telephony.cdma.CdmaCellLocation; | 
| Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 87 | import android.telephony.data.ApnSetting; | 
| calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 88 | import android.telephony.emergency.EmergencyNumber; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 89 | import android.telephony.gsm.GsmCellLocation; | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 90 | import android.telephony.ims.ProvisioningManager; | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 91 | import android.telephony.ims.aidl.IImsCapabilityCallback; | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 92 | import android.telephony.ims.aidl.IImsConfig; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 93 | import android.telephony.ims.aidl.IImsConfigCallback; | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 94 | import android.telephony.ims.aidl.IImsMmTelFeature; | 
|  | 95 | import android.telephony.ims.aidl.IImsRcsFeature; | 
|  | 96 | import android.telephony.ims.aidl.IImsRegistration; | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 97 | import android.telephony.ims.aidl.IImsRegistrationCallback; | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 98 | import android.telephony.ims.feature.MmTelFeature; | 
|  | 99 | import android.telephony.ims.stub.ImsConfigImplBase; | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 100 | import android.telephony.ims.stub.ImsRegistrationImplBase; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 101 | import android.text.TextUtils; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 102 | import android.util.ArraySet; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 103 | import android.util.Log; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 104 | import android.util.Pair; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 105 | import android.util.Slog; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 106 |  | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 107 | import com.android.ims.ImsException; | 
| Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 108 | import com.android.ims.ImsManager; | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 109 | import com.android.ims.internal.IImsServiceFeatureCallback; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 110 | import com.android.internal.telephony.CallManager; | 
| Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 111 | import com.android.internal.telephony.CallStateException; | 
| pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 112 | import com.android.internal.telephony.CarrierInfoManager; | 
| chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 113 | import com.android.internal.telephony.CarrierResolver; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 114 | import com.android.internal.telephony.CellNetworkScanResult; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 115 | import com.android.internal.telephony.CommandException; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 116 | import com.android.internal.telephony.DefaultPhoneNotifier; | 
| Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 117 | import com.android.internal.telephony.HalVersion; | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 118 | import com.android.internal.telephony.INumberVerificationCallback; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 119 | import com.android.internal.telephony.ITelephony; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 120 | import com.android.internal.telephony.IccCard; | 
| Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 121 | import com.android.internal.telephony.LocaleTracker; | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 122 | import com.android.internal.telephony.MccTable; | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.NetworkScanRequestTracker; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.OperatorInfo; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.Phone; | 
| Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.PhoneConfigurationManager; | 
| Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 127 | import com.android.internal.telephony.PhoneConstantConversions; | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.PhoneConstants; | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.PhoneFactory; | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.ProxyController; | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.RIL; | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.RILConstants; | 
| Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.ServiceStateTracker; | 
| sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.SmsApplication; | 
|  | 135 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.SubscriptionController; | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 137 | import com.android.internal.telephony.TelephonyPermissions; | 
| sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.euicc.EuiccConnector; | 
| Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 140 | import com.android.internal.telephony.metrics.TelephonyMetrics; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.uicc.IccIoResult; | 
|  | 142 | import com.android.internal.telephony.uicc.IccUtils; | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.uicc.SIMRecords; | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.uicc.UiccCard; | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.uicc.UiccCardApplication; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.uicc.UiccController; | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 147 | import com.android.internal.telephony.uicc.UiccProfile; | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 148 | import com.android.internal.telephony.uicc.UiccSlot; | 
| fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 150 | import com.android.internal.util.HexDump; | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 151 | import com.android.phone.vvm.PhoneAccountHandleConverter; | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 152 | import com.android.phone.vvm.RemoteVvmTaskManager; | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 153 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; | 
| Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 154 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 155 |  | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 156 | import java.io.FileDescriptor; | 
|  | 157 | import java.io.PrintWriter; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 158 | import java.nio.charset.StandardCharsets; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 159 | import java.util.ArrayList; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 160 | import java.util.Arrays; | 
| sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 161 | import java.util.Collection; | 
| sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 162 | import java.util.HashMap; | 
| sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 163 | import java.util.HashSet; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 164 | import java.util.List; | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 165 | import java.util.Locale; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 166 | import java.util.Map; | 
| sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 167 | import java.util.Set; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 168 |  | 
|  | 169 | /** | 
|  | 170 | * Implementation of the ITelephony interface. | 
|  | 171 | */ | 
| Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 172 | public class PhoneInterfaceManager extends ITelephony.Stub { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 173 | private static final String LOG_TAG = "PhoneInterfaceManager"; | 
|  | 174 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); | 
|  | 175 | private static final boolean DBG_LOC = false; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 176 | private static final boolean DBG_MERGE = false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 177 |  | 
|  | 178 | // Message codes used with mMainThreadHandler | 
|  | 179 | private static final int CMD_HANDLE_PIN_MMI = 1; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 180 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; | 
|  | 181 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 182 | private static final int CMD_OPEN_CHANNEL = 9; | 
|  | 183 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; | 
|  | 184 | private static final int CMD_CLOSE_CHANNEL = 11; | 
|  | 185 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 186 | private static final int CMD_NV_READ_ITEM = 13; | 
|  | 187 | private static final int EVENT_NV_READ_ITEM_DONE = 14; | 
|  | 188 | private static final int CMD_NV_WRITE_ITEM = 15; | 
|  | 189 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; | 
|  | 190 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; | 
|  | 191 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 192 | private static final int CMD_RESET_MODEM_CONFIG = 19; | 
|  | 193 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 194 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; | 
|  | 195 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; | 
|  | 196 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; | 
|  | 197 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; | 
| Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 198 | private static final int CMD_SEND_ENVELOPE = 25; | 
|  | 199 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 200 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; | 
|  | 201 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; | 
| Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 202 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; | 
|  | 203 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; | 
|  | 204 | private static final int CMD_EXCHANGE_SIM_IO = 31; | 
|  | 205 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 206 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; | 
|  | 207 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 208 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; | 
|  | 209 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 210 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; | 
|  | 211 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 212 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; | 
|  | 213 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; | 
|  | 214 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; | 
|  | 215 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 216 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; | 
|  | 217 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; | 
|  | 218 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; | 
|  | 219 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 220 | private static final int CMD_HANDLE_USSD_REQUEST = 47; | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 221 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; | 
|  | 222 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 223 | private static final int CMD_SWITCH_SLOTS = 50; | 
|  | 224 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 225 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; | 
|  | 226 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; | 
|  | 227 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; | 
|  | 228 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; | 
|  | 229 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; | 
|  | 230 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; | 
|  | 231 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; | 
|  | 232 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 233 | private static final int CMD_GET_ALL_CELL_INFO = 60; | 
|  | 234 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; | 
|  | 235 | private static final int CMD_GET_CELL_LOCATION = 62; | 
|  | 236 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 237 | private static final int CMD_MODEM_REBOOT = 64; | 
|  | 238 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 239 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; | 
|  | 240 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; | 
| Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 241 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; | 
|  | 242 | private static final int EVENT_ENABLE_MODEM_DONE = 69; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 243 |  | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 244 | // Parameters of select command. | 
|  | 245 | private static final int SELECT_COMMAND = 0xA4; | 
|  | 246 | private static final int SELECT_P1 = 0x04; | 
|  | 247 | private static final int SELECT_P2 = 0; | 
|  | 248 | private static final int SELECT_P3 = 0x10; | 
|  | 249 |  | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 250 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; | 
|  | 251 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; | 
|  | 252 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; | 
|  | 253 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 254 | /** The singleton instance. */ | 
|  | 255 | private static PhoneInterfaceManager sInstance; | 
|  | 256 |  | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 257 | private PhoneGlobals mApp; | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 258 | private CallManager mCM; | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 259 | private UserManager mUserManager; | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 260 | private AppOpsManager mAppOps; | 
|  | 261 | private MainThreadHandler mMainThreadHandler; | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 262 | private SubscriptionController mSubscriptionController; | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 263 | private SharedPreferences mTelephonySharedPreferences; | 
| Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 264 | private PhoneConfigurationManager mPhoneConfigurationManager; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 265 |  | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 266 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; | 
|  | 267 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 268 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 269 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; | 
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 270 |  | 
| Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 271 | // String to store multi SIM allowed | 
|  | 272 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; | 
|  | 273 |  | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 274 | // The AID of ISD-R. | 
|  | 275 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; | 
|  | 276 |  | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 277 | private NetworkScanRequestTracker mNetworkScanRequestTracker; | 
|  | 278 |  | 
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 279 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; | 
|  | 280 | private static final int MANUFACTURER_CODE_LENGTH = 8; | 
|  | 281 |  | 
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 282 | /** | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 283 | * A request object to use for transmitting data to an ICC. | 
|  | 284 | */ | 
|  | 285 | private static final class IccAPDUArgument { | 
|  | 286 | public int channel, cla, command, p1, p2, p3; | 
|  | 287 | public String data; | 
|  | 288 |  | 
|  | 289 | public IccAPDUArgument(int channel, int cla, int command, | 
|  | 290 | int p1, int p2, int p3, String data) { | 
|  | 291 | this.channel = channel; | 
|  | 292 | this.cla = cla; | 
|  | 293 | this.command = command; | 
|  | 294 | this.p1 = p1; | 
|  | 295 | this.p2 = p2; | 
|  | 296 | this.p3 = p3; | 
|  | 297 | this.data = data; | 
|  | 298 | } | 
|  | 299 | } | 
|  | 300 |  | 
|  | 301 | /** | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 302 | * A request object to use for transmitting data to an ICC. | 
|  | 303 | */ | 
|  | 304 | private static final class ManualNetworkSelectionArgument { | 
|  | 305 | public OperatorInfo operatorInfo; | 
|  | 306 | public boolean persistSelection; | 
|  | 307 |  | 
|  | 308 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { | 
|  | 309 | this.operatorInfo = operatorInfo; | 
|  | 310 | this.persistSelection = persistSelection; | 
|  | 311 | } | 
|  | 312 | } | 
|  | 313 |  | 
|  | 314 | /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 315 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the | 
|  | 316 | * request after sending. The main thread will notify the request when it is complete. | 
|  | 317 | */ | 
|  | 318 | private static final class MainThreadRequest { | 
|  | 319 | /** The argument to use for the request */ | 
|  | 320 | public Object argument; | 
|  | 321 | /** The result of the request that is run on the main thread */ | 
|  | 322 | public Object result; | 
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 323 | // The subscriber id that this request applies to. Defaults to | 
|  | 324 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID | 
|  | 325 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 326 |  | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 327 | // In cases where subId is unavailable, the caller needs to specify the phone. | 
|  | 328 | public Phone phone; | 
|  | 329 |  | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 330 | public WorkSource workSource; | 
|  | 331 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 332 | public MainThreadRequest(Object argument) { | 
|  | 333 | this.argument = argument; | 
|  | 334 | } | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 335 |  | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 336 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { | 
|  | 337 | this.argument = argument; | 
|  | 338 | if (phone != null) { | 
|  | 339 | this.phone = phone; | 
|  | 340 | } | 
|  | 341 | this.workSource = workSource; | 
|  | 342 | } | 
|  | 343 |  | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 344 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 345 | this.argument = argument; | 
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 346 | if (subId != null) { | 
|  | 347 | this.subId = subId; | 
|  | 348 | } | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 349 | this.workSource = workSource; | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 350 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 351 | } | 
|  | 352 |  | 
| Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 353 | private static final class IncomingThirdPartyCallArgs { | 
|  | 354 | public final ComponentName component; | 
|  | 355 | public final String callId; | 
|  | 356 | public final String callerDisplayName; | 
|  | 357 |  | 
|  | 358 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, | 
|  | 359 | String callerDisplayName) { | 
|  | 360 | this.component = component; | 
|  | 361 | this.callId = callId; | 
|  | 362 | this.callerDisplayName = callerDisplayName; | 
|  | 363 | } | 
|  | 364 | } | 
|  | 365 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 366 | /** | 
|  | 367 | * A handler that processes messages on the main thread in the phone process. Since many | 
|  | 368 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the | 
|  | 369 | * inbound binder threads to the main thread in the phone process.  The Binder thread | 
|  | 370 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting | 
|  | 371 | * on, which will be notified when the operation completes and will contain the result of the | 
|  | 372 | * request. | 
|  | 373 | * | 
|  | 374 | * <p>If a MainThreadRequest object is provided in the msg.obj field, | 
|  | 375 | * note that request.result must be set to something non-null for the calling thread to | 
|  | 376 | * unblock. | 
|  | 377 | */ | 
|  | 378 | private final class MainThreadHandler extends Handler { | 
|  | 379 | @Override | 
|  | 380 | public void handleMessage(Message msg) { | 
|  | 381 | MainThreadRequest request; | 
|  | 382 | Message onCompleted; | 
|  | 383 | AsyncResult ar; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 384 | UiccCard uiccCard; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 385 | IccAPDUArgument iccArgument; | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 386 | final Phone defaultPhone = getDefaultPhone(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 387 |  | 
|  | 388 | switch (msg.what) { | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 389 | case CMD_HANDLE_USSD_REQUEST: { | 
|  | 390 | request = (MainThreadRequest) msg.obj; | 
|  | 391 | final Phone phone = getPhoneFromRequest(request); | 
|  | 392 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; | 
|  | 393 | String ussdRequest =  ussdObject.first; | 
|  | 394 | ResultReceiver wrappedCallback = ussdObject.second; | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 395 |  | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 396 | if (!isUssdApiAllowed(request.subId)) { | 
|  | 397 | // Carrier does not support use of this API, return failure. | 
|  | 398 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); | 
|  | 399 | UssdResponse response = new UssdResponse(ussdRequest, null); | 
|  | 400 | Bundle returnData = new Bundle(); | 
|  | 401 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); | 
|  | 402 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 403 |  | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 404 | request.result = true; | 
|  | 405 | notifyRequester(request); | 
|  | 406 | return; | 
|  | 407 | } | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 408 |  | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 409 | try { | 
|  | 410 | request.result = phone != null | 
|  | 411 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; | 
|  | 412 | } catch (CallStateException cse) { | 
|  | 413 | request.result = false; | 
|  | 414 | } | 
|  | 415 | // Wake up the requesting thread | 
|  | 416 | notifyRequester(request); | 
|  | 417 | break; | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 418 | } | 
|  | 419 |  | 
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 420 | case CMD_HANDLE_PIN_MMI: { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 421 | request = (MainThreadRequest) msg.obj; | 
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 422 | final Phone phone = getPhoneFromRequest(request); | 
|  | 423 | request.result = phone != null ? | 
|  | 424 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) | 
|  | 425 | : false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 426 | // Wake up the requesting thread | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 427 | notifyRequester(request); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 428 | break; | 
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 429 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 430 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 431 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 432 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 433 | iccArgument = (IccAPDUArgument) request.argument; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 434 | uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 435 | if (uiccCard == null) { | 
|  | 436 | loge("iccTransmitApduLogicalChannel: No UICC"); | 
|  | 437 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 438 | notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 439 | } else { | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 440 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, | 
|  | 441 | request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 442 | uiccCard.iccTransmitApduLogicalChannel( | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 443 | iccArgument.channel, iccArgument.cla, iccArgument.command, | 
|  | 444 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 445 | onCompleted); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 446 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 447 | break; | 
|  | 448 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 449 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 450 | ar = (AsyncResult) msg.obj; | 
|  | 451 | request = (MainThreadRequest) ar.userObj; | 
|  | 452 | if (ar.exception == null && ar.result != null) { | 
|  | 453 | request.result = ar.result; | 
|  | 454 | } else { | 
|  | 455 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
|  | 456 | if (ar.result == null) { | 
|  | 457 | loge("iccTransmitApduLogicalChannel: Empty response"); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 458 | } else if (ar.exception instanceof CommandException) { | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 459 | loge("iccTransmitApduLogicalChannel: CommandException: " + | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 460 | ar.exception); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 461 | } else { | 
|  | 462 | loge("iccTransmitApduLogicalChannel: Unknown exception"); | 
|  | 463 | } | 
|  | 464 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 465 | notifyRequester(request); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 466 | break; | 
|  | 467 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 468 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: | 
|  | 469 | request = (MainThreadRequest) msg.obj; | 
|  | 470 | iccArgument = (IccAPDUArgument) request.argument; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 471 | uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 472 | if (uiccCard == null) { | 
|  | 473 | loge("iccTransmitApduBasicChannel: No UICC"); | 
|  | 474 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 475 | notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 476 | } else { | 
|  | 477 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, | 
|  | 478 | request); | 
|  | 479 | uiccCard.iccTransmitApduBasicChannel( | 
|  | 480 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, | 
|  | 481 | iccArgument.p3, iccArgument.data, onCompleted); | 
|  | 482 | } | 
|  | 483 | break; | 
|  | 484 |  | 
|  | 485 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: | 
|  | 486 | ar = (AsyncResult) msg.obj; | 
|  | 487 | request = (MainThreadRequest) ar.userObj; | 
|  | 488 | if (ar.exception == null && ar.result != null) { | 
|  | 489 | request.result = ar.result; | 
|  | 490 | } else { | 
|  | 491 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
|  | 492 | if (ar.result == null) { | 
|  | 493 | loge("iccTransmitApduBasicChannel: Empty response"); | 
|  | 494 | } else if (ar.exception instanceof CommandException) { | 
|  | 495 | loge("iccTransmitApduBasicChannel: CommandException: " + | 
|  | 496 | ar.exception); | 
|  | 497 | } else { | 
|  | 498 | loge("iccTransmitApduBasicChannel: Unknown exception"); | 
|  | 499 | } | 
|  | 500 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 501 | notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 502 | break; | 
|  | 503 |  | 
|  | 504 | case CMD_EXCHANGE_SIM_IO: | 
|  | 505 | request = (MainThreadRequest) msg.obj; | 
|  | 506 | iccArgument = (IccAPDUArgument) request.argument; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 507 | uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 508 | if (uiccCard == null) { | 
|  | 509 | loge("iccExchangeSimIO: No UICC"); | 
|  | 510 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 511 | notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 512 | } else { | 
|  | 513 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, | 
|  | 514 | request); | 
|  | 515 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ | 
|  | 516 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, | 
|  | 517 | iccArgument.data, onCompleted); | 
|  | 518 | } | 
|  | 519 | break; | 
|  | 520 |  | 
|  | 521 | case EVENT_EXCHANGE_SIM_IO_DONE: | 
|  | 522 | ar = (AsyncResult) msg.obj; | 
|  | 523 | request = (MainThreadRequest) ar.userObj; | 
|  | 524 | if (ar.exception == null && ar.result != null) { | 
|  | 525 | request.result = ar.result; | 
|  | 526 | } else { | 
|  | 527 | request.result = new IccIoResult(0x6f, 0, (byte[])null); | 
|  | 528 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 529 | notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 530 | break; | 
|  | 531 |  | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 532 | case CMD_SEND_ENVELOPE: | 
|  | 533 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 534 | uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 535 | if (uiccCard == null) { | 
|  | 536 | loge("sendEnvelopeWithStatus: No UICC"); | 
|  | 537 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 538 | notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 539 | } else { | 
|  | 540 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); | 
|  | 541 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); | 
|  | 542 | } | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 543 | break; | 
|  | 544 |  | 
|  | 545 | case EVENT_SEND_ENVELOPE_DONE: | 
|  | 546 | ar = (AsyncResult) msg.obj; | 
|  | 547 | request = (MainThreadRequest) ar.userObj; | 
| Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 548 | if (ar.exception == null && ar.result != null) { | 
|  | 549 | request.result = ar.result; | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 550 | } else { | 
| Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 551 | request.result = new IccIoResult(0x6F, 0, (byte[])null); | 
|  | 552 | if (ar.result == null) { | 
|  | 553 | loge("sendEnvelopeWithStatus: Empty response"); | 
|  | 554 | } else if (ar.exception instanceof CommandException) { | 
|  | 555 | loge("sendEnvelopeWithStatus: CommandException: " + | 
|  | 556 | ar.exception); | 
|  | 557 | } else { | 
|  | 558 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); | 
|  | 559 | } | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 560 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 561 | notifyRequester(request); | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 562 | break; | 
|  | 563 |  | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 564 | case CMD_OPEN_CHANNEL: | 
|  | 565 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 566 | uiccCard = getUiccCardFromRequest(request); | 
| Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 567 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 568 | if (uiccCard == null) { | 
|  | 569 | loge("iccOpenLogicalChannel: No UICC"); | 
| Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 570 | request.result = new IccOpenLogicalChannelResponse(-1, | 
|  | 571 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 572 | notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 573 | } else { | 
|  | 574 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); | 
| Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 575 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, | 
|  | 576 | openChannelArgs.second, onCompleted); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 577 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 578 | break; | 
|  | 579 |  | 
|  | 580 | case EVENT_OPEN_CHANNEL_DONE: | 
|  | 581 | ar = (AsyncResult) msg.obj; | 
|  | 582 | request = (MainThreadRequest) ar.userObj; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 583 | IccOpenLogicalChannelResponse openChannelResp; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 584 | if (ar.exception == null && ar.result != null) { | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 585 | int[] result = (int[]) ar.result; | 
|  | 586 | int channelId = result[0]; | 
|  | 587 | byte[] selectResponse = null; | 
|  | 588 | if (result.length > 1) { | 
|  | 589 | selectResponse = new byte[result.length - 1]; | 
|  | 590 | for (int i = 1; i < result.length; ++i) { | 
|  | 591 | selectResponse[i - 1] = (byte) result[i]; | 
|  | 592 | } | 
|  | 593 | } | 
|  | 594 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 595 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 596 | } else { | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 597 | if (ar.result == null) { | 
|  | 598 | loge("iccOpenLogicalChannel: Empty response"); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 599 | } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 600 | if (ar.exception != null) { | 
|  | 601 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); | 
|  | 602 | } | 
|  | 603 |  | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 604 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; | 
| Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 605 | if (ar.exception instanceof CommandException) { | 
|  | 606 | CommandException.Error error = | 
|  | 607 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 608 | if (error == CommandException.Error.MISSING_RESOURCE) { | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 609 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; | 
| Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 610 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 611 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 612 | } | 
|  | 613 | } | 
|  | 614 | openChannelResp = new IccOpenLogicalChannelResponse( | 
|  | 615 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 616 | } | 
| Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 617 | request.result = openChannelResp; | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 618 | notifyRequester(request); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 619 | break; | 
|  | 620 |  | 
|  | 621 | case CMD_CLOSE_CHANNEL: | 
|  | 622 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 623 | uiccCard = getUiccCardFromRequest(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 624 | if (uiccCard == null) { | 
|  | 625 | loge("iccCloseLogicalChannel: No UICC"); | 
| Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 626 | request.result = false; | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 627 | notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 628 | } else { | 
|  | 629 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); | 
|  | 630 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); | 
|  | 631 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 632 | break; | 
|  | 633 |  | 
|  | 634 | case EVENT_CLOSE_CHANNEL_DONE: | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 635 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); | 
|  | 636 | break; | 
|  | 637 |  | 
|  | 638 | case CMD_NV_READ_ITEM: | 
|  | 639 | request = (MainThreadRequest) msg.obj; | 
|  | 640 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 641 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, | 
|  | 642 | request.workSource); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 643 | break; | 
|  | 644 |  | 
|  | 645 | case EVENT_NV_READ_ITEM_DONE: | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 646 | ar = (AsyncResult) msg.obj; | 
|  | 647 | request = (MainThreadRequest) ar.userObj; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 648 | if (ar.exception == null && ar.result != null) { | 
|  | 649 | request.result = ar.result;     // String | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 650 | } else { | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 651 | request.result = ""; | 
|  | 652 | if (ar.result == null) { | 
|  | 653 | loge("nvReadItem: Empty response"); | 
|  | 654 | } else if (ar.exception instanceof CommandException) { | 
|  | 655 | loge("nvReadItem: CommandException: " + | 
|  | 656 | ar.exception); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 657 | } else { | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 658 | loge("nvReadItem: Unknown exception"); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 659 | } | 
|  | 660 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 661 | notifyRequester(request); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 662 | break; | 
|  | 663 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 664 | case CMD_NV_WRITE_ITEM: | 
|  | 665 | request = (MainThreadRequest) msg.obj; | 
|  | 666 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); | 
|  | 667 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 668 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 669 | request.workSource); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 670 | break; | 
|  | 671 |  | 
|  | 672 | case EVENT_NV_WRITE_ITEM_DONE: | 
|  | 673 | handleNullReturnEvent(msg, "nvWriteItem"); | 
|  | 674 | break; | 
|  | 675 |  | 
|  | 676 | case CMD_NV_WRITE_CDMA_PRL: | 
|  | 677 | request = (MainThreadRequest) msg.obj; | 
|  | 678 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 679 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 680 | break; | 
|  | 681 |  | 
|  | 682 | case EVENT_NV_WRITE_CDMA_PRL_DONE: | 
|  | 683 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); | 
|  | 684 | break; | 
|  | 685 |  | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 686 | case CMD_RESET_MODEM_CONFIG: | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 687 | request = (MainThreadRequest) msg.obj; | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 688 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 689 | defaultPhone.resetModemConfig(onCompleted); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 690 | break; | 
|  | 691 |  | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 692 | case EVENT_RESET_MODEM_CONFIG_DONE: | 
|  | 693 | handleNullReturnEvent(msg, "resetModemConfig"); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 694 | break; | 
|  | 695 |  | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 696 | case CMD_GET_PREFERRED_NETWORK_TYPE: | 
|  | 697 | request = (MainThreadRequest) msg.obj; | 
|  | 698 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 699 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 700 | break; | 
|  | 701 |  | 
|  | 702 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: | 
|  | 703 | ar = (AsyncResult) msg.obj; | 
|  | 704 | request = (MainThreadRequest) ar.userObj; | 
|  | 705 | if (ar.exception == null && ar.result != null) { | 
|  | 706 | request.result = ar.result;     // Integer | 
|  | 707 | } else { | 
| Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 708 | request.result = null; | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 709 | if (ar.result == null) { | 
|  | 710 | loge("getPreferredNetworkType: Empty response"); | 
|  | 711 | } else if (ar.exception instanceof CommandException) { | 
|  | 712 | loge("getPreferredNetworkType: CommandException: " + | 
|  | 713 | ar.exception); | 
|  | 714 | } else { | 
|  | 715 | loge("getPreferredNetworkType: Unknown exception"); | 
|  | 716 | } | 
|  | 717 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 718 | notifyRequester(request); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 719 | break; | 
|  | 720 |  | 
|  | 721 | case CMD_SET_PREFERRED_NETWORK_TYPE: | 
|  | 722 | request = (MainThreadRequest) msg.obj; | 
|  | 723 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); | 
|  | 724 | int networkType = (Integer) request.argument; | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 725 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 726 | break; | 
|  | 727 |  | 
|  | 728 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: | 
|  | 729 | handleNullReturnEvent(msg, "setPreferredNetworkType"); | 
|  | 730 | break; | 
|  | 731 |  | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 732 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: | 
|  | 733 | request = (MainThreadRequest)msg.obj; | 
|  | 734 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 735 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 736 | break; | 
|  | 737 |  | 
|  | 738 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: | 
|  | 739 | ar = (AsyncResult)msg.obj; | 
|  | 740 | request = (MainThreadRequest)ar.userObj; | 
|  | 741 | request.result = ar; | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 742 | notifyRequester(request); | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 743 | break; | 
|  | 744 |  | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 745 | case CMD_SET_VOICEMAIL_NUMBER: | 
|  | 746 | request = (MainThreadRequest) msg.obj; | 
|  | 747 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); | 
|  | 748 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 749 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, | 
|  | 750 | onCompleted); | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 751 | break; | 
|  | 752 |  | 
|  | 753 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: | 
|  | 754 | handleNullReturnEvent(msg, "setVoicemailNumber"); | 
|  | 755 | break; | 
|  | 756 |  | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 757 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: | 
|  | 758 | request = (MainThreadRequest) msg.obj; | 
|  | 759 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, | 
|  | 760 | request); | 
|  | 761 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); | 
|  | 762 | break; | 
|  | 763 |  | 
|  | 764 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: | 
|  | 765 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); | 
|  | 766 | break; | 
|  | 767 |  | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 768 | case CMD_PERFORM_NETWORK_SCAN: | 
|  | 769 | request = (MainThreadRequest) msg.obj; | 
|  | 770 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); | 
|  | 771 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); | 
|  | 772 | break; | 
|  | 773 |  | 
|  | 774 | case EVENT_PERFORM_NETWORK_SCAN_DONE: | 
|  | 775 | ar = (AsyncResult) msg.obj; | 
|  | 776 | request = (MainThreadRequest) ar.userObj; | 
|  | 777 | CellNetworkScanResult cellScanResult; | 
|  | 778 | if (ar.exception == null && ar.result != null) { | 
|  | 779 | cellScanResult = new CellNetworkScanResult( | 
|  | 780 | CellNetworkScanResult.STATUS_SUCCESS, | 
|  | 781 | (List<OperatorInfo>) ar.result); | 
|  | 782 | } else { | 
|  | 783 | if (ar.result == null) { | 
|  | 784 | loge("getCellNetworkScanResults: Empty response"); | 
|  | 785 | } | 
|  | 786 | if (ar.exception != null) { | 
|  | 787 | loge("getCellNetworkScanResults: Exception: " + ar.exception); | 
|  | 788 | } | 
|  | 789 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; | 
|  | 790 | if (ar.exception instanceof CommandException) { | 
|  | 791 | CommandException.Error error = | 
|  | 792 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 793 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { | 
|  | 794 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; | 
|  | 795 | } else if (error == CommandException.Error.GENERIC_FAILURE) { | 
|  | 796 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; | 
|  | 797 | } | 
|  | 798 | } | 
|  | 799 | cellScanResult = new CellNetworkScanResult(errorCode, null); | 
|  | 800 | } | 
|  | 801 | request.result = cellScanResult; | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 802 | notifyRequester(request); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 803 | break; | 
|  | 804 |  | 
|  | 805 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: | 
|  | 806 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 807 | ManualNetworkSelectionArgument selArg = | 
|  | 808 | (ManualNetworkSelectionArgument) request.argument; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 809 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, | 
|  | 810 | request); | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 811 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, | 
|  | 812 | selArg.persistSelection, onCompleted); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 813 | break; | 
|  | 814 |  | 
|  | 815 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: | 
| Pengquan Meng | dd9ac82 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 816 | ar = (AsyncResult) msg.obj; | 
|  | 817 | request = (MainThreadRequest) ar.userObj; | 
|  | 818 | if (ar.exception == null) { | 
|  | 819 | request.result = true; | 
|  | 820 | } else { | 
|  | 821 | request.result = false; | 
|  | 822 | loge("setNetworkSelectionModeManual " + ar.exception); | 
|  | 823 | } | 
|  | 824 | notifyRequester(request); | 
|  | 825 | mApp.onNetworkSelectionChanged(request.subId); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 826 | break; | 
|  | 827 |  | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 828 | case CMD_GET_MODEM_ACTIVITY_INFO: | 
|  | 829 | request = (MainThreadRequest) msg.obj; | 
|  | 830 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 831 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 832 | break; | 
|  | 833 |  | 
|  | 834 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: | 
|  | 835 | ar = (AsyncResult) msg.obj; | 
|  | 836 | request = (MainThreadRequest) ar.userObj; | 
|  | 837 | if (ar.exception == null && ar.result != null) { | 
|  | 838 | request.result = ar.result; | 
|  | 839 | } else { | 
|  | 840 | if (ar.result == null) { | 
|  | 841 | loge("queryModemActivityInfo: Empty response"); | 
|  | 842 | } else if (ar.exception instanceof CommandException) { | 
|  | 843 | loge("queryModemActivityInfo: CommandException: " + | 
|  | 844 | ar.exception); | 
|  | 845 | } else { | 
|  | 846 | loge("queryModemActivityInfo: Unknown exception"); | 
|  | 847 | } | 
|  | 848 | } | 
| Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 849 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. | 
|  | 850 | if (request.result == null) { | 
|  | 851 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); | 
|  | 852 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 853 | notifyRequester(request); | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 854 | break; | 
|  | 855 |  | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 856 | case CMD_SET_ALLOWED_CARRIERS: | 
|  | 857 | request = (MainThreadRequest) msg.obj; | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 858 | CarrierRestrictionRules argument = | 
|  | 859 | (CarrierRestrictionRules) request.argument; | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 860 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 861 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 862 | break; | 
|  | 863 |  | 
|  | 864 | case EVENT_SET_ALLOWED_CARRIERS_DONE: | 
|  | 865 | ar = (AsyncResult) msg.obj; | 
|  | 866 | request = (MainThreadRequest) ar.userObj; | 
|  | 867 | if (ar.exception == null && ar.result != null) { | 
|  | 868 | request.result = ar.result; | 
|  | 869 | } else { | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 870 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; | 
|  | 871 | if (ar.exception instanceof CommandException) { | 
|  | 872 | loge("setAllowedCarriers: CommandException: " + ar.exception); | 
|  | 873 | CommandException.Error error = | 
|  | 874 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 875 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
|  | 876 | request.result = | 
|  | 877 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; | 
|  | 878 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 879 | } else { | 
|  | 880 | loge("setAllowedCarriers: Unknown exception"); | 
|  | 881 | } | 
|  | 882 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 883 | notifyRequester(request); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 884 | break; | 
|  | 885 |  | 
|  | 886 | case CMD_GET_ALLOWED_CARRIERS: | 
|  | 887 | request = (MainThreadRequest) msg.obj; | 
|  | 888 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 889 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 890 | break; | 
|  | 891 |  | 
|  | 892 | case EVENT_GET_ALLOWED_CARRIERS_DONE: | 
|  | 893 | ar = (AsyncResult) msg.obj; | 
|  | 894 | request = (MainThreadRequest) ar.userObj; | 
|  | 895 | if (ar.exception == null && ar.result != null) { | 
|  | 896 | request.result = ar.result; | 
|  | 897 | } else { | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 898 | request.result = new IllegalStateException( | 
|  | 899 | "Failed to get carrier restrictions"); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 900 | if (ar.result == null) { | 
|  | 901 | loge("getAllowedCarriers: Empty response"); | 
|  | 902 | } else if (ar.exception instanceof CommandException) { | 
|  | 903 | loge("getAllowedCarriers: CommandException: " + | 
|  | 904 | ar.exception); | 
|  | 905 | } else { | 
|  | 906 | loge("getAllowedCarriers: Unknown exception"); | 
|  | 907 | } | 
|  | 908 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 909 | notifyRequester(request); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 910 | break; | 
|  | 911 |  | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 912 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: | 
|  | 913 | ar = (AsyncResult) msg.obj; | 
|  | 914 | request = (MainThreadRequest) ar.userObj; | 
|  | 915 | if (ar.exception == null && ar.result != null) { | 
|  | 916 | request.result = ar.result; | 
|  | 917 | } else { | 
|  | 918 | request.result = new IllegalArgumentException( | 
|  | 919 | "Failed to retrieve Forbidden Plmns"); | 
|  | 920 | if (ar.result == null) { | 
|  | 921 | loge("getForbiddenPlmns: Empty response"); | 
|  | 922 | } else { | 
|  | 923 | loge("getForbiddenPlmns: Unknown exception"); | 
|  | 924 | } | 
|  | 925 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 926 | notifyRequester(request); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 927 | break; | 
|  | 928 |  | 
|  | 929 | case CMD_GET_FORBIDDEN_PLMNS: | 
|  | 930 | request = (MainThreadRequest) msg.obj; | 
|  | 931 | uiccCard = getUiccCardFromRequest(request); | 
|  | 932 | if (uiccCard == null) { | 
|  | 933 | loge("getForbiddenPlmns() UiccCard is null"); | 
|  | 934 | request.result = new IllegalArgumentException( | 
|  | 935 | "getForbiddenPlmns() UiccCard is null"); | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 936 | notifyRequester(request); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 937 | break; | 
|  | 938 | } | 
|  | 939 | Integer appType = (Integer) request.argument; | 
|  | 940 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); | 
|  | 941 | if (uiccApp == null) { | 
|  | 942 | loge("getForbiddenPlmns() no app with specified type -- " | 
|  | 943 | + appType); | 
|  | 944 | request.result = new IllegalArgumentException("Failed to get UICC App"); | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 945 | notifyRequester(request); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 946 | break; | 
|  | 947 | } else { | 
|  | 948 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() | 
|  | 949 | + " specified type -- " + appType); | 
|  | 950 | } | 
|  | 951 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); | 
|  | 952 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( | 
|  | 953 | onCompleted); | 
|  | 954 | break; | 
|  | 955 |  | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 956 | case CMD_SWITCH_SLOTS: | 
|  | 957 | request = (MainThreadRequest) msg.obj; | 
|  | 958 | int[] physicalSlots = (int[]) request.argument; | 
|  | 959 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); | 
|  | 960 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); | 
|  | 961 | break; | 
|  | 962 |  | 
|  | 963 | case EVENT_SWITCH_SLOTS_DONE: | 
|  | 964 | ar = (AsyncResult) msg.obj; | 
|  | 965 | request = (MainThreadRequest) ar.userObj; | 
|  | 966 | request.result = (ar.exception == null); | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 967 | notifyRequester(request); | 
|  | 968 | break; | 
|  | 969 | case CMD_GET_NETWORK_SELECTION_MODE: | 
|  | 970 | request = (MainThreadRequest) msg.obj; | 
|  | 971 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); | 
|  | 972 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); | 
|  | 973 | break; | 
|  | 974 |  | 
|  | 975 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: | 
|  | 976 | ar = (AsyncResult) msg.obj; | 
|  | 977 | request = (MainThreadRequest) ar.userObj; | 
|  | 978 | if (ar.exception != null) { | 
|  | 979 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; | 
|  | 980 | } else { | 
|  | 981 | int mode = ((int[]) ar.result)[0]; | 
|  | 982 | if (mode == 0) { | 
|  | 983 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; | 
|  | 984 | } else { | 
|  | 985 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; | 
|  | 986 | } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 987 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 988 | notifyRequester(request); | 
|  | 989 | break; | 
|  | 990 | case CMD_GET_CDMA_ROAMING_MODE: | 
|  | 991 | request = (MainThreadRequest) msg.obj; | 
|  | 992 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); | 
|  | 993 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); | 
|  | 994 | break; | 
|  | 995 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: | 
|  | 996 | ar = (AsyncResult) msg.obj; | 
|  | 997 | request = (MainThreadRequest) ar.userObj; | 
|  | 998 | if (ar.exception != null) { | 
|  | 999 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; | 
|  | 1000 | } else { | 
|  | 1001 | request.result = ((int[]) ar.result)[0]; | 
|  | 1002 | } | 
|  | 1003 | notifyRequester(request); | 
|  | 1004 | break; | 
|  | 1005 | case CMD_SET_CDMA_ROAMING_MODE: | 
|  | 1006 | request = (MainThreadRequest) msg.obj; | 
|  | 1007 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); | 
|  | 1008 | int mode = (int) request.argument; | 
|  | 1009 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); | 
|  | 1010 | break; | 
|  | 1011 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: | 
|  | 1012 | ar = (AsyncResult) msg.obj; | 
|  | 1013 | request = (MainThreadRequest) ar.userObj; | 
|  | 1014 | request.result = ar.exception == null; | 
|  | 1015 | notifyRequester(request); | 
|  | 1016 | break; | 
|  | 1017 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: | 
|  | 1018 | request = (MainThreadRequest) msg.obj; | 
|  | 1019 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); | 
|  | 1020 | int subscriptionMode = (int) request.argument; | 
|  | 1021 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); | 
|  | 1022 | break; | 
|  | 1023 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: | 
|  | 1024 | ar = (AsyncResult) msg.obj; | 
|  | 1025 | request = (MainThreadRequest) ar.userObj; | 
|  | 1026 | request.result = ar.exception == null; | 
|  | 1027 | notifyRequester(request); | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1028 | break; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1029 | case CMD_GET_ALL_CELL_INFO: | 
|  | 1030 | request = (MainThreadRequest) msg.obj; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1031 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1032 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1033 | break; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1034 | case EVENT_GET_ALL_CELL_INFO_DONE: | 
|  | 1035 | ar = (AsyncResult) msg.obj; | 
|  | 1036 | request = (MainThreadRequest) ar.userObj; | 
| Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1037 | // If a timeout occurs, the response will be null | 
|  | 1038 | request.result = (ar.exception == null && ar.result != null) | 
|  | 1039 | ? ar.result : new ArrayList<CellInfo>(); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1040 | synchronized (request) { | 
|  | 1041 | request.notifyAll(); | 
|  | 1042 | } | 
|  | 1043 | break; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1044 | case CMD_REQUEST_CELL_INFO_UPDATE: | 
|  | 1045 | request = (MainThreadRequest) msg.obj; | 
|  | 1046 | request.phone.requestCellInfoUpdate(request.workSource, | 
|  | 1047 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); | 
|  | 1048 | break; | 
|  | 1049 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: | 
|  | 1050 | ar = (AsyncResult) msg.obj; | 
|  | 1051 | request = (MainThreadRequest) ar.userObj; | 
|  | 1052 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; | 
|  | 1053 | try { | 
|  | 1054 | if (ar.exception != null) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1055 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); | 
| Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1056 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, | 
|  | 1057 | new android.os.ParcelableException(ar.exception)); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1058 | } else if (ar.result == null) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1059 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); | 
| Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1060 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1061 | } else { | 
|  | 1062 | // use the result as returned | 
|  | 1063 | cb.onCellInfo((List<CellInfo>) ar.result); | 
|  | 1064 | } | 
|  | 1065 | } catch (RemoteException re) { | 
|  | 1066 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); | 
|  | 1067 | } | 
|  | 1068 | break; | 
|  | 1069 | case CMD_GET_CELL_LOCATION: | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1070 | request = (MainThreadRequest) msg.obj; | 
|  | 1071 | WorkSource ws = (WorkSource) request.argument; | 
|  | 1072 | Phone phone = getPhoneFromRequest(request); | 
|  | 1073 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); | 
|  | 1074 | break; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1075 | case EVENT_GET_CELL_LOCATION_DONE: | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1076 | ar = (AsyncResult) msg.obj; | 
|  | 1077 | request = (MainThreadRequest) ar.userObj; | 
|  | 1078 | if (ar.exception == null) { | 
|  | 1079 | request.result = ar.result; | 
|  | 1080 | } else { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1081 | phone = getPhoneFromRequest(request); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1082 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) | 
|  | 1083 | ? new CdmaCellLocation() : new GsmCellLocation(); | 
|  | 1084 | } | 
|  | 1085 |  | 
|  | 1086 | synchronized (request) { | 
|  | 1087 | request.notifyAll(); | 
|  | 1088 | } | 
|  | 1089 | break; | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1090 | case CMD_MODEM_REBOOT: | 
|  | 1091 | request = (MainThreadRequest) msg.obj; | 
|  | 1092 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1093 | defaultPhone.rebootModem(onCompleted); | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1094 | break; | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1095 | case EVENT_CMD_MODEM_REBOOT_DONE: | 
|  | 1096 | handleNullReturnEvent(msg, "rebootModem"); | 
|  | 1097 | break; | 
| Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1098 | case CMD_REQUEST_ENABLE_MODEM: | 
|  | 1099 | request = (MainThreadRequest) msg.obj; | 
|  | 1100 | boolean enable = (boolean) request.argument; | 
|  | 1101 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); | 
|  | 1102 | PhoneConfigurationManager.getInstance() | 
|  | 1103 | .enablePhone(request.phone, enable, onCompleted); | 
|  | 1104 | break; | 
|  | 1105 | case EVENT_ENABLE_MODEM_DONE: | 
|  | 1106 | ar = (AsyncResult) msg.obj; | 
|  | 1107 | request = (MainThreadRequest) ar.userObj; | 
|  | 1108 | request.result = (ar.exception == null); | 
| Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 1109 | updateModemStateMetrics(); | 
| Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1110 | notifyRequester(request); | 
|  | 1111 | break; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1112 | default: | 
|  | 1113 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); | 
|  | 1114 | break; | 
|  | 1115 | } | 
|  | 1116 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1117 |  | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1118 | private void notifyRequester(MainThreadRequest request) { | 
|  | 1119 | synchronized (request) { | 
|  | 1120 | request.notifyAll(); | 
|  | 1121 | } | 
|  | 1122 | } | 
|  | 1123 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1124 | private void handleNullReturnEvent(Message msg, String command) { | 
|  | 1125 | AsyncResult ar = (AsyncResult) msg.obj; | 
|  | 1126 | MainThreadRequest request = (MainThreadRequest) ar.userObj; | 
|  | 1127 | if (ar.exception == null) { | 
|  | 1128 | request.result = true; | 
|  | 1129 | } else { | 
|  | 1130 | request.result = false; | 
|  | 1131 | if (ar.exception instanceof CommandException) { | 
|  | 1132 | loge(command + ": CommandException: " + ar.exception); | 
|  | 1133 | } else { | 
|  | 1134 | loge(command + ": Unknown exception"); | 
|  | 1135 | } | 
|  | 1136 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1137 | notifyRequester(request); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1138 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1139 | } | 
|  | 1140 |  | 
|  | 1141 | /** | 
|  | 1142 | * Posts the specified command to be executed on the main thread, | 
|  | 1143 | * waits for the request to complete, and returns the result. | 
|  | 1144 | * @see #sendRequestAsync | 
|  | 1145 | */ | 
|  | 1146 | private Object sendRequest(int command, Object argument) { | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1147 | return sendRequest( | 
|  | 1148 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1149 | } | 
|  | 1150 |  | 
|  | 1151 | /** | 
|  | 1152 | * Posts the specified command to be executed on the main thread, | 
|  | 1153 | * waits for the request to complete, and returns the result. | 
|  | 1154 | * @see #sendRequestAsync | 
|  | 1155 | */ | 
|  | 1156 | private Object sendRequest(int command, Object argument, WorkSource workSource) { | 
|  | 1157 | return sendRequest(command, argument,  SubscriptionManager.INVALID_SUBSCRIPTION_ID, | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1158 | null, workSource); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1159 | } | 
|  | 1160 |  | 
|  | 1161 | /** | 
|  | 1162 | * Posts the specified command to be executed on the main thread, | 
|  | 1163 | * waits for the request to complete, and returns the result. | 
|  | 1164 | * @see #sendRequestAsync | 
|  | 1165 | */ | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1166 | private Object sendRequest(int command, Object argument, Integer subId) { | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1167 | return sendRequest(command, argument, subId, null, null); | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1168 | } | 
|  | 1169 |  | 
|  | 1170 | /** | 
|  | 1171 | * Posts the specified command to be executed on the main thread, | 
|  | 1172 | * waits for the request to complete, and returns the result. | 
|  | 1173 | * @see #sendRequestAsync | 
|  | 1174 | */ | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1175 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { | 
|  | 1176 | return sendRequest(command, argument, subId, null, workSource); | 
|  | 1177 | } | 
|  | 1178 |  | 
|  | 1179 | /** | 
|  | 1180 | * Posts the specified command to be executed on the main thread, | 
|  | 1181 | * waits for the request to complete, and returns the result. | 
|  | 1182 | * @see #sendRequestAsync | 
|  | 1183 | */ | 
|  | 1184 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { | 
|  | 1185 | return sendRequest( | 
|  | 1186 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); | 
|  | 1187 | } | 
|  | 1188 |  | 
|  | 1189 | /** | 
|  | 1190 | * Posts the specified command to be executed on the main thread, | 
|  | 1191 | * waits for the request to complete, and returns the result. | 
|  | 1192 | * @see #sendRequestAsync | 
|  | 1193 | */ | 
|  | 1194 | private Object sendRequest( | 
|  | 1195 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1196 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { | 
|  | 1197 | throw new RuntimeException("This method will deadlock if called from the main thread."); | 
|  | 1198 | } | 
|  | 1199 |  | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1200 | MainThreadRequest request = null; | 
|  | 1201 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { | 
|  | 1202 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); | 
|  | 1203 | } else if (phone != null) { | 
|  | 1204 | request = new MainThreadRequest(argument, phone, workSource); | 
|  | 1205 | } else { | 
|  | 1206 | request = new MainThreadRequest(argument, subId, workSource); | 
|  | 1207 | } | 
|  | 1208 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1209 | Message msg = mMainThreadHandler.obtainMessage(command, request); | 
|  | 1210 | msg.sendToTarget(); | 
|  | 1211 |  | 
|  | 1212 | // Wait for the request to complete | 
|  | 1213 | synchronized (request) { | 
|  | 1214 | while (request.result == null) { | 
|  | 1215 | try { | 
|  | 1216 | request.wait(); | 
|  | 1217 | } catch (InterruptedException e) { | 
|  | 1218 | // Do nothing, go back and wait until the request is complete | 
|  | 1219 | } | 
|  | 1220 | } | 
|  | 1221 | } | 
|  | 1222 | return request.result; | 
|  | 1223 | } | 
|  | 1224 |  | 
|  | 1225 | /** | 
|  | 1226 | * Asynchronous ("fire and forget") version of sendRequest(): | 
|  | 1227 | * Posts the specified command to be executed on the main thread, and | 
|  | 1228 | * returns immediately. | 
|  | 1229 | * @see #sendRequest | 
|  | 1230 | */ | 
|  | 1231 | private void sendRequestAsync(int command) { | 
|  | 1232 | mMainThreadHandler.sendEmptyMessage(command); | 
|  | 1233 | } | 
|  | 1234 |  | 
|  | 1235 | /** | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1236 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1237 | * @see {@link #sendRequest(int)} | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1238 | */ | 
|  | 1239 | private void sendRequestAsync(int command, Object argument) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1240 | sendRequestAsync(command, argument, null, null); | 
|  | 1241 | } | 
|  | 1242 |  | 
|  | 1243 | /** | 
|  | 1244 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. | 
|  | 1245 | * @see {@link #sendRequest(int,Object)} | 
|  | 1246 | */ | 
|  | 1247 | private void sendRequestAsync( | 
|  | 1248 | int command, Object argument, Phone phone, WorkSource workSource) { | 
|  | 1249 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1250 | Message msg = mMainThreadHandler.obtainMessage(command, request); | 
|  | 1251 | msg.sendToTarget(); | 
|  | 1252 | } | 
|  | 1253 |  | 
|  | 1254 | /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1255 | * Initialize the singleton PhoneInterfaceManager instance. | 
|  | 1256 | * This is only done once, at startup, from PhoneApp.onCreate(). | 
|  | 1257 | */ | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1258 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1259 | synchronized (PhoneInterfaceManager.class) { | 
|  | 1260 | if (sInstance == null) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1261 | sInstance = new PhoneInterfaceManager(app); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1262 | } else { | 
|  | 1263 | Log.wtf(LOG_TAG, "init() called multiple times!  sInstance = " + sInstance); | 
|  | 1264 | } | 
|  | 1265 | return sInstance; | 
|  | 1266 | } | 
|  | 1267 | } | 
|  | 1268 |  | 
|  | 1269 | /** Private constructor; @see init() */ | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1270 | private PhoneInterfaceManager(PhoneGlobals app) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1271 | mApp = app; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1272 | mCM = PhoneGlobals.getInstance().mCM; | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1273 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1274 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); | 
|  | 1275 | mMainThreadHandler = new MainThreadHandler(); | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1276 | mSubscriptionController = SubscriptionController.getInstance(); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1277 | mTelephonySharedPreferences = | 
|  | 1278 | PreferenceManager.getDefaultSharedPreferences(mApp); | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1279 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); | 
| Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1280 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1281 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1282 | publish(); | 
|  | 1283 | } | 
|  | 1284 |  | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1285 | private Phone getDefaultPhone() { | 
|  | 1286 | Phone thePhone = getPhone(getDefaultSubscription()); | 
|  | 1287 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); | 
|  | 1288 | } | 
|  | 1289 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1290 | private void publish() { | 
|  | 1291 | if (DBG) log("publish: " + this); | 
|  | 1292 |  | 
|  | 1293 | ServiceManager.addService("phone", this); | 
|  | 1294 | } | 
|  | 1295 |  | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1296 | private Phone getPhoneFromRequest(MainThreadRequest request) { | 
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 1297 | return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1298 | ? getDefaultPhone() : getPhone(request.subId); | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1299 | } | 
|  | 1300 |  | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1301 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { | 
|  | 1302 | Phone phone = getPhoneFromRequest(request); | 
|  | 1303 | return phone == null ? null : | 
|  | 1304 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); | 
|  | 1305 | } | 
|  | 1306 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1307 | // returns phone associated with the subId. | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1308 | private Phone getPhone(int subId) { | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1309 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1310 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1311 |  | 
|  | 1312 | public void dial(String number) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1313 | dialForSubscriber(getPreferredVoiceSubscription(), number); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1314 | } | 
|  | 1315 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1316 | public void dialForSubscriber(int subId, String number) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1317 | if (DBG) log("dial: " + number); | 
|  | 1318 | // No permission check needed here: This is just a wrapper around the | 
|  | 1319 | // ACTION_DIAL intent, which is available to any app since it puts up | 
|  | 1320 | // the UI before it does anything. | 
|  | 1321 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1322 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1323 | try { | 
|  | 1324 | String url = createTelUrl(number); | 
|  | 1325 | if (url == null) { | 
|  | 1326 | return; | 
|  | 1327 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1328 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1329 | // PENDING: should we just silently fail if phone is offhook or ringing? | 
|  | 1330 | PhoneConstants.State state = mCM.getState(subId); | 
|  | 1331 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { | 
|  | 1332 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); | 
|  | 1333 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 
|  | 1334 | mApp.startActivity(intent); | 
|  | 1335 | } | 
|  | 1336 | } finally { | 
|  | 1337 | Binder.restoreCallingIdentity(identity); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1338 | } | 
|  | 1339 | } | 
|  | 1340 |  | 
|  | 1341 | public void call(String callingPackage, String number) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1342 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1343 | } | 
|  | 1344 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1345 | public void callForSubscriber(int subId, String callingPackage, String number) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1346 | if (DBG) log("call: " + number); | 
|  | 1347 |  | 
|  | 1348 | // This is just a wrapper around the ACTION_CALL intent, but we still | 
|  | 1349 | // need to do a permission check since we're calling startActivity() | 
|  | 1350 | // from the context of the phone app. | 
|  | 1351 | enforceCallPermission(); | 
|  | 1352 |  | 
|  | 1353 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) | 
|  | 1354 | != AppOpsManager.MODE_ALLOWED) { | 
|  | 1355 | return; | 
|  | 1356 | } | 
|  | 1357 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1358 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1359 | try { | 
|  | 1360 | String url = createTelUrl(number); | 
|  | 1361 | if (url == null) { | 
|  | 1362 | return; | 
|  | 1363 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1364 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1365 | boolean isValid = false; | 
|  | 1366 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); | 
|  | 1367 | if (slist != null) { | 
|  | 1368 | for (SubscriptionInfo subInfoRecord : slist) { | 
|  | 1369 | if (subInfoRecord.getSubscriptionId() == subId) { | 
|  | 1370 | isValid = true; | 
|  | 1371 | break; | 
|  | 1372 | } | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1373 | } | 
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1374 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1375 | if (!isValid) { | 
|  | 1376 | return; | 
|  | 1377 | } | 
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1378 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1379 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); | 
|  | 1380 | intent.putExtra(SUBSCRIPTION_KEY, subId); | 
|  | 1381 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 
|  | 1382 | mApp.startActivity(intent); | 
|  | 1383 | } finally { | 
|  | 1384 | Binder.restoreCallingIdentity(identity); | 
|  | 1385 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1386 | } | 
|  | 1387 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1388 | public boolean supplyPin(String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1389 | return supplyPinForSubscriber(getDefaultSubscription(), pin); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1390 | } | 
|  | 1391 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1392 | public boolean supplyPinForSubscriber(int subId, String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1393 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1394 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; | 
|  | 1395 | } | 
|  | 1396 |  | 
|  | 1397 | public boolean supplyPuk(String puk, String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1398 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1399 | } | 
|  | 1400 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1401 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1402 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1403 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; | 
|  | 1404 | } | 
|  | 1405 |  | 
|  | 1406 | /** {@hide} */ | 
|  | 1407 | public int[] supplyPinReportResult(String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1408 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1409 | } | 
|  | 1410 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1411 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1412 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1413 |  | 
|  | 1414 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1415 | try { | 
|  | 1416 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); | 
|  | 1417 | checkSimPin.start(); | 
|  | 1418 | return checkSimPin.unlockSim(null, pin); | 
|  | 1419 | } finally { | 
|  | 1420 | Binder.restoreCallingIdentity(identity); | 
|  | 1421 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1422 | } | 
|  | 1423 |  | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1424 | /** {@hide} */ | 
|  | 1425 | public int[] supplyPukReportResult(String puk, String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1426 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1427 | } | 
|  | 1428 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1429 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1430 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1431 |  | 
|  | 1432 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1433 | try { | 
|  | 1434 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); | 
|  | 1435 | checkSimPuk.start(); | 
|  | 1436 | return checkSimPuk.unlockSim(puk, pin); | 
|  | 1437 | } finally { | 
|  | 1438 | Binder.restoreCallingIdentity(identity); | 
|  | 1439 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1440 | } | 
|  | 1441 |  | 
|  | 1442 | /** | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1443 | * Helper thread to turn async call to SimCard#supplyPin into | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1444 | * a synchronous one. | 
|  | 1445 | */ | 
|  | 1446 | private static class UnlockSim extends Thread { | 
|  | 1447 |  | 
|  | 1448 | private final IccCard mSimCard; | 
|  | 1449 |  | 
|  | 1450 | private boolean mDone = false; | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1451 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; | 
|  | 1452 | private int mRetryCount = -1; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1453 |  | 
|  | 1454 | // For replies from SimCard interface | 
|  | 1455 | private Handler mHandler; | 
|  | 1456 |  | 
|  | 1457 | // For async handler to identify request type | 
|  | 1458 | private static final int SUPPLY_PIN_COMPLETE = 100; | 
|  | 1459 |  | 
|  | 1460 | public UnlockSim(IccCard simCard) { | 
|  | 1461 | mSimCard = simCard; | 
|  | 1462 | } | 
|  | 1463 |  | 
|  | 1464 | @Override | 
|  | 1465 | public void run() { | 
|  | 1466 | Looper.prepare(); | 
|  | 1467 | synchronized (UnlockSim.this) { | 
|  | 1468 | mHandler = new Handler() { | 
|  | 1469 | @Override | 
|  | 1470 | public void handleMessage(Message msg) { | 
|  | 1471 | AsyncResult ar = (AsyncResult) msg.obj; | 
|  | 1472 | switch (msg.what) { | 
|  | 1473 | case SUPPLY_PIN_COMPLETE: | 
|  | 1474 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); | 
|  | 1475 | synchronized (UnlockSim.this) { | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1476 | mRetryCount = msg.arg1; | 
|  | 1477 | if (ar.exception != null) { | 
|  | 1478 | if (ar.exception instanceof CommandException && | 
|  | 1479 | ((CommandException)(ar.exception)).getCommandError() | 
|  | 1480 | == CommandException.Error.PASSWORD_INCORRECT) { | 
|  | 1481 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; | 
|  | 1482 | } else { | 
|  | 1483 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; | 
|  | 1484 | } | 
|  | 1485 | } else { | 
|  | 1486 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; | 
|  | 1487 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1488 | mDone = true; | 
|  | 1489 | UnlockSim.this.notifyAll(); | 
|  | 1490 | } | 
|  | 1491 | break; | 
|  | 1492 | } | 
|  | 1493 | } | 
|  | 1494 | }; | 
|  | 1495 | UnlockSim.this.notifyAll(); | 
|  | 1496 | } | 
|  | 1497 | Looper.loop(); | 
|  | 1498 | } | 
|  | 1499 |  | 
|  | 1500 | /* | 
|  | 1501 | * Use PIN or PUK to unlock SIM card | 
|  | 1502 | * | 
|  | 1503 | * If PUK is null, unlock SIM card with PIN | 
|  | 1504 | * | 
|  | 1505 | * If PUK is not null, unlock SIM card with PUK and set PIN code | 
|  | 1506 | */ | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1507 | synchronized int[] unlockSim(String puk, String pin) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1508 |  | 
|  | 1509 | while (mHandler == null) { | 
|  | 1510 | try { | 
|  | 1511 | wait(); | 
|  | 1512 | } catch (InterruptedException e) { | 
|  | 1513 | Thread.currentThread().interrupt(); | 
|  | 1514 | } | 
|  | 1515 | } | 
|  | 1516 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); | 
|  | 1517 |  | 
|  | 1518 | if (puk == null) { | 
|  | 1519 | mSimCard.supplyPin(pin, callback); | 
|  | 1520 | } else { | 
|  | 1521 | mSimCard.supplyPuk(puk, pin, callback); | 
|  | 1522 | } | 
|  | 1523 |  | 
|  | 1524 | while (!mDone) { | 
|  | 1525 | try { | 
|  | 1526 | Log.d(LOG_TAG, "wait for done"); | 
|  | 1527 | wait(); | 
|  | 1528 | } catch (InterruptedException e) { | 
|  | 1529 | // Restore the interrupted status | 
|  | 1530 | Thread.currentThread().interrupt(); | 
|  | 1531 | } | 
|  | 1532 | } | 
|  | 1533 | Log.d(LOG_TAG, "done"); | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1534 | int[] resultArray = new int[2]; | 
|  | 1535 | resultArray[0] = mResult; | 
|  | 1536 | resultArray[1] = mRetryCount; | 
|  | 1537 | return resultArray; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1538 | } | 
|  | 1539 | } | 
|  | 1540 |  | 
|  | 1541 | public void updateServiceLocation() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1542 | updateServiceLocationForSubscriber(getDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1543 |  | 
|  | 1544 | } | 
|  | 1545 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1546 | public void updateServiceLocationForSubscriber(int subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1547 | // No permission check needed here: this call is harmless, and it's | 
|  | 1548 | // needed for the ServiceState.requestStateUpdate() call (which is | 
|  | 1549 | // already intentionally exposed to 3rd parties.) | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1550 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1551 | try { | 
|  | 1552 | final Phone phone = getPhone(subId); | 
|  | 1553 | if (phone != null) { | 
|  | 1554 | phone.updateServiceLocation(); | 
|  | 1555 | } | 
|  | 1556 | } finally { | 
|  | 1557 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1558 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1559 | } | 
|  | 1560 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1561 | @Override | 
|  | 1562 | public boolean isRadioOn(String callingPackage) { | 
|  | 1563 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1564 | } | 
|  | 1565 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1566 | @Override | 
|  | 1567 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1568 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1569 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1570 | return false; | 
|  | 1571 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1572 |  | 
|  | 1573 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1574 | try { | 
|  | 1575 | return isRadioOnForSubscriber(subId); | 
|  | 1576 | } finally { | 
|  | 1577 | Binder.restoreCallingIdentity(identity); | 
|  | 1578 | } | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1579 | } | 
|  | 1580 |  | 
|  | 1581 | private boolean isRadioOnForSubscriber(int subId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1582 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1583 | try { | 
|  | 1584 | final Phone phone = getPhone(subId); | 
|  | 1585 | if (phone != null) { | 
|  | 1586 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; | 
|  | 1587 | } else { | 
|  | 1588 | return false; | 
|  | 1589 | } | 
|  | 1590 | } finally { | 
|  | 1591 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1592 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1593 | } | 
|  | 1594 |  | 
|  | 1595 | public void toggleRadioOnOff() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1596 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1597 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1598 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1599 | public void toggleRadioOnOffForSubscriber(int subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1600 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1601 |  | 
|  | 1602 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1603 | try { | 
|  | 1604 | final Phone phone = getPhone(subId); | 
|  | 1605 | if (phone != null) { | 
|  | 1606 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); | 
|  | 1607 | } | 
|  | 1608 | } finally { | 
|  | 1609 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1610 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1611 | } | 
|  | 1612 |  | 
|  | 1613 | public boolean setRadio(boolean turnOn) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1614 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1615 | } | 
|  | 1616 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1617 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1618 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1619 |  | 
|  | 1620 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1621 | try { | 
|  | 1622 | final Phone phone = getPhone(subId); | 
|  | 1623 | if (phone == null) { | 
|  | 1624 | return false; | 
|  | 1625 | } | 
|  | 1626 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { | 
|  | 1627 | toggleRadioOnOffForSubscriber(subId); | 
|  | 1628 | } | 
|  | 1629 | return true; | 
|  | 1630 | } finally { | 
|  | 1631 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1632 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1633 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1634 |  | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1635 | public boolean needMobileRadioShutdown() { | 
|  | 1636 | /* | 
|  | 1637 | * If any of the Radios are available, it will need to be | 
|  | 1638 | * shutdown. So return true if any Radio is available. | 
|  | 1639 | */ | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1640 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1641 | try { | 
|  | 1642 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
|  | 1643 | Phone phone = PhoneFactory.getPhone(i); | 
|  | 1644 | if (phone != null && phone.isRadioAvailable()) return true; | 
|  | 1645 | } | 
|  | 1646 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); | 
|  | 1647 | return false; | 
|  | 1648 | } finally { | 
|  | 1649 | Binder.restoreCallingIdentity(identity); | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1650 | } | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1651 | } | 
|  | 1652 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1653 | @Override | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1654 | public void shutdownMobileRadios() { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1655 | enforceModifyPermission(); | 
|  | 1656 |  | 
|  | 1657 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1658 | try { | 
|  | 1659 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
|  | 1660 | logv("Shutting down Phone " + i); | 
|  | 1661 | shutdownRadioUsingPhoneId(i); | 
|  | 1662 | } | 
|  | 1663 | } finally { | 
|  | 1664 | Binder.restoreCallingIdentity(identity); | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1665 | } | 
|  | 1666 | } | 
|  | 1667 |  | 
|  | 1668 | private void shutdownRadioUsingPhoneId(int phoneId) { | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1669 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 1670 | if (phone != null && phone.isRadioAvailable()) { | 
|  | 1671 | phone.shutdownRadio(); | 
|  | 1672 | } | 
|  | 1673 | } | 
|  | 1674 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1675 | public boolean setRadioPower(boolean turnOn) { | 
| Jack Yu | b4e1616 | 2017-05-15 12:48:40 -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 defaultPhone = PhoneFactory.getDefaultPhone(); | 
|  | 1681 | if (defaultPhone != null) { | 
|  | 1682 | defaultPhone.setRadioPower(turnOn); | 
|  | 1683 | return true; | 
|  | 1684 | } else { | 
|  | 1685 | loge("There's no default phone."); | 
|  | 1686 | return false; | 
|  | 1687 | } | 
|  | 1688 | } finally { | 
|  | 1689 | Binder.restoreCallingIdentity(identity); | 
| Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1690 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1691 | } | 
|  | 1692 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1693 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1694 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1695 |  | 
|  | 1696 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1697 | try { | 
|  | 1698 | final Phone phone = getPhone(subId); | 
|  | 1699 | if (phone != null) { | 
|  | 1700 | phone.setRadioPower(turnOn); | 
|  | 1701 | return true; | 
|  | 1702 | } else { | 
|  | 1703 | return false; | 
|  | 1704 | } | 
|  | 1705 | } finally { | 
|  | 1706 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1707 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1708 | } | 
|  | 1709 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1710 | // FIXME: subId version needed | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1711 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1712 | public boolean enableDataConnectivity() { | 
|  | 1713 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1714 |  | 
|  | 1715 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1716 | try { | 
|  | 1717 | int subId = mSubscriptionController.getDefaultDataSubId(); | 
|  | 1718 | final Phone phone = getPhone(subId); | 
|  | 1719 | if (phone != null) { | 
| Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1720 | phone.getDataEnabledSettings().setUserDataEnabled(true); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1721 | return true; | 
|  | 1722 | } else { | 
|  | 1723 | return false; | 
|  | 1724 | } | 
|  | 1725 | } finally { | 
|  | 1726 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1727 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1728 | } | 
|  | 1729 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1730 | // FIXME: subId version needed | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1731 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1732 | public boolean disableDataConnectivity() { | 
|  | 1733 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1734 |  | 
|  | 1735 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1736 | try { | 
|  | 1737 | int subId = mSubscriptionController.getDefaultDataSubId(); | 
|  | 1738 | final Phone phone = getPhone(subId); | 
|  | 1739 | if (phone != null) { | 
| Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1740 | phone.getDataEnabledSettings().setUserDataEnabled(false); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1741 | return true; | 
|  | 1742 | } else { | 
|  | 1743 | return false; | 
|  | 1744 | } | 
|  | 1745 | } finally { | 
|  | 1746 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1747 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1748 | } | 
|  | 1749 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1750 | @Override | 
| Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1751 | public boolean isDataConnectivityPossible(int subId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1752 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1753 | try { | 
|  | 1754 | final Phone phone = getPhone(subId); | 
|  | 1755 | if (phone != null) { | 
| Jack Yu | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1756 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1757 | } else { | 
|  | 1758 | return false; | 
|  | 1759 | } | 
|  | 1760 | } finally { | 
|  | 1761 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1762 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1763 | } | 
|  | 1764 |  | 
|  | 1765 | public boolean handlePinMmi(String dialString) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1766 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1767 | } | 
|  | 1768 |  | 
| pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1769 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1770 | enforceCallPermission(); | 
|  | 1771 |  | 
|  | 1772 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1773 | try { | 
|  | 1774 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 1775 | return; | 
|  | 1776 | } | 
|  | 1777 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); | 
|  | 1778 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); | 
|  | 1779 | } finally { | 
|  | 1780 | Binder.restoreCallingIdentity(identity); | 
|  | 1781 | } | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1782 | }; | 
|  | 1783 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1784 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1785 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1786 |  | 
|  | 1787 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1788 | try { | 
|  | 1789 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 1790 | return false; | 
|  | 1791 | } | 
|  | 1792 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); | 
|  | 1793 | } finally { | 
|  | 1794 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1795 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1796 | } | 
|  | 1797 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1798 | public int getCallState() { | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1799 | return getCallStateForSlot(getSlotForDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1800 | } | 
|  | 1801 |  | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1802 | public int getCallStateForSlot(int slotIndex) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1803 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1804 | try { | 
|  | 1805 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 1806 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : | 
|  | 1807 | PhoneConstantConversions.convertCallState(phone.getState()); | 
|  | 1808 | } finally { | 
|  | 1809 | Binder.restoreCallingIdentity(identity); | 
|  | 1810 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1811 | } | 
|  | 1812 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1813 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1814 | public int getDataState() { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1815 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1816 | try { | 
|  | 1817 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); | 
|  | 1818 | if (phone != null) { | 
|  | 1819 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); | 
|  | 1820 | } else { | 
|  | 1821 | return PhoneConstantConversions.convertDataState( | 
|  | 1822 | PhoneConstants.DataState.DISCONNECTED); | 
|  | 1823 | } | 
|  | 1824 | } finally { | 
|  | 1825 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1826 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1827 | } | 
|  | 1828 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1829 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1830 | public int getDataActivity() { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1831 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1832 | try { | 
|  | 1833 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); | 
|  | 1834 | if (phone != null) { | 
|  | 1835 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); | 
|  | 1836 | } else { | 
|  | 1837 | return TelephonyManager.DATA_ACTIVITY_NONE; | 
|  | 1838 | } | 
|  | 1839 | } finally { | 
|  | 1840 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1841 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1842 | } | 
|  | 1843 |  | 
|  | 1844 | @Override | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1845 | public Bundle getCellLocation(String callingPackage) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1846 | mApp.getSystemService(AppOpsManager.class) | 
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1847 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1848 |  | 
|  | 1849 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 1850 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 1851 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 1852 | .setCallingPackage(callingPackage) | 
|  | 1853 | .setCallingPid(Binder.getCallingPid()) | 
|  | 1854 | .setCallingUid(Binder.getCallingUid()) | 
|  | 1855 | .setMethod("getCellLocation") | 
|  | 1856 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 1857 | .build()); | 
|  | 1858 | switch (locationResult) { | 
|  | 1859 | case DENIED_HARD: | 
|  | 1860 | throw new SecurityException("Not allowed to access cell location"); | 
|  | 1861 | case DENIED_SOFT: | 
|  | 1862 | return new Bundle(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1863 | } | 
|  | 1864 |  | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1865 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1866 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1867 | try { | 
|  | 1868 | if (DBG_LOC) log("getCellLocation: is active user"); | 
|  | 1869 | Bundle data = new Bundle(); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1870 | int subId = mSubscriptionController.getDefaultDataSubId(); | 
|  | 1871 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); | 
|  | 1872 | cl.fillInNotifierBundle(data); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1873 | return data; | 
|  | 1874 | } finally { | 
|  | 1875 | Binder.restoreCallingIdentity(identity); | 
|  | 1876 | } | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1877 | } | 
|  | 1878 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1879 | @Override | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1880 | public String getNetworkCountryIsoForPhone(int phoneId) { | 
|  | 1881 | // Reporting the correct network country is ambiguous when IWLAN could conflict with | 
|  | 1882 | // registered cell info, so return a NULL country instead. | 
|  | 1883 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1884 | try { | 
| Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1885 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { | 
|  | 1886 | // Get default phone in this case. | 
|  | 1887 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; | 
|  | 1888 | } | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1889 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); | 
| Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1890 | // Todo: fix this when we can get the actual cellular network info when the device | 
|  | 1891 | // is on IWLAN. | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1892 | if (TelephonyManager.NETWORK_TYPE_IWLAN | 
|  | 1893 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { | 
|  | 1894 | return ""; | 
|  | 1895 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1896 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 1897 | if (phone != null) { | 
|  | 1898 | ServiceStateTracker sst = phone.getServiceStateTracker(); | 
|  | 1899 | if (sst != null) { | 
|  | 1900 | LocaleTracker lt = sst.getLocaleTracker(); | 
|  | 1901 | if (lt != null) { | 
|  | 1902 | return lt.getCurrentCountry(); | 
|  | 1903 | } | 
|  | 1904 | } | 
|  | 1905 | } | 
|  | 1906 | return ""; | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1907 | } finally { | 
|  | 1908 | Binder.restoreCallingIdentity(identity); | 
|  | 1909 | } | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1910 | } | 
|  | 1911 |  | 
|  | 1912 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1913 | public void enableLocationUpdates() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1914 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1915 | } | 
|  | 1916 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1917 | @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1918 | public void enableLocationUpdatesForSubscriber(int subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1919 | mApp.enforceCallingOrSelfPermission( | 
|  | 1920 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1921 |  | 
|  | 1922 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1923 | try { | 
|  | 1924 | final Phone phone = getPhone(subId); | 
|  | 1925 | if (phone != null) { | 
|  | 1926 | phone.enableLocationUpdates(); | 
|  | 1927 | } | 
|  | 1928 | } finally { | 
|  | 1929 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1930 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1931 | } | 
|  | 1932 |  | 
|  | 1933 | @Override | 
|  | 1934 | public void disableLocationUpdates() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1935 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1936 | } | 
|  | 1937 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1938 | @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1939 | public void disableLocationUpdatesForSubscriber(int subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1940 | mApp.enforceCallingOrSelfPermission( | 
|  | 1941 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1942 |  | 
|  | 1943 | final long identity = Binder.clearCallingIdentity(); | 
|  | 1944 | try { | 
|  | 1945 | final Phone phone = getPhone(subId); | 
|  | 1946 | if (phone != null) { | 
|  | 1947 | phone.disableLocationUpdates(); | 
|  | 1948 | } | 
|  | 1949 | } finally { | 
|  | 1950 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1951 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1952 | } | 
|  | 1953 |  | 
| Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1954 | /** | 
|  | 1955 | * Returns the target SDK version number for a given package name. | 
|  | 1956 | * | 
|  | 1957 | * @return target SDK if the package is found or INT_MAX. | 
|  | 1958 | */ | 
|  | 1959 | private int getTargetSdk(String packageName) { | 
|  | 1960 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1961 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo( | 
|  | 1962 | packageName, 0); | 
| Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1963 | if (ai != null) return ai.targetSdkVersion; | 
|  | 1964 | } catch (PackageManager.NameNotFoundException unexpected) { | 
|  | 1965 | } | 
|  | 1966 | return Integer.MAX_VALUE; | 
|  | 1967 | } | 
|  | 1968 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1969 | @Override | 
|  | 1970 | @SuppressWarnings("unchecked") | 
| Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1971 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { | 
|  | 1972 | final int targetSdk = getTargetSdk(callingPackage); | 
| Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 1973 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { | 
|  | 1974 | throw new SecurityException( | 
|  | 1975 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); | 
|  | 1976 | } | 
| Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 1977 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1978 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), | 
|  | 1979 | callingPackage) != AppOpsManager.MODE_ALLOWED) { | 
|  | 1980 | return null; | 
|  | 1981 | } | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1982 |  | 
| Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1983 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1984 |  | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1985 | List<CellInfo> info = getAllCellInfo(callingPackage); | 
|  | 1986 | if (info == null) return null; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1987 |  | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1988 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); | 
|  | 1989 | for (CellInfo ci : info) { | 
|  | 1990 | if (ci instanceof CellInfoGsm) { | 
|  | 1991 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); | 
|  | 1992 | } else if (ci instanceof CellInfoWcdma) { | 
|  | 1993 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); | 
|  | 1994 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1995 | } | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 1996 | return (neighbors.size()) > 0 ? neighbors : null; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1997 | } | 
|  | 1998 |  | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1999 | private List<CellInfo> getCachedCellInfo() { | 
|  | 2000 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); | 
|  | 2001 | for (Phone phone : PhoneFactory.getPhones()) { | 
|  | 2002 | List<CellInfo> info = phone.getAllCellInfo(); | 
|  | 2003 | if (info != null) cellInfos.addAll(info); | 
|  | 2004 | } | 
|  | 2005 | return cellInfos; | 
|  | 2006 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2007 |  | 
|  | 2008 | @Override | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2009 | public List<CellInfo> getAllCellInfo(String callingPackage) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2010 | mApp.getSystemService(AppOpsManager.class) | 
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2011 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2012 |  | 
|  | 2013 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 2014 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 2015 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 2016 | .setCallingPackage(callingPackage) | 
|  | 2017 | .setCallingPid(Binder.getCallingPid()) | 
|  | 2018 | .setCallingUid(Binder.getCallingUid()) | 
|  | 2019 | .setMethod("getAllCellInfo") | 
|  | 2020 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 2021 | .build()); | 
|  | 2022 | switch (locationResult) { | 
|  | 2023 | case DENIED_HARD: | 
|  | 2024 | throw new SecurityException("Not allowed to access cell info"); | 
|  | 2025 | case DENIED_SOFT: | 
|  | 2026 | return new ArrayList<>(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2027 | } | 
|  | 2028 |  | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2029 | final int targetSdk = getTargetSdk(callingPackage); | 
|  | 2030 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { | 
|  | 2031 | return getCachedCellInfo(); | 
|  | 2032 | } | 
|  | 2033 |  | 
| Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2034 | if (DBG_LOC) log("getAllCellInfo: is active user"); | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2035 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2036 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2037 | try { | 
|  | 2038 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); | 
|  | 2039 | for (Phone phone : PhoneFactory.getPhones()) { | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2040 | final List<CellInfo> info = (List<CellInfo>) sendRequest( | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2041 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2042 | if (info != null) cellInfos.addAll(info); | 
|  | 2043 | } | 
|  | 2044 | return cellInfos; | 
|  | 2045 | } finally { | 
|  | 2046 | Binder.restoreCallingIdentity(identity); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2047 | } | 
|  | 2048 | } | 
|  | 2049 |  | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2050 | @Override | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2051 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { | 
|  | 2052 | requestCellInfoUpdateInternal( | 
|  | 2053 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); | 
|  | 2054 | } | 
|  | 2055 |  | 
|  | 2056 | @Override | 
|  | 2057 | public void requestCellInfoUpdateWithWorkSource( | 
|  | 2058 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { | 
|  | 2059 | enforceModifyPermission(); | 
|  | 2060 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); | 
|  | 2061 | } | 
|  | 2062 |  | 
|  | 2063 | private void requestCellInfoUpdateInternal( | 
|  | 2064 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2065 | mApp.getSystemService(AppOpsManager.class) | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2066 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2067 |  | 
|  | 2068 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 2069 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 2070 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 2071 | .setCallingPackage(callingPackage) | 
|  | 2072 | .setCallingPid(Binder.getCallingPid()) | 
|  | 2073 | .setCallingUid(Binder.getCallingUid()) | 
|  | 2074 | .setMethod("requestCellInfoUpdate") | 
|  | 2075 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 2076 | .build()); | 
|  | 2077 | switch (locationResult) { | 
|  | 2078 | case DENIED_HARD: | 
|  | 2079 | throw new SecurityException("Not allowed to access cell info"); | 
|  | 2080 | case DENIED_SOFT: | 
|  | 2081 | return; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2082 | } | 
|  | 2083 |  | 
|  | 2084 | final Phone phone = getPhone(subId); | 
|  | 2085 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); | 
|  | 2086 |  | 
|  | 2087 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); | 
|  | 2088 | } | 
|  | 2089 |  | 
|  | 2090 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2091 | public void setCellInfoListRate(int rateInMillis) { | 
| Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2092 | enforceModifyPermission(); | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2093 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2094 |  | 
|  | 2095 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2096 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2097 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2098 | } finally { | 
|  | 2099 | Binder.restoreCallingIdentity(identity); | 
|  | 2100 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2101 | } | 
|  | 2102 |  | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2103 | @Override | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2104 | public String getImeiForSlot(int slotIndex, String callingPackage) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2105 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2106 | if (phone == null) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2107 | return null; | 
|  | 2108 | } | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2109 | int subId = phone.getSubId(); | 
|  | 2110 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 2111 | mApp, subId, callingPackage, "getImeiForSlot")) { | 
|  | 2112 | return null; | 
|  | 2113 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2114 |  | 
|  | 2115 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2116 | try { | 
|  | 2117 | return phone.getImei(); | 
|  | 2118 | } finally { | 
|  | 2119 | Binder.restoreCallingIdentity(identity); | 
|  | 2120 | } | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2121 | } | 
|  | 2122 |  | 
|  | 2123 | @Override | 
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2124 | public String getTypeAllocationCodeForSlot(int slotIndex) { | 
|  | 2125 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2126 | String tac = null; | 
|  | 2127 | if (phone != null) { | 
|  | 2128 | String imei = phone.getImei(); | 
|  | 2129 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); | 
|  | 2130 | } | 
|  | 2131 | return tac; | 
|  | 2132 | } | 
|  | 2133 |  | 
|  | 2134 | @Override | 
| Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2135 | public String getMeidForSlot(int slotIndex, String callingPackage) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2136 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2137 | if (phone == null) { | 
| Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2138 | return null; | 
|  | 2139 | } | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2140 |  | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2141 | int subId = phone.getSubId(); | 
|  | 2142 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 2143 | mApp, subId, callingPackage, "getMeidForSlot")) { | 
|  | 2144 | return null; | 
|  | 2145 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2146 |  | 
|  | 2147 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2148 | try { | 
|  | 2149 | return phone.getMeid(); | 
|  | 2150 | } finally { | 
|  | 2151 | Binder.restoreCallingIdentity(identity); | 
|  | 2152 | } | 
| Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2153 | } | 
|  | 2154 |  | 
|  | 2155 | @Override | 
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2156 | public String getManufacturerCodeForSlot(int slotIndex) { | 
|  | 2157 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2158 | String manufacturerCode = null; | 
|  | 2159 | if (phone != null) { | 
|  | 2160 | String meid = phone.getMeid(); | 
|  | 2161 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); | 
|  | 2162 | } | 
|  | 2163 | return manufacturerCode; | 
|  | 2164 | } | 
|  | 2165 |  | 
|  | 2166 | @Override | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2167 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2168 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2169 | if (phone == null) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2170 | return null; | 
|  | 2171 | } | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2172 | int subId = phone.getSubId(); | 
|  | 2173 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 2174 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { | 
|  | 2175 | return null; | 
|  | 2176 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2177 |  | 
|  | 2178 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2179 | try { | 
|  | 2180 | return phone.getDeviceSvn(); | 
|  | 2181 | } finally { | 
|  | 2182 | Binder.restoreCallingIdentity(identity); | 
|  | 2183 | } | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2184 | } | 
|  | 2185 |  | 
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2186 | @Override | 
|  | 2187 | public int getSubscriptionCarrierId(int subId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2188 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2189 | try { | 
|  | 2190 | final Phone phone = getPhone(subId); | 
|  | 2191 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); | 
|  | 2192 | } finally { | 
|  | 2193 | Binder.restoreCallingIdentity(identity); | 
|  | 2194 | } | 
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2195 | } | 
|  | 2196 |  | 
|  | 2197 | @Override | 
|  | 2198 | public String getSubscriptionCarrierName(int subId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2199 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2200 | try { | 
|  | 2201 | final Phone phone = getPhone(subId); | 
|  | 2202 | return phone == null ? null : phone.getCarrierName(); | 
|  | 2203 | } finally { | 
|  | 2204 | Binder.restoreCallingIdentity(identity); | 
|  | 2205 | } | 
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2206 | } | 
|  | 2207 |  | 
| calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2208 | @Override | 
| chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2209 | public int getSubscriptionPreciseCarrierId(int subId) { | 
|  | 2210 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2211 | try { | 
|  | 2212 | final Phone phone = getPhone(subId); | 
|  | 2213 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID | 
|  | 2214 | : phone.getPreciseCarrierId(); | 
|  | 2215 | } finally { | 
|  | 2216 | Binder.restoreCallingIdentity(identity); | 
|  | 2217 | } | 
|  | 2218 | } | 
|  | 2219 |  | 
|  | 2220 | @Override | 
|  | 2221 | public String getSubscriptionPreciseCarrierName(int subId) { | 
|  | 2222 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2223 | try { | 
|  | 2224 | final Phone phone = getPhone(subId); | 
|  | 2225 | return phone == null ? null : phone.getPreciseCarrierName(); | 
|  | 2226 | } finally { | 
|  | 2227 | Binder.restoreCallingIdentity(identity); | 
|  | 2228 | } | 
|  | 2229 | } | 
|  | 2230 |  | 
| chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2231 | @Override | 
| chen xu | 4ca4e69 | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2232 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { | 
|  | 2233 | if (!isSubscriptionMccMnc) { | 
|  | 2234 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); | 
|  | 2235 | } | 
| chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2236 | final Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2237 | if (phone == null) { | 
|  | 2238 | return TelephonyManager.UNKNOWN_CARRIER_ID; | 
|  | 2239 | } | 
|  | 2240 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2241 | try { | 
|  | 2242 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); | 
|  | 2243 | } finally { | 
|  | 2244 | Binder.restoreCallingIdentity(identity); | 
|  | 2245 | } | 
|  | 2246 | } | 
|  | 2247 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2248 | // | 
|  | 2249 | // Internal helper methods. | 
|  | 2250 | // | 
|  | 2251 |  | 
| Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2252 | /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2253 | * Make sure the caller has the MODIFY_PHONE_STATE permission. | 
|  | 2254 | * | 
|  | 2255 | * @throws SecurityException if the caller does not have the required permission | 
|  | 2256 | */ | 
|  | 2257 | private void enforceModifyPermission() { | 
|  | 2258 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); | 
|  | 2259 | } | 
|  | 2260 |  | 
|  | 2261 | /** | 
|  | 2262 | * Make sure the caller has the CALL_PHONE permission. | 
|  | 2263 | * | 
|  | 2264 | * @throws SecurityException if the caller does not have the required permission | 
|  | 2265 | */ | 
|  | 2266 | private void enforceCallPermission() { | 
|  | 2267 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); | 
|  | 2268 | } | 
|  | 2269 |  | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2270 | private void enforceConnectivityInternalPermission() { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2271 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2272 | "ConnectivityService"); | 
|  | 2273 | } | 
|  | 2274 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2275 | private String createTelUrl(String number) { | 
|  | 2276 | if (TextUtils.isEmpty(number)) { | 
|  | 2277 | return null; | 
|  | 2278 | } | 
|  | 2279 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2280 | return "tel:" + number; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2281 | } | 
|  | 2282 |  | 
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2283 | private static void log(String msg) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2284 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); | 
|  | 2285 | } | 
|  | 2286 |  | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2287 | private static void logv(String msg) { | 
|  | 2288 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); | 
|  | 2289 | } | 
|  | 2290 |  | 
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2291 | private static void loge(String msg) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2292 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); | 
|  | 2293 | } | 
|  | 2294 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2295 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2296 | public int getActivePhoneType() { | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2297 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2298 | } | 
|  | 2299 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2300 | @Override | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2301 | public int getActivePhoneTypeForSlot(int slotIndex) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2302 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2303 | try { | 
|  | 2304 | final Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 2305 | if (phone == null) { | 
|  | 2306 | return PhoneConstants.PHONE_TYPE_NONE; | 
|  | 2307 | } else { | 
|  | 2308 | return phone.getPhoneType(); | 
|  | 2309 | } | 
|  | 2310 | } finally { | 
|  | 2311 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2312 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2313 | } | 
|  | 2314 |  | 
|  | 2315 | /** | 
|  | 2316 | * Returns the CDMA ERI icon index to display | 
|  | 2317 | */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2318 | @Override | 
|  | 2319 | public int getCdmaEriIconIndex(String callingPackage) { | 
|  | 2320 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2321 | } | 
|  | 2322 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2323 | @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2324 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2325 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2326 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2327 | return -1; | 
|  | 2328 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2329 |  | 
|  | 2330 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2331 | try { | 
|  | 2332 | final Phone phone = getPhone(subId); | 
|  | 2333 | if (phone != null) { | 
|  | 2334 | return phone.getCdmaEriIconIndex(); | 
|  | 2335 | } else { | 
|  | 2336 | return -1; | 
|  | 2337 | } | 
|  | 2338 | } finally { | 
|  | 2339 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2340 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2341 | } | 
|  | 2342 |  | 
|  | 2343 | /** | 
|  | 2344 | * Returns the CDMA ERI icon mode, | 
|  | 2345 | * 0 - ON | 
|  | 2346 | * 1 - FLASHING | 
|  | 2347 | */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2348 | @Override | 
|  | 2349 | public int getCdmaEriIconMode(String callingPackage) { | 
|  | 2350 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2351 | } | 
|  | 2352 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2353 | @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2354 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2355 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2356 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2357 | return -1; | 
|  | 2358 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2359 |  | 
|  | 2360 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2361 | try { | 
|  | 2362 | final Phone phone = getPhone(subId); | 
|  | 2363 | if (phone != null) { | 
|  | 2364 | return phone.getCdmaEriIconMode(); | 
|  | 2365 | } else { | 
|  | 2366 | return -1; | 
|  | 2367 | } | 
|  | 2368 | } finally { | 
|  | 2369 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2370 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2371 | } | 
|  | 2372 |  | 
|  | 2373 | /** | 
|  | 2374 | * Returns the CDMA ERI text, | 
|  | 2375 | */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2376 | @Override | 
|  | 2377 | public String getCdmaEriText(String callingPackage) { | 
|  | 2378 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2379 | } | 
|  | 2380 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2381 | @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2382 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2383 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2384 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2385 | return null; | 
|  | 2386 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2387 |  | 
|  | 2388 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2389 | try { | 
|  | 2390 | final Phone phone = getPhone(subId); | 
|  | 2391 | if (phone != null) { | 
|  | 2392 | return phone.getCdmaEriText(); | 
|  | 2393 | } else { | 
|  | 2394 | return null; | 
|  | 2395 | } | 
|  | 2396 | } finally { | 
|  | 2397 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2398 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2399 | } | 
|  | 2400 |  | 
|  | 2401 | /** | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2402 | * Returns the CDMA MDN. | 
|  | 2403 | */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2404 | @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2405 | public String getCdmaMdn(int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2406 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 2407 | mApp, subId, "getCdmaMdn"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2408 |  | 
|  | 2409 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2410 | try { | 
|  | 2411 | final Phone phone = getPhone(subId); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2412 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2413 | return phone.getLine1Number(); | 
|  | 2414 | } else { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2415 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2416 | return null; | 
|  | 2417 | } | 
|  | 2418 | } finally { | 
|  | 2419 | Binder.restoreCallingIdentity(identity); | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2420 | } | 
|  | 2421 | } | 
|  | 2422 |  | 
|  | 2423 | /** | 
|  | 2424 | * Returns the CDMA MIN. | 
|  | 2425 | */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2426 | @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2427 | public String getCdmaMin(int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2428 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 2429 | mApp, subId, "getCdmaMin"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2430 |  | 
|  | 2431 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2432 | try { | 
|  | 2433 | final Phone phone = getPhone(subId); | 
|  | 2434 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { | 
|  | 2435 | return phone.getCdmaMin(); | 
|  | 2436 | } else { | 
|  | 2437 | return null; | 
|  | 2438 | } | 
|  | 2439 | } finally { | 
|  | 2440 | Binder.restoreCallingIdentity(identity); | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2441 | } | 
|  | 2442 | } | 
|  | 2443 |  | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2444 | @Override | 
|  | 2445 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, | 
|  | 2446 | INumberVerificationCallback callback, String callingPackage) { | 
|  | 2447 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) | 
|  | 2448 | != PERMISSION_GRANTED) { | 
|  | 2449 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); | 
|  | 2450 | } | 
|  | 2451 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 2452 |  | 
|  | 2453 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); | 
|  | 2454 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { | 
|  | 2455 | throw new SecurityException("Calling package must be configured in the device config"); | 
|  | 2456 | } | 
|  | 2457 |  | 
|  | 2458 | if (range == null) { | 
|  | 2459 | throw new NullPointerException("Range must be non-null"); | 
|  | 2460 | } | 
|  | 2461 |  | 
|  | 2462 | timeoutMillis = Math.min(timeoutMillis, | 
|  | 2463 | TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS); | 
|  | 2464 |  | 
|  | 2465 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); | 
|  | 2466 | } | 
|  | 2467 |  | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2468 | /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2469 | * Returns true if CDMA provisioning needs to run. | 
|  | 2470 | */ | 
|  | 2471 | public boolean needsOtaServiceProvisioning() { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2472 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2473 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2474 | return getDefaultPhone().needsOtaServiceProvisioning(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2475 | } finally { | 
|  | 2476 | Binder.restoreCallingIdentity(identity); | 
|  | 2477 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2478 | } | 
|  | 2479 |  | 
|  | 2480 | /** | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2481 | * Sets the voice mail number of a given subId. | 
|  | 2482 | */ | 
|  | 2483 | @Override | 
|  | 2484 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2485 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2486 |  | 
|  | 2487 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2488 | try { | 
|  | 2489 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, | 
|  | 2490 | new Pair<String, String>(alphaTag, number), new Integer(subId)); | 
|  | 2491 | return success; | 
|  | 2492 | } finally { | 
|  | 2493 | Binder.restoreCallingIdentity(identity); | 
|  | 2494 | } | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2495 | } | 
|  | 2496 |  | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2497 | @Override | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2498 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { | 
|  | 2499 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2500 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2501 | if (!TextUtils.equals(callingPackage, systemDialer)) { | 
|  | 2502 | throw new SecurityException("caller must be system dialer"); | 
|  | 2503 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2504 |  | 
|  | 2505 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2506 | try { | 
|  | 2507 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); | 
|  | 2508 | if (phoneAccountHandle == null) { | 
|  | 2509 | return null; | 
|  | 2510 | } | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2511 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2512 | } finally { | 
|  | 2513 | Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2514 | } | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2515 | } | 
|  | 2516 |  | 
|  | 2517 | @Override | 
| Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2518 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { | 
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2519 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2520 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2521 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { | 
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2522 | return null; | 
|  | 2523 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2524 |  | 
| Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2525 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2526 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2527 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); | 
| Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2528 | } finally { | 
|  | 2529 | Binder.restoreCallingIdentity(identity); | 
|  | 2530 | } | 
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2531 | } | 
|  | 2532 |  | 
|  | 2533 | @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2534 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, | 
|  | 2535 | VisualVoicemailSmsFilterSettings settings) { | 
|  | 2536 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2537 |  | 
|  | 2538 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2539 | try { | 
|  | 2540 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2541 | mApp, callingPackage, subId, settings); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2542 | } finally { | 
|  | 2543 | Binder.restoreCallingIdentity(identity); | 
|  | 2544 | } | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2545 | } | 
|  | 2546 |  | 
|  | 2547 | @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2548 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { | 
|  | 2549 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2550 |  | 
|  | 2551 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2552 | try { | 
|  | 2553 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2554 | mApp, callingPackage, subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2555 | } finally { | 
|  | 2556 | Binder.restoreCallingIdentity(identity); | 
|  | 2557 | } | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2558 | } | 
|  | 2559 |  | 
|  | 2560 | @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2561 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( | 
|  | 2562 | String callingPackage, int subId) { | 
|  | 2563 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2564 |  | 
|  | 2565 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2566 | try { | 
|  | 2567 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2568 | mApp, callingPackage, subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2569 | } finally { | 
|  | 2570 | Binder.restoreCallingIdentity(identity); | 
|  | 2571 | } | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2572 | } | 
|  | 2573 |  | 
|  | 2574 | @Override | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2575 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2576 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2577 |  | 
|  | 2578 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2579 | try { | 
|  | 2580 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2581 | mApp, subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2582 | } finally { | 
|  | 2583 | Binder.restoreCallingIdentity(identity); | 
|  | 2584 | } | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2585 | } | 
|  | 2586 |  | 
|  | 2587 | @Override | 
|  | 2588 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, | 
|  | 2589 | String number, int port, String text, PendingIntent sentIntent) { | 
|  | 2590 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2591 | enforceVisualVoicemailPackage(callingPackage, subId); | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2592 | enforceSendSmsPermission(); | 
|  | 2593 | // Make the calls as the phone process. | 
|  | 2594 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2595 | try { | 
|  | 2596 | SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); | 
|  | 2597 | if (port == 0) { | 
|  | 2598 | smsManager.sendTextMessageWithSelfPermissions(number, null, text, | 
|  | 2599 | sentIntent, null, false); | 
|  | 2600 | } else { | 
|  | 2601 | byte[] data = text.getBytes(StandardCharsets.UTF_8); | 
|  | 2602 | smsManager.sendDataMessageWithSelfPermissions(number, null, | 
|  | 2603 | (short) port, data, sentIntent, null); | 
|  | 2604 | } | 
|  | 2605 | } finally { | 
|  | 2606 | Binder.restoreCallingIdentity(identity); | 
|  | 2607 | } | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2608 | } | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2609 | /** | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2610 | * Sets the voice activation state of a given subId. | 
|  | 2611 | */ | 
|  | 2612 | @Override | 
|  | 2613 | public void setVoiceActivationState(int subId, int activationState) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2614 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 2615 | mApp, subId, "setVoiceActivationState"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2616 |  | 
|  | 2617 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2618 | try { | 
|  | 2619 | final Phone phone = getPhone(subId); | 
|  | 2620 | if (phone != null) { | 
|  | 2621 | phone.setVoiceActivationState(activationState); | 
|  | 2622 | } else { | 
|  | 2623 | loge("setVoiceActivationState fails with invalid subId: " + subId); | 
|  | 2624 | } | 
|  | 2625 | } finally { | 
|  | 2626 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2627 | } | 
|  | 2628 | } | 
|  | 2629 |  | 
|  | 2630 | /** | 
|  | 2631 | * Sets the data activation state of a given subId. | 
|  | 2632 | */ | 
|  | 2633 | @Override | 
|  | 2634 | public void setDataActivationState(int subId, int activationState) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2635 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 2636 | mApp, subId, "setDataActivationState"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2637 |  | 
|  | 2638 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2639 | try { | 
|  | 2640 | final Phone phone = getPhone(subId); | 
|  | 2641 | if (phone != null) { | 
|  | 2642 | phone.setDataActivationState(activationState); | 
|  | 2643 | } else { | 
|  | 2644 | loge("setVoiceActivationState fails with invalid subId: " + subId); | 
|  | 2645 | } | 
|  | 2646 | } finally { | 
|  | 2647 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2648 | } | 
|  | 2649 | } | 
|  | 2650 |  | 
|  | 2651 | /** | 
|  | 2652 | * Returns the voice activation state of a given subId. | 
|  | 2653 | */ | 
|  | 2654 | @Override | 
|  | 2655 | public int getVoiceActivationState(int subId, String callingPackage) { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2656 | enforceReadPrivilegedPermission("getVoiceActivationState"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2657 |  | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2658 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2659 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2660 | try { | 
|  | 2661 | if (phone != null) { | 
|  | 2662 | return phone.getVoiceActivationState(); | 
|  | 2663 | } else { | 
|  | 2664 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; | 
|  | 2665 | } | 
|  | 2666 | } finally { | 
|  | 2667 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2668 | } | 
|  | 2669 | } | 
|  | 2670 |  | 
|  | 2671 | /** | 
|  | 2672 | * Returns the data activation state of a given subId. | 
|  | 2673 | */ | 
|  | 2674 | @Override | 
|  | 2675 | public int getDataActivationState(int subId, String callingPackage) { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2676 | enforceReadPrivilegedPermission("getDataActivationState"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2677 |  | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2678 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2679 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2680 | try { | 
|  | 2681 | if (phone != null) { | 
|  | 2682 | return phone.getDataActivationState(); | 
|  | 2683 | } else { | 
|  | 2684 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; | 
|  | 2685 | } | 
|  | 2686 | } finally { | 
|  | 2687 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2688 | } | 
|  | 2689 | } | 
|  | 2690 |  | 
|  | 2691 | /** | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2692 | * Returns the unread count of voicemails for a subId | 
|  | 2693 | */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2694 | @Override | 
| Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2695 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { | 
|  | 2696 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 2697 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { | 
|  | 2698 | return 0; | 
|  | 2699 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2700 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2701 | try { | 
|  | 2702 | final Phone phone = getPhone(subId); | 
|  | 2703 | if (phone != null) { | 
|  | 2704 | return phone.getVoiceMessageCount(); | 
|  | 2705 | } else { | 
|  | 2706 | return 0; | 
|  | 2707 | } | 
|  | 2708 | } finally { | 
|  | 2709 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2710 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2711 | } | 
|  | 2712 |  | 
|  | 2713 | /** | 
| pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2714 | * returns true, if the device is in a state where both voice and data | 
|  | 2715 | * are supported simultaneously. This can change based on location or network condition. | 
|  | 2716 | */ | 
|  | 2717 | @Override | 
|  | 2718 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2719 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2720 | try { | 
|  | 2721 | final Phone phone = getPhone(subId); | 
|  | 2722 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); | 
|  | 2723 | } finally { | 
|  | 2724 | Binder.restoreCallingIdentity(identity); | 
|  | 2725 | } | 
| pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2726 | } | 
|  | 2727 |  | 
|  | 2728 | /** | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2729 | * Send the dialer code if called from the current default dialer or the caller has | 
|  | 2730 | * carrier privilege. | 
|  | 2731 | * @param inputCode The dialer code to send | 
|  | 2732 | */ | 
|  | 2733 | @Override | 
|  | 2734 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2735 | final Phone defaultPhone = getDefaultPhone(); | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2736 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2737 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) | 
|  | 2738 | .getDefaultDialerPackage(); | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2739 | if (!TextUtils.equals(callingPackage, defaultDialer)) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2740 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( | 
|  | 2741 | getDefaultSubscription(), "sendDialerSpecialCode"); | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2742 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2743 |  | 
|  | 2744 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2745 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2746 | defaultPhone.sendDialerSpecialCode(inputCode); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2747 | } finally { | 
|  | 2748 | Binder.restoreCallingIdentity(identity); | 
|  | 2749 | } | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2750 | } | 
|  | 2751 |  | 
|  | 2752 | /** | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2753 | * Returns the data network type. | 
|  | 2754 | * Legacy call, permission-free. | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2755 | * | 
|  | 2756 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. | 
|  | 2757 | */ | 
|  | 2758 | @Override | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2759 | public int getNetworkType() { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2760 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2761 | try { | 
|  | 2762 | final Phone phone = getPhone(getDefaultSubscription()); | 
|  | 2763 | if (phone != null) { | 
|  | 2764 | return phone.getServiceState().getDataNetworkType(); | 
|  | 2765 | } else { | 
|  | 2766 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 2767 | } | 
|  | 2768 | } finally { | 
|  | 2769 | Binder.restoreCallingIdentity(identity); | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2770 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2771 | } | 
|  | 2772 |  | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2773 | @Override | 
|  | 2774 | public int getNetworkSelectionMode(int subId) { | 
| Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2775 | if (!isActiveSubscription(subId)) { | 
|  | 2776 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; | 
|  | 2777 | } | 
|  | 2778 |  | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2779 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); | 
|  | 2780 | } | 
|  | 2781 |  | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2782 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2783 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) | 
|  | 2784 | throws RemoteException { | 
|  | 2785 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2786 | final long token = Binder.clearCallingIdentity(); | 
|  | 2787 | try { | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2788 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2789 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2790 | .addRegistrationCallbackForSubscription(c, subId); | 
|  | 2791 | } finally { | 
|  | 2792 | Binder.restoreCallingIdentity(token); | 
|  | 2793 | } | 
|  | 2794 | } | 
|  | 2795 |  | 
|  | 2796 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2797 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { | 
|  | 2798 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2799 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 2800 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 2801 | } | 
|  | 2802 | Binder.withCleanCallingIdentity(() -> { | 
|  | 2803 | try { | 
|  | 2804 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2805 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2806 | .removeRegistrationCallbackForSubscription(c, subId); | 
|  | 2807 | } catch (IllegalArgumentException e) { | 
|  | 2808 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId | 
|  | 2809 | + "is inactive, ignoring unregister."); | 
|  | 2810 | // If the subscription is no longer active, just return, since the callback | 
|  | 2811 | // will already have been removed internally. | 
|  | 2812 | } | 
|  | 2813 | }); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2814 | } | 
|  | 2815 |  | 
|  | 2816 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2817 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) | 
|  | 2818 | throws RemoteException { | 
|  | 2819 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2820 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 2821 | final long token = Binder.clearCallingIdentity(); | 
|  | 2822 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2823 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2824 | .addCapabilitiesCallbackForSubscription(c, subId); | 
|  | 2825 | } finally { | 
|  | 2826 | Binder.restoreCallingIdentity(token); | 
|  | 2827 | } | 
|  | 2828 | } | 
|  | 2829 |  | 
|  | 2830 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2831 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { | 
|  | 2832 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2833 |  | 
|  | 2834 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 2835 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 2836 | } | 
|  | 2837 | Binder.withCleanCallingIdentity(() -> { | 
|  | 2838 | try { | 
|  | 2839 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2840 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2841 | .removeCapabilitiesCallbackForSubscription(c, subId); | 
|  | 2842 | } catch (IllegalArgumentException e) { | 
|  | 2843 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId | 
|  | 2844 | + "is inactive, ignoring unregister."); | 
|  | 2845 | // If the subscription is no longer active, just return, since the callback | 
|  | 2846 | // will already have been removed internally. | 
|  | 2847 | } | 
|  | 2848 | }); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2849 | } | 
|  | 2850 |  | 
|  | 2851 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2852 | public boolean isCapable(int subId, int capability, int regTech) { | 
|  | 2853 | enforceReadPrivilegedPermission("isCapable"); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2854 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 2855 | final long token = Binder.clearCallingIdentity(); | 
|  | 2856 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2857 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2858 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); | 
|  | 2859 | } catch (ImsException e) { | 
|  | 2860 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); | 
|  | 2861 | return false; | 
| Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2862 | } catch (IllegalArgumentException e) { | 
|  | 2863 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); | 
|  | 2864 | return false; | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2865 | } finally { | 
|  | 2866 | Binder.restoreCallingIdentity(token); | 
|  | 2867 | } | 
|  | 2868 | } | 
|  | 2869 |  | 
|  | 2870 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2871 | public boolean isAvailable(int subId, int capability, int regTech) { | 
|  | 2872 | enforceReadPrivilegedPermission("isAvailable"); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2873 | final long token = Binder.clearCallingIdentity(); | 
|  | 2874 | try { | 
|  | 2875 | Phone phone = getPhone(subId); | 
|  | 2876 | if (phone == null) return false; | 
|  | 2877 | return phone.isImsCapabilityAvailable(capability, regTech); | 
|  | 2878 | } finally { | 
|  | 2879 | Binder.restoreCallingIdentity(token); | 
|  | 2880 | } | 
|  | 2881 | } | 
|  | 2882 |  | 
|  | 2883 | @Override | 
|  | 2884 | public boolean isAdvancedCallingSettingEnabled(int subId) { | 
|  | 2885 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); | 
|  | 2886 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 2887 | final long token = Binder.clearCallingIdentity(); | 
|  | 2888 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2889 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2890 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); | 
|  | 2891 | } finally { | 
|  | 2892 | Binder.restoreCallingIdentity(token); | 
|  | 2893 | } | 
|  | 2894 | } | 
|  | 2895 |  | 
|  | 2896 | @Override | 
|  | 2897 | public void setAdvancedCallingSetting(int subId, boolean isEnabled) { | 
|  | 2898 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 2899 | "setAdvancedCallingSetting"); | 
|  | 2900 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2901 | try { | 
|  | 2902 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2903 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2904 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); | 
|  | 2905 | } finally { | 
|  | 2906 | Binder.restoreCallingIdentity(identity); | 
|  | 2907 | } | 
|  | 2908 | } | 
|  | 2909 |  | 
|  | 2910 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2911 | public boolean isVtSettingEnabled(int subId) { | 
|  | 2912 | enforceReadPrivilegedPermission("isVtSettingEnabled"); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2913 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2914 | try { | 
|  | 2915 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2916 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2917 | getSlotIndexOrException(subId)).isVtEnabledByUser(); | 
|  | 2918 | } finally { | 
|  | 2919 | Binder.restoreCallingIdentity(identity); | 
|  | 2920 | } | 
|  | 2921 | } | 
|  | 2922 |  | 
|  | 2923 | @Override | 
|  | 2924 | public void setVtSetting(int subId, boolean isEnabled) { | 
|  | 2925 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 2926 | "setVtSetting"); | 
|  | 2927 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2928 | try { | 
|  | 2929 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2930 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2931 | } finally { | 
|  | 2932 | Binder.restoreCallingIdentity(identity); | 
|  | 2933 | } | 
|  | 2934 | } | 
|  | 2935 |  | 
|  | 2936 | @Override | 
|  | 2937 | public boolean isVoWiFiSettingEnabled(int subId) { | 
|  | 2938 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); | 
|  | 2939 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2940 | try { | 
|  | 2941 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2942 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2943 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); | 
|  | 2944 | } finally { | 
|  | 2945 | Binder.restoreCallingIdentity(identity); | 
|  | 2946 | } | 
|  | 2947 | } | 
|  | 2948 |  | 
|  | 2949 | @Override | 
|  | 2950 | public void setVoWiFiSetting(int subId, boolean isEnabled) { | 
|  | 2951 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 2952 | "setVoWiFiSetting"); | 
|  | 2953 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2954 | try { | 
|  | 2955 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2956 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2957 | } finally { | 
|  | 2958 | Binder.restoreCallingIdentity(identity); | 
|  | 2959 | } | 
|  | 2960 | } | 
|  | 2961 |  | 
|  | 2962 | @Override | 
|  | 2963 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { | 
|  | 2964 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); | 
|  | 2965 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2966 | try { | 
|  | 2967 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2968 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2969 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); | 
|  | 2970 | } finally { | 
|  | 2971 | Binder.restoreCallingIdentity(identity); | 
|  | 2972 | } | 
|  | 2973 | } | 
|  | 2974 |  | 
|  | 2975 | @Override | 
|  | 2976 | public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) { | 
|  | 2977 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 2978 | "setVoWiFiRoamingSetting"); | 
|  | 2979 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2980 | try { | 
|  | 2981 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2982 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2983 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); | 
|  | 2984 | } finally { | 
|  | 2985 | Binder.restoreCallingIdentity(identity); | 
|  | 2986 | } | 
|  | 2987 | } | 
|  | 2988 |  | 
|  | 2989 | @Override | 
|  | 2990 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { | 
|  | 2991 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 2992 | "setVoWiFiNonPersistent"); | 
|  | 2993 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2994 | try { | 
|  | 2995 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 2996 | boolean isRoaming = TelephonyManager.from( | 
|  | 2997 | getPhone(subId).getContext()).isNetworkRoaming(subId); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2998 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 2999 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3000 | } finally { | 
|  | 3001 | Binder.restoreCallingIdentity(identity); | 
|  | 3002 | } | 
|  | 3003 | } | 
|  | 3004 |  | 
|  | 3005 | @Override | 
|  | 3006 | public int getVoWiFiModeSetting(int subId) { | 
|  | 3007 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); | 
|  | 3008 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3009 | try { | 
|  | 3010 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3011 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3012 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); | 
|  | 3013 | } finally { | 
|  | 3014 | Binder.restoreCallingIdentity(identity); | 
|  | 3015 | } | 
|  | 3016 | } | 
|  | 3017 |  | 
|  | 3018 | @Override | 
|  | 3019 | public void setVoWiFiModeSetting(int subId, int mode) { | 
|  | 3020 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 3021 | "setVoWiFiModeSetting"); | 
|  | 3022 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3023 | try { | 
|  | 3024 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3025 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3026 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); | 
|  | 3027 | } finally { | 
|  | 3028 | Binder.restoreCallingIdentity(identity); | 
|  | 3029 | } | 
|  | 3030 | } | 
|  | 3031 |  | 
|  | 3032 | @Override | 
|  | 3033 | public int getVoWiFiRoamingModeSetting(int subId) { | 
|  | 3034 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); | 
|  | 3035 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3036 | try { | 
|  | 3037 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3038 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3039 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); | 
|  | 3040 | } finally { | 
|  | 3041 | Binder.restoreCallingIdentity(identity); | 
|  | 3042 | } | 
|  | 3043 | } | 
|  | 3044 |  | 
|  | 3045 | @Override | 
|  | 3046 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { | 
|  | 3047 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 3048 | "setVoWiFiRoamingModeSetting"); | 
|  | 3049 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3050 | try { | 
|  | 3051 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3052 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3053 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); | 
|  | 3054 | } finally { | 
|  | 3055 | Binder.restoreCallingIdentity(identity); | 
|  | 3056 | } | 
|  | 3057 | } | 
|  | 3058 |  | 
|  | 3059 | @Override | 
|  | 3060 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { | 
|  | 3061 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 3062 | "setRttCapabilityEnabled"); | 
|  | 3063 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3064 | try { | 
|  | 3065 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3066 | ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3067 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); | 
|  | 3068 | } finally { | 
|  | 3069 | Binder.restoreCallingIdentity(identity); | 
|  | 3070 | } | 
|  | 3071 | } | 
|  | 3072 |  | 
|  | 3073 | @Override | 
|  | 3074 | public boolean isTtyOverVolteEnabled(int subId) { | 
|  | 3075 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); | 
|  | 3076 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3077 | try { | 
|  | 3078 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3079 | return ImsManager.getInstance(mApp, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3080 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); | 
|  | 3081 | } finally { | 
|  | 3082 | Binder.restoreCallingIdentity(identity); | 
|  | 3083 | } | 
|  | 3084 | } | 
|  | 3085 |  | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3086 | @Override | 
|  | 3087 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { | 
|  | 3088 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); | 
|  | 3089 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3090 | try { | 
|  | 3091 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3092 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3093 | .addProvisioningCallbackForSubscription(callback, subId); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3094 | } finally { | 
|  | 3095 | Binder.restoreCallingIdentity(identity); | 
|  | 3096 | } | 
|  | 3097 | } | 
|  | 3098 |  | 
|  | 3099 | @Override | 
|  | 3100 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { | 
|  | 3101 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); | 
|  | 3102 | final long identity = Binder.clearCallingIdentity(); | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3103 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 3104 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 3105 | } | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3106 | try { | 
|  | 3107 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3108 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3109 | .removeProvisioningCallbackForSubscription(callback, subId); | 
|  | 3110 | } catch (IllegalArgumentException e) { | 
|  | 3111 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId | 
|  | 3112 | + "is inactive, ignoring unregister."); | 
|  | 3113 | // If the subscription is no longer active, just return, since the callback will already | 
|  | 3114 | // have been removed internally. | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3115 | } finally { | 
|  | 3116 | Binder.restoreCallingIdentity(identity); | 
|  | 3117 | } | 
|  | 3118 | } | 
|  | 3119 |  | 
|  | 3120 | @Override | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3121 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, | 
|  | 3122 | boolean isProvisioned) { | 
|  | 3123 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN | 
|  | 3124 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 3125 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); | 
|  | 3126 | } | 
|  | 3127 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 3128 | "setProvisioningStatusForCapability"); | 
|  | 3129 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3130 | try { | 
|  | 3131 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 3132 | Phone phone = getPhone(subId); | 
|  | 3133 | if (phone == null) { | 
|  | 3134 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " | 
|  | 3135 | + subId); | 
|  | 3136 | return; | 
|  | 3137 | } | 
|  | 3138 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { | 
|  | 3139 | return; | 
|  | 3140 | } | 
|  | 3141 |  | 
|  | 3142 | // this capability requires provisioning, route to the correct API. | 
|  | 3143 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); | 
|  | 3144 | switch (capability) { | 
|  | 3145 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { | 
|  | 3146 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 3147 | ims.setVolteProvisioned(isProvisioned); | 
|  | 3148 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { | 
|  | 3149 | ims.setWfcProvisioned(isProvisioned); | 
|  | 3150 | } | 
|  | 3151 | break; | 
|  | 3152 | } | 
|  | 3153 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { | 
|  | 3154 | // There is currently no difference in VT provisioning type. | 
|  | 3155 | ims.setVtProvisioned(isProvisioned); | 
|  | 3156 | break; | 
|  | 3157 | } | 
|  | 3158 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { | 
|  | 3159 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so | 
|  | 3160 | // change the capability of the feature instead if needed. | 
|  | 3161 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) | 
|  | 3162 | == isProvisioned) { | 
|  | 3163 | // No change in provisioning. | 
|  | 3164 | return; | 
|  | 3165 | } | 
|  | 3166 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); | 
|  | 3167 | try { | 
|  | 3168 | ims.changeMmTelCapability(capability, tech, isProvisioned); | 
|  | 3169 | } catch (ImsException e) { | 
|  | 3170 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" | 
|  | 3171 | + ", Exception" + e.getMessage()); | 
|  | 3172 | } | 
|  | 3173 | break; | 
|  | 3174 | } | 
|  | 3175 | default: { | 
|  | 3176 | throw new IllegalArgumentException("Tried to set provisioning for capability '" | 
|  | 3177 | + capability + "', which does not require provisioning."); | 
|  | 3178 | } | 
|  | 3179 | } | 
|  | 3180 |  | 
|  | 3181 | } finally { | 
|  | 3182 | Binder.restoreCallingIdentity(identity); | 
|  | 3183 | } | 
|  | 3184 | } | 
|  | 3185 |  | 
|  | 3186 | @Override | 
|  | 3187 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { | 
|  | 3188 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN | 
|  | 3189 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 3190 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); | 
|  | 3191 | } | 
|  | 3192 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); | 
|  | 3193 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3194 | try { | 
|  | 3195 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
|  | 3196 | Phone phone = getPhone(subId); | 
|  | 3197 | if (phone == null) { | 
|  | 3198 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " | 
|  | 3199 | + subId); | 
|  | 3200 | // We will fail with "true" as the provisioning status because this is the default | 
|  | 3201 | // if we do not require provisioning. | 
|  | 3202 | return true; | 
|  | 3203 | } | 
|  | 3204 |  | 
|  | 3205 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { | 
|  | 3206 | return true; | 
|  | 3207 | } | 
|  | 3208 |  | 
|  | 3209 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); | 
|  | 3210 | switch (capability) { | 
|  | 3211 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { | 
|  | 3212 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 3213 | return ims.isVolteProvisionedOnDevice(); | 
|  | 3214 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { | 
|  | 3215 | return ims.isWfcProvisionedOnDevice(); | 
|  | 3216 | } | 
|  | 3217 | // This should never happen, since we are checking tech above to make sure it | 
|  | 3218 | // is either LTE or IWLAN. | 
|  | 3219 | throw new IllegalArgumentException("Invalid radio technology for voice " | 
|  | 3220 | + "capability."); | 
|  | 3221 | } | 
|  | 3222 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { | 
|  | 3223 | // There is currently no difference in VT provisioning type. | 
|  | 3224 | return ims.isVtProvisionedOnDevice(); | 
|  | 3225 | } | 
|  | 3226 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { | 
|  | 3227 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. | 
|  | 3228 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); | 
|  | 3229 | } | 
|  | 3230 | default: { | 
|  | 3231 | throw new IllegalArgumentException("Tried to get provisioning for capability '" | 
|  | 3232 | + capability + "', which does not require provisioning."); | 
|  | 3233 | } | 
|  | 3234 | } | 
|  | 3235 |  | 
|  | 3236 | } finally { | 
|  | 3237 | Binder.restoreCallingIdentity(identity); | 
|  | 3238 | } | 
|  | 3239 | } | 
|  | 3240 |  | 
|  | 3241 | @Override | 
|  | 3242 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { | 
|  | 3243 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN | 
|  | 3244 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 3245 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); | 
|  | 3246 | } | 
|  | 3247 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); | 
|  | 3248 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); | 
|  | 3249 | return (provisionedBits & capability) > 0; | 
|  | 3250 | } | 
|  | 3251 |  | 
|  | 3252 | @Override | 
|  | 3253 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, | 
|  | 3254 | boolean isProvisioned) { | 
|  | 3255 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN | 
|  | 3256 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { | 
|  | 3257 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); | 
|  | 3258 | } | 
|  | 3259 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 3260 | "setProvisioningStatusForCapability"); | 
|  | 3261 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); | 
|  | 3262 | // If the current provisioning status for capability already matches isProvisioned, | 
|  | 3263 | // do nothing. | 
|  | 3264 | if (((provisionedBits & capability) > 0) == isProvisioned) { | 
|  | 3265 | return; | 
|  | 3266 | } | 
|  | 3267 | if (isProvisioned) { | 
|  | 3268 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); | 
|  | 3269 | } else { | 
|  | 3270 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); | 
|  | 3271 | } | 
|  | 3272 | } | 
|  | 3273 |  | 
|  | 3274 | /** | 
|  | 3275 | * @return the bitfield containing the MmTel provisioning for the provided subscription and | 
|  | 3276 | * technology. The bitfield should mirror the bitfield defined by | 
|  | 3277 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. | 
|  | 3278 | */ | 
|  | 3279 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { | 
|  | 3280 | String key = getMmTelProvisioningKey(subId, tech); | 
|  | 3281 | // Default is no capabilities are provisioned. | 
|  | 3282 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); | 
|  | 3283 | } | 
|  | 3284 |  | 
|  | 3285 | /** | 
|  | 3286 | * Sets the MmTel capability provisioning bitfield (defined by | 
|  | 3287 | *     {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and | 
|  | 3288 | *     technology specified. | 
|  | 3289 | * | 
|  | 3290 | * Note: This is a synchronous command and should not be called on UI thread. | 
|  | 3291 | */ | 
|  | 3292 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { | 
|  | 3293 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); | 
|  | 3294 | String key = getMmTelProvisioningKey(subId, tech); | 
|  | 3295 | editor.putInt(key, newField); | 
|  | 3296 | editor.commit(); | 
|  | 3297 | } | 
|  | 3298 |  | 
|  | 3299 | private static String getMmTelProvisioningKey(int subId, int tech) { | 
|  | 3300 | // resulting key is provision_ims_mmtel_{subId}_{tech} | 
|  | 3301 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; | 
|  | 3302 | } | 
|  | 3303 |  | 
|  | 3304 | /** | 
|  | 3305 | * Query CarrierConfig to see if the specified capability requires provisioning for the | 
|  | 3306 | * carrier associated with the subscription id. | 
|  | 3307 | */ | 
|  | 3308 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, | 
|  | 3309 | int capability) { | 
|  | 3310 | CarrierConfigManager configManager = new CarrierConfigManager(context); | 
|  | 3311 | PersistableBundle c = configManager.getConfigForSubId(subId); | 
|  | 3312 | boolean requireUtProvisioning = c.getBoolean( | 
|  | 3313 | // By default, this config is true (even if there is no SIM). We also check to make | 
|  | 3314 | // sure the subscription needs provisioning here, so we do not need to check for | 
|  | 3315 | // the no-SIM case, where we would normally shortcut this to false. | 
|  | 3316 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true) | 
|  | 3317 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, | 
|  | 3318 | false); | 
|  | 3319 | boolean requireVoiceVtProvisioning = c.getBoolean( | 
|  | 3320 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); | 
|  | 3321 |  | 
|  | 3322 | // First check to make sure that the capability requires provisioning. | 
|  | 3323 | switch (capability) { | 
|  | 3324 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: | 
|  | 3325 | // intentional fallthrough | 
|  | 3326 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { | 
|  | 3327 | if (requireVoiceVtProvisioning) { | 
|  | 3328 | // Voice and Video requires provisioning | 
|  | 3329 | return true; | 
|  | 3330 | } | 
|  | 3331 | break; | 
|  | 3332 | } | 
|  | 3333 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { | 
|  | 3334 | if (requireUtProvisioning) { | 
|  | 3335 | // UT requires provisioning | 
|  | 3336 | return true; | 
|  | 3337 | } | 
|  | 3338 | break; | 
|  | 3339 | } | 
|  | 3340 | } | 
|  | 3341 | return false; | 
|  | 3342 | } | 
|  | 3343 |  | 
|  | 3344 | @Override | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3345 | public int getImsProvisioningInt(int subId, int key) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3346 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 3347 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
|  | 3348 | } | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3349 | enforceReadPrivilegedPermission("getImsProvisioningInt"); | 
|  | 3350 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3351 | try { | 
|  | 3352 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3353 | int slotId = getSlotIndex(subId); | 
|  | 3354 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 3355 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" | 
|  | 3356 | + subId + "' for key:" + key); | 
|  | 3357 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; | 
|  | 3358 | } | 
|  | 3359 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3360 | } catch (ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3361 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" | 
|  | 3362 | + subId + "' for key:" + key); | 
|  | 3363 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3364 | } finally { | 
|  | 3365 | Binder.restoreCallingIdentity(identity); | 
|  | 3366 | } | 
|  | 3367 | } | 
|  | 3368 |  | 
|  | 3369 | @Override | 
|  | 3370 | public String getImsProvisioningString(int subId, int key) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3371 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 3372 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
|  | 3373 | } | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3374 | enforceReadPrivilegedPermission("getImsProvisioningString"); | 
|  | 3375 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3376 | try { | 
|  | 3377 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3378 | int slotId = getSlotIndex(subId); | 
|  | 3379 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 3380 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" | 
|  | 3381 | + subId + "' for key:" + key); | 
|  | 3382 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; | 
|  | 3383 | } | 
|  | 3384 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3385 | } catch (ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3386 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" | 
|  | 3387 | + subId + "' for key:" + key); | 
|  | 3388 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3389 | } finally { | 
|  | 3390 | Binder.restoreCallingIdentity(identity); | 
|  | 3391 | } | 
|  | 3392 | } | 
|  | 3393 |  | 
|  | 3394 | @Override | 
|  | 3395 | public int setImsProvisioningInt(int subId, int key, int value) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3396 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 3397 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
|  | 3398 | } | 
| Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3399 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 3400 | "setImsProvisioningInt"); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3401 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3402 | try { | 
|  | 3403 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3404 | int slotId = getSlotIndex(subId); | 
|  | 3405 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 3406 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" | 
|  | 3407 | + subId + "' for key:" + key); | 
|  | 3408 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
|  | 3409 | } | 
|  | 3410 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3411 | } catch (ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3412 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId | 
|  | 3413 | + "' for key:" + key); | 
|  | 3414 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3415 | } finally { | 
|  | 3416 | Binder.restoreCallingIdentity(identity); | 
|  | 3417 | } | 
|  | 3418 | } | 
|  | 3419 |  | 
|  | 3420 | @Override | 
|  | 3421 | public int setImsProvisioningString(int subId, int key, String value) { | 
| 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 | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3425 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 3426 | "setImsProvisioningString"); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3427 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3428 | try { | 
|  | 3429 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3430 | int slotId = getSlotIndex(subId); | 
|  | 3431 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 3432 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" | 
|  | 3433 | + subId + "' for key:" + key); | 
|  | 3434 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
|  | 3435 | } | 
|  | 3436 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3437 | } catch (ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3438 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId | 
|  | 3439 | + "' for key:" + key); | 
|  | 3440 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3441 | } finally { | 
|  | 3442 | Binder.restoreCallingIdentity(identity); | 
|  | 3443 | } | 
|  | 3444 | } | 
|  | 3445 |  | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3446 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { | 
|  | 3447 | int slotId = SubscriptionManager.getSlotIndex(subId); | 
|  | 3448 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { | 
| Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3449 | throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId); | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3450 | } | 
|  | 3451 | return slotId; | 
|  | 3452 | } | 
|  | 3453 |  | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3454 | private int getSlotIndex(int subId) { | 
|  | 3455 | int slotId = SubscriptionManager.getSlotIndex(subId); | 
|  | 3456 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { | 
|  | 3457 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; | 
|  | 3458 | } | 
|  | 3459 | return slotId; | 
|  | 3460 | } | 
|  | 3461 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3462 | /** | 
|  | 3463 | * Returns the network type for a subId | 
|  | 3464 | */ | 
|  | 3465 | @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3466 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3467 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3468 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3469 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 3470 | } | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3471 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3472 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3473 | try { | 
|  | 3474 | final Phone phone = getPhone(subId); | 
|  | 3475 | if (phone != null) { | 
|  | 3476 | return phone.getServiceState().getDataNetworkType(); | 
|  | 3477 | } else { | 
|  | 3478 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 3479 | } | 
|  | 3480 | } finally { | 
|  | 3481 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3482 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3483 | } | 
|  | 3484 |  | 
|  | 3485 | /** | 
|  | 3486 | * Returns the data network type | 
|  | 3487 | */ | 
|  | 3488 | @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3489 | public int getDataNetworkType(String callingPackage) { | 
|  | 3490 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3491 | } | 
|  | 3492 |  | 
|  | 3493 | /** | 
|  | 3494 | * Returns the data network type for a subId | 
|  | 3495 | */ | 
|  | 3496 | @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3497 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3498 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3499 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3500 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 3501 | } | 
|  | 3502 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3503 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3504 | try { | 
|  | 3505 | final Phone phone = getPhone(subId); | 
|  | 3506 | if (phone != null) { | 
|  | 3507 | return phone.getServiceState().getDataNetworkType(); | 
|  | 3508 | } else { | 
|  | 3509 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 3510 | } | 
|  | 3511 | } finally { | 
|  | 3512 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3513 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3514 | } | 
|  | 3515 |  | 
|  | 3516 | /** | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3517 | * Returns the Voice network type for a subId | 
|  | 3518 | */ | 
|  | 3519 | @Override | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3520 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3521 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3522 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3523 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 3524 | } | 
|  | 3525 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3526 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3527 | try { | 
|  | 3528 | final Phone phone = getPhone(subId); | 
|  | 3529 | if (phone != null) { | 
|  | 3530 | return phone.getServiceState().getVoiceNetworkType(); | 
|  | 3531 | } else { | 
|  | 3532 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 3533 | } | 
|  | 3534 | } finally { | 
|  | 3535 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3536 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3537 | } | 
|  | 3538 |  | 
|  | 3539 | /** | 
|  | 3540 | * @return true if a ICC card is present | 
|  | 3541 | */ | 
|  | 3542 | public boolean hasIccCard() { | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3543 | // FIXME Make changes to pass defaultSimId of type int | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3544 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( | 
|  | 3545 | getDefaultSubscription())); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3546 | } | 
|  | 3547 |  | 
|  | 3548 | /** | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3549 | * @return true if a ICC card is present for a slotIndex | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3550 | */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3551 | @Override | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3552 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3553 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3554 | try { | 
|  | 3555 | final Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 3556 | if (phone != null) { | 
|  | 3557 | return phone.getIccCard().hasIccCard(); | 
|  | 3558 | } else { | 
|  | 3559 | return false; | 
|  | 3560 | } | 
|  | 3561 | } finally { | 
|  | 3562 | Binder.restoreCallingIdentity(identity); | 
| Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3563 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3564 | } | 
|  | 3565 |  | 
|  | 3566 | /** | 
|  | 3567 | * Return if the current radio is LTE on CDMA. This | 
|  | 3568 | * is a tri-state return value as for a period of time | 
|  | 3569 | * the mode may be unknown. | 
|  | 3570 | * | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3571 | * @param callingPackage the name of the package making the call. | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3572 | * @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] | 3573 | * or {@link Phone#LTE_ON_CDMA_TRUE} | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3574 | */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3575 | @Override | 
|  | 3576 | public int getLteOnCdmaMode(String callingPackage) { | 
|  | 3577 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3578 | } | 
|  | 3579 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3580 | @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3581 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3582 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3583 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3584 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; | 
|  | 3585 | } | 
|  | 3586 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3587 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3588 | try { | 
|  | 3589 | final Phone phone = getPhone(subId); | 
|  | 3590 | if (phone == null) { | 
|  | 3591 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; | 
|  | 3592 | } else { | 
|  | 3593 | return phone.getLteOnCdmaMode(); | 
|  | 3594 | } | 
|  | 3595 | } finally { | 
|  | 3596 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3597 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3598 | } | 
|  | 3599 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3600 | /** | 
|  | 3601 | * {@hide} | 
|  | 3602 | * Returns Default subId, 0 in the case of single standby. | 
|  | 3603 | */ | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3604 | private int getDefaultSubscription() { | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3605 | return mSubscriptionController.getDefaultSubId(); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3606 | } | 
|  | 3607 |  | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3608 | private int getSlotForDefaultSubscription() { | 
|  | 3609 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); | 
|  | 3610 | } | 
|  | 3611 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3612 | private int getPreferredVoiceSubscription() { | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3613 | return mSubscriptionController.getDefaultVoiceSubId(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3614 | } | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3615 |  | 
| Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3616 | private boolean isActiveSubscription(int subId) { | 
|  | 3617 | return mSubscriptionController.isActiveSubId(subId); | 
|  | 3618 | } | 
|  | 3619 |  | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3620 | /** | 
|  | 3621 | * @see android.telephony.TelephonyManager.WifiCallingChoices | 
|  | 3622 | */ | 
|  | 3623 | public int getWhenToMakeWifiCalls() { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3624 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3625 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3626 | return Settings.System.getInt(mApp.getContentResolver(), | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3627 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, | 
|  | 3628 | getWhenToMakeWifiCallsDefaultPreference()); | 
|  | 3629 | } finally { | 
|  | 3630 | Binder.restoreCallingIdentity(identity); | 
|  | 3631 | } | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3632 | } | 
|  | 3633 |  | 
|  | 3634 | /** | 
|  | 3635 | * @see android.telephony.TelephonyManager.WifiCallingChoices | 
|  | 3636 | */ | 
|  | 3637 | public void setWhenToMakeWifiCalls(int preference) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3638 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3639 | try { | 
|  | 3640 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3641 | Settings.System.putInt(mApp.getContentResolver(), | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3642 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); | 
|  | 3643 | } finally { | 
|  | 3644 | Binder.restoreCallingIdentity(identity); | 
|  | 3645 | } | 
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3646 | } | 
|  | 3647 |  | 
| Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3648 | private static int getWhenToMakeWifiCallsDefaultPreference() { | 
| Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3649 | // TODO: Use a build property to choose this value. | 
| Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3650 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3651 | } | 
| Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3652 |  | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3653 | @Override | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3654 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( | 
|  | 3655 | int subId, String callingPackage, String aid, int p2) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3656 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3657 | mApp, subId, "iccOpenLogicalChannel"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3658 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3659 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3660 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3661 | try { | 
|  | 3662 | if (TextUtils.equals(ISDR_AID, aid)) { | 
|  | 3663 | // Only allows LPA to open logical channel to ISD-R. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3664 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() | 
|  | 3665 | .getContext().getPackageManager()); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3666 | if (bestComponent == null | 
|  | 3667 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { | 
|  | 3668 | loge("The calling package is not allowed to access ISD-R."); | 
|  | 3669 | throw new SecurityException( | 
|  | 3670 | "The calling package is not allowed to access ISD-R."); | 
|  | 3671 | } | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3672 | } | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3673 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3674 | if (DBG) { | 
|  | 3675 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); | 
|  | 3676 | } | 
|  | 3677 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( | 
|  | 3678 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId); | 
|  | 3679 | if (DBG) log("iccOpenLogicalChannel: " + response); | 
|  | 3680 | return response; | 
|  | 3681 | } finally { | 
|  | 3682 | Binder.restoreCallingIdentity(identity); | 
|  | 3683 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3684 | } | 
|  | 3685 |  | 
|  | 3686 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3687 | public boolean iccCloseLogicalChannel(int subId, int channel) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3688 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3689 | mApp, subId, "iccCloseLogicalChannel"); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3690 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3691 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3692 | try { | 
|  | 3693 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); | 
|  | 3694 | if (channel < 0) { | 
|  | 3695 | return false; | 
|  | 3696 | } | 
|  | 3697 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId); | 
|  | 3698 | if (DBG) log("iccCloseLogicalChannel: " + success); | 
|  | 3699 | return success; | 
|  | 3700 | } finally { | 
|  | 3701 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3702 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3703 | } | 
|  | 3704 |  | 
|  | 3705 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3706 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3707 | int command, int p1, int p2, int p3, String data) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3708 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3709 | mApp, subId, "iccTransmitApduLogicalChannel"); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3710 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3711 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3712 | try { | 
|  | 3713 | if (DBG) { | 
|  | 3714 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel | 
|  | 3715 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" | 
|  | 3716 | + p3 + " data=" + data); | 
|  | 3717 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3718 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3719 | if (channel < 0) { | 
|  | 3720 | return ""; | 
|  | 3721 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3722 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3723 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, | 
|  | 3724 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId); | 
|  | 3725 | if (DBG) log("iccTransmitApduLogicalChannel: " + response); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3726 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3727 | // Append the returned status code to the end of the response payload. | 
|  | 3728 | String s = Integer.toHexString( | 
|  | 3729 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); | 
|  | 3730 | if (response.payload != null) { | 
|  | 3731 | s = IccUtils.bytesToHexString(response.payload) + s; | 
|  | 3732 | } | 
|  | 3733 | return s; | 
|  | 3734 | } finally { | 
|  | 3735 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3736 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3737 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3738 |  | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3739 | @Override | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3740 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, | 
|  | 3741 | int command, int p1, int p2, int p3, String data) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3742 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3743 | mApp, subId, "iccTransmitApduBasicChannel"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3744 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3745 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3746 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3747 | try { | 
|  | 3748 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 | 
|  | 3749 | && TextUtils.equals(ISDR_AID, data)) { | 
|  | 3750 | // Only allows LPA to select ISD-R. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3751 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() | 
|  | 3752 | .getContext().getPackageManager()); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3753 | if (bestComponent == null | 
|  | 3754 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { | 
|  | 3755 | loge("The calling package is not allowed to select ISD-R."); | 
|  | 3756 | throw new SecurityException( | 
|  | 3757 | "The calling package is not allowed to select ISD-R."); | 
|  | 3758 | } | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3759 | } | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3760 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3761 | if (DBG) { | 
|  | 3762 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" | 
|  | 3763 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); | 
|  | 3764 | } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3765 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3766 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, | 
|  | 3767 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId); | 
|  | 3768 | if (DBG) log("iccTransmitApduBasicChannel: " + response); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3769 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3770 | // Append the returned status code to the end of the response payload. | 
|  | 3771 | String s = Integer.toHexString( | 
|  | 3772 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); | 
|  | 3773 | if (response.payload != null) { | 
|  | 3774 | s = IccUtils.bytesToHexString(response.payload) + s; | 
|  | 3775 | } | 
|  | 3776 | return s; | 
|  | 3777 | } finally { | 
|  | 3778 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3779 | } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3780 | } | 
|  | 3781 |  | 
|  | 3782 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3783 | 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] | 3784 | String filePath) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3785 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3786 | mApp, subId, "iccExchangeSimIO"); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3787 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3788 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3789 | try { | 
|  | 3790 | if (DBG) { | 
|  | 3791 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " | 
|  | 3792 | + p1 + " " + p2 + " " + p3 + ":" + filePath); | 
|  | 3793 | } | 
|  | 3794 |  | 
|  | 3795 | IccIoResult response = | 
|  | 3796 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, | 
|  | 3797 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), | 
|  | 3798 | subId); | 
|  | 3799 |  | 
|  | 3800 | if (DBG) { | 
|  | 3801 | log("Exchange SIM_IO [R]" + response); | 
|  | 3802 | } | 
|  | 3803 |  | 
|  | 3804 | byte[] result = null; | 
|  | 3805 | int length = 2; | 
|  | 3806 | if (response.payload != null) { | 
|  | 3807 | length = 2 + response.payload.length; | 
|  | 3808 | result = new byte[length]; | 
|  | 3809 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); | 
|  | 3810 | } else { | 
|  | 3811 | result = new byte[length]; | 
|  | 3812 | } | 
|  | 3813 |  | 
|  | 3814 | result[length - 1] = (byte) response.sw2; | 
|  | 3815 | result[length - 2] = (byte) response.sw1; | 
|  | 3816 | return result; | 
|  | 3817 | } finally { | 
|  | 3818 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3819 | } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3820 | } | 
|  | 3821 |  | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3822 | /** | 
|  | 3823 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) | 
|  | 3824 | * on a particular subscription | 
|  | 3825 | */ | 
| sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3826 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { | 
|  | 3827 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 3828 | mApp, subId, callingPackage, "getForbiddenPlmns")) { | 
|  | 3829 | return null; | 
|  | 3830 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3831 |  | 
|  | 3832 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3833 | try { | 
|  | 3834 | if (appType != TelephonyManager.APPTYPE_USIM | 
|  | 3835 | && appType != TelephonyManager.APPTYPE_SIM) { | 
|  | 3836 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); | 
|  | 3837 | return null; | 
|  | 3838 | } | 
|  | 3839 | Object response = sendRequest( | 
|  | 3840 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); | 
|  | 3841 | if (response instanceof String[]) { | 
|  | 3842 | return (String[]) response; | 
|  | 3843 | } | 
|  | 3844 | // Response is an Exception of some kind, | 
|  | 3845 | // which is signalled to the user as a NULL retval | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3846 | return null; | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3847 | } finally { | 
|  | 3848 | Binder.restoreCallingIdentity(identity); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3849 | } | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3850 | } | 
|  | 3851 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3852 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3853 | public String sendEnvelopeWithStatus(int subId, String content) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3854 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3855 | mApp, subId, "sendEnvelopeWithStatus"); | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3856 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3857 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3858 | try { | 
|  | 3859 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); | 
|  | 3860 | if (response.payload == null) { | 
|  | 3861 | return ""; | 
|  | 3862 | } | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3863 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3864 | // Append the returned status code to the end of the response payload. | 
|  | 3865 | String s = Integer.toHexString( | 
|  | 3866 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); | 
|  | 3867 | s = IccUtils.bytesToHexString(response.payload) + s; | 
|  | 3868 | return s; | 
|  | 3869 | } finally { | 
|  | 3870 | Binder.restoreCallingIdentity(identity); | 
|  | 3871 | } | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3872 | } | 
|  | 3873 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3874 | /** | 
|  | 3875 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} | 
|  | 3876 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. | 
|  | 3877 | * | 
|  | 3878 | * @param itemID the ID of the item to read | 
|  | 3879 | * @return the NV item as a String, or null on error. | 
|  | 3880 | */ | 
|  | 3881 | @Override | 
|  | 3882 | public String nvReadItem(int itemID) { | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3883 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3884 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3885 | mApp, getDefaultSubscription(), "nvReadItem"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3886 |  | 
|  | 3887 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3888 | try { | 
|  | 3889 | if (DBG) log("nvReadItem: item " + itemID); | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3890 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3891 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); | 
|  | 3892 | return value; | 
|  | 3893 | } finally { | 
|  | 3894 | Binder.restoreCallingIdentity(identity); | 
|  | 3895 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3896 | } | 
|  | 3897 |  | 
|  | 3898 | /** | 
|  | 3899 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} | 
|  | 3900 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. | 
|  | 3901 | * | 
|  | 3902 | * @param itemID the ID of the item to read | 
|  | 3903 | * @param itemValue the value to write, as a String | 
|  | 3904 | * @return true on success; false on any failure | 
|  | 3905 | */ | 
|  | 3906 | @Override | 
|  | 3907 | public boolean nvWriteItem(int itemID, String itemValue) { | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3908 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3909 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3910 | mApp, getDefaultSubscription(), "nvWriteItem"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3911 |  | 
|  | 3912 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3913 | try { | 
|  | 3914 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); | 
|  | 3915 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3916 | new Pair<Integer, String>(itemID, itemValue), workSource); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3917 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); | 
|  | 3918 | return success; | 
|  | 3919 | } finally { | 
|  | 3920 | Binder.restoreCallingIdentity(identity); | 
|  | 3921 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3922 | } | 
|  | 3923 |  | 
|  | 3924 | /** | 
|  | 3925 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. | 
|  | 3926 | * Used for device configuration by some CDMA operators. | 
|  | 3927 | * | 
|  | 3928 | * @param preferredRoamingList byte array containing the new PRL | 
|  | 3929 | * @return true on success; false on any failure | 
|  | 3930 | */ | 
|  | 3931 | @Override | 
|  | 3932 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3933 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3934 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3935 |  | 
|  | 3936 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3937 | try { | 
|  | 3938 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); | 
|  | 3939 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); | 
|  | 3940 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); | 
|  | 3941 | return success; | 
|  | 3942 | } finally { | 
|  | 3943 | Binder.restoreCallingIdentity(identity); | 
|  | 3944 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3945 | } | 
|  | 3946 |  | 
|  | 3947 | /** | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3948 | * 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] | 3949 | * Used for device configuration by some CDMA operators. | 
|  | 3950 | * | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3951 | * @param slotIndex - device slot. | 
|  | 3952 | * | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3953 | * @return true on success; false on any failure | 
|  | 3954 | */ | 
|  | 3955 | @Override | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3956 | public boolean resetModemConfig(int slotIndex) { | 
|  | 3957 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 3958 | if (phone != null) { | 
|  | 3959 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3960 | mApp, phone.getSubId(), "resetModemConfig"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3961 |  | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3962 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3963 | try { | 
|  | 3964 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); | 
|  | 3965 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); | 
|  | 3966 | return success; | 
|  | 3967 | } finally { | 
|  | 3968 | Binder.restoreCallingIdentity(identity); | 
|  | 3969 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3970 | } | 
| chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 3971 | return false; | 
|  | 3972 | } | 
|  | 3973 |  | 
|  | 3974 | /** | 
|  | 3975 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. | 
|  | 3976 | * | 
|  | 3977 | * @param slotIndex - device slot. | 
|  | 3978 | * | 
|  | 3979 | * @return true on success; false on any failure | 
|  | 3980 | */ | 
|  | 3981 | @Override | 
|  | 3982 | public boolean rebootModem(int slotIndex) { | 
|  | 3983 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 3984 | if (phone != null) { | 
|  | 3985 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3986 | mApp, phone.getSubId(), "rebootModem"); | 
|  | 3987 |  | 
|  | 3988 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3989 | try { | 
|  | 3990 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); | 
|  | 3991 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); | 
|  | 3992 | return success; | 
|  | 3993 | } finally { | 
|  | 3994 | Binder.restoreCallingIdentity(identity); | 
|  | 3995 | } | 
|  | 3996 | } | 
|  | 3997 | return false; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3998 | } | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 3999 |  | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4000 | public String[] getPcscfAddress(String apnType, String callingPackage) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4001 | final Phone defaultPhone = getDefaultPhone(); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4002 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4003 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4004 | return new String[0]; | 
|  | 4005 | } | 
|  | 4006 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4007 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4008 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4009 | return defaultPhone.getPcscfAddress(apnType); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4010 | } finally { | 
|  | 4011 | Binder.restoreCallingIdentity(identity); | 
|  | 4012 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4013 | } | 
|  | 4014 |  | 
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4015 | /** | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4016 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability | 
|  | 4017 | * status updates, if not already enabled. | 
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4018 | */ | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4019 | public void enableIms(int slotId) { | 
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4020 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4021 |  | 
|  | 4022 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4023 | try { | 
|  | 4024 | PhoneFactory.getImsResolver().enableIms(slotId); | 
|  | 4025 | } finally { | 
|  | 4026 | Binder.restoreCallingIdentity(identity); | 
|  | 4027 | } | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4028 | } | 
|  | 4029 |  | 
|  | 4030 | /** | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4031 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature | 
|  | 4032 | * status updates to disabled. | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4033 | */ | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4034 | public void disableIms(int slotId) { | 
|  | 4035 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4036 |  | 
|  | 4037 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4038 | try { | 
|  | 4039 | PhoneFactory.getImsResolver().disableIms(slotId); | 
|  | 4040 | } finally { | 
|  | 4041 | Binder.restoreCallingIdentity(identity); | 
|  | 4042 | } | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4043 | } | 
|  | 4044 |  | 
|  | 4045 | /** | 
|  | 4046 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel | 
|  | 4047 | * feature or {@link null} if the service is not available. If the feature is available, the | 
|  | 4048 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. | 
|  | 4049 | */ | 
|  | 4050 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4051 | IImsServiceFeatureCallback callback) { | 
|  | 4052 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4053 |  | 
|  | 4054 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4055 | try { | 
|  | 4056 | return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback); | 
|  | 4057 | } finally { | 
|  | 4058 | Binder.restoreCallingIdentity(identity); | 
|  | 4059 | } | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4060 | } | 
|  | 4061 |  | 
|  | 4062 | /** | 
|  | 4063 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS | 
|  | 4064 | * feature during emergency calling or {@link null} if the service is not available. If the | 
|  | 4065 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a | 
|  | 4066 | * listener for feature updates. | 
|  | 4067 | */ | 
|  | 4068 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { | 
|  | 4069 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4070 |  | 
|  | 4071 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4072 | try { | 
|  | 4073 | return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback); | 
|  | 4074 | } finally { | 
|  | 4075 | Binder.restoreCallingIdentity(identity); | 
|  | 4076 | } | 
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4077 | } | 
|  | 4078 |  | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4079 | /** | 
|  | 4080 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature | 
|  | 4081 | * specified. | 
|  | 4082 | */ | 
|  | 4083 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { | 
|  | 4084 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4085 |  | 
|  | 4086 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4087 | try { | 
|  | 4088 | return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature); | 
|  | 4089 | } finally { | 
|  | 4090 | Binder.restoreCallingIdentity(identity); | 
|  | 4091 | } | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4092 | } | 
|  | 4093 |  | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4094 | /** | 
|  | 4095 | * Returns the {@link IImsConfig} structure associated with the slotId and feature | 
|  | 4096 | * specified. | 
|  | 4097 | */ | 
|  | 4098 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { | 
|  | 4099 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4100 |  | 
|  | 4101 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4102 | try { | 
|  | 4103 | return PhoneFactory.getImsResolver().getImsConfig(slotId, feature); | 
|  | 4104 | } finally { | 
|  | 4105 | Binder.restoreCallingIdentity(identity); | 
|  | 4106 | } | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4107 | } | 
|  | 4108 |  | 
| Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4109 | /** | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4110 | * Sets the ImsService Package Name that Telephony will bind to. | 
|  | 4111 | * | 
|  | 4112 | * @param slotId the slot ID that the ImsService should bind for. | 
|  | 4113 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the | 
|  | 4114 | *         ImsService is the device default ImsService. | 
|  | 4115 | * @param packageName The package name of the application that contains the ImsService to bind | 
|  | 4116 | *         to. | 
|  | 4117 | * @return true if setting the ImsService to bind to succeeded, false if it did not. | 
|  | 4118 | * @hide | 
|  | 4119 | */ | 
|  | 4120 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { | 
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4121 | int[] subIds = SubscriptionManager.getSubId(slotId); | 
|  | 4122 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, | 
|  | 4123 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), | 
|  | 4124 | "setImsService"); | 
|  | 4125 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4126 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4127 | try { | 
|  | 4128 | return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId, | 
|  | 4129 | isCarrierImsService, packageName); | 
|  | 4130 | } finally { | 
|  | 4131 | Binder.restoreCallingIdentity(identity); | 
|  | 4132 | } | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4133 | } | 
|  | 4134 |  | 
|  | 4135 | /** | 
|  | 4136 | * Return the ImsService configuration. | 
|  | 4137 | * | 
|  | 4138 | * @param slotId The slot that the ImsService is associated with. | 
|  | 4139 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is | 
|  | 4140 | *         the device default. | 
|  | 4141 | * @return the package name of the ImsService configuration. | 
|  | 4142 | */ | 
|  | 4143 | public String getImsService(int slotId, boolean isCarrierImsService) { | 
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4144 | int[] subIds = SubscriptionManager.getSubId(slotId); | 
|  | 4145 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, | 
|  | 4146 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), | 
|  | 4147 | "getImsService"); | 
|  | 4148 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4149 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4150 | try { | 
|  | 4151 | return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId, | 
|  | 4152 | isCarrierImsService); | 
|  | 4153 | } finally { | 
|  | 4154 | Binder.restoreCallingIdentity(identity); | 
|  | 4155 | } | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4156 | } | 
|  | 4157 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4158 | public void setImsRegistrationState(boolean registered) { | 
|  | 4159 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4160 |  | 
|  | 4161 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4162 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4163 | getDefaultPhone().setImsRegistrationState(registered); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4164 | } finally { | 
|  | 4165 | Binder.restoreCallingIdentity(identity); | 
|  | 4166 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4167 | } | 
|  | 4168 |  | 
|  | 4169 | /** | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4170 | * Set the network selection mode to automatic. | 
|  | 4171 | * | 
|  | 4172 | */ | 
|  | 4173 | @Override | 
|  | 4174 | public void setNetworkSelectionModeAutomatic(int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4175 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4176 | mApp, subId, "setNetworkSelectionModeAutomatic"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4177 |  | 
| Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4178 | if (!isActiveSubscription(subId)) { | 
|  | 4179 | return; | 
|  | 4180 | } | 
|  | 4181 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4182 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4183 | try { | 
|  | 4184 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); | 
|  | 4185 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); | 
|  | 4186 | } finally { | 
|  | 4187 | Binder.restoreCallingIdentity(identity); | 
|  | 4188 | } | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4189 | } | 
|  | 4190 |  | 
| Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4191 | /** | 
|  | 4192 | * Ask the radio to connect to the input network and change selection mode to manual. | 
|  | 4193 | * | 
|  | 4194 | * @param subId the id of the subscription. | 
|  | 4195 | * @param operatorInfo the operator information, included the PLMN, long name and short name of | 
|  | 4196 | * the operator to attach to. | 
|  | 4197 | * @param persistSelection whether the selection will persist until reboot. If true, only allows | 
|  | 4198 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume | 
|  | 4199 | * normal network selection next time. | 
|  | 4200 | * @return {@code true} on success; {@code true} on any failure. | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4201 | */ | 
|  | 4202 | @Override | 
| Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4203 | public boolean setNetworkSelectionModeManual( | 
|  | 4204 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4205 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4206 | mApp, subId, "setNetworkSelectionModeManual"); | 
| Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4207 |  | 
|  | 4208 | if (!isActiveSubscription(subId)) { | 
|  | 4209 | return false; | 
|  | 4210 | } | 
|  | 4211 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4212 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4213 | try { | 
| Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4214 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4215 | persistSelection); | 
| Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4216 | if (DBG) { | 
|  | 4217 | log("setNetworkSelectionModeManual: subId: " + subId | 
|  | 4218 | + " operator: " + operatorInfo); | 
|  | 4219 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4220 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); | 
|  | 4221 | } finally { | 
|  | 4222 | Binder.restoreCallingIdentity(identity); | 
|  | 4223 | } | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4224 | } | 
|  | 4225 |  | 
|  | 4226 | /** | 
|  | 4227 | * Scans for available networks. | 
|  | 4228 | */ | 
|  | 4229 | @Override | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4230 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4231 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4232 | mApp, subId, "getCellNetworkScanResults"); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4233 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 4234 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 4235 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 4236 | .setCallingPackage(callingPackage) | 
|  | 4237 | .setCallingPid(Binder.getCallingPid()) | 
|  | 4238 | .setCallingUid(Binder.getCallingUid()) | 
|  | 4239 | .setMethod("getCellNetworkScanResults") | 
|  | 4240 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 4241 | .build()); | 
|  | 4242 | switch (locationResult) { | 
|  | 4243 | case DENIED_HARD: | 
|  | 4244 | throw new SecurityException("Not allowed to access scan results -- location"); | 
|  | 4245 | case DENIED_SOFT: | 
|  | 4246 | return null; | 
|  | 4247 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4248 |  | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4249 | long identity = Binder.clearCallingIdentity(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4250 | try { | 
|  | 4251 | if (DBG) log("getCellNetworkScanResults: subId " + subId); | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4252 | return (CellNetworkScanResult) sendRequest( | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4253 | CMD_PERFORM_NETWORK_SCAN, null, subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4254 | } finally { | 
|  | 4255 | Binder.restoreCallingIdentity(identity); | 
|  | 4256 | } | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4257 | } | 
|  | 4258 |  | 
|  | 4259 | /** | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4260 | * Starts a new network scan and returns the id of this scan. | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4261 | * | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4262 | * @param subId id of the subscription | 
|  | 4263 | * @param request contains the radio access networks with bands/channels to scan | 
|  | 4264 | * @param messenger callback messenger for scan results or errors | 
|  | 4265 | * @param binder for the purpose of auto clean when the user thread crashes | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4266 | * @return the id of the requested scan which can be used to stop the scan. | 
|  | 4267 | */ | 
|  | 4268 | @Override | 
|  | 4269 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4270 | IBinder binder, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4271 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4272 | mApp, subId, "requestNetworkScan"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4273 |  | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4274 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 4275 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 4276 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 4277 | .setCallingPackage(callingPackage) | 
|  | 4278 | .setCallingPid(Binder.getCallingPid()) | 
|  | 4279 | .setCallingUid(Binder.getCallingUid()) | 
|  | 4280 | .setMethod("requestNetworkScan") | 
|  | 4281 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 4282 | .build()); | 
|  | 4283 | switch (locationResult) { | 
|  | 4284 | case DENIED_HARD: | 
|  | 4285 | throw new SecurityException("Not allowed to request network scan -- location"); | 
|  | 4286 | case DENIED_SOFT: | 
|  | 4287 | return -1; | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4288 | } | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4289 |  | 
|  | 4290 | return mNetworkScanRequestTracker.startNetworkScan( | 
|  | 4291 | request, messenger, binder, getPhone(subId), | 
|  | 4292 | callingPackage); | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4293 | } | 
|  | 4294 |  | 
|  | 4295 | /** | 
|  | 4296 | * Stops an existing network scan with the given scanId. | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4297 | * | 
|  | 4298 | * @param subId id of the subscription | 
|  | 4299 | * @param scanId id of the scan that needs to be stopped | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4300 | */ | 
|  | 4301 | @Override | 
|  | 4302 | public void stopNetworkScan(int subId, int scanId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4303 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4304 | mApp, subId, "stopNetworkScan"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4305 |  | 
|  | 4306 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4307 | try { | 
|  | 4308 | mNetworkScanRequestTracker.stopNetworkScan(scanId); | 
|  | 4309 | } finally { | 
|  | 4310 | Binder.restoreCallingIdentity(identity); | 
|  | 4311 | } | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4312 | } | 
|  | 4313 |  | 
|  | 4314 | /** | 
| Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4315 | * Get the calculated preferred network type. | 
|  | 4316 | * Used for debugging incorrect network type. | 
|  | 4317 | * | 
|  | 4318 | * @return the preferred network type, defined in RILConstants.java. | 
|  | 4319 | */ | 
|  | 4320 | @Override | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4321 | public int getCalculatedPreferredNetworkType(String callingPackage) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4322 | final Phone defaultPhone = getDefaultPhone(); | 
|  | 4323 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), | 
|  | 4324 | callingPackage, "getCalculatedPreferredNetworkType")) { | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4325 | return RILConstants.PREFERRED_NETWORK_MODE; | 
|  | 4326 | } | 
|  | 4327 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4328 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4329 | try { | 
|  | 4330 | // FIXME: need to get SubId from somewhere. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4331 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4332 | } finally { | 
|  | 4333 | Binder.restoreCallingIdentity(identity); | 
|  | 4334 | } | 
| Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4335 | } | 
|  | 4336 |  | 
|  | 4337 | /** | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4338 | * Get the preferred network type. | 
|  | 4339 | * Used for device configuration by some CDMA operators. | 
|  | 4340 | * | 
|  | 4341 | * @return the preferred network type, defined in RILConstants.java. | 
|  | 4342 | */ | 
|  | 4343 | @Override | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4344 | public int getPreferredNetworkType(int subId) { | 
| Pengquan Meng | 4848cd0 | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4345 | TelephonyPermissions | 
|  | 4346 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 4347 | mApp, subId, "getPreferredNetworkType"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4348 |  | 
|  | 4349 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4350 | try { | 
|  | 4351 | if (DBG) log("getPreferredNetworkType"); | 
|  | 4352 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); | 
|  | 4353 | int networkType = (result != null ? result[0] : -1); | 
|  | 4354 | if (DBG) log("getPreferredNetworkType: " + networkType); | 
|  | 4355 | return networkType; | 
|  | 4356 | } finally { | 
|  | 4357 | Binder.restoreCallingIdentity(identity); | 
|  | 4358 | } | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4359 | } | 
|  | 4360 |  | 
|  | 4361 | /** | 
|  | 4362 | * Set the preferred network type. | 
|  | 4363 | * Used for device configuration by some CDMA operators. | 
|  | 4364 | * | 
|  | 4365 | * @param networkType the preferred network type, defined in RILConstants.java. | 
|  | 4366 | * @return true on success; false on any failure. | 
|  | 4367 | */ | 
|  | 4368 | @Override | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4369 | public boolean setPreferredNetworkType(int subId, int networkType) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4370 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4371 | mApp, subId, "setPreferredNetworkType"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4372 |  | 
|  | 4373 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4374 | try { | 
|  | 4375 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); | 
|  | 4376 | Boolean success = (Boolean) sendRequest( | 
|  | 4377 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); | 
|  | 4378 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); | 
|  | 4379 | if (success) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4380 | Settings.Global.putInt(mApp.getContentResolver(), | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4381 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); | 
|  | 4382 | } | 
|  | 4383 | return success; | 
|  | 4384 | } finally { | 
|  | 4385 | Binder.restoreCallingIdentity(identity); | 
| Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4386 | } | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4387 | } | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4388 |  | 
|  | 4389 | /** | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4390 | * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning | 
| Jack Yu | 13db0fe | 2018-10-30 17:41:31 -0700 | [diff] [blame] | 4391 | * SystemProperty to decide whether DUN APN is required for | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4392 | * tethering. | 
|  | 4393 | * | 
|  | 4394 | * @return 0: Not required. 1: required. 2: Not set. | 
|  | 4395 | * @hide | 
|  | 4396 | */ | 
|  | 4397 | @Override | 
|  | 4398 | public int getTetherApnRequired() { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4399 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4400 |  | 
|  | 4401 | final long identity = Binder.clearCallingIdentity(); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4402 | final Phone defaultPhone = getDefaultPhone(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4403 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4404 | int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(), | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4405 | Settings.Global.TETHER_DUN_REQUIRED, 2); | 
| Jack Yu | 13db0fe | 2018-10-30 17:41:31 -0700 | [diff] [blame] | 4406 | // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4407 | if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4408 | dunRequired = 1; | 
|  | 4409 | } | 
|  | 4410 | return dunRequired; | 
|  | 4411 | } finally { | 
|  | 4412 | Binder.restoreCallingIdentity(identity); | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4413 | } | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4414 | } | 
|  | 4415 |  | 
|  | 4416 | /** | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4417 | * Set mobile data enabled | 
|  | 4418 | * Used by the user through settings etc to turn on/off mobile data | 
|  | 4419 | * | 
|  | 4420 | * @param enable {@code true} turn turn data on, else {@code false} | 
|  | 4421 | */ | 
|  | 4422 | @Override | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4423 | public void setUserDataEnabled(int subId, boolean enable) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4424 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4425 | mApp, subId, "setUserDataEnabled"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4426 |  | 
|  | 4427 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4428 | try { | 
|  | 4429 | int phoneId = mSubscriptionController.getPhoneId(subId); | 
|  | 4430 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); | 
|  | 4431 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 4432 | if (phone != null) { | 
|  | 4433 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); | 
| Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4434 | phone.getDataEnabledSettings().setUserDataEnabled(enable); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4435 | } else { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4436 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4437 | } | 
|  | 4438 | } finally { | 
|  | 4439 | Binder.restoreCallingIdentity(identity); | 
| Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4440 | } | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4441 | } | 
|  | 4442 |  | 
|  | 4443 | /** | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4444 | * Get the user enabled state of Mobile Data. | 
|  | 4445 | * | 
|  | 4446 | * TODO: remove and use isUserDataEnabled. | 
|  | 4447 | * This can't be removed now because some vendor codes | 
|  | 4448 | * calls through ITelephony directly while they should | 
|  | 4449 | * use TelephonyManager. | 
|  | 4450 | * | 
|  | 4451 | * @return true on enabled | 
|  | 4452 | */ | 
|  | 4453 | @Override | 
|  | 4454 | public boolean getDataEnabled(int subId) { | 
|  | 4455 | return isUserDataEnabled(subId); | 
|  | 4456 | } | 
|  | 4457 |  | 
|  | 4458 | /** | 
|  | 4459 | * Get whether mobile data is enabled per user setting. | 
|  | 4460 | * | 
|  | 4461 | * There are other factors deciding whether mobile data is actually enabled, but they are | 
|  | 4462 | * not considered here. See {@link #isDataEnabled(int)} for more details. | 
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4463 | * | 
| Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4464 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4465 | * | 
|  | 4466 | * @return {@code true} if data is enabled else {@code false} | 
|  | 4467 | */ | 
|  | 4468 | @Override | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4469 | public boolean isUserDataEnabled(int subId) { | 
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4470 | try { | 
|  | 4471 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, | 
|  | 4472 | null); | 
|  | 4473 | } catch (Exception e) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4474 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4475 | mApp, subId, "isUserDataEnabled"); | 
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4476 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4477 |  | 
|  | 4478 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4479 | try { | 
|  | 4480 | int phoneId = mSubscriptionController.getPhoneId(subId); | 
|  | 4481 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); | 
|  | 4482 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 4483 | if (phone != null) { | 
|  | 4484 | boolean retVal = phone.isUserDataEnabled(); | 
|  | 4485 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); | 
|  | 4486 | return retVal; | 
|  | 4487 | } else { | 
|  | 4488 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); | 
|  | 4489 | return false; | 
|  | 4490 | } | 
|  | 4491 | } finally { | 
|  | 4492 | Binder.restoreCallingIdentity(identity); | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4493 | } | 
|  | 4494 | } | 
|  | 4495 |  | 
|  | 4496 | /** | 
|  | 4497 | * Get whether mobile data is enabled. | 
|  | 4498 | * | 
|  | 4499 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding | 
|  | 4500 | * whether mobile data is actually enabled. | 
|  | 4501 | * | 
|  | 4502 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. | 
|  | 4503 | * | 
|  | 4504 | * @return {@code true} if data is enabled else {@code false} | 
|  | 4505 | */ | 
|  | 4506 | @Override | 
|  | 4507 | public boolean isDataEnabled(int subId) { | 
|  | 4508 | try { | 
|  | 4509 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, | 
|  | 4510 | null); | 
|  | 4511 | } catch (Exception e) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4512 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4513 | mApp, subId, "isDataEnabled"); | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4514 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4515 |  | 
|  | 4516 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4517 | try { | 
|  | 4518 | int phoneId = mSubscriptionController.getPhoneId(subId); | 
|  | 4519 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); | 
|  | 4520 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 4521 | if (phone != null) { | 
| Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4522 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4523 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); | 
|  | 4524 | return retVal; | 
|  | 4525 | } else { | 
|  | 4526 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); | 
|  | 4527 | return false; | 
|  | 4528 | } | 
|  | 4529 | } finally { | 
|  | 4530 | Binder.restoreCallingIdentity(identity); | 
| Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4531 | } | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4532 | } | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4533 |  | 
|  | 4534 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4535 | public int getCarrierPrivilegeStatus(int subId) { | 
|  | 4536 | final Phone phone = getPhone(subId); | 
|  | 4537 | if (phone == null) { | 
|  | 4538 | loge("getCarrierPrivilegeStatus: Invalid subId"); | 
|  | 4539 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
|  | 4540 | } | 
|  | 4541 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4542 | if (card == null) { | 
| Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4543 | loge("getCarrierPrivilegeStatus: No UICC"); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4544 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
|  | 4545 | } | 
|  | 4546 | return card.getCarrierPrivilegeStatusForCurrentTransaction( | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4547 | phone.getContext().getPackageManager()); | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4548 | } | 
| Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4549 |  | 
|  | 4550 | @Override | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4551 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { | 
|  | 4552 | final Phone phone = getPhone(subId); | 
|  | 4553 | if (phone == null) { | 
|  | 4554 | loge("getCarrierPrivilegeStatus: Invalid subId"); | 
|  | 4555 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
|  | 4556 | } | 
|  | 4557 | UiccProfile profile = | 
|  | 4558 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); | 
|  | 4559 | if (profile == null) { | 
|  | 4560 | loge("getCarrierPrivilegeStatus: No UICC"); | 
|  | 4561 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
|  | 4562 | } | 
|  | 4563 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); | 
|  | 4564 | } | 
|  | 4565 |  | 
|  | 4566 | @Override | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4567 | public int checkCarrierPrivilegesForPackage(String pkgName) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4568 | final Phone defaultPhone = getDefaultPhone(); | 
| Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4569 | if (TextUtils.isEmpty(pkgName)) | 
|  | 4570 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4571 | UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId()); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4572 | if (card == null) { | 
|  | 4573 | loge("checkCarrierPrivilegesForPackage: No UICC"); | 
|  | 4574 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
|  | 4575 | } | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4576 | return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(), | 
|  | 4577 | pkgName); | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4578 | } | 
|  | 4579 |  | 
|  | 4580 | @Override | 
|  | 4581 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { | 
| Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4582 | if (TextUtils.isEmpty(pkgName)) | 
|  | 4583 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4584 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
|  | 4585 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
|  | 4586 | UiccCard card = UiccController.getInstance().getUiccCard(i); | 
|  | 4587 | if (card == null) { | 
| Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4588 | // No UICC in that slot. | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4589 | continue; | 
|  | 4590 | } | 
|  | 4591 |  | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4592 | result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4593 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
|  | 4594 | break; | 
|  | 4595 | } | 
|  | 4596 | } | 
|  | 4597 |  | 
|  | 4598 | return result; | 
| Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4599 | } | 
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4600 |  | 
|  | 4601 | @Override | 
| Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4602 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { | 
|  | 4603 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { | 
|  | 4604 | loge("phoneId " + phoneId + " is not valid."); | 
|  | 4605 | return null; | 
|  | 4606 | } | 
|  | 4607 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4608 | if (card == null) { | 
| Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4609 | loge("getCarrierPackageNamesForIntent: No UICC"); | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4610 | return null ; | 
|  | 4611 | } | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4612 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4613 | } | 
|  | 4614 |  | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4615 | @Override | 
|  | 4616 | public List<String> getPackagesWithCarrierPrivileges() { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4617 | PackageManager pm = mApp.getPackageManager(); | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4618 | List<String> privilegedPackages = new ArrayList<>(); | 
|  | 4619 | List<PackageInfo> packages = null; | 
|  | 4620 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
|  | 4621 | UiccCard card = UiccController.getInstance().getUiccCard(i); | 
|  | 4622 | if (card == null) { | 
|  | 4623 | // No UICC in that slot. | 
|  | 4624 | continue; | 
|  | 4625 | } | 
|  | 4626 | if (card.hasCarrierPrivilegeRules()) { | 
|  | 4627 | if (packages == null) { | 
|  | 4628 | // Only check packages in user 0 for now | 
|  | 4629 | packages = pm.getInstalledPackagesAsUser( | 
|  | 4630 | PackageManager.MATCH_DISABLED_COMPONENTS | 
|  | 4631 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS | 
|  | 4632 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); | 
|  | 4633 | } | 
|  | 4634 | for (int p = packages.size() - 1; p >= 0; p--) { | 
|  | 4635 | PackageInfo pkgInfo = packages.get(p); | 
|  | 4636 | if (pkgInfo != null && pkgInfo.packageName != null | 
|  | 4637 | && card.getCarrierPrivilegeStatus(pkgInfo) | 
|  | 4638 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
|  | 4639 | privilegedPackages.add(pkgInfo.packageName); | 
|  | 4640 | } | 
|  | 4641 | } | 
|  | 4642 | } | 
|  | 4643 | } | 
|  | 4644 | return privilegedPackages; | 
|  | 4645 | } | 
|  | 4646 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4647 | private String getIccId(int subId) { | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4648 | final Phone phone = getPhone(subId); | 
|  | 4649 | UiccCard card = phone == null ? null : phone.getUiccCard(); | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4650 | if (card == null) { | 
|  | 4651 | loge("getIccId: No UICC"); | 
|  | 4652 | return null; | 
|  | 4653 | } | 
|  | 4654 | String iccId = card.getIccId(); | 
|  | 4655 | if (TextUtils.isEmpty(iccId)) { | 
|  | 4656 | loge("getIccId: ICC ID is null or empty."); | 
|  | 4657 | return null; | 
|  | 4658 | } | 
|  | 4659 | return iccId; | 
|  | 4660 | } | 
|  | 4661 |  | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4662 | @Override | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4663 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, | 
|  | 4664 | String number) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4665 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( | 
|  | 4666 | subId, "setLine1NumberForDisplayForSubscriber"); | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4667 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4668 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4669 | try { | 
|  | 4670 | final String iccId = getIccId(subId); | 
|  | 4671 | final Phone phone = getPhone(subId); | 
|  | 4672 | if (phone == null) { | 
|  | 4673 | return false; | 
|  | 4674 | } | 
|  | 4675 | final String subscriberId = phone.getSubscriberId(); | 
|  | 4676 |  | 
|  | 4677 | if (DBG_MERGE) { | 
|  | 4678 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" | 
|  | 4679 | + subscriberId + " to " + number); | 
|  | 4680 | } | 
|  | 4681 |  | 
|  | 4682 | if (TextUtils.isEmpty(iccId)) { | 
|  | 4683 | return false; | 
|  | 4684 | } | 
|  | 4685 |  | 
|  | 4686 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); | 
|  | 4687 |  | 
|  | 4688 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; | 
|  | 4689 | if (alphaTag == null) { | 
|  | 4690 | editor.remove(alphaTagPrefKey); | 
|  | 4691 | } else { | 
|  | 4692 | editor.putString(alphaTagPrefKey, alphaTag); | 
|  | 4693 | } | 
|  | 4694 |  | 
|  | 4695 | // Record both the line number and IMSI for this ICCID, since we need to | 
|  | 4696 | // track all merged IMSIs based on line number | 
|  | 4697 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; | 
|  | 4698 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; | 
|  | 4699 | if (number == null) { | 
|  | 4700 | editor.remove(numberPrefKey); | 
|  | 4701 | editor.remove(subscriberPrefKey); | 
|  | 4702 | } else { | 
|  | 4703 | editor.putString(numberPrefKey, number); | 
|  | 4704 | editor.putString(subscriberPrefKey, subscriberId); | 
|  | 4705 | } | 
|  | 4706 |  | 
|  | 4707 | editor.commit(); | 
|  | 4708 | return true; | 
|  | 4709 | } finally { | 
|  | 4710 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4711 | } | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4712 | } | 
|  | 4713 |  | 
|  | 4714 | @Override | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4715 | public String getLine1NumberForDisplay(int subId, String callingPackage) { | 
| Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4716 | // This is open to apps with WRITE_SMS. | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4717 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4718 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { | 
| Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4719 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4720 | return null; | 
|  | 4721 | } | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4722 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4723 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4724 | try { | 
|  | 4725 | String iccId = getIccId(subId); | 
|  | 4726 | if (iccId != null) { | 
|  | 4727 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; | 
|  | 4728 | if (DBG_MERGE) { | 
|  | 4729 | log("getLine1NumberForDisplay returning " | 
|  | 4730 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); | 
|  | 4731 | } | 
|  | 4732 | return mTelephonySharedPreferences.getString(numberPrefKey, null); | 
| Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4733 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4734 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); | 
|  | 4735 | return null; | 
|  | 4736 | } finally { | 
|  | 4737 | Binder.restoreCallingIdentity(identity); | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4738 | } | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4739 | } | 
|  | 4740 |  | 
|  | 4741 | @Override | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4742 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4743 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4744 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4745 | return null; | 
|  | 4746 | } | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4747 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4748 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4749 | try { | 
|  | 4750 | String iccId = getIccId(subId); | 
|  | 4751 | if (iccId != null) { | 
|  | 4752 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; | 
|  | 4753 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); | 
|  | 4754 | } | 
|  | 4755 | return null; | 
|  | 4756 | } finally { | 
|  | 4757 | Binder.restoreCallingIdentity(identity); | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4758 | } | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4759 | } | 
| Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4760 |  | 
|  | 4761 | @Override | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4762 | public String[] getMergedSubscriberIds(String callingPackage) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4763 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried | 
|  | 4764 | // about carrier-privileged callers not having access. | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4765 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4766 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, | 
|  | 4767 | "getMergedSubscriberIds")) { | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4768 | return null; | 
|  | 4769 | } | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4770 |  | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4771 | final long identity  = Binder.clearCallingIdentity(); | 
|  | 4772 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4773 | final Context context = mApp; | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4774 | final TelephonyManager tele = TelephonyManager.from(context); | 
|  | 4775 | final SubscriptionManager sub = SubscriptionManager.from(context); | 
|  | 4776 |  | 
|  | 4777 | // Figure out what subscribers are currently active | 
|  | 4778 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); | 
|  | 4779 | // Clear calling identity, when calling TelephonyManager, because callerUid must be | 
|  | 4780 | // the process, where TelephonyManager was instantiated. | 
|  | 4781 | // Otherwise AppOps check will fail. | 
|  | 4782 |  | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4783 | final int[] subIds = sub.getActiveSubscriptionIdList(); | 
|  | 4784 | for (int subId : subIds) { | 
|  | 4785 | activeSubscriberIds.add(tele.getSubscriberId(subId)); | 
|  | 4786 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4787 |  | 
|  | 4788 | // First pass, find a number override for an active subscriber | 
|  | 4789 | String mergeNumber = null; | 
|  | 4790 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); | 
|  | 4791 | for (String key : prefs.keySet()) { | 
|  | 4792 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { | 
|  | 4793 | final String subscriberId = (String) prefs.get(key); | 
|  | 4794 | if (activeSubscriberIds.contains(subscriberId)) { | 
|  | 4795 | final String iccId = key.substring( | 
|  | 4796 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); | 
|  | 4797 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; | 
|  | 4798 | mergeNumber = (String) prefs.get(numberKey); | 
|  | 4799 | if (DBG_MERGE) { | 
|  | 4800 | Slog.d(LOG_TAG, "Found line number " + mergeNumber | 
|  | 4801 | + " for active subscriber " + subscriberId); | 
|  | 4802 | } | 
|  | 4803 | if (!TextUtils.isEmpty(mergeNumber)) { | 
|  | 4804 | break; | 
|  | 4805 | } | 
|  | 4806 | } | 
|  | 4807 | } | 
|  | 4808 | } | 
|  | 4809 |  | 
|  | 4810 | // Shortcut when no active merged subscribers | 
|  | 4811 | if (TextUtils.isEmpty(mergeNumber)) { | 
|  | 4812 | return null; | 
|  | 4813 | } | 
|  | 4814 |  | 
|  | 4815 | // Second pass, find all subscribers under that line override | 
|  | 4816 | final ArraySet<String> result = new ArraySet<>(); | 
|  | 4817 | for (String key : prefs.keySet()) { | 
|  | 4818 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { | 
|  | 4819 | final String number = (String) prefs.get(key); | 
|  | 4820 | if (mergeNumber.equals(number)) { | 
|  | 4821 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); | 
|  | 4822 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; | 
|  | 4823 | final String subscriberId = (String) prefs.get(subscriberKey); | 
|  | 4824 | if (!TextUtils.isEmpty(subscriberId)) { | 
|  | 4825 | result.add(subscriberId); | 
|  | 4826 | } | 
|  | 4827 | } | 
|  | 4828 | } | 
|  | 4829 | } | 
|  | 4830 |  | 
|  | 4831 | final String[] resultArray = result.toArray(new String[result.size()]); | 
|  | 4832 | Arrays.sort(resultArray); | 
|  | 4833 | if (DBG_MERGE) { | 
|  | 4834 | Slog.d(LOG_TAG, | 
|  | 4835 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); | 
|  | 4836 | } | 
|  | 4837 | return resultArray; | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4838 | } finally { | 
|  | 4839 | Binder.restoreCallingIdentity(identity); | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4840 | } | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4841 | } | 
|  | 4842 |  | 
|  | 4843 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4844 | public boolean setOperatorBrandOverride(int subId, String brand) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4845 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( | 
|  | 4846 | subId, "setOperatorBrandOverride"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4847 |  | 
|  | 4848 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4849 | try { | 
|  | 4850 | final Phone phone = getPhone(subId); | 
|  | 4851 | return phone == null ? false : phone.setOperatorBrandOverride(brand); | 
|  | 4852 | } finally { | 
|  | 4853 | Binder.restoreCallingIdentity(identity); | 
|  | 4854 | } | 
| Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4855 | } | 
| Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 4856 |  | 
|  | 4857 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4858 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, | 
| Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4859 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, | 
|  | 4860 | List<String> cdmaNonRoamingList) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4861 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4862 |  | 
|  | 4863 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4864 | try { | 
|  | 4865 | final Phone phone = getPhone(subId); | 
|  | 4866 | if (phone == null) { | 
|  | 4867 | return false; | 
|  | 4868 | } | 
|  | 4869 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, | 
|  | 4870 | cdmaNonRoamingList); | 
|  | 4871 | } finally { | 
|  | 4872 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4873 | } | 
| Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4874 | } | 
|  | 4875 |  | 
|  | 4876 | @Override | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4877 | @Deprecated | 
|  | 4878 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { | 
|  | 4879 | enforceModifyPermission(); | 
|  | 4880 |  | 
|  | 4881 | int returnValue = 0; | 
|  | 4882 | try { | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4883 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 4884 | if(result.exception == null) { | 
|  | 4885 | if (result.result != null) { | 
|  | 4886 | byte[] responseData = (byte[])(result.result); | 
|  | 4887 | if(responseData.length > oemResp.length) { | 
|  | 4888 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + | 
|  | 4889 | responseData.length +  "bytes. Buffer Size is " + | 
|  | 4890 | oemResp.length + "bytes."); | 
|  | 4891 | } | 
|  | 4892 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); | 
|  | 4893 | returnValue = responseData.length; | 
|  | 4894 | } | 
|  | 4895 | } else { | 
|  | 4896 | CommandException ex = (CommandException) result.exception; | 
|  | 4897 | returnValue = ex.getCommandError().ordinal(); | 
|  | 4898 | if(returnValue > 0) returnValue *= -1; | 
|  | 4899 | } | 
|  | 4900 | } catch (RuntimeException e) { | 
|  | 4901 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); | 
|  | 4902 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); | 
|  | 4903 | if(returnValue > 0) returnValue *= -1; | 
|  | 4904 | } | 
|  | 4905 |  | 
|  | 4906 | return returnValue; | 
|  | 4907 | } | 
|  | 4908 |  | 
|  | 4909 | @Override | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4910 | public void setRadioCapability(RadioAccessFamily[] rafs) { | 
|  | 4911 | try { | 
|  | 4912 | ProxyController.getInstance().setRadioCapability(rafs); | 
|  | 4913 | } catch (RuntimeException e) { | 
|  | 4914 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); | 
|  | 4915 | } | 
|  | 4916 | } | 
|  | 4917 |  | 
|  | 4918 | @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4919 | public int getRadioAccessFamily(int phoneId, String callingPackage) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4920 | Phone phone = PhoneFactory.getPhone(phoneId); | 
| chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4921 | int raf = RadioAccessFamily.RAF_UNKNOWN; | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4922 | if (phone == null) { | 
| chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4923 | return raf; | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4924 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4925 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4926 | try { | 
| chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4927 | TelephonyPermissions | 
|  | 4928 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 4929 | mApp, phone.getSubId(), "getRadioAccessFamily"); | 
|  | 4930 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4931 | } finally { | 
|  | 4932 | Binder.restoreCallingIdentity(identity); | 
|  | 4933 | } | 
| chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 4934 | return raf; | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 4935 | } | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4936 |  | 
|  | 4937 | @Override | 
|  | 4938 | public void enableVideoCalling(boolean enable) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4939 | final Phone defaultPhone = getDefaultPhone(); | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4940 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4941 |  | 
|  | 4942 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4943 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4944 | ImsManager.getInstance(defaultPhone.getContext(), | 
|  | 4945 | defaultPhone.getPhoneId()).setVtSetting(enable); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4946 | } finally { | 
|  | 4947 | Binder.restoreCallingIdentity(identity); | 
|  | 4948 | } | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4949 | } | 
|  | 4950 |  | 
|  | 4951 | @Override | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4952 | public boolean isVideoCallingEnabled(String callingPackage) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4953 | final Phone defaultPhone = getDefaultPhone(); | 
| Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4954 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4955 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { | 
| Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 4956 | return false; | 
|  | 4957 | } | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4958 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4959 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4960 | try { | 
|  | 4961 | // Check the user preference and the  system-level IMS setting. Even if the user has | 
|  | 4962 | // enabled video calling, if IMS is disabled we aren't able to support video calling. | 
|  | 4963 | // In the long run, we may instead need to check if there exists a connection service | 
|  | 4964 | // which can support video calling. | 
|  | 4965 | ImsManager imsManager = | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4966 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4967 | return imsManager.isVtEnabledByPlatform() | 
|  | 4968 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() | 
|  | 4969 | && imsManager.isVtEnabledByUser(); | 
|  | 4970 | } finally { | 
|  | 4971 | Binder.restoreCallingIdentity(identity); | 
|  | 4972 | } | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 4973 | } | 
| Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 4974 |  | 
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4975 | @Override | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4976 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { | 
|  | 4977 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 4978 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { | 
|  | 4979 | return false; | 
|  | 4980 | } | 
|  | 4981 |  | 
|  | 4982 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4983 | try { | 
|  | 4984 | CarrierConfigManager configManager = | 
|  | 4985 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4986 | return configManager.getConfigForSubId(subId) | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4987 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); | 
|  | 4988 | } finally { | 
|  | 4989 | Binder.restoreCallingIdentity(identity); | 
|  | 4990 | } | 
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 4991 | } | 
|  | 4992 |  | 
|  | 4993 | @Override | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4994 | public boolean isWorldPhone(int subId, String callingPackage) { | 
|  | 4995 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 4996 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { | 
|  | 4997 | return false; | 
|  | 4998 | } | 
|  | 4999 |  | 
|  | 5000 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5001 | try { | 
|  | 5002 | CarrierConfigManager configManager = | 
|  | 5003 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5004 | return configManager.getConfigForSubId(subId) | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5005 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); | 
|  | 5006 | } finally { | 
|  | 5007 | Binder.restoreCallingIdentity(identity); | 
|  | 5008 | } | 
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5009 | } | 
|  | 5010 |  | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5011 | @Override | 
|  | 5012 | public boolean isTtyModeSupported() { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5013 | TelecomManager telecomManager = TelecomManager.from(mApp); | 
| Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5014 | return telecomManager.isTtySupported(); | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5015 | } | 
|  | 5016 |  | 
|  | 5017 | @Override | 
|  | 5018 | public boolean isHearingAidCompatibilitySupported() { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5019 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5020 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5021 | return mApp.getResources().getBoolean(R.bool.hac_enabled); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5022 | } finally { | 
|  | 5023 | Binder.restoreCallingIdentity(identity); | 
|  | 5024 | } | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5025 | } | 
|  | 5026 |  | 
| Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5027 | /** | 
|  | 5028 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier | 
|  | 5029 | * support for the feature and device firmware support. | 
|  | 5030 | * | 
|  | 5031 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. | 
|  | 5032 | */ | 
|  | 5033 | @Override | 
|  | 5034 | public boolean isRttSupported(int subscriptionId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5035 | final long identity = Binder.clearCallingIdentity(); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5036 | final Phone phone = getPhone(subscriptionId); | 
|  | 5037 | if (phone == null) { | 
|  | 5038 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); | 
|  | 5039 | return false; | 
|  | 5040 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5041 | try { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5042 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5043 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); | 
|  | 5044 | boolean isDeviceSupported = | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5045 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5046 | return isCarrierSupported && isDeviceSupported; | 
|  | 5047 | } finally { | 
|  | 5048 | Binder.restoreCallingIdentity(identity); | 
|  | 5049 | } | 
| Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5050 | } | 
|  | 5051 |  | 
| Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5052 | /** | 
|  | 5053 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier | 
|  | 5054 | * both also support RTT. | 
|  | 5055 | */ | 
|  | 5056 | public boolean isRttEnabled(int subscriptionId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5057 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5058 | try { | 
| Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5059 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5060 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5061 | } finally { | 
|  | 5062 | Binder.restoreCallingIdentity(identity); | 
|  | 5063 | } | 
| Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5064 | } | 
|  | 5065 |  | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5066 | /** | 
|  | 5067 | * Returns the unique device ID of phone, for example, the IMEI for | 
|  | 5068 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. | 
|  | 5069 | * | 
|  | 5070 | * <p>Requires Permission: | 
|  | 5071 | *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} | 
|  | 5072 | */ | 
|  | 5073 | @Override | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5074 | public String getDeviceId(String callingPackage) { | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5075 | final Phone phone = PhoneFactory.getPhone(0); | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5076 | if (phone == null) { | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5077 | return null; | 
|  | 5078 | } | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5079 | int subId = phone.getSubId(); | 
|  | 5080 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 5081 | mApp, subId, callingPackage, "getDeviceId")) { | 
|  | 5082 | return null; | 
|  | 5083 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5084 |  | 
|  | 5085 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5086 | try { | 
|  | 5087 | return phone.getDeviceId(); | 
|  | 5088 | } finally { | 
|  | 5089 | Binder.restoreCallingIdentity(identity); | 
|  | 5090 | } | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5091 | } | 
|  | 5092 |  | 
| Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5093 | /** | 
|  | 5094 | * {@hide} | 
|  | 5095 | * Returns the IMS Registration Status on a particular subid | 
|  | 5096 | * | 
|  | 5097 | * @param subId | 
|  | 5098 | */ | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5099 | public boolean isImsRegistered(int subId) { | 
| Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5100 | Phone phone = getPhone(subId); | 
|  | 5101 | if (phone != null) { | 
|  | 5102 | return phone.isImsRegistered(); | 
|  | 5103 | } else { | 
|  | 5104 | return false; | 
|  | 5105 | } | 
|  | 5106 | } | 
|  | 5107 |  | 
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5108 | @Override | 
|  | 5109 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5110 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5111 | try { | 
|  | 5112 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); | 
|  | 5113 | } finally { | 
|  | 5114 | Binder.restoreCallingIdentity(identity); | 
|  | 5115 | } | 
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5116 | } | 
| Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5117 |  | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5118 | /** | 
|  | 5119 | * @return the VoWiFi calling availability. | 
| Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5120 | */ | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5121 | public boolean isWifiCallingAvailable(int subId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5122 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5123 | try { | 
|  | 5124 | Phone phone = getPhone(subId); | 
|  | 5125 | if (phone != null) { | 
|  | 5126 | return phone.isWifiCallingEnabled(); | 
|  | 5127 | } else { | 
|  | 5128 | return false; | 
|  | 5129 | } | 
|  | 5130 | } finally { | 
|  | 5131 | Binder.restoreCallingIdentity(identity); | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5132 | } | 
| Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5133 | } | 
|  | 5134 |  | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5135 | /** | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5136 | * @return the VT calling availability. | 
| Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5137 | */ | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5138 | public boolean isVideoTelephonyAvailable(int subId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5139 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5140 | try { | 
|  | 5141 | Phone phone = getPhone(subId); | 
|  | 5142 | if (phone != null) { | 
|  | 5143 | return phone.isVideoEnabled(); | 
|  | 5144 | } else { | 
|  | 5145 | return false; | 
|  | 5146 | } | 
|  | 5147 | } finally { | 
|  | 5148 | Binder.restoreCallingIdentity(identity); | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5149 | } | 
|  | 5150 | } | 
|  | 5151 |  | 
|  | 5152 | /** | 
|  | 5153 | * @return the IMS registration technology for the MMTEL feature. Valid return values are | 
|  | 5154 | * defined in {@link ImsRegistrationImplBase}. | 
|  | 5155 | */ | 
|  | 5156 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5157 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5158 | try { | 
|  | 5159 | Phone phone = getPhone(subId); | 
|  | 5160 | if (phone != null) { | 
|  | 5161 | return phone.getImsRegistrationTech(); | 
|  | 5162 | } else { | 
|  | 5163 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; | 
|  | 5164 | } | 
|  | 5165 | } finally { | 
|  | 5166 | Binder.restoreCallingIdentity(identity); | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5167 | } | 
| Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5168 | } | 
|  | 5169 |  | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5170 | @Override | 
|  | 5171 | public void factoryReset(int subId) { | 
|  | 5172 | enforceConnectivityInternalPermission(); | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5173 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { | 
|  | 5174 | return; | 
|  | 5175 | } | 
|  | 5176 |  | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5177 | final long identity = Binder.clearCallingIdentity(); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5178 |  | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5179 | try { | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5180 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( | 
|  | 5181 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5182 | setUserDataEnabled(subId, getDefaultDataEnabled()); | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5183 | setNetworkSelectionModeAutomatic(subId); | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5184 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5185 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); | 
|  | 5186 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5187 | } | 
|  | 5188 | } finally { | 
|  | 5189 | Binder.restoreCallingIdentity(identity); | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5190 | } | 
|  | 5191 | } | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5192 |  | 
|  | 5193 | @Override | 
| chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5194 | public String getSimLocaleForSubscriber(int subId) { | 
|  | 5195 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); | 
|  | 5196 | final Phone phone = getPhone(subId); | 
|  | 5197 | if (phone == null) { | 
|  | 5198 | log("getSimLocaleForSubscriber, invalid subId"); | 
| Pengquan Meng | 9c29148 | 2019-01-28 16:26:29 -0800 | [diff] [blame] | 5199 | return null; | 
| chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5200 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5201 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5202 | try { | 
| chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5203 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, | 
|  | 5204 | phone.getContext().getOpPackageName()); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5205 | // Try and fetch the locale from the carrier properties or from the SIM language | 
|  | 5206 | // preferences (EF-PL and EF-LI)... | 
|  | 5207 | final int mcc = info.getMcc(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5208 | String simLanguage = null; | 
| chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5209 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); | 
|  | 5210 | if (localeFromDefaultSim != null) { | 
|  | 5211 | if (!localeFromDefaultSim.getCountry().isEmpty()) { | 
|  | 5212 | if (DBG) log("Using locale from subId: " + subId + " locale: " | 
|  | 5213 | + localeFromDefaultSim); | 
|  | 5214 | return localeFromDefaultSim.toLanguageTag(); | 
|  | 5215 | } else { | 
|  | 5216 | simLanguage = localeFromDefaultSim.getLanguage(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5217 | } | 
|  | 5218 | } | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5219 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5220 | // The SIM language preferences only store a language (e.g. fr = French), not an | 
|  | 5221 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from | 
|  | 5222 | // the SIM and carrier preferences does not include a country we add the country | 
|  | 5223 | // determined from the SIM MCC to provide an exact locale. | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5224 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5225 | if (mccLocale != null) { | 
| chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5226 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5227 | return mccLocale.toLanguageTag(); | 
|  | 5228 | } | 
|  | 5229 |  | 
|  | 5230 | if (DBG) log("No locale found - returning null"); | 
|  | 5231 | return null; | 
|  | 5232 | } finally { | 
|  | 5233 | Binder.restoreCallingIdentity(identity); | 
|  | 5234 | } | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5235 | } | 
|  | 5236 |  | 
|  | 5237 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5238 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5239 | } | 
|  | 5240 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5241 | /** | 
|  | 5242 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. | 
|  | 5243 | */ | 
|  | 5244 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5245 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5246 | } | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5247 |  | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5248 | private final ModemActivityInfo mLastModemActivityInfo = | 
|  | 5249 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); | 
|  | 5250 |  | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5251 | /** | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5252 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object | 
|  | 5253 | * representing the state of the modem. | 
|  | 5254 | * | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5255 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one | 
|  | 5256 | * caller to it. Everyone should call this class to get cumulative data. | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5257 | * @hide | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5258 | */ | 
|  | 5259 | @Override | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5260 | public void requestModemActivityInfo(ResultReceiver result) { | 
|  | 5261 | enforceModifyPermission(); | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5262 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5263 |  | 
|  | 5264 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5265 | try { | 
|  | 5266 | ModemActivityInfo ret = null; | 
|  | 5267 | synchronized (mLastModemActivityInfo) { | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5268 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( | 
|  | 5269 | CMD_GET_MODEM_ACTIVITY_INFO, | 
|  | 5270 | null, workSource); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5271 | if (isModemActivityInfoValid(info)) { | 
|  | 5272 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; | 
|  | 5273 | for (int i = 0; i < mergedTxTimeMs.length; i++) { | 
|  | 5274 | mergedTxTimeMs[i] = | 
|  | 5275 | info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i]; | 
|  | 5276 | } | 
|  | 5277 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); | 
|  | 5278 | mLastModemActivityInfo.setSleepTimeMillis( | 
|  | 5279 | info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis()); | 
|  | 5280 | mLastModemActivityInfo.setIdleTimeMillis( | 
|  | 5281 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); | 
|  | 5282 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); | 
|  | 5283 | mLastModemActivityInfo.setRxTimeMillis( | 
|  | 5284 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); | 
|  | 5285 | mLastModemActivityInfo.setEnergyUsed( | 
|  | 5286 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5287 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5288 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), | 
|  | 5289 | mLastModemActivityInfo.getSleepTimeMillis(), | 
|  | 5290 | mLastModemActivityInfo.getIdleTimeMillis(), | 
|  | 5291 | mLastModemActivityInfo.getTxTimeMillis(), | 
|  | 5292 | mLastModemActivityInfo.getRxTimeMillis(), | 
|  | 5293 | mLastModemActivityInfo.getEnergyUsed()); | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5294 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5295 | Bundle bundle = new Bundle(); | 
|  | 5296 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); | 
|  | 5297 | result.send(0, bundle); | 
|  | 5298 | } finally { | 
|  | 5299 | Binder.restoreCallingIdentity(identity); | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5300 | } | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5301 | } | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5302 |  | 
| Siddharth Ray | f5d2955 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5303 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be | 
|  | 5304 | // less than total activity duration. | 
|  | 5305 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { | 
|  | 5306 | if (info == null) { | 
|  | 5307 | return false; | 
|  | 5308 | } | 
|  | 5309 | int activityDurationMs = | 
|  | 5310 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); | 
|  | 5311 | int totalTxTimeMs = 0; | 
|  | 5312 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { | 
|  | 5313 | totalTxTimeMs += info.getTxTimeMillis()[i]; | 
|  | 5314 | } | 
|  | 5315 | return (info.isValid() | 
|  | 5316 | && (info.getSleepTimeMillis() <= activityDurationMs) | 
|  | 5317 | && (info.getIdleTimeMillis() <= activityDurationMs) | 
|  | 5318 | && (info.getRxTimeMillis() <= activityDurationMs) | 
|  | 5319 | && (totalTxTimeMs <= activityDurationMs)); | 
|  | 5320 | } | 
|  | 5321 |  | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5322 | /** | 
|  | 5323 | * {@hide} | 
|  | 5324 | * Returns the service state information on specified subscription. | 
|  | 5325 | */ | 
|  | 5326 | @Override | 
|  | 5327 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5328 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5329 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5330 | return null; | 
|  | 5331 | } | 
|  | 5332 |  | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5333 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = | 
|  | 5334 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 5335 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 5336 | .setCallingPackage(callingPackage) | 
|  | 5337 | .setCallingPid(Binder.getCallingPid()) | 
|  | 5338 | .setCallingUid(Binder.getCallingUid()) | 
|  | 5339 | .setMethod("getServiceStateForSubscriber") | 
|  | 5340 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 5341 | .build()); | 
|  | 5342 |  | 
|  | 5343 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = | 
|  | 5344 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 5345 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 5346 | .setCallingPackage(callingPackage) | 
|  | 5347 | .setCallingPid(Binder.getCallingPid()) | 
|  | 5348 | .setCallingUid(Binder.getCallingUid()) | 
|  | 5349 | .setMethod("getServiceStateForSubscriber") | 
|  | 5350 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) | 
|  | 5351 | .build()); | 
|  | 5352 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. | 
|  | 5353 | boolean hasFinePermission = | 
|  | 5354 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; | 
|  | 5355 | boolean hasCoarsePermission = | 
|  | 5356 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; | 
|  | 5357 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5358 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5359 | try { | 
|  | 5360 | final Phone phone = getPhone(subId); | 
|  | 5361 | if (phone == null) { | 
|  | 5362 | return null; | 
|  | 5363 | } | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5364 |  | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5365 | ServiceState ss = phone.getServiceState(); | 
|  | 5366 |  | 
|  | 5367 | // Scrub out the location info in ServiceState depending on what level of access | 
|  | 5368 | // the caller has. | 
|  | 5369 | if (hasFinePermission) return ss; | 
|  | 5370 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); | 
|  | 5371 | return ss.sanitizeLocationInfo(true); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5372 | } finally { | 
|  | 5373 | Binder.restoreCallingIdentity(identity); | 
|  | 5374 | } | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5375 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5376 |  | 
|  | 5377 | /** | 
|  | 5378 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. | 
|  | 5379 | * | 
|  | 5380 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the | 
|  | 5381 | * voicemail ringtone. | 
|  | 5382 | * @return The URI for the ringtone to play when receiving a voicemail from a specific | 
|  | 5383 | * PhoneAccount. | 
|  | 5384 | */ | 
|  | 5385 | @Override | 
|  | 5386 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5387 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5388 | try { | 
|  | 5389 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); | 
|  | 5390 | if (phone == null) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5391 | phone = getDefaultPhone(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5392 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5393 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5394 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); | 
|  | 5395 | } finally { | 
|  | 5396 | Binder.restoreCallingIdentity(identity); | 
|  | 5397 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5398 | } | 
|  | 5399 |  | 
|  | 5400 | /** | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5401 | * Sets the per-account voicemail ringtone. | 
|  | 5402 | * | 
|  | 5403 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or | 
|  | 5404 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. | 
|  | 5405 | * | 
|  | 5406 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the | 
|  | 5407 | * voicemail ringtone. | 
|  | 5408 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific | 
|  | 5409 | * PhoneAccount. | 
|  | 5410 | */ | 
|  | 5411 | @Override | 
|  | 5412 | public void setVoicemailRingtoneUri(String callingPackage, | 
|  | 5413 | PhoneAccountHandle phoneAccountHandle, Uri uri) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5414 | final Phone defaultPhone = getDefaultPhone(); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5415 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 5416 | if (!TextUtils.equals(callingPackage, | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5417 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5418 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5419 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), | 
|  | 5420 | "setVoicemailRingtoneUri"); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5421 | } | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5422 |  | 
|  | 5423 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5424 | try { | 
|  | 5425 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); | 
|  | 5426 | if (phone == null) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5427 | phone = defaultPhone; | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5428 | } | 
|  | 5429 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); | 
|  | 5430 | } finally { | 
|  | 5431 | Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5432 | } | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5433 | } | 
|  | 5434 |  | 
|  | 5435 | /** | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5436 | * Returns whether vibration is set for voicemail notification in Phone settings. | 
|  | 5437 | * | 
|  | 5438 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the | 
|  | 5439 | * voicemail vibration setting. | 
|  | 5440 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. | 
|  | 5441 | */ | 
|  | 5442 | @Override | 
|  | 5443 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5444 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5445 | try { | 
|  | 5446 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); | 
|  | 5447 | if (phone == null) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5448 | phone = getDefaultPhone(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5449 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5450 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5451 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); | 
|  | 5452 | } finally { | 
|  | 5453 | Binder.restoreCallingIdentity(identity); | 
|  | 5454 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5455 | } | 
|  | 5456 |  | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5457 | /** | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5458 | * Sets the per-account voicemail vibration. | 
|  | 5459 | * | 
|  | 5460 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or | 
|  | 5461 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. | 
|  | 5462 | * | 
|  | 5463 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the | 
|  | 5464 | * voicemail vibration setting. | 
|  | 5465 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a | 
|  | 5466 | * specific PhoneAccount. | 
|  | 5467 | */ | 
|  | 5468 | @Override | 
|  | 5469 | public void setVoicemailVibrationEnabled(String callingPackage, | 
|  | 5470 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5471 | final Phone defaultPhone = getDefaultPhone(); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5472 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 5473 | if (!TextUtils.equals(callingPackage, | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5474 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5475 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5476 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), | 
|  | 5477 | "setVoicemailVibrationEnabled"); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5478 | } | 
|  | 5479 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5480 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5481 | try { | 
|  | 5482 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); | 
|  | 5483 | if (phone == null) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5484 | phone = defaultPhone; | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5485 | } | 
|  | 5486 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); | 
|  | 5487 | } finally { | 
|  | 5488 | Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5489 | } | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5490 | } | 
|  | 5491 |  | 
|  | 5492 | /** | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5493 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. | 
|  | 5494 | * | 
|  | 5495 | * @throws SecurityException if the caller does not have the required permission | 
|  | 5496 | */ | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5497 | private void enforceReadPrivilegedPermission(String message) { | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5498 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5499 | message); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5500 | } | 
|  | 5501 |  | 
|  | 5502 | /** | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5503 | * Make sure either called from same process as self (phone) or IPC caller has send SMS | 
|  | 5504 | * permission. | 
|  | 5505 | * | 
|  | 5506 | * @throws SecurityException if the caller does not have the required permission | 
|  | 5507 | */ | 
|  | 5508 | private void enforceSendSmsPermission() { | 
|  | 5509 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); | 
|  | 5510 | } | 
|  | 5511 |  | 
|  | 5512 | /** | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5513 | * Make sure called from the package in charge of visual voicemail. | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5514 | * | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5515 | * @throws SecurityException if the caller is not the visual voicemail package. | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5516 | */ | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5517 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5518 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5519 | try { | 
|  | 5520 | ComponentName componentName = | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5521 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5522 | if (componentName == null) { | 
|  | 5523 | throw new SecurityException( | 
|  | 5524 | "Caller not current active visual voicemail package[null]"); | 
|  | 5525 | } | 
|  | 5526 | String vvmPackage = componentName.getPackageName(); | 
|  | 5527 | if (!callingPackage.equals(vvmPackage)) { | 
|  | 5528 | throw new SecurityException("Caller not current active visual voicemail package[" | 
|  | 5529 | + vvmPackage + "]"); | 
|  | 5530 | } | 
|  | 5531 | } finally { | 
|  | 5532 | Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5533 | } | 
|  | 5534 | } | 
|  | 5535 |  | 
|  | 5536 | /** | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5537 | * Return the application ID for the app type. | 
|  | 5538 | * | 
|  | 5539 | * @param subId the subscription ID that this request applies to. | 
|  | 5540 | * @param appType the uicc app type. | 
|  | 5541 | * @return Application ID for specificied app type, or null if no uicc. | 
|  | 5542 | */ | 
|  | 5543 | @Override | 
|  | 5544 | public String getAidForAppType(int subId, int appType) { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5545 | enforceReadPrivilegedPermission("getAidForAppType"); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5546 | Phone phone = getPhone(subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5547 |  | 
|  | 5548 | final long identity = Binder.clearCallingIdentity(); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5549 | try { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5550 | if (phone == null) { | 
|  | 5551 | return null; | 
|  | 5552 | } | 
|  | 5553 | String aid = null; | 
|  | 5554 | try { | 
|  | 5555 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) | 
|  | 5556 | .getApplicationByType(appType).getAid(); | 
|  | 5557 | } catch (Exception e) { | 
|  | 5558 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); | 
|  | 5559 | } | 
|  | 5560 | return aid; | 
|  | 5561 | } finally { | 
|  | 5562 | Binder.restoreCallingIdentity(identity); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5563 | } | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5564 | } | 
|  | 5565 |  | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5566 | /** | 
|  | 5567 | * Return the Electronic Serial Number. | 
|  | 5568 | * | 
|  | 5569 | * @param subId the subscription ID that this request applies to. | 
|  | 5570 | * @return ESN or null if error. | 
|  | 5571 | */ | 
|  | 5572 | @Override | 
|  | 5573 | public String getEsn(int subId) { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5574 | enforceReadPrivilegedPermission("getEsn"); | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5575 | Phone phone = getPhone(subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5576 |  | 
|  | 5577 | final long identity = Binder.clearCallingIdentity(); | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5578 | try { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5579 | if (phone == null) { | 
|  | 5580 | return null; | 
|  | 5581 | } | 
|  | 5582 | String esn = null; | 
|  | 5583 | try { | 
|  | 5584 | esn = phone.getEsn(); | 
|  | 5585 | } catch (Exception e) { | 
|  | 5586 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); | 
|  | 5587 | } | 
|  | 5588 | return esn; | 
|  | 5589 | } finally { | 
|  | 5590 | Binder.restoreCallingIdentity(identity); | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5591 | } | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5592 | } | 
|  | 5593 |  | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5594 | /** | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5595 | * Return the Preferred Roaming List Version. | 
|  | 5596 | * | 
|  | 5597 | * @param subId the subscription ID that this request applies to. | 
|  | 5598 | * @return PRLVersion or null if error. | 
|  | 5599 | */ | 
|  | 5600 | @Override | 
|  | 5601 | public String getCdmaPrlVersion(int subId) { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5602 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5603 | Phone phone = getPhone(subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5604 |  | 
|  | 5605 | final long identity = Binder.clearCallingIdentity(); | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5606 | try { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5607 | if (phone == null) { | 
|  | 5608 | return null; | 
|  | 5609 | } | 
|  | 5610 | String cdmaPrlVersion = null; | 
|  | 5611 | try { | 
|  | 5612 | cdmaPrlVersion = phone.getCdmaPrlVersion(); | 
|  | 5613 | } catch (Exception e) { | 
|  | 5614 | Log.e(LOG_TAG, "Not getting PRLVersion", e); | 
|  | 5615 | } | 
|  | 5616 | return cdmaPrlVersion; | 
|  | 5617 | } finally { | 
|  | 5618 | Binder.restoreCallingIdentity(identity); | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5619 | } | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5620 | } | 
|  | 5621 |  | 
|  | 5622 | /** | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5623 | * Get snapshot of Telephony histograms | 
|  | 5624 | * @return List of Telephony histograms | 
|  | 5625 | * @hide | 
|  | 5626 | */ | 
|  | 5627 | @Override | 
|  | 5628 | public List<TelephonyHistogram> getTelephonyHistograms() { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5629 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5630 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5631 |  | 
|  | 5632 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5633 | try { | 
|  | 5634 | return RIL.getTelephonyRILTimingHistograms(); | 
|  | 5635 | } finally { | 
|  | 5636 | Binder.restoreCallingIdentity(identity); | 
|  | 5637 | } | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5638 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5639 |  | 
|  | 5640 | /** | 
|  | 5641 | * {@hide} | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5642 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between | 
|  | 5643 | * the two lists. | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5644 | * Require system privileges. In the future we may add this to carrier APIs. | 
|  | 5645 | * | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5646 | * @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] | 5647 | */ | 
|  | 5648 | @Override | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5649 | @TelephonyManager.SetCarrierRestrictionResult | 
|  | 5650 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5651 | enforceModifyPermission(); | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5652 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5653 |  | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5654 | if (carrierRestrictionRules == null) { | 
|  | 5655 | throw new NullPointerException("carrier restriction cannot be null"); | 
| Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5656 | } | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5657 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5658 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5659 | try { | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5660 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5661 | workSource); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5662 | } finally { | 
|  | 5663 | Binder.restoreCallingIdentity(identity); | 
|  | 5664 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5665 | } | 
|  | 5666 |  | 
|  | 5667 | /** | 
|  | 5668 | * {@hide} | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5669 | * Get the allowed carrier list and the excluded carrier list, including the priority between | 
|  | 5670 | * the two lists. | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5671 | * Require system privileges. In the future we may add this to carrier APIs. | 
|  | 5672 | * | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5673 | * @return {@link android.telephony.CarrierRestrictionRules} | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5674 | */ | 
|  | 5675 | @Override | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5676 | public CarrierRestrictionRules getAllowedCarriers() { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5677 | enforceReadPrivilegedPermission("getAllowedCarriers"); | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5678 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5679 |  | 
|  | 5680 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5681 | try { | 
| Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5682 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); | 
|  | 5683 | if (response instanceof CarrierRestrictionRules) { | 
|  | 5684 | return (CarrierRestrictionRules) response; | 
|  | 5685 | } | 
|  | 5686 | // Response is an Exception of some kind, | 
|  | 5687 | // which is signalled to the user as a NULL retval | 
|  | 5688 | return null; | 
|  | 5689 | } catch (Exception e) { | 
|  | 5690 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); | 
|  | 5691 | return null; | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5692 | } finally { | 
|  | 5693 | Binder.restoreCallingIdentity(identity); | 
|  | 5694 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5695 | } | 
|  | 5696 |  | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5697 | /** | 
|  | 5698 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns | 
|  | 5699 | * @param subId the subscription ID that this action applies to. | 
|  | 5700 | * @param enabled control enable or disable metered apns. | 
|  | 5701 | * {@hide} | 
|  | 5702 | */ | 
|  | 5703 | @Override | 
|  | 5704 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { | 
|  | 5705 | enforceModifyPermission(); | 
|  | 5706 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5707 |  | 
|  | 5708 | final long identity = Binder.clearCallingIdentity(); | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5709 | if (phone == null) { | 
|  | 5710 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); | 
|  | 5711 | return; | 
|  | 5712 | } | 
|  | 5713 | try { | 
|  | 5714 | phone.carrierActionSetMeteredApnsEnabled(enabled); | 
|  | 5715 | } catch (Exception e) { | 
|  | 5716 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5717 | } finally { | 
|  | 5718 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5719 | } | 
|  | 5720 | } | 
|  | 5721 |  | 
|  | 5722 | /** | 
|  | 5723 | * Action set from carrier signalling broadcast receivers to enable/disable radio | 
|  | 5724 | * @param subId the subscription ID that this action applies to. | 
|  | 5725 | * @param enabled control enable or disable radio. | 
|  | 5726 | * {@hide} | 
|  | 5727 | */ | 
|  | 5728 | @Override | 
|  | 5729 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { | 
|  | 5730 | enforceModifyPermission(); | 
|  | 5731 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5732 |  | 
|  | 5733 | final long identity = Binder.clearCallingIdentity(); | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5734 | if (phone == null) { | 
|  | 5735 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); | 
|  | 5736 | return; | 
|  | 5737 | } | 
|  | 5738 | try { | 
|  | 5739 | phone.carrierActionSetRadioEnabled(enabled); | 
|  | 5740 | } catch (Exception e) { | 
|  | 5741 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5742 | } finally { | 
|  | 5743 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5744 | } | 
|  | 5745 | } | 
|  | 5746 |  | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5747 | /** | 
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5748 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default | 
|  | 5749 | * network status based on which carrier apps could apply actions accordingly, | 
|  | 5750 | * enable/disable default url handler for example. | 
|  | 5751 | * | 
|  | 5752 | * @param subId the subscription ID that this action applies to. | 
|  | 5753 | * @param report control start/stop reporting the default network status. | 
|  | 5754 | * {@hide} | 
|  | 5755 | */ | 
|  | 5756 | @Override | 
|  | 5757 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { | 
|  | 5758 | enforceModifyPermission(); | 
|  | 5759 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5760 |  | 
|  | 5761 | final long identity = Binder.clearCallingIdentity(); | 
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5762 | if (phone == null) { | 
|  | 5763 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); | 
|  | 5764 | return; | 
|  | 5765 | } | 
|  | 5766 | try { | 
|  | 5767 | phone.carrierActionReportDefaultNetworkStatus(report); | 
|  | 5768 | } catch (Exception e) { | 
|  | 5769 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5770 | } finally { | 
|  | 5771 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5772 | } | 
|  | 5773 | } | 
|  | 5774 |  | 
|  | 5775 | /** | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5776 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a | 
|  | 5777 | * bug report is being generated. | 
|  | 5778 | */ | 
|  | 5779 | @Override | 
| Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 5780 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5781 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) | 
|  | 5782 | != PackageManager.PERMISSION_GRANTED) { | 
| dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 5783 | writer.println("Permission Denial: can't dump Phone from pid=" | 
|  | 5784 | + Binder.getCallingPid() | 
|  | 5785 | + ", uid=" + Binder.getCallingUid() | 
|  | 5786 | + "without permission " | 
|  | 5787 | + android.Manifest.permission.DUMP); | 
|  | 5788 | return; | 
|  | 5789 | } | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5790 | DumpsysHandler.dump(mApp, fd, writer, args); | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5791 | } | 
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5792 |  | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5793 | @Override | 
|  | 5794 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, | 
|  | 5795 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) | 
|  | 5796 | throws RemoteException { | 
|  | 5797 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); | 
|  | 5798 | } | 
|  | 5799 |  | 
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5800 | /** | 
| Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5801 | * Get aggregated video call data usage since boot. | 
|  | 5802 | * | 
|  | 5803 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. | 
|  | 5804 | * @return Snapshot of video call data usage | 
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5805 | * {@hide} | 
|  | 5806 | */ | 
|  | 5807 | @Override | 
| Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5808 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { | 
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5809 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, | 
|  | 5810 | null); | 
|  | 5811 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5812 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5813 | try { | 
|  | 5814 | // NetworkStatsService keeps tracking the active network interface and identity. It | 
|  | 5815 | // records the delta with the corresponding network identity. | 
|  | 5816 | // We just return the total video call data usage snapshot since boot. | 
|  | 5817 | Phone phone = getPhone(subId); | 
|  | 5818 | if (phone != null) { | 
|  | 5819 | return phone.getVtDataUsage(perUidStats); | 
|  | 5820 | } | 
|  | 5821 | return null; | 
|  | 5822 | } finally { | 
|  | 5823 | Binder.restoreCallingIdentity(identity); | 
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5824 | } | 
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5825 | } | 
| Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5826 |  | 
|  | 5827 | /** | 
|  | 5828 | * Policy control of data connection. Usually used when data limit is passed. | 
|  | 5829 | * @param enabled True if enabling the data, otherwise disabling. | 
|  | 5830 | * @param subId Subscription index | 
|  | 5831 | * {@hide} | 
|  | 5832 | */ | 
|  | 5833 | @Override | 
|  | 5834 | public void setPolicyDataEnabled(boolean enabled, int subId) { | 
|  | 5835 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5836 |  | 
|  | 5837 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5838 | try { | 
|  | 5839 | Phone phone = getPhone(subId); | 
|  | 5840 | if (phone != null) { | 
| Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5841 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5842 | } | 
|  | 5843 | } finally { | 
|  | 5844 | Binder.restoreCallingIdentity(identity); | 
| Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5845 | } | 
|  | 5846 | } | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5847 |  | 
|  | 5848 | /** | 
|  | 5849 | * Get Client request stats | 
|  | 5850 | * @return List of Client Request Stats | 
|  | 5851 | * @hide | 
|  | 5852 | */ | 
|  | 5853 | @Override | 
|  | 5854 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5855 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5856 | mApp, subId, callingPackage, "getClientRequestStats")) { | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5857 | return null; | 
|  | 5858 | } | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5859 | Phone phone = getPhone(subId); | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5860 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5861 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5862 | try { | 
|  | 5863 | if (phone != null) { | 
|  | 5864 | return phone.getClientRequestStats(); | 
|  | 5865 | } | 
|  | 5866 |  | 
|  | 5867 | return null; | 
|  | 5868 | } finally { | 
|  | 5869 | Binder.restoreCallingIdentity(identity); | 
|  | 5870 | } | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5871 | } | 
|  | 5872 |  | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5873 | private WorkSource getWorkSource(int uid) { | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5874 | String packageName = mApp.getPackageManager().getNameForUid(uid); | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 5875 | return new WorkSource(uid, packageName); | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5876 | } | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5877 |  | 
|  | 5878 | /** | 
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5879 | * Set SIM card power state. | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5880 | * | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5881 | * @param slotIndex SIM slot id. | 
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5882 | * @param state  State of SIM (power down, power up, pass through) | 
|  | 5883 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} | 
|  | 5884 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} | 
|  | 5885 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5886 | * | 
|  | 5887 | **/ | 
|  | 5888 | @Override | 
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 5889 | public void setSimPowerStateForSlot(int slotIndex, int state) { | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5890 | enforceModifyPermission(); | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5891 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 5892 |  | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5893 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 5894 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5895 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5896 | try { | 
|  | 5897 | if (phone != null) { | 
| vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5898 | phone.setSimPowerState(state, workSource); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5899 | } | 
|  | 5900 | } finally { | 
|  | 5901 | Binder.restoreCallingIdentity(identity); | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 5902 | } | 
|  | 5903 | } | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5904 |  | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5905 | private boolean isUssdApiAllowed(int subId) { | 
|  | 5906 | CarrierConfigManager configManager = | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5907 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 5908 | if (configManager == null) { | 
|  | 5909 | return false; | 
|  | 5910 | } | 
|  | 5911 | PersistableBundle pb = configManager.getConfigForSubId(subId); | 
|  | 5912 | if (pb == null) { | 
|  | 5913 | return false; | 
|  | 5914 | } | 
|  | 5915 | return pb.getBoolean( | 
|  | 5916 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); | 
|  | 5917 | } | 
|  | 5918 |  | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5919 | /** | 
|  | 5920 | * Check if phone is in emergency callback mode | 
|  | 5921 | * @return true if phone is in emergency callback mode | 
|  | 5922 | * @param subId sub id | 
|  | 5923 | */ | 
| goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 5924 | @Override | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5925 | public boolean getEmergencyCallbackMode(int subId) { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5926 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5927 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5928 |  | 
|  | 5929 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5930 | try { | 
|  | 5931 | if (phone != null) { | 
|  | 5932 | return phone.isInEcm(); | 
|  | 5933 | } else { | 
|  | 5934 | return false; | 
|  | 5935 | } | 
|  | 5936 | } finally { | 
|  | 5937 | Binder.restoreCallingIdentity(identity); | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 5938 | } | 
|  | 5939 | } | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5940 |  | 
|  | 5941 | /** | 
|  | 5942 | * Get the current signal strength information for the given subscription. | 
|  | 5943 | * Because this information is not updated when the device is in a low power state | 
|  | 5944 | * it should not be relied-upon to be current. | 
|  | 5945 | * @param subId Subscription index | 
|  | 5946 | * @return the most recent cached signal strength info from the modem | 
|  | 5947 | */ | 
|  | 5948 | @Override | 
|  | 5949 | public SignalStrength getSignalStrength(int subId) { | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5950 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5951 | try { | 
|  | 5952 | Phone p = getPhone(subId); | 
|  | 5953 | if (p == null) { | 
|  | 5954 | return null; | 
|  | 5955 | } | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5956 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5957 | return p.getSignalStrength(); | 
|  | 5958 | } finally { | 
|  | 5959 | Binder.restoreCallingIdentity(identity); | 
|  | 5960 | } | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 5961 | } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 5962 |  | 
| Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5963 | /** | 
| chen xu | 907e5a2 | 2018-10-11 13:21:04 -0700 | [diff] [blame] | 5964 | * Get the current modem radio state for the given slot. | 
|  | 5965 | * @param slotIndex slot index. | 
|  | 5966 | * @param callingPackage the name of the package making the call. | 
|  | 5967 | * @return the current radio power state from the modem | 
|  | 5968 | */ | 
|  | 5969 | @Override | 
|  | 5970 | public int getRadioPowerState(int slotIndex, String callingPackage) { | 
|  | 5971 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 5972 | if (phone != null) { | 
|  | 5973 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 5974 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { | 
|  | 5975 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; | 
|  | 5976 | } | 
|  | 5977 |  | 
|  | 5978 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5979 | try { | 
|  | 5980 | return phone.getRadioPowerState(); | 
|  | 5981 | } finally { | 
|  | 5982 | Binder.restoreCallingIdentity(identity); | 
|  | 5983 | } | 
|  | 5984 | } | 
|  | 5985 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; | 
|  | 5986 | } | 
|  | 5987 |  | 
|  | 5988 | /** | 
| Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 5989 | * Checks if data roaming is enabled on the subscription with id {@code subId}. | 
|  | 5990 | * | 
|  | 5991 | * <p>Requires one of the following permissions: | 
|  | 5992 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, | 
|  | 5993 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier | 
|  | 5994 | * privileges. | 
|  | 5995 | * | 
|  | 5996 | * @param subId subscription id | 
|  | 5997 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return | 
|  | 5998 | * {@code false}. | 
|  | 5999 | */ | 
|  | 6000 | @Override | 
|  | 6001 | public boolean isDataRoamingEnabled(int subId) { | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6002 | boolean isEnabled = false; | 
|  | 6003 | final long identity = Binder.clearCallingIdentity(); | 
| Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6004 | try { | 
|  | 6005 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6006 | null /* message */); | 
|  | 6007 | Phone phone = getPhone(subId); | 
|  | 6008 | isEnabled =  phone != null ? phone.getDataRoamingEnabled() : false; | 
| Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6009 | } catch (Exception e) { | 
|  | 6010 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( | 
|  | 6011 | mApp, subId, "isDataRoamingEnabled"); | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6012 | } finally { | 
|  | 6013 | Binder.restoreCallingIdentity(identity); | 
| Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6014 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6015 | return isEnabled; | 
| Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6016 | } | 
|  | 6017 |  | 
|  | 6018 |  | 
|  | 6019 | /** | 
|  | 6020 | * Enables/Disables the data roaming on the subscription with id {@code subId}. | 
|  | 6021 | * | 
|  | 6022 | * <p> Requires permission: | 
|  | 6023 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier | 
|  | 6024 | * privileges. | 
|  | 6025 | * | 
|  | 6026 | * @param subId subscription id | 
|  | 6027 | * @param isEnabled {@code true} means enable, {@code false} means disable. | 
|  | 6028 | */ | 
|  | 6029 | @Override | 
|  | 6030 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6031 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6032 | try { | 
|  | 6033 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6034 | mApp, subId, "setDataRoamingEnabled"); | 
| Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6035 |  | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6036 | Phone phone = getPhone(subId); | 
|  | 6037 | if (phone != null) { | 
|  | 6038 | phone.setDataRoamingEnabled(isEnabled); | 
|  | 6039 | } | 
|  | 6040 | } finally { | 
|  | 6041 | Binder.restoreCallingIdentity(identity); | 
| Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6042 | } | 
|  | 6043 | } | 
|  | 6044 |  | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6045 | @Override | 
| Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6046 | public boolean isManualNetworkSelectionAllowed(int subId) { | 
|  | 6047 | boolean isAllowed = true; | 
|  | 6048 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6049 | try { | 
|  | 6050 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( | 
|  | 6051 | mApp, subId, "isManualNetworkSelectionAllowed"); | 
|  | 6052 | Phone phone = getPhone(subId); | 
|  | 6053 | if (phone != null) { | 
|  | 6054 | isAllowed = phone.isCspPlmnEnabled(); | 
|  | 6055 | } | 
|  | 6056 | } finally { | 
|  | 6057 | Binder.restoreCallingIdentity(identity); | 
|  | 6058 | } | 
|  | 6059 | return isAllowed; | 
|  | 6060 | } | 
|  | 6061 |  | 
|  | 6062 | @Override | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6063 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { | 
| Jordan Liu | 53fdb78 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6064 | try { | 
|  | 6065 | enforceReadPrivilegedPermission("getUiccCardsInfo"); | 
|  | 6066 | } catch (SecurityException e) { | 
|  | 6067 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller | 
|  | 6068 | // has carrier privileges on an active UICC | 
|  | 6069 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) | 
|  | 6070 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
|  | 6071 | throw new SecurityException("Caller does not have carrier privileges on any UICC"); | 
|  | 6072 | } | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6073 | } | 
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6074 |  | 
|  | 6075 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6076 | try { | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6077 | UiccController uiccController = UiccController.getInstance(); | 
|  | 6078 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); | 
|  | 6079 |  | 
|  | 6080 | ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0); | 
|  | 6081 | if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { | 
|  | 6082 | // Remove private info if the caller doesn't have access | 
|  | 6083 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); | 
|  | 6084 | for (UiccCardInfo cardInfo : cardInfos) { | 
|  | 6085 | UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex()); | 
|  | 6086 | UiccProfile profile = card.getUiccProfile(); | 
|  | 6087 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) | 
|  | 6088 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
|  | 6089 | filteredInfos.add(cardInfo.getUnprivileged()); | 
|  | 6090 | } else { | 
|  | 6091 | filteredInfos.add(cardInfo); | 
|  | 6092 | } | 
|  | 6093 | } | 
|  | 6094 | return filteredInfos; | 
|  | 6095 | } | 
|  | 6096 | return cardInfos; | 
|  | 6097 | } catch (PackageManager.NameNotFoundException e) { | 
|  | 6098 | // This should not happen since we pass the package info in from TelephonyManager | 
|  | 6099 | throw new SecurityException("Invalid calling package."); | 
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6100 | } finally { | 
|  | 6101 | Binder.restoreCallingIdentity(identity); | 
|  | 6102 | } | 
|  | 6103 | } | 
|  | 6104 |  | 
|  | 6105 | @Override | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6106 | public UiccSlotInfo[] getUiccSlotsInfo() { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6107 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6108 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6109 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6110 | try { | 
|  | 6111 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); | 
|  | 6112 | if (slots == null) { | 
|  | 6113 | Rlog.i(LOG_TAG, "slots is null."); | 
|  | 6114 | return null; | 
|  | 6115 | } | 
|  | 6116 |  | 
|  | 6117 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; | 
|  | 6118 | for (int i = 0; i < slots.length; i++) { | 
|  | 6119 | UiccSlot slot = slots[i]; | 
|  | 6120 | if (slot == null) { | 
|  | 6121 | continue; | 
|  | 6122 | } | 
|  | 6123 |  | 
|  | 6124 | String cardId; | 
|  | 6125 | UiccCard card = slot.getUiccCard(); | 
|  | 6126 | if (card != null) { | 
|  | 6127 | cardId = card.getCardId(); | 
|  | 6128 | } else { | 
|  | 6129 | cardId = slot.getIccId(); | 
|  | 6130 | } | 
|  | 6131 |  | 
|  | 6132 | int cardState = 0; | 
|  | 6133 | switch (slot.getCardState()) { | 
|  | 6134 | case CARDSTATE_ABSENT: | 
|  | 6135 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; | 
|  | 6136 | break; | 
|  | 6137 | case CARDSTATE_PRESENT: | 
|  | 6138 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; | 
|  | 6139 | break; | 
|  | 6140 | case CARDSTATE_ERROR: | 
|  | 6141 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; | 
|  | 6142 | break; | 
|  | 6143 | case CARDSTATE_RESTRICTED: | 
|  | 6144 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; | 
|  | 6145 | break; | 
|  | 6146 | default: | 
|  | 6147 | break; | 
|  | 6148 |  | 
|  | 6149 | } | 
|  | 6150 |  | 
|  | 6151 | infos[i] = new UiccSlotInfo( | 
|  | 6152 | slot.isActive(), | 
|  | 6153 | slot.isEuicc(), | 
|  | 6154 | cardId, | 
|  | 6155 | cardState, | 
|  | 6156 | slot.getPhoneId(), | 
|  | 6157 | slot.isExtendedApduSupported()); | 
|  | 6158 | } | 
|  | 6159 | return infos; | 
|  | 6160 | } finally { | 
|  | 6161 | Binder.restoreCallingIdentity(identity); | 
| Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6162 | } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6163 | } | 
|  | 6164 |  | 
|  | 6165 | @Override | 
|  | 6166 | public boolean switchSlots(int[] physicalSlots) { | 
|  | 6167 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6168 |  | 
|  | 6169 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6170 | try { | 
|  | 6171 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); | 
|  | 6172 | } finally { | 
|  | 6173 | Binder.restoreCallingIdentity(identity); | 
|  | 6174 | } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6175 | } | 
| Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6176 |  | 
|  | 6177 | @Override | 
| Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6178 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { | 
| Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6179 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6180 | try { | 
|  | 6181 | return UiccController.getInstance().getCardIdForDefaultEuicc(); | 
|  | 6182 | } finally { | 
|  | 6183 | Binder.restoreCallingIdentity(identity); | 
|  | 6184 | } | 
|  | 6185 | } | 
|  | 6186 |  | 
|  | 6187 | @Override | 
| Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6188 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { | 
|  | 6189 | enforceModifyPermission(); | 
|  | 6190 | final Phone phone = getPhone(subId); | 
|  | 6191 | if (phone == null) { | 
|  | 6192 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); | 
|  | 6193 | return; | 
|  | 6194 | } | 
|  | 6195 |  | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6196 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6197 | try { | 
|  | 6198 | phone.setRadioIndicationUpdateMode(filters, mode); | 
|  | 6199 | } finally { | 
|  | 6200 | Binder.restoreCallingIdentity(identity); | 
|  | 6201 | } | 
| Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6202 | } | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6203 |  | 
|  | 6204 | /** | 
| goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6205 | * A test API to reload the UICC profile. | 
|  | 6206 | * | 
|  | 6207 | * <p>Requires that the calling app has permission | 
|  | 6208 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. | 
|  | 6209 | * @hide | 
|  | 6210 | */ | 
|  | 6211 | @Override | 
|  | 6212 | public void refreshUiccProfile(int subId) { | 
|  | 6213 | enforceModifyPermission(); | 
|  | 6214 |  | 
|  | 6215 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6216 | try { | 
|  | 6217 | Phone phone = getPhone(subId); | 
|  | 6218 | if (phone == null) { | 
|  | 6219 | return; | 
|  | 6220 | } | 
|  | 6221 | UiccCard uiccCard = phone.getUiccCard(); | 
|  | 6222 | if (uiccCard == null) { | 
|  | 6223 | return; | 
|  | 6224 | } | 
|  | 6225 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); | 
|  | 6226 | if (uiccProfile == null) { | 
|  | 6227 | return; | 
|  | 6228 | } | 
|  | 6229 | uiccProfile.refresh(); | 
|  | 6230 | } finally { | 
|  | 6231 | Binder.restoreCallingIdentity(identity); | 
|  | 6232 | } | 
|  | 6233 | } | 
|  | 6234 |  | 
|  | 6235 | /** | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6236 | * Returns false if the mobile data is disabled by default, otherwise return true. | 
|  | 6237 | */ | 
|  | 6238 | private boolean getDefaultDataEnabled() { | 
|  | 6239 | return "true".equalsIgnoreCase( | 
|  | 6240 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); | 
|  | 6241 | } | 
|  | 6242 |  | 
|  | 6243 | /** | 
|  | 6244 | * Returns true if the data roaming is enabled by default, i.e the system property | 
|  | 6245 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of | 
|  | 6246 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. | 
|  | 6247 | */ | 
|  | 6248 | private boolean getDefaultDataRoamingEnabled(int subId) { | 
|  | 6249 | final CarrierConfigManager configMgr = (CarrierConfigManager) | 
| Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6250 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6251 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( | 
|  | 6252 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); | 
|  | 6253 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( | 
|  | 6254 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); | 
|  | 6255 | return isDataRoamingEnabled; | 
|  | 6256 | } | 
|  | 6257 |  | 
|  | 6258 | /** | 
|  | 6259 | * Returns the default network type for the given {@code subId}, if the default network type is | 
|  | 6260 | * not set, return {@link Phone#PREFERRED_NT_MODE}. | 
|  | 6261 | */ | 
|  | 6262 | private int getDefaultNetworkType(int subId) { | 
|  | 6263 | return Integer.parseInt( | 
|  | 6264 | TelephonyManager.getTelephonyProperty( | 
|  | 6265 | mSubscriptionController.getPhoneId(subId), | 
|  | 6266 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, | 
|  | 6267 | String.valueOf(Phone.PREFERRED_NT_MODE))); | 
|  | 6268 | } | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6269 |  | 
|  | 6270 | @Override | 
|  | 6271 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String | 
|  | 6272 | gid1, String gid2, String plmn, String spn) { | 
|  | 6273 | enforceModifyPermission(); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6274 |  | 
|  | 6275 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6276 | try { | 
|  | 6277 | final Phone phone = getPhone(subId); | 
|  | 6278 | if (phone == null) { | 
|  | 6279 | loge("setCarrierTestOverride fails with invalid subId: " + subId); | 
|  | 6280 | return; | 
|  | 6281 | } | 
|  | 6282 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn); | 
|  | 6283 | } finally { | 
|  | 6284 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6285 | } | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6286 | } | 
|  | 6287 |  | 
|  | 6288 | @Override | 
|  | 6289 | public int getCarrierIdListVersion(int subId) { | 
| Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6290 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); | 
| Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6291 |  | 
|  | 6292 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6293 | try { | 
|  | 6294 | final Phone phone = getPhone(subId); | 
|  | 6295 | if (phone == null) { | 
|  | 6296 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); | 
|  | 6297 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; | 
|  | 6298 | } | 
|  | 6299 | return phone.getCarrierIdListVersion(); | 
|  | 6300 | } finally { | 
|  | 6301 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6302 | } | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6303 | } | 
| Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6304 |  | 
|  | 6305 | @Override | 
|  | 6306 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { | 
|  | 6307 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 6308 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { | 
|  | 6309 | return -1; | 
|  | 6310 | } | 
|  | 6311 |  | 
|  | 6312 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6313 | try { | 
|  | 6314 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); | 
|  | 6315 | } finally { | 
|  | 6316 | Binder.restoreCallingIdentity(identity); | 
|  | 6317 | } | 
|  | 6318 | } | 
| Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6319 |  | 
|  | 6320 | @Override | 
|  | 6321 | public int getCdmaRoamingMode(int subId) { | 
|  | 6322 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6323 | mApp, subId, "getCdmaRoamingMode"); | 
|  | 6324 |  | 
|  | 6325 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6326 | try { | 
|  | 6327 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); | 
|  | 6328 | } finally { | 
|  | 6329 | Binder.restoreCallingIdentity(identity); | 
|  | 6330 | } | 
|  | 6331 | } | 
|  | 6332 |  | 
|  | 6333 | @Override | 
|  | 6334 | public boolean setCdmaRoamingMode(int subId, int mode) { | 
|  | 6335 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6336 | mApp, subId, "setCdmaRoamingMode"); | 
|  | 6337 |  | 
|  | 6338 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6339 | try { | 
|  | 6340 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); | 
|  | 6341 | } finally { | 
|  | 6342 | Binder.restoreCallingIdentity(identity); | 
|  | 6343 | } | 
|  | 6344 | } | 
|  | 6345 |  | 
|  | 6346 | @Override | 
|  | 6347 | public boolean setCdmaSubscriptionMode(int subId, int mode) { | 
|  | 6348 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6349 | mApp, subId, "setCdmaSubscriptionMode"); | 
|  | 6350 |  | 
|  | 6351 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6352 | try { | 
|  | 6353 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); | 
|  | 6354 | } finally { | 
|  | 6355 | Binder.restoreCallingIdentity(identity); | 
|  | 6356 | } | 
|  | 6357 | } | 
| chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6358 |  | 
| sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 6359 | private void ensureUserRunning(int userId) { | 
|  | 6360 | if (!mUserManager.isUserRunning(userId)) { | 
|  | 6361 | throw new IllegalStateException("User " + userId + " does not exist or not running"); | 
|  | 6362 | } | 
|  | 6363 | } | 
|  | 6364 |  | 
|  | 6365 | /** | 
|  | 6366 | * Returns a list of SMS apps on a given user. | 
|  | 6367 | * | 
|  | 6368 | * Only the shell user (UID 2000 or 0) can call it. | 
|  | 6369 | * Target user must be running. | 
|  | 6370 | */ | 
|  | 6371 | @Override | 
|  | 6372 | public String[] getSmsApps(int userId) { | 
|  | 6373 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); | 
|  | 6374 | ensureUserRunning(userId); | 
|  | 6375 |  | 
|  | 6376 | final Collection<SmsApplicationData> apps = | 
|  | 6377 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); | 
|  | 6378 |  | 
|  | 6379 | String[] ret = new String[apps.size()]; | 
|  | 6380 | int i = 0; | 
|  | 6381 | for (SmsApplicationData app : apps) { | 
|  | 6382 | ret[i++] = app.mPackageName; | 
|  | 6383 | } | 
|  | 6384 | return ret; | 
|  | 6385 | } | 
|  | 6386 |  | 
|  | 6387 | /** | 
|  | 6388 | * Returns the default SMS app package name on a given user. | 
|  | 6389 | * | 
|  | 6390 | * Only the shell user (UID 2000 or 0) can call it. | 
|  | 6391 | * Target user must be running. | 
|  | 6392 | */ | 
|  | 6393 | @Override | 
|  | 6394 | public String getDefaultSmsApp(int userId) { | 
|  | 6395 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); | 
|  | 6396 | ensureUserRunning(userId); | 
|  | 6397 |  | 
|  | 6398 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, | 
|  | 6399 | /* updateIfNeeded= */ true, userId); | 
|  | 6400 | return cn == null ? null : cn.getPackageName(); | 
|  | 6401 | } | 
|  | 6402 |  | 
|  | 6403 | /** | 
|  | 6404 | * Set a package as the default SMS app on a given user. | 
|  | 6405 | * | 
|  | 6406 | * Only the shell user (UID 2000 or 0) can call it. | 
|  | 6407 | * Target user must be running. | 
|  | 6408 | */ | 
|  | 6409 | @Override | 
|  | 6410 | public void setDefaultSmsApp(int userId, String packageName) { | 
|  | 6411 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); | 
|  | 6412 | ensureUserRunning(userId); | 
|  | 6413 |  | 
|  | 6414 | boolean found = false; | 
|  | 6415 | for (String pkg : getSmsApps(userId)) { | 
|  | 6416 | if (TextUtils.equals(packageName, pkg)) { | 
|  | 6417 | found = true; | 
|  | 6418 | break; | 
|  | 6419 | } | 
|  | 6420 | } | 
|  | 6421 | if (!found) { | 
|  | 6422 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); | 
|  | 6423 | } | 
|  | 6424 |  | 
|  | 6425 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); | 
|  | 6426 | } | 
|  | 6427 |  | 
| chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6428 | @Override | 
| sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6429 | public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList( | 
|  | 6430 | String callingPackage) { | 
| sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6431 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 6432 | mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) { | 
|  | 6433 | throw new SecurityException("Requires READ_PHONE_STATE permission."); | 
|  | 6434 | } | 
|  | 6435 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6436 | try { | 
| sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6437 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); | 
|  | 6438 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 6439 | if (phone.getEmergencyNumberTracker() != null | 
|  | 6440 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { | 
|  | 6441 | emergencyNumberListInternal.put( | 
|  | 6442 | phone.getSubId(), | 
|  | 6443 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); | 
|  | 6444 | } | 
| sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6445 | } | 
| sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6446 | return emergencyNumberListInternal; | 
| sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6447 | } finally { | 
|  | 6448 | Binder.restoreCallingIdentity(identity); | 
|  | 6449 | } | 
| sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6450 | } | 
|  | 6451 |  | 
|  | 6452 | @Override | 
| sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6453 | public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) { | 
|  | 6454 | final Phone defaultPhone = getDefaultPhone(); | 
|  | 6455 | if (!exactMatch) { | 
|  | 6456 | TelephonyPermissions | 
|  | 6457 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 6458 | mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)"); | 
|  | 6459 | } | 
|  | 6460 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6461 | try { | 
| sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6462 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 6463 | if (phone.getEmergencyNumberTracker() != null | 
|  | 6464 | && phone.getEmergencyNumberTracker() != null) { | 
|  | 6465 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( | 
|  | 6466 | number, exactMatch)) { | 
|  | 6467 | return true; | 
| sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6468 | } | 
|  | 6469 | } | 
| sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6470 | } | 
|  | 6471 | return false; | 
|  | 6472 | } finally { | 
|  | 6473 | Binder.restoreCallingIdentity(identity); | 
|  | 6474 | } | 
|  | 6475 | } | 
|  | 6476 |  | 
| sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6477 | /** | 
|  | 6478 | * Update emergency number list for test mode. | 
|  | 6479 | */ | 
|  | 6480 | @Override | 
|  | 6481 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { | 
|  | 6482 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 6483 | "updateEmergencyNumberListTestMode"); | 
|  | 6484 |  | 
|  | 6485 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6486 | try { | 
|  | 6487 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 6488 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
|  | 6489 | if (tracker != null) { | 
|  | 6490 | tracker.executeEmergencyNumberTestModeCommand(action, num); | 
|  | 6491 | } | 
|  | 6492 | } | 
|  | 6493 | } finally { | 
|  | 6494 | Binder.restoreCallingIdentity(identity); | 
|  | 6495 | } | 
|  | 6496 | } | 
|  | 6497 |  | 
|  | 6498 | /** | 
|  | 6499 | * Get the full emergency number list for test mode. | 
|  | 6500 | */ | 
|  | 6501 | @Override | 
|  | 6502 | public List<String> getEmergencyNumberListTestMode() { | 
|  | 6503 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 6504 | "getEmergencyNumberListTestMode"); | 
|  | 6505 |  | 
|  | 6506 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6507 | try { | 
|  | 6508 | Set<String> emergencyNumbers = new HashSet<>(); | 
|  | 6509 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 6510 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
|  | 6511 | if (tracker != null) { | 
|  | 6512 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { | 
|  | 6513 | emergencyNumbers.add(num.getNumber()); | 
|  | 6514 | } | 
|  | 6515 | } | 
|  | 6516 | } | 
|  | 6517 | return new ArrayList<>(emergencyNumbers); | 
|  | 6518 | } finally { | 
|  | 6519 | Binder.restoreCallingIdentity(identity); | 
|  | 6520 | } | 
|  | 6521 | } | 
|  | 6522 |  | 
| sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6523 | @Override | 
| chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6524 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { | 
|  | 6525 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); | 
|  | 6526 | Phone phone = getPhone(subId); | 
|  | 6527 | if (phone == null) { | 
|  | 6528 | return null; | 
|  | 6529 | } | 
|  | 6530 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6531 | try { | 
|  | 6532 | UiccProfile profile = UiccController.getInstance() | 
|  | 6533 | .getUiccProfileForPhone(phone.getPhoneId()); | 
|  | 6534 | if (profile != null) { | 
|  | 6535 | return profile.getCertsFromCarrierPrivilegeAccessRules(); | 
|  | 6536 | } | 
|  | 6537 | } finally { | 
|  | 6538 | Binder.restoreCallingIdentity(identity); | 
|  | 6539 | } | 
|  | 6540 | return null; | 
|  | 6541 | } | 
| Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6542 |  | 
|  | 6543 | /** | 
|  | 6544 | * Enable or disable a modem stack. | 
|  | 6545 | */ | 
|  | 6546 | @Override | 
|  | 6547 | public boolean enableModemForSlot(int slotIndex, boolean enable) { | 
|  | 6548 | enforceModifyPermission(); | 
|  | 6549 |  | 
|  | 6550 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6551 | try { | 
|  | 6552 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 6553 | if (phone == null) { | 
|  | 6554 | return false; | 
|  | 6555 | } else { | 
|  | 6556 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); | 
|  | 6557 | } | 
|  | 6558 | } finally { | 
|  | 6559 | Binder.restoreCallingIdentity(identity); | 
|  | 6560 | } | 
|  | 6561 | } | 
| Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6562 |  | 
|  | 6563 | @Override | 
|  | 6564 | public void setMultisimCarrierRestriction(boolean isMultisimCarrierRestricted) { | 
|  | 6565 | enforceModifyPermission(); | 
|  | 6566 |  | 
|  | 6567 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6568 | try { | 
|  | 6569 | mTelephonySharedPreferences.edit() | 
|  | 6570 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultisimCarrierRestricted) | 
|  | 6571 | .commit(); | 
|  | 6572 | } finally { | 
|  | 6573 | Binder.restoreCallingIdentity(identity); | 
|  | 6574 | } | 
|  | 6575 | } | 
|  | 6576 |  | 
|  | 6577 | @Override | 
|  | 6578 | public boolean isMultisimCarrierRestricted() { | 
|  | 6579 | enforceReadPrivilegedPermission("isMultisimCarrierRestricted"); | 
|  | 6580 |  | 
|  | 6581 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6582 | try { | 
|  | 6583 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. | 
|  | 6584 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; | 
|  | 6585 | if (numPhysicalSlots < 2) { | 
|  | 6586 | loge("isMultisimCarrierRestricted: requires at least 2 cards"); | 
|  | 6587 | return true; | 
|  | 6588 | } | 
|  | 6589 |  | 
|  | 6590 | // Default value is false. Multi SIM is allowed unless explicitly restricted. | 
|  | 6591 | return mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false); | 
|  | 6592 | } finally { | 
|  | 6593 | Binder.restoreCallingIdentity(identity); | 
|  | 6594 | } | 
|  | 6595 | } | 
| Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6596 |  | 
|  | 6597 | /** | 
|  | 6598 | * Switch configs to enable multi-sim or switch back to single-sim | 
|  | 6599 | * @param numOfSims number of active sims we want to switch to | 
|  | 6600 | */ | 
|  | 6601 | @Override | 
|  | 6602 | public void switchMultiSimConfig(int numOfSims) { | 
|  | 6603 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6604 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); | 
|  | 6605 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6606 | try { | 
|  | 6607 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); | 
|  | 6608 | } finally { | 
|  | 6609 | Binder.restoreCallingIdentity(identity); | 
|  | 6610 | } | 
|  | 6611 | } | 
|  | 6612 |  | 
|  | 6613 | /** | 
| Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6614 | * 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] | 6615 | * Return value defaults to true | 
| Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6616 | */ | 
|  | 6617 | @Override | 
|  | 6618 | public boolean isRebootRequiredForModemConfigChange() { | 
|  | 6619 | enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange"); | 
|  | 6620 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6621 | try { | 
|  | 6622 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); | 
|  | 6623 | } finally { | 
|  | 6624 | Binder.restoreCallingIdentity(identity); | 
|  | 6625 | } | 
|  | 6626 | } | 
|  | 6627 |  | 
| Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 6628 | private void updateModemStateMetrics() { | 
|  | 6629 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); | 
|  | 6630 | // TODO: check the state for each modem if the api is ready. | 
|  | 6631 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); | 
|  | 6632 | } | 
|  | 6633 |  | 
| Pengquan Meng | 3aceaec | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 6634 | @Override | 
|  | 6635 | public int[] getSlotsMapping() { | 
|  | 6636 | enforceReadPrivilegedPermission("getSlotsMapping"); | 
|  | 6637 |  | 
|  | 6638 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6639 | try { | 
|  | 6640 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); | 
|  | 6641 | // All logical slots should have a mapping to a physical slot. | 
|  | 6642 | int[] logicalSlotsMapping = new int[phoneCount]; | 
|  | 6643 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); | 
|  | 6644 | for (int i = 0; i < slotInfos.length; i++) { | 
|  | 6645 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { | 
|  | 6646 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; | 
|  | 6647 | } | 
|  | 6648 | } | 
|  | 6649 | return logicalSlotsMapping; | 
|  | 6650 | } finally { | 
|  | 6651 | Binder.restoreCallingIdentity(identity); | 
|  | 6652 | } | 
|  | 6653 | } | 
| Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 6654 |  | 
|  | 6655 | /** | 
|  | 6656 | * Get the IRadio HAL Version | 
|  | 6657 | */ | 
|  | 6658 | @Override | 
|  | 6659 | public int getRadioHalVersion() { | 
|  | 6660 | Phone phone = getDefaultPhone(); | 
|  | 6661 | if (phone == null) return -1; | 
|  | 6662 | HalVersion hv = phone.getHalVersion(); | 
|  | 6663 | if (hv.equals(HalVersion.UNKNOWN)) return -1; | 
|  | 6664 | return hv.major * 100 + hv.minor; | 
|  | 6665 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6666 | } |