Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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.server.telecom; |
| 18 | |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 19 | import static android.Manifest.permission.CALL_PHONE; |
Tyler Gunn | b652dad | 2018-03-27 18:49:49 +0000 | [diff] [blame] | 20 | import static android.Manifest.permission.CALL_PRIVILEGED; |
Hall Liu | ecd74a5 | 2016-01-12 15:26:36 -0800 | [diff] [blame] | 21 | import static android.Manifest.permission.DUMP; |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 22 | import static android.Manifest.permission.MODIFY_PHONE_STATE; |
| 23 | import static android.Manifest.permission.READ_PHONE_STATE; |
Amit Mahajan | 3c29693 | 2015-07-14 10:23:15 -0700 | [diff] [blame] | 24 | import static android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE; |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 25 | import static android.Manifest.permission.REGISTER_SIM_SUBSCRIPTION; |
Yorke Lee | 71734c2 | 2015-06-02 14:22:56 -0700 | [diff] [blame] | 26 | import static android.Manifest.permission.WRITE_SECURE_SETTINGS; |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 27 | |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 28 | import android.Manifest; |
Yorke Lee | b398430 | 2015-06-15 12:06:35 -0700 | [diff] [blame] | 29 | import android.app.ActivityManager; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 30 | import android.app.AppOpsManager; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 31 | import android.content.ComponentName; |
| 32 | import android.content.Context; |
| 33 | import android.content.Intent; |
| 34 | import android.content.pm.ApplicationInfo; |
| 35 | import android.content.pm.PackageManager; |
| 36 | import android.content.res.Resources; |
| 37 | import android.net.Uri; |
| 38 | import android.os.Binder; |
| 39 | import android.os.Bundle; |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 40 | import android.os.Process; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 41 | import android.os.UserHandle; |
Brad Ebinger | a3eccfe | 2016-10-05 15:45:22 -0700 | [diff] [blame] | 42 | import android.telecom.Log; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 43 | import android.telecom.PhoneAccount; |
| 44 | import android.telecom.PhoneAccountHandle; |
Hall Liu | 874c0f8 | 2016-04-29 18:13:18 -0700 | [diff] [blame] | 45 | import android.telecom.TelecomAnalytics; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 46 | import android.telecom.TelecomManager; |
Tyler Gunn | 42ef808 | 2015-11-24 15:34:34 -0800 | [diff] [blame] | 47 | import android.telecom.VideoProfile; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 48 | import android.telephony.SubscriptionManager; |
| 49 | import android.telephony.TelephonyManager; |
Tyler Gunn | 0edfc66 | 2017-04-14 13:46:21 -0700 | [diff] [blame] | 50 | import android.text.TextUtils; |
Brad Ebinger | 62da8e1 | 2016-01-28 19:16:08 -0800 | [diff] [blame] | 51 | import android.util.EventLog; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 52 | |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 53 | import com.android.internal.telecom.ITelecomService; |
| 54 | import com.android.internal.util.IndentingPrintWriter; |
Hall Liu | ecda554 | 2015-12-04 11:31:31 -0800 | [diff] [blame] | 55 | import com.android.server.telecom.components.UserCallIntentProcessorFactory; |
Mohamed | c926185 | 2016-02-05 14:10:17 -0800 | [diff] [blame] | 56 | import com.android.server.telecom.settings.BlockedNumbersActivity; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 57 | |
| 58 | import java.io.FileDescriptor; |
| 59 | import java.io.PrintWriter; |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 60 | import java.util.Collections; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 61 | import java.util.List; |
| 62 | |
Eugene Susla | ccba720 | 2017-02-10 10:56:53 -0800 | [diff] [blame] | 63 | // TODO: Needed for move to system service: import com.android.internal.R; |
| 64 | |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 65 | /** |
| 66 | * Implementation of the ITelecom interface. |
| 67 | */ |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 68 | public class TelecomServiceImpl { |
Hall Liu | 0a6dd30 | 2015-12-16 15:06:49 -0800 | [diff] [blame] | 69 | |
| 70 | public interface SubscriptionManagerAdapter { |
| 71 | int getDefaultVoiceSubId(); |
| 72 | } |
| 73 | |
| 74 | static class SubscriptionManagerAdapterImpl implements SubscriptionManagerAdapter { |
| 75 | @Override |
| 76 | public int getDefaultVoiceSubId() { |
Shishir Agrawal | ce68874 | 2016-01-25 15:02:21 -0800 | [diff] [blame] | 77 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Hall Liu | 0a6dd30 | 2015-12-16 15:06:49 -0800 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
Tyler Gunn | 897e851 | 2017-05-18 15:46:51 -0700 | [diff] [blame] | 81 | private static final String TIME_LINE_ARG = "timeline"; |
Tyler Gunn | 42ef808 | 2015-11-24 15:34:34 -0800 | [diff] [blame] | 82 | private static final int DEFAULT_VIDEO_STATE = -1; |
Santos Cordon | 7385396 | 2015-02-27 15:13:35 -0800 | [diff] [blame] | 83 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 84 | private final ITelecomService.Stub mBinderImpl = new ITelecomService.Stub() { |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 85 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 86 | public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme, |
| 87 | String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 88 | try { |
| 89 | Log.startSession("TSI.gDOPA"); |
| 90 | synchronized (mLock) { |
| 91 | if (!canReadPhoneState(callingPackage, "getDefaultOutgoingPhoneAccount")) { |
| 92 | return null; |
| 93 | } |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 94 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 95 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 96 | long token = Binder.clearCallingIdentity(); |
| 97 | try { |
| 98 | return mPhoneAccountRegistrar |
| 99 | .getOutgoingPhoneAccountForScheme(uriScheme, callingUserHandle); |
| 100 | } catch (Exception e) { |
| 101 | Log.e(this, e, "getDefaultOutgoingPhoneAccount"); |
| 102 | throw e; |
| 103 | } finally { |
| 104 | Binder.restoreCallingIdentity(token); |
| 105 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 106 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 107 | } finally { |
| 108 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 114 | synchronized (mLock) { |
| 115 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 116 | Log.startSession("TSI.gUSOPA"); |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 117 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 118 | return mPhoneAccountRegistrar.getUserSelectedOutgoingPhoneAccount( |
| 119 | callingUserHandle); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 120 | } catch (Exception e) { |
| 121 | Log.e(this, e, "getUserSelectedOutgoingPhoneAccount"); |
| 122 | throw e; |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 123 | } finally { |
| 124 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 125 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 131 | try { |
| 132 | Log.startSession("TSI.sUSOPA"); |
| 133 | synchronized (mLock) { |
| 134 | enforceModifyPermission(); |
| 135 | UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 136 | long token = Binder.clearCallingIdentity(); |
| 137 | try { |
| 138 | mPhoneAccountRegistrar.setUserSelectedOutgoingPhoneAccount( |
| 139 | accountHandle, callingUserHandle); |
| 140 | } catch (Exception e) { |
| 141 | Log.e(this, e, "setUserSelectedOutgoingPhoneAccount"); |
| 142 | throw e; |
| 143 | } finally { |
| 144 | Binder.restoreCallingIdentity(token); |
| 145 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 146 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 147 | } finally { |
| 148 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | |
| 152 | @Override |
Santos Cordon | ea5cb93 | 2015-05-07 16:28:38 -0700 | [diff] [blame] | 153 | public List<PhoneAccountHandle> getCallCapablePhoneAccounts( |
| 154 | boolean includeDisabledAccounts, String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 155 | try { |
| 156 | Log.startSession("TSI.gCCPA"); |
| 157 | if (!canReadPhoneState(callingPackage, "getDefaultOutgoingPhoneAccount")) { |
| 158 | return Collections.emptyList(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 159 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 160 | synchronized (mLock) { |
| 161 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 162 | long token = Binder.clearCallingIdentity(); |
| 163 | try { |
| 164 | return mPhoneAccountRegistrar.getCallCapablePhoneAccounts(null, |
| 165 | includeDisabledAccounts, callingUserHandle); |
| 166 | } catch (Exception e) { |
| 167 | Log.e(this, e, "getCallCapablePhoneAccounts"); |
| 168 | throw e; |
| 169 | } finally { |
| 170 | Binder.restoreCallingIdentity(token); |
| 171 | } |
| 172 | } |
| 173 | } finally { |
| 174 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | |
| 178 | @Override |
Tyler Gunn | ebfc916 | 2017-04-07 15:00:49 -0700 | [diff] [blame] | 179 | public List<PhoneAccountHandle> getSelfManagedPhoneAccounts(String callingPackage) { |
| 180 | try { |
| 181 | Log.startSession("TSI.gSMPA"); |
| 182 | if (!canReadPhoneState(callingPackage, "Requires READ_PHONE_STATE permission.")) { |
| 183 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 184 | } |
| 185 | synchronized (mLock) { |
| 186 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 187 | long token = Binder.clearCallingIdentity(); |
| 188 | try { |
| 189 | return mPhoneAccountRegistrar.getSelfManagedPhoneAccounts( |
| 190 | callingUserHandle); |
| 191 | } catch (Exception e) { |
| 192 | Log.e(this, e, "getSelfManagedPhoneAccounts"); |
| 193 | throw e; |
| 194 | } finally { |
| 195 | Binder.restoreCallingIdentity(token); |
| 196 | } |
| 197 | } |
| 198 | } finally { |
| 199 | Log.endSession(); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 204 | public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme, |
| 205 | String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 206 | try { |
| 207 | Log.startSession("TSI.gPASS"); |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 208 | try { |
| 209 | enforceModifyPermission( |
| 210 | "getPhoneAccountsSupportingScheme requires MODIFY_PHONE_STATE"); |
| 211 | } catch (SecurityException e) { |
| 212 | EventLog.writeEvent(0x534e4554, "62347125", Binder.getCallingUid(), |
| 213 | "getPhoneAccountsSupportingScheme: " + callingPackage); |
| 214 | return Collections.emptyList(); |
| 215 | } |
| 216 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 217 | synchronized (mLock) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 218 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 219 | long token = Binder.clearCallingIdentity(); |
| 220 | try { |
| 221 | return mPhoneAccountRegistrar.getCallCapablePhoneAccounts(uriScheme, false, |
| 222 | callingUserHandle); |
| 223 | } catch (Exception e) { |
| 224 | Log.e(this, e, "getPhoneAccountsSupportingScheme %s", uriScheme); |
| 225 | throw e; |
| 226 | } finally { |
| 227 | Binder.restoreCallingIdentity(token); |
| 228 | } |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 229 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 230 | } finally { |
| 231 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | |
| 235 | @Override |
| 236 | public List<PhoneAccountHandle> getPhoneAccountsForPackage(String packageName) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 237 | synchronized (mLock) { |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 238 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 239 | long token = Binder.clearCallingIdentity(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 240 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 241 | Log.startSession("TSI.gPAFP"); |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 242 | return mPhoneAccountRegistrar.getPhoneAccountsForPackage(packageName, |
| 243 | callingUserHandle); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 244 | } catch (Exception e) { |
| 245 | Log.e(this, e, "getPhoneAccountsForPackage %s", packageName); |
| 246 | throw e; |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 247 | } finally { |
| 248 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 249 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 250 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
| 254 | @Override |
| 255 | public PhoneAccount getPhoneAccount(PhoneAccountHandle accountHandle) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 256 | synchronized (mLock) { |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 257 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 258 | long token = Binder.clearCallingIdentity(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 259 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 260 | Log.startSession("TSI.gPA"); |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 261 | // In ideal case, we should not resolve the handle across profiles. But given |
| 262 | // the fact that profile's call is handled by its parent user's in-call UI, |
| 263 | // parent user's in call UI need to be able to get phone account from the |
| 264 | // profile's phone account handle. |
| 265 | return mPhoneAccountRegistrar |
| 266 | .getPhoneAccount(accountHandle, callingUserHandle, |
| 267 | /* acrossProfiles */ true); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 268 | } catch (Exception e) { |
| 269 | Log.e(this, e, "getPhoneAccount %s", accountHandle); |
| 270 | throw e; |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 271 | } finally { |
| 272 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 273 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 274 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | |
| 278 | @Override |
| 279 | public int getAllPhoneAccountsCount() { |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 280 | try { |
| 281 | Log.startSession("TSI.gAPAC"); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 282 | try { |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 283 | enforceModifyPermission( |
| 284 | "getAllPhoneAccountsCount requires MODIFY_PHONE_STATE permission."); |
| 285 | } catch (SecurityException e) { |
| 286 | EventLog.writeEvent(0x534e4554, "62347125", Binder.getCallingUid(), |
| 287 | "getAllPhoneAccountsCount"); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 288 | throw e; |
| 289 | } |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 290 | |
| 291 | synchronized (mLock) { |
| 292 | try { |
| 293 | // This list is pre-filtered for the calling user. |
| 294 | return getAllPhoneAccounts().size(); |
| 295 | } catch (Exception e) { |
| 296 | Log.e(this, e, "getAllPhoneAccountsCount"); |
| 297 | throw e; |
| 298 | |
| 299 | } |
| 300 | } |
| 301 | } finally { |
| 302 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
| 306 | @Override |
| 307 | public List<PhoneAccount> getAllPhoneAccounts() { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 308 | synchronized (mLock) { |
| 309 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 310 | Log.startSession("TSI.gAPA"); |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 311 | try { |
| 312 | enforceModifyPermission( |
| 313 | "getAllPhoneAccounts requires MODIFY_PHONE_STATE permission."); |
| 314 | } catch (SecurityException e) { |
| 315 | EventLog.writeEvent(0x534e4554, "62347125", Binder.getCallingUid(), |
| 316 | "getAllPhoneAccounts"); |
| 317 | throw e; |
| 318 | } |
| 319 | |
| 320 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 321 | long token = Binder.clearCallingIdentity(); |
| 322 | try { |
| 323 | return mPhoneAccountRegistrar.getAllPhoneAccounts(callingUserHandle); |
| 324 | } catch (Exception e) { |
| 325 | Log.e(this, e, "getAllPhoneAccounts"); |
| 326 | throw e; |
| 327 | } finally { |
| 328 | Binder.restoreCallingIdentity(token); |
| 329 | } |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 330 | } finally { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 331 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 332 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | |
| 336 | @Override |
| 337 | public List<PhoneAccountHandle> getAllPhoneAccountHandles() { |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 338 | try { |
| 339 | Log.startSession("TSI.gAPAH"); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 340 | try { |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 341 | enforceModifyPermission( |
| 342 | "getAllPhoneAccountHandles requires MODIFY_PHONE_STATE permission."); |
| 343 | } catch (SecurityException e) { |
| 344 | EventLog.writeEvent(0x534e4554, "62347125", Binder.getCallingUid(), |
| 345 | "getAllPhoneAccountHandles"); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 346 | throw e; |
| 347 | } |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 348 | |
| 349 | synchronized (mLock) { |
| 350 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 351 | long token = Binder.clearCallingIdentity(); |
| 352 | try { |
| 353 | return mPhoneAccountRegistrar.getAllPhoneAccountHandles(callingUserHandle); |
| 354 | } catch (Exception e) { |
| 355 | Log.e(this, e, "getAllPhoneAccounts"); |
| 356 | throw e; |
| 357 | } finally { |
| 358 | Binder.restoreCallingIdentity(token); |
| 359 | } |
| 360 | } |
| 361 | } finally { |
| 362 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | |
| 366 | @Override |
| 367 | public PhoneAccountHandle getSimCallManager() { |
Sailesh Nepal | fc43ea8 | 2015-07-28 19:30:28 -0700 | [diff] [blame] | 368 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 369 | Log.startSession("TSI.gSCM"); |
| 370 | long token = Binder.clearCallingIdentity(); |
| 371 | int user; |
| 372 | try { |
| 373 | user = ActivityManager.getCurrentUser(); |
| 374 | return getSimCallManagerForUser(user); |
| 375 | } finally { |
| 376 | Binder.restoreCallingIdentity(token); |
| 377 | } |
Sailesh Nepal | fc43ea8 | 2015-07-28 19:30:28 -0700 | [diff] [blame] | 378 | } finally { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 379 | Log.endSession(); |
Sailesh Nepal | fc43ea8 | 2015-07-28 19:30:28 -0700 | [diff] [blame] | 380 | } |
Sailesh Nepal | fc43ea8 | 2015-07-28 19:30:28 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | @Override |
| 384 | public PhoneAccountHandle getSimCallManagerForUser(int user) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 385 | synchronized (mLock) { |
| 386 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 387 | Log.startSession("TSI.gSCMFU"); |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 388 | final int callingUid = Binder.getCallingUid(); |
Santos Cordon | 59c21a7 | 2015-06-11 10:11:21 -0700 | [diff] [blame] | 389 | long token = Binder.clearCallingIdentity(); |
| 390 | try { |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 391 | if (user != ActivityManager.getCurrentUser()) { |
| 392 | enforceCrossUserPermission(callingUid); |
| 393 | } |
| 394 | return mPhoneAccountRegistrar.getSimCallManager(UserHandle.of(user)); |
Santos Cordon | 59c21a7 | 2015-06-11 10:11:21 -0700 | [diff] [blame] | 395 | } finally { |
Santos Cordon | 59c21a7 | 2015-06-11 10:11:21 -0700 | [diff] [blame] | 396 | Binder.restoreCallingIdentity(token); |
| 397 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 398 | } catch (Exception e) { |
| 399 | Log.e(this, e, "getSimCallManager"); |
| 400 | throw e; |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 401 | } finally { |
| 402 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 403 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | |
| 407 | @Override |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 408 | public void registerPhoneAccount(PhoneAccount account) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 409 | try { |
| 410 | Log.startSession("TSI.rPA"); |
| 411 | synchronized (mLock) { |
| 412 | if (!mContext.getApplicationContext().getResources().getBoolean( |
| 413 | com.android.internal.R.bool.config_voice_capable)) { |
| 414 | Log.w(this, |
| 415 | "registerPhoneAccount not allowed on non-voice capable device."); |
| 416 | return; |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 417 | } |
Yorke Lee | 5806175 | 2015-05-04 11:06:26 -0700 | [diff] [blame] | 418 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 419 | enforcePhoneAccountModificationForPackage( |
| 420 | account.getAccountHandle().getComponentName().getPackageName()); |
Tyler Gunn | acb3bc8 | 2017-01-09 09:43:56 -0800 | [diff] [blame] | 421 | if (account.hasCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED)) { |
| 422 | enforceRegisterSelfManaged(); |
Tyler Gunn | 9e806ee | 2017-02-06 20:49:24 -0800 | [diff] [blame] | 423 | if (account.hasCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER) || |
| 424 | account.hasCapabilities( |
| 425 | PhoneAccount.CAPABILITY_CONNECTION_MANAGER) || |
| 426 | account.hasCapabilities( |
| 427 | PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) { |
| 428 | throw new SecurityException("Self-managed ConnectionServices " + |
| 429 | "cannot also be call capable, connection managers, or " + |
| 430 | "SIM accounts."); |
| 431 | } |
Tyler Gunn | 2b17f23 | 2017-03-08 08:51:00 -0800 | [diff] [blame] | 432 | |
| 433 | // For self-managed CS, the phone account registrar will override the |
| 434 | // label the user has set for the phone account. This ensures the |
| 435 | // self-managed cs implementation can't spoof their app name. |
Tyler Gunn | acb3bc8 | 2017-01-09 09:43:56 -0800 | [diff] [blame] | 436 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 437 | if (account.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) { |
| 438 | enforceRegisterSimSubscriptionPermission(); |
| 439 | } |
| 440 | if (account.hasCapabilities(PhoneAccount.CAPABILITY_MULTI_USER)) { |
| 441 | enforceRegisterMultiUser(); |
| 442 | } |
| 443 | enforceUserHandleMatchesCaller(account.getAccountHandle()); |
Tyler Gunn | cbc9be2 | 2017-04-19 10:52:36 -0700 | [diff] [blame] | 444 | final long token = Binder.clearCallingIdentity(); |
| 445 | try { |
| 446 | mPhoneAccountRegistrar.registerPhoneAccount(account); |
| 447 | } finally { |
| 448 | Binder.restoreCallingIdentity(token); |
| 449 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 450 | } catch (Exception e) { |
| 451 | Log.e(this, e, "registerPhoneAccount %s", account); |
| 452 | throw e; |
Yorke Lee | 5806175 | 2015-05-04 11:06:26 -0700 | [diff] [blame] | 453 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 454 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 455 | } finally { |
| 456 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | |
| 460 | @Override |
| 461 | public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 462 | synchronized (mLock) { |
| 463 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 464 | Log.startSession("TSI.uPA"); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 465 | enforcePhoneAccountModificationForPackage( |
| 466 | accountHandle.getComponentName().getPackageName()); |
| 467 | enforceUserHandleMatchesCaller(accountHandle); |
Tyler Gunn | cbc9be2 | 2017-04-19 10:52:36 -0700 | [diff] [blame] | 468 | final long token = Binder.clearCallingIdentity(); |
| 469 | try { |
| 470 | mPhoneAccountRegistrar.unregisterPhoneAccount(accountHandle); |
| 471 | } finally { |
| 472 | Binder.restoreCallingIdentity(token); |
| 473 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 474 | } catch (Exception e) { |
| 475 | Log.e(this, e, "unregisterPhoneAccount %s", accountHandle); |
| 476 | throw e; |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 477 | } finally { |
| 478 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 479 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 480 | } |
| 481 | } |
| 482 | |
| 483 | @Override |
| 484 | public void clearAccounts(String packageName) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 485 | synchronized (mLock) { |
| 486 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 487 | Log.startSession("TSI.cA"); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 488 | enforcePhoneAccountModificationForPackage(packageName); |
| 489 | mPhoneAccountRegistrar |
| 490 | .clearAccounts(packageName, Binder.getCallingUserHandle()); |
| 491 | } catch (Exception e) { |
| 492 | Log.e(this, e, "clearAccounts %s", packageName); |
| 493 | throw e; |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 494 | } finally { |
| 495 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 496 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * @see android.telecom.TelecomManager#isVoiceMailNumber |
| 502 | */ |
| 503 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 504 | public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number, |
| 505 | String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 506 | try { |
| 507 | Log.startSession("TSI.iVMN"); |
| 508 | synchronized (mLock) { |
| 509 | if (!canReadPhoneState(callingPackage, "isVoiceMailNumber")) { |
| 510 | return false; |
| 511 | } |
| 512 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 513 | if (!isPhoneAccountHandleVisibleToCallingUser(accountHandle, |
| 514 | callingUserHandle)) { |
| 515 | Log.d(this, "%s is not visible for the calling user [iVMN]", accountHandle); |
| 516 | return false; |
| 517 | } |
| 518 | long token = Binder.clearCallingIdentity(); |
| 519 | try { |
| 520 | return mPhoneAccountRegistrar.isVoiceMailNumber(accountHandle, number); |
| 521 | } catch (Exception e) { |
| 522 | Log.e(this, e, "getSubscriptionIdForPhoneAccount"); |
| 523 | throw e; |
| 524 | } finally { |
| 525 | Binder.restoreCallingIdentity(token); |
| 526 | } |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 527 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 528 | } finally { |
| 529 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | |
| 533 | /** |
Yorke Lee | fb5ec30 | 2015-04-15 16:15:55 -0700 | [diff] [blame] | 534 | * @see android.telecom.TelecomManager#getVoiceMailNumber |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 535 | */ |
| 536 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 537 | public String getVoiceMailNumber(PhoneAccountHandle accountHandle, String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 538 | try { |
| 539 | Log.startSession("TSI.gVMN"); |
| 540 | synchronized (mLock) { |
| 541 | if (!canReadPhoneState(callingPackage, "getVoiceMailNumber")) { |
Yorke Lee | fb5ec30 | 2015-04-15 16:15:55 -0700 | [diff] [blame] | 542 | return null; |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 543 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 544 | try { |
| 545 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 546 | if (!isPhoneAccountHandleVisibleToCallingUser(accountHandle, |
| 547 | callingUserHandle)) { |
| 548 | Log.d(this, "%s is not visible for the calling user [gVMN]", |
| 549 | accountHandle); |
| 550 | return null; |
| 551 | } |
Hall Liu | 0a6dd30 | 2015-12-16 15:06:49 -0800 | [diff] [blame] | 552 | int subId = mSubscriptionManagerAdapter.getDefaultVoiceSubId(); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 553 | if (accountHandle != null) { |
| 554 | subId = mPhoneAccountRegistrar |
| 555 | .getSubscriptionIdForPhoneAccount(accountHandle); |
| 556 | } |
| 557 | return getTelephonyManager().getVoiceMailNumber(subId); |
| 558 | } catch (Exception e) { |
| 559 | Log.e(this, e, "getSubscriptionIdForPhoneAccount"); |
| 560 | throw e; |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 561 | } |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 562 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 563 | } finally { |
| 564 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | |
| 568 | /** |
Nancy Chen | ba30475 | 2015-01-24 23:29:22 -0800 | [diff] [blame] | 569 | * @see android.telecom.TelecomManager#getLine1Number |
| 570 | */ |
| 571 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 572 | public String getLine1Number(PhoneAccountHandle accountHandle, String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 573 | try { |
| 574 | Log.startSession("getL1N"); |
| 575 | if (!canReadPhoneState(callingPackage, "getLine1Number")) { |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 576 | return null; |
| 577 | } |
| 578 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 579 | synchronized (mLock) { |
| 580 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 581 | if (!isPhoneAccountHandleVisibleToCallingUser(accountHandle, |
| 582 | callingUserHandle)) { |
| 583 | Log.d(this, "%s is not visible for the calling user [gL1N]", accountHandle); |
| 584 | return null; |
| 585 | } |
| 586 | |
| 587 | long token = Binder.clearCallingIdentity(); |
| 588 | try { |
| 589 | int subId = mPhoneAccountRegistrar.getSubscriptionIdForPhoneAccount( |
| 590 | accountHandle); |
Shishir Agrawal | ce68874 | 2016-01-25 15:02:21 -0800 | [diff] [blame] | 591 | return getTelephonyManager().getLine1Number(subId); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 592 | } catch (Exception e) { |
| 593 | Log.e(this, e, "getSubscriptionIdForPhoneAccount"); |
| 594 | throw e; |
| 595 | } finally { |
| 596 | Binder.restoreCallingIdentity(token); |
| 597 | } |
Nancy Chen | ba30475 | 2015-01-24 23:29:22 -0800 | [diff] [blame] | 598 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 599 | } finally { |
| 600 | Log.endSession(); |
Nancy Chen | ba30475 | 2015-01-24 23:29:22 -0800 | [diff] [blame] | 601 | } |
| 602 | } |
| 603 | |
| 604 | /** |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 605 | * @see android.telecom.TelecomManager#silenceRinger |
| 606 | */ |
| 607 | @Override |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 608 | public void silenceRinger(String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 609 | try { |
| 610 | Log.startSession("TSI.sR"); |
| 611 | synchronized (mLock) { |
| 612 | enforcePermissionOrPrivilegedDialer(MODIFY_PHONE_STATE, callingPackage); |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 613 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 614 | long token = Binder.clearCallingIdentity(); |
| 615 | try { |
| 616 | Log.i(this, "Silence Ringer requested by %s", callingPackage); |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 617 | mCallsManager.getCallAudioManager().silenceRingers(); |
Sailesh Nepal | c07b8e1 | 2016-01-23 16:43:10 -0800 | [diff] [blame] | 618 | mCallsManager.getInCallController().silenceRinger(); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 619 | } finally { |
| 620 | Binder.restoreCallingIdentity(token); |
| 621 | } |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 622 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 623 | } finally { |
| 624 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 625 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | /** |
| 629 | * @see android.telecom.TelecomManager#getDefaultPhoneApp |
Yorke Lee | 5b3fc0a | 2015-04-23 17:42:57 -0700 | [diff] [blame] | 630 | * @deprecated - Use {@link android.telecom.TelecomManager#getDefaultDialerPackage()} |
| 631 | * instead. |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 632 | */ |
| 633 | @Override |
| 634 | public ComponentName getDefaultPhoneApp() { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 635 | try { |
| 636 | Log.startSession("TSI.gDPA"); |
| 637 | // No need to synchronize |
| 638 | Resources resources = mContext.getResources(); |
| 639 | return new ComponentName( |
| 640 | resources.getString(R.string.ui_default_package), |
| 641 | resources.getString(R.string.dialer_default_class)); |
| 642 | } finally { |
| 643 | Log.endSession(); |
| 644 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | /** |
Yorke Lee | 5291d4a | 2015-04-24 16:42:36 -0700 | [diff] [blame] | 648 | * @return the package name of the current user-selected default dialer. If no default |
| 649 | * has been selected, the package name of the system dialer is returned. If |
| 650 | * neither exists, then {@code null} is returned. |
Yorke Lee | 5b3fc0a | 2015-04-23 17:42:57 -0700 | [diff] [blame] | 651 | * @see android.telecom.TelecomManager#getDefaultDialerPackage |
| 652 | */ |
| 653 | @Override |
| 654 | public String getDefaultDialerPackage() { |
Yorke Lee | 29c003e | 2015-05-04 17:09:27 -0700 | [diff] [blame] | 655 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 656 | Log.startSession("TSI.gDDP"); |
| 657 | final long token = Binder.clearCallingIdentity(); |
| 658 | try { |
Hall Liu | 7c92832 | 2016-12-06 18:15:39 -0800 | [diff] [blame] | 659 | return mDefaultDialerCache.getDefaultDialerApplication( |
| 660 | ActivityManager.getCurrentUser()); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 661 | } finally { |
| 662 | Binder.restoreCallingIdentity(token); |
| 663 | } |
Yorke Lee | 29c003e | 2015-05-04 17:09:27 -0700 | [diff] [blame] | 664 | } finally { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 665 | Log.endSession(); |
Yorke Lee | 29c003e | 2015-05-04 17:09:27 -0700 | [diff] [blame] | 666 | } |
Yorke Lee | 5b3fc0a | 2015-04-23 17:42:57 -0700 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | /** |
| 670 | * @see android.telecom.TelecomManager#getSystemDialerPackage |
| 671 | */ |
| 672 | @Override |
| 673 | public String getSystemDialerPackage() { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 674 | try { |
| 675 | Log.startSession("TSI.gSDP"); |
| 676 | return mContext.getResources().getString(R.string.ui_default_package); |
| 677 | } finally { |
| 678 | Log.endSession(); |
| 679 | } |
Yorke Lee | 5b3fc0a | 2015-04-23 17:42:57 -0700 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | /** |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 683 | * @see android.telecom.TelecomManager#isInCall |
| 684 | */ |
| 685 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 686 | public boolean isInCall(String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 687 | try { |
| 688 | Log.startSession("TSI.iIC"); |
| 689 | if (!canReadPhoneState(callingPackage, "isInCall")) { |
| 690 | return false; |
| 691 | } |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 692 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 693 | synchronized (mLock) { |
Tyler Gunn | baf105b | 2017-04-11 15:21:03 -0700 | [diff] [blame] | 694 | return mCallsManager.hasOngoingCalls(); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 695 | } |
| 696 | } finally { |
| 697 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 698 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | /** |
Tyler Gunn | 37e782b | 2017-02-10 09:42:03 -0800 | [diff] [blame] | 702 | * @see android.telecom.TelecomManager#isInManagedCall |
| 703 | */ |
| 704 | @Override |
| 705 | public boolean isInManagedCall(String callingPackage) { |
| 706 | try { |
| 707 | Log.startSession("TSI.iIMC"); |
| 708 | if (!canReadPhoneState(callingPackage, "isInManagedCall")) { |
| 709 | throw new SecurityException("Only the default dialer or caller with " + |
| 710 | "READ_PHONE_STATE permission can use this method."); |
| 711 | } |
| 712 | |
| 713 | synchronized (mLock) { |
| 714 | return mCallsManager.hasOngoingManagedCalls(); |
| 715 | } |
| 716 | } finally { |
| 717 | Log.endSession(); |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | /** |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 722 | * @see android.telecom.TelecomManager#isRinging |
| 723 | */ |
| 724 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 725 | public boolean isRinging(String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 726 | try { |
| 727 | Log.startSession("TSI.iR"); |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 728 | if (!isPrivilegedDialerCalling(callingPackage)) { |
| 729 | try { |
| 730 | enforceModifyPermission( |
| 731 | "isRinging requires MODIFY_PHONE_STATE permission."); |
| 732 | } catch (SecurityException e) { |
| 733 | EventLog.writeEvent(0x534e4554, "62347125", "isRinging: " + callingPackage); |
| 734 | throw e; |
| 735 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 736 | } |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 737 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 738 | synchronized (mLock) { |
| 739 | // Note: We are explicitly checking the calls telecom is tracking rather than |
| 740 | // relying on mCallsManager#getCallState(). Since getCallState() relies on the |
| 741 | // current state as tracked by PhoneStateBroadcaster, any failure to properly |
| 742 | // track the current call state there could result in the wrong ringing state |
| 743 | // being reported by this API. |
| 744 | return mCallsManager.hasRingingCall(); |
| 745 | } |
| 746 | } finally { |
| 747 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 748 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | /** |
| 752 | * @see TelecomManager#getCallState |
| 753 | */ |
| 754 | @Override |
| 755 | public int getCallState() { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 756 | try { |
| 757 | Log.startSession("TSI.getCallState"); |
| 758 | synchronized (mLock) { |
| 759 | return mCallsManager.getCallState(); |
| 760 | } |
| 761 | } finally { |
| 762 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 763 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | /** |
| 767 | * @see android.telecom.TelecomManager#endCall |
| 768 | */ |
| 769 | @Override |
Tyler Gunn | 587fc27 | 2018-02-07 16:07:29 -0800 | [diff] [blame] | 770 | public boolean endCall(String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 771 | try { |
| 772 | Log.startSession("TSI.eC"); |
| 773 | synchronized (mLock) { |
| 774 | enforceModifyPermission(); |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 775 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 776 | long token = Binder.clearCallingIdentity(); |
| 777 | try { |
Tyler Gunn | 587fc27 | 2018-02-07 16:07:29 -0800 | [diff] [blame] | 778 | return endCallInternal(callingPackage); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 779 | } finally { |
| 780 | Binder.restoreCallingIdentity(token); |
| 781 | } |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 782 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 783 | } finally { |
| 784 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 785 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | /** |
| 789 | * @see android.telecom.TelecomManager#acceptRingingCall |
| 790 | */ |
| 791 | @Override |
Eugene Susla | ccba720 | 2017-02-10 10:56:53 -0800 | [diff] [blame] | 792 | public void acceptRingingCall(String packageName) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 793 | try { |
| 794 | Log.startSession("TSI.aRC"); |
| 795 | synchronized (mLock) { |
Eugene Susla | ccba720 | 2017-02-10 10:56:53 -0800 | [diff] [blame] | 796 | if (!enforceAnswerCallPermission(packageName, Binder.getCallingUid())) return; |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 797 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 798 | long token = Binder.clearCallingIdentity(); |
| 799 | try { |
| 800 | acceptRingingCallInternal(DEFAULT_VIDEO_STATE); |
| 801 | } finally { |
| 802 | Binder.restoreCallingIdentity(token); |
| 803 | } |
Tyler Gunn | 42ef808 | 2015-11-24 15:34:34 -0800 | [diff] [blame] | 804 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 805 | } finally { |
| 806 | Log.endSession(); |
Tyler Gunn | 42ef808 | 2015-11-24 15:34:34 -0800 | [diff] [blame] | 807 | } |
| 808 | } |
| 809 | |
| 810 | /** |
| 811 | * @see android.telecom.TelecomManager#acceptRingingCall(int) |
| 812 | * |
| 813 | */ |
| 814 | @Override |
Eugene Susla | ccba720 | 2017-02-10 10:56:53 -0800 | [diff] [blame] | 815 | public void acceptRingingCallWithVideoState(String packageName, int videoState) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 816 | try { |
| 817 | Log.startSession("TSI.aRCWVS"); |
| 818 | synchronized (mLock) { |
Eugene Susla | ccba720 | 2017-02-10 10:56:53 -0800 | [diff] [blame] | 819 | if (!enforceAnswerCallPermission(packageName, Binder.getCallingUid())) return; |
Tyler Gunn | 42ef808 | 2015-11-24 15:34:34 -0800 | [diff] [blame] | 820 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 821 | long token = Binder.clearCallingIdentity(); |
| 822 | try { |
| 823 | acceptRingingCallInternal(videoState); |
| 824 | } finally { |
| 825 | Binder.restoreCallingIdentity(token); |
| 826 | } |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 827 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 828 | } finally { |
| 829 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 830 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | /** |
| 834 | * @see android.telecom.TelecomManager#showInCallScreen |
| 835 | */ |
| 836 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 837 | public void showInCallScreen(boolean showDialpad, String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 838 | try { |
| 839 | Log.startSession("TSI.sICS"); |
| 840 | if (!canReadPhoneState(callingPackage, "showInCallScreen")) { |
| 841 | return; |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 842 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 843 | |
| 844 | synchronized (mLock) { |
| 845 | |
| 846 | long token = Binder.clearCallingIdentity(); |
| 847 | try { |
| 848 | mCallsManager.getInCallController().bringToForeground(showDialpad); |
| 849 | } finally { |
| 850 | Binder.restoreCallingIdentity(token); |
| 851 | } |
| 852 | } |
| 853 | } finally { |
| 854 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 855 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | /** |
| 859 | * @see android.telecom.TelecomManager#cancelMissedCallsNotification |
| 860 | */ |
| 861 | @Override |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 862 | public void cancelMissedCallsNotification(String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 863 | try { |
| 864 | Log.startSession("TSI.cMCN"); |
| 865 | synchronized (mLock) { |
| 866 | enforcePermissionOrPrivilegedDialer(MODIFY_PHONE_STATE, callingPackage); |
Tony Mak | a993094 | 2016-01-15 10:57:14 +0000 | [diff] [blame] | 867 | UserHandle userHandle = Binder.getCallingUserHandle(); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 868 | long token = Binder.clearCallingIdentity(); |
| 869 | try { |
Tony Mak | a993094 | 2016-01-15 10:57:14 +0000 | [diff] [blame] | 870 | mCallsManager.getMissedCallNotifier().clearMissedCalls(userHandle); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 871 | } finally { |
| 872 | Binder.restoreCallingIdentity(token); |
| 873 | } |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 874 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 875 | } finally { |
| 876 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 877 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 878 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 879 | /** |
| 880 | * @see android.telecom.TelecomManager#handleMmi |
| 881 | */ |
| 882 | @Override |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 883 | public boolean handlePinMmi(String dialString, String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 884 | try { |
| 885 | Log.startSession("TSI.hPM"); |
| 886 | synchronized (mLock) { |
| 887 | enforcePermissionOrPrivilegedDialer(MODIFY_PHONE_STATE, callingPackage); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 888 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 889 | // Switch identity so that TelephonyManager checks Telecom's permissions |
| 890 | // instead. |
| 891 | long token = Binder.clearCallingIdentity(); |
| 892 | boolean retval = false; |
| 893 | try { |
| 894 | retval = getTelephonyManager().handlePinMmi(dialString); |
| 895 | } finally { |
| 896 | Binder.restoreCallingIdentity(token); |
| 897 | } |
| 898 | |
| 899 | return retval; |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 900 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 901 | }finally { |
| 902 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 903 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | /** |
| 907 | * @see android.telecom.TelecomManager#handleMmi |
| 908 | */ |
| 909 | @Override |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 910 | public boolean handlePinMmiForPhoneAccount(PhoneAccountHandle accountHandle, |
| 911 | String dialString, String callingPackage) { |
| 912 | try { |
| 913 | Log.startSession("TSI.hPMFPA"); |
| 914 | synchronized (mLock) { |
| 915 | enforcePermissionOrPrivilegedDialer(MODIFY_PHONE_STATE, callingPackage); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 916 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 917 | UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
| 918 | if (!isPhoneAccountHandleVisibleToCallingUser(accountHandle, |
| 919 | callingUserHandle)) { |
| 920 | Log.d(this, "%s is not visible for the calling user [hMMI]", accountHandle); |
| 921 | return false; |
| 922 | } |
| 923 | |
| 924 | // Switch identity so that TelephonyManager checks Telecom's permissions |
| 925 | // instead. |
| 926 | long token = Binder.clearCallingIdentity(); |
| 927 | boolean retval = false; |
| 928 | try { |
| 929 | int subId = mPhoneAccountRegistrar.getSubscriptionIdForPhoneAccount( |
| 930 | accountHandle); |
| 931 | retval = getTelephonyManager().handlePinMmiForSubscriber(subId, dialString); |
| 932 | } finally { |
| 933 | Binder.restoreCallingIdentity(token); |
| 934 | } |
| 935 | return retval; |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 936 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 937 | }finally { |
| 938 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 939 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | /** |
| 943 | * @see android.telecom.TelecomManager#getAdnUriForPhoneAccount |
| 944 | */ |
| 945 | @Override |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 946 | public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle, |
| 947 | String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 948 | try { |
| 949 | Log.startSession("TSI.aAUFPA"); |
| 950 | synchronized (mLock) { |
| 951 | enforcePermissionOrPrivilegedDialer(MODIFY_PHONE_STATE, callingPackage); |
| 952 | if (!isPhoneAccountHandleVisibleToCallingUser(accountHandle, |
| 953 | Binder.getCallingUserHandle())) { |
| 954 | Log.d(this, "%s is not visible for the calling user [gA4PA]", |
| 955 | accountHandle); |
| 956 | return null; |
| 957 | } |
| 958 | // Switch identity so that TelephonyManager checks Telecom's permissions |
| 959 | // instead. |
| 960 | long token = Binder.clearCallingIdentity(); |
| 961 | String retval = "content://icc/adn/"; |
| 962 | try { |
| 963 | long subId = mPhoneAccountRegistrar |
| 964 | .getSubscriptionIdForPhoneAccount(accountHandle); |
| 965 | retval = retval + "subId/" + subId; |
| 966 | } finally { |
| 967 | Binder.restoreCallingIdentity(token); |
| 968 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 969 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 970 | return Uri.parse(retval); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 971 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 972 | } finally { |
| 973 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 974 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | /** |
| 978 | * @see android.telecom.TelecomManager#isTtySupported |
| 979 | */ |
| 980 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 981 | public boolean isTtySupported(String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 982 | try { |
| 983 | Log.startSession("TSI.iTS"); |
Sanket Padawe | 88efa0c | 2017-09-08 11:46:34 -0700 | [diff] [blame] | 984 | if (!canReadPhoneState(callingPackage, "isTtySupported")) { |
| 985 | throw new SecurityException("Only default dialer or an app with" + |
| 986 | "READ_PRIVILEGED_PHONE_STATE or READ_PHONE_STATE can call this api"); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 987 | } |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 988 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 989 | synchronized (mLock) { |
| 990 | return mCallsManager.isTtySupported(); |
| 991 | } |
| 992 | } finally { |
| 993 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 994 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | /** |
| 998 | * @see android.telecom.TelecomManager#getCurrentTtyMode |
| 999 | */ |
| 1000 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 1001 | public int getCurrentTtyMode(String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1002 | try { |
| 1003 | Log.startSession("TSI.gCTM"); |
| 1004 | if (!canReadPhoneState(callingPackage, "getCurrentTtyMode")) { |
| 1005 | return TelecomManager.TTY_MODE_OFF; |
| 1006 | } |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 1007 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1008 | synchronized (mLock) { |
| 1009 | return mCallsManager.getCurrentTtyMode(); |
| 1010 | } |
| 1011 | } finally { |
| 1012 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1013 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | /** |
| 1017 | * @see android.telecom.TelecomManager#addNewIncomingCall |
| 1018 | */ |
| 1019 | @Override |
| 1020 | public void addNewIncomingCall(PhoneAccountHandle phoneAccountHandle, Bundle extras) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1021 | try { |
| 1022 | Log.startSession("TSI.aNIC"); |
| 1023 | synchronized (mLock) { |
| 1024 | Log.i(this, "Adding new incoming call with phoneAccountHandle %s", |
Sharvil Nanavati | 6d3efb4 | 2015-05-14 11:36:40 -0700 | [diff] [blame] | 1025 | phoneAccountHandle); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1026 | if (phoneAccountHandle != null && |
| 1027 | phoneAccountHandle.getComponentName() != null) { |
| 1028 | // TODO(sail): Add unit tests for adding incoming calls from a SIM call |
| 1029 | // manager. |
| 1030 | if (isCallerSimCallManager() && TelephonyUtil.isPstnComponentName( |
| 1031 | phoneAccountHandle.getComponentName())) { |
| 1032 | Log.v(this, "Allowing call manager to add incoming call with PSTN" + |
| 1033 | " handle"); |
| 1034 | } else { |
| 1035 | mAppOpsManager.checkPackage( |
| 1036 | Binder.getCallingUid(), |
| 1037 | phoneAccountHandle.getComponentName().getPackageName()); |
| 1038 | // Make sure it doesn't cross the UserHandle boundary |
| 1039 | enforceUserHandleMatchesCaller(phoneAccountHandle); |
Tony Mak | 5851fa0 | 2016-02-23 19:41:52 +0000 | [diff] [blame] | 1040 | enforcePhoneAccountIsRegisteredEnabled(phoneAccountHandle, |
| 1041 | Binder.getCallingUserHandle()); |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1042 | if (isSelfManagedConnectionService(phoneAccountHandle)) { |
| 1043 | // Self-managed phone account, ensure it has MANAGE_OWN_CALLS. |
| 1044 | mContext.enforceCallingOrSelfPermission( |
| 1045 | android.Manifest.permission.MANAGE_OWN_CALLS, |
| 1046 | "Self-managed phone accounts must have MANAGE_OWN_CALLS " + |
| 1047 | "permission."); |
Tyler Gunn | 0c7cf9a | 2017-05-17 11:15:57 -0700 | [diff] [blame] | 1048 | |
| 1049 | // Self-managed ConnectionServices can ONLY add new incoming calls |
| 1050 | // using their own PhoneAccounts. The checkPackage(..) app opps |
| 1051 | // check above ensures this. |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1052 | } |
Sharvil Nanavati | 6d3efb4 | 2015-05-14 11:36:40 -0700 | [diff] [blame] | 1053 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1054 | long token = Binder.clearCallingIdentity(); |
| 1055 | try { |
| 1056 | Intent intent = new Intent(TelecomManager.ACTION_INCOMING_CALL); |
| 1057 | intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, |
| 1058 | phoneAccountHandle); |
| 1059 | intent.putExtra(CallIntentProcessor.KEY_IS_INCOMING_CALL, true); |
| 1060 | if (extras != null) { |
Jeff Sharkey | e2e4cdf | 2016-03-18 12:19:02 -0600 | [diff] [blame] | 1061 | extras.setDefusable(true); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1062 | intent.putExtra(TelecomManager.EXTRA_INCOMING_CALL_EXTRAS, extras); |
| 1063 | } |
Hall Liu | ecda554 | 2015-12-04 11:31:31 -0800 | [diff] [blame] | 1064 | mCallIntentProcessorAdapter.processIncomingCallIntent( |
| 1065 | mCallsManager, intent); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1066 | } finally { |
| 1067 | Binder.restoreCallingIdentity(token); |
| 1068 | } |
| 1069 | } else { |
| 1070 | Log.w(this, "Null phoneAccountHandle. Ignoring request to add new" + |
| 1071 | " incoming call"); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1072 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1073 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1074 | } finally { |
| 1075 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | /** |
Sanket Padawe | ccdf364 | 2017-11-10 14:49:05 -0800 | [diff] [blame] | 1080 | * @see android.telecom.TelecomManager#acceptHandover |
| 1081 | */ |
| 1082 | @Override |
| 1083 | public void acceptHandover(Uri srcAddr, int videoState, PhoneAccountHandle destAcct) { |
| 1084 | try { |
| 1085 | Log.startSession("TSI.aHO"); |
| 1086 | synchronized (mLock) { |
Tyler Gunn | 37a4dca | 2018-01-18 15:00:41 -0800 | [diff] [blame] | 1087 | Log.i(this, "acceptHandover; srcAddr=%s, videoState=%s, dest=%s", |
| 1088 | Log.pii(srcAddr), VideoProfile.videoStateToString(videoState), |
Sanket Padawe | ccdf364 | 2017-11-10 14:49:05 -0800 | [diff] [blame] | 1089 | destAcct); |
Tyler Gunn | 37a4dca | 2018-01-18 15:00:41 -0800 | [diff] [blame] | 1090 | |
Sanket Padawe | ccdf364 | 2017-11-10 14:49:05 -0800 | [diff] [blame] | 1091 | if (destAcct != null && destAcct.getComponentName() != null) { |
| 1092 | mAppOpsManager.checkPackage( |
| 1093 | Binder.getCallingUid(), |
| 1094 | destAcct.getComponentName().getPackageName()); |
| 1095 | enforceUserHandleMatchesCaller(destAcct); |
| 1096 | enforcePhoneAccountIsRegisteredEnabled(destAcct, |
| 1097 | Binder.getCallingUserHandle()); |
| 1098 | if (isSelfManagedConnectionService(destAcct)) { |
| 1099 | // Self-managed phone account, ensure it has MANAGE_OWN_CALLS. |
| 1100 | mContext.enforceCallingOrSelfPermission( |
| 1101 | android.Manifest.permission.MANAGE_OWN_CALLS, |
| 1102 | "Self-managed phone accounts must have MANAGE_OWN_CALLS " + |
| 1103 | "permission."); |
| 1104 | } |
Tyler Gunn | 37a4dca | 2018-01-18 15:00:41 -0800 | [diff] [blame] | 1105 | if (!enforceAcceptHandoverPermission( |
| 1106 | destAcct.getComponentName().getPackageName(), |
| 1107 | Binder.getCallingUid())) { |
| 1108 | throw new SecurityException("App must be granted runtime " |
| 1109 | + "ACCEPT_HANDOVER permission."); |
| 1110 | } |
Sanket Padawe | ccdf364 | 2017-11-10 14:49:05 -0800 | [diff] [blame] | 1111 | |
Tyler Gunn | 37a4dca | 2018-01-18 15:00:41 -0800 | [diff] [blame] | 1112 | long token = Binder.clearCallingIdentity(); |
| 1113 | try { |
| 1114 | mCallsManager.acceptHandover(srcAddr, videoState, destAcct); |
| 1115 | } finally { |
| 1116 | Binder.restoreCallingIdentity(token); |
| 1117 | } |
Sanket Padawe | ccdf364 | 2017-11-10 14:49:05 -0800 | [diff] [blame] | 1118 | } else { |
| 1119 | Log.w(this, "Null phoneAccountHandle. Ignoring request " + |
| 1120 | "to handover the call"); |
| 1121 | } |
| 1122 | } |
| 1123 | } finally { |
| 1124 | Log.endSession(); |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | /** |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1129 | * @see android.telecom.TelecomManager#addNewUnknownCall |
| 1130 | */ |
| 1131 | @Override |
| 1132 | public void addNewUnknownCall(PhoneAccountHandle phoneAccountHandle, Bundle extras) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1133 | try { |
| 1134 | Log.startSession("TSI.aNUC"); |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 1135 | try { |
| 1136 | enforceModifyPermission( |
| 1137 | "addNewUnknownCall requires MODIFY_PHONE_STATE permission."); |
| 1138 | } catch (SecurityException e) { |
| 1139 | EventLog.writeEvent(0x534e4554, "62347125", Binder.getCallingUid(), |
| 1140 | "addNewUnknownCall"); |
| 1141 | throw e; |
| 1142 | } |
| 1143 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1144 | synchronized (mLock) { |
| 1145 | if (phoneAccountHandle != null && |
| 1146 | phoneAccountHandle.getComponentName() != null) { |
| 1147 | mAppOpsManager.checkPackage( |
| 1148 | Binder.getCallingUid(), |
| 1149 | phoneAccountHandle.getComponentName().getPackageName()); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1150 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1151 | // Make sure it doesn't cross the UserHandle boundary |
| 1152 | enforceUserHandleMatchesCaller(phoneAccountHandle); |
Tony Mak | 5851fa0 | 2016-02-23 19:41:52 +0000 | [diff] [blame] | 1153 | enforcePhoneAccountIsRegisteredEnabled(phoneAccountHandle, |
| 1154 | Binder.getCallingUserHandle()); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1155 | long token = Binder.clearCallingIdentity(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1156 | |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1157 | try { |
| 1158 | Intent intent = new Intent(TelecomManager.ACTION_NEW_UNKNOWN_CALL); |
Jeff Sharkey | e2e4cdf | 2016-03-18 12:19:02 -0600 | [diff] [blame] | 1159 | if (extras != null) { |
| 1160 | extras.setDefusable(true); |
| 1161 | intent.putExtras(extras); |
| 1162 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1163 | intent.putExtra(CallIntentProcessor.KEY_IS_UNKNOWN_CALL, true); |
| 1164 | intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, |
| 1165 | phoneAccountHandle); |
Hall Liu | ecda554 | 2015-12-04 11:31:31 -0800 | [diff] [blame] | 1166 | mCallIntentProcessorAdapter.processUnknownCallIntent(mCallsManager, intent); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1167 | } finally { |
| 1168 | Binder.restoreCallingIdentity(token); |
| 1169 | } |
| 1170 | } else { |
| 1171 | Log.i(this, |
| 1172 | "Null phoneAccountHandle or not initiated by Telephony. " + |
| 1173 | "Ignoring request to add new unknown call."); |
Sharvil Nanavati | 6d3efb4 | 2015-05-14 11:36:40 -0700 | [diff] [blame] | 1174 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1175 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1176 | } finally { |
| 1177 | Log.endSession(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1178 | } |
| 1179 | } |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 1180 | |
| 1181 | /** |
Yorke Lee | a3a3adc | 2015-04-23 12:49:01 -0700 | [diff] [blame] | 1182 | * @see android.telecom.TelecomManager#placeCall |
| 1183 | */ |
| 1184 | @Override |
| 1185 | public void placeCall(Uri handle, Bundle extras, String callingPackage) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1186 | try { |
| 1187 | Log.startSession("TSI.pC"); |
| 1188 | enforceCallingPackage(callingPackage); |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1189 | |
| 1190 | PhoneAccountHandle phoneAccountHandle = null; |
| 1191 | if (extras != null) { |
| 1192 | phoneAccountHandle = extras.getParcelable( |
| 1193 | TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE); |
Tyler Gunn | 141ef58 | 2017-05-26 13:38:13 -0700 | [diff] [blame] | 1194 | if (extras.containsKey(TelecomManager.EXTRA_IS_HANDOVER)) { |
| 1195 | // This extra is for Telecom use only so should never be passed in. |
| 1196 | extras.remove(TelecomManager.EXTRA_IS_HANDOVER); |
| 1197 | } |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1198 | } |
| 1199 | boolean isSelfManaged = phoneAccountHandle != null && |
| 1200 | isSelfManagedConnectionService(phoneAccountHandle); |
| 1201 | if (isSelfManaged) { |
| 1202 | mContext.enforceCallingOrSelfPermission(Manifest.permission.MANAGE_OWN_CALLS, |
| 1203 | "Self-managed ConnectionServices require MANAGE_OWN_CALLS permission."); |
Tyler Gunn | 0c7cf9a | 2017-05-17 11:15:57 -0700 | [diff] [blame] | 1204 | |
| 1205 | if (!callingPackage.equals( |
| 1206 | phoneAccountHandle.getComponentName().getPackageName()) |
| 1207 | && !canCallPhone(callingPackage, |
| 1208 | "CALL_PHONE permission required to place calls.")) { |
| 1209 | // The caller is not allowed to place calls, so we want to ensure that it |
| 1210 | // can only place calls through itself. |
| 1211 | throw new SecurityException("Self-managed ConnectionServices can only " |
| 1212 | + "place calls through their own ConnectionService."); |
| 1213 | } |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1214 | } else if (!canCallPhone(callingPackage, "placeCall")) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1215 | throw new SecurityException("Package " + callingPackage |
| 1216 | + " is not allowed to place phone calls"); |
Yorke Lee | 5806175 | 2015-05-04 11:06:26 -0700 | [diff] [blame] | 1217 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1218 | |
| 1219 | // Note: we can still get here for the default/system dialer, even if the Phone |
| 1220 | // permission is turned off. This is because the default/system dialer is always |
| 1221 | // allowed to attempt to place a call (regardless of permission state), in case |
| 1222 | // it turns out to be an emergency call. If the permission is denied and the |
| 1223 | // call is being made to a non-emergency number, the call will be denied later on |
| 1224 | // by {@link UserCallIntentProcessor}. |
| 1225 | |
| 1226 | final boolean hasCallAppOp = mAppOpsManager.noteOp(AppOpsManager.OP_CALL_PHONE, |
| 1227 | Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED; |
| 1228 | |
| 1229 | final boolean hasCallPermission = mContext.checkCallingPermission(CALL_PHONE) == |
| 1230 | PackageManager.PERMISSION_GRANTED; |
Tyler Gunn | b652dad | 2018-03-27 18:49:49 +0000 | [diff] [blame] | 1231 | // The Emergency Dialer has call privileged permission and uses this to place |
| 1232 | // emergency calls. We ensure permission checks in |
| 1233 | // NewOutgoingCallIntentBroadcaster#process pass by sending this to |
| 1234 | // Telecom as an ACTION_CALL_PRIVILEGED intent (which makes sense since the |
| 1235 | // com.android.phone process has that permission). |
| 1236 | final boolean hasCallPrivilegedPermission = mContext.checkCallingPermission( |
| 1237 | CALL_PRIVILEGED) == PackageManager.PERMISSION_GRANTED; |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1238 | |
| 1239 | synchronized (mLock) { |
| 1240 | final UserHandle userHandle = Binder.getCallingUserHandle(); |
| 1241 | long token = Binder.clearCallingIdentity(); |
| 1242 | try { |
Tyler Gunn | b652dad | 2018-03-27 18:49:49 +0000 | [diff] [blame] | 1243 | final Intent intent = new Intent(hasCallPrivilegedPermission ? |
| 1244 | Intent.ACTION_CALL_PRIVILEGED : Intent.ACTION_CALL, handle); |
Jeff Sharkey | e2e4cdf | 2016-03-18 12:19:02 -0600 | [diff] [blame] | 1245 | if (extras != null) { |
| 1246 | extras.setDefusable(true); |
| 1247 | intent.putExtras(extras); |
| 1248 | } |
Hall Liu | ecda554 | 2015-12-04 11:31:31 -0800 | [diff] [blame] | 1249 | mUserCallIntentProcessorFactory.create(mContext, userHandle) |
| 1250 | .processIntent( |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1251 | intent, callingPackage, isSelfManaged || |
Tyler Gunn | b652dad | 2018-03-27 18:49:49 +0000 | [diff] [blame] | 1252 | (hasCallAppOp && hasCallPermission), |
| 1253 | true /* isLocalInvocation */); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1254 | } finally { |
| 1255 | Binder.restoreCallingIdentity(token); |
| 1256 | } |
| 1257 | } |
| 1258 | } finally { |
| 1259 | Log.endSession(); |
Yorke Lee | a3a3adc | 2015-04-23 12:49:01 -0700 | [diff] [blame] | 1260 | } |
| 1261 | } |
| 1262 | |
| 1263 | /** |
Santos Cordon | ea5cb93 | 2015-05-07 16:28:38 -0700 | [diff] [blame] | 1264 | * @see android.telecom.TelecomManager#enablePhoneAccount |
| 1265 | */ |
| 1266 | @Override |
Yorke Lee | 71734c2 | 2015-06-02 14:22:56 -0700 | [diff] [blame] | 1267 | public boolean enablePhoneAccount(PhoneAccountHandle accountHandle, boolean isEnabled) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1268 | try { |
| 1269 | Log.startSession("TSI.ePA"); |
| 1270 | enforceModifyPermission(); |
| 1271 | synchronized (mLock) { |
| 1272 | long token = Binder.clearCallingIdentity(); |
| 1273 | try { |
| 1274 | // enable/disable phone account |
| 1275 | return mPhoneAccountRegistrar.enablePhoneAccount(accountHandle, isEnabled); |
| 1276 | } finally { |
| 1277 | Binder.restoreCallingIdentity(token); |
| 1278 | } |
Yorke Lee | 71734c2 | 2015-06-02 14:22:56 -0700 | [diff] [blame] | 1279 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1280 | } finally { |
| 1281 | Log.endSession(); |
Yorke Lee | 71734c2 | 2015-06-02 14:22:56 -0700 | [diff] [blame] | 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | @Override |
| 1286 | public boolean setDefaultDialer(String packageName) { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1287 | try { |
| 1288 | Log.startSession("TSI.sDD"); |
| 1289 | enforcePermission(MODIFY_PHONE_STATE); |
| 1290 | enforcePermission(WRITE_SECURE_SETTINGS); |
| 1291 | synchronized (mLock) { |
| 1292 | long token = Binder.clearCallingIdentity(); |
| 1293 | try { |
Hall Liu | 7c92832 | 2016-12-06 18:15:39 -0800 | [diff] [blame] | 1294 | final boolean result = mDefaultDialerCache.setDefaultDialer( |
| 1295 | packageName, ActivityManager.getCurrentUser()); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1296 | if (result) { |
| 1297 | final Intent intent = |
| 1298 | new Intent(TelecomManager.ACTION_DEFAULT_DIALER_CHANGED); |
| 1299 | intent.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, |
| 1300 | packageName); |
| 1301 | mContext.sendBroadcastAsUser(intent, |
| 1302 | new UserHandle(ActivityManager.getCurrentUser())); |
| 1303 | } |
| 1304 | return result; |
| 1305 | } finally { |
| 1306 | Binder.restoreCallingIdentity(token); |
Yorke Lee | b398430 | 2015-06-15 12:06:35 -0700 | [diff] [blame] | 1307 | } |
Santos Cordon | ea5cb93 | 2015-05-07 16:28:38 -0700 | [diff] [blame] | 1308 | } |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1309 | } finally { |
| 1310 | Log.endSession(); |
Santos Cordon | ea5cb93 | 2015-05-07 16:28:38 -0700 | [diff] [blame] | 1311 | } |
| 1312 | } |
| 1313 | |
Hall Liu | ecd74a5 | 2016-01-12 15:26:36 -0800 | [diff] [blame] | 1314 | @Override |
Hall Liu | 874c0f8 | 2016-04-29 18:13:18 -0700 | [diff] [blame] | 1315 | public TelecomAnalytics dumpCallAnalytics() { |
Hall Liu | ecd74a5 | 2016-01-12 15:26:36 -0800 | [diff] [blame] | 1316 | try { |
| 1317 | Log.startSession("TSI.dCA"); |
| 1318 | enforcePermission(DUMP); |
Hall Liu | 874c0f8 | 2016-04-29 18:13:18 -0700 | [diff] [blame] | 1319 | return Analytics.dumpToParcelableAnalytics(); |
Hall Liu | ecd74a5 | 2016-01-12 15:26:36 -0800 | [diff] [blame] | 1320 | } finally { |
| 1321 | Log.endSession(); |
| 1322 | } |
| 1323 | } |
| 1324 | |
Santos Cordon | ea5cb93 | 2015-05-07 16:28:38 -0700 | [diff] [blame] | 1325 | /** |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 1326 | * Dumps the current state of the TelecomService. Used when generating problem reports. |
| 1327 | * |
| 1328 | * @param fd The file descriptor. |
| 1329 | * @param writer The print writer to dump the state to. |
| 1330 | * @param args Optional dump arguments. |
| 1331 | */ |
| 1332 | @Override |
| 1333 | protected void dump(FileDescriptor fd, final PrintWriter writer, String[] args) { |
| 1334 | if (mContext.checkCallingOrSelfPermission( |
| 1335 | android.Manifest.permission.DUMP) |
| 1336 | != PackageManager.PERMISSION_GRANTED) { |
| 1337 | writer.println("Permission Denial: can't dump TelecomService " + |
| 1338 | "from from pid=" + Binder.getCallingPid() + ", uid=" + |
| 1339 | Binder.getCallingUid()); |
| 1340 | return; |
| 1341 | } |
| 1342 | |
Hall Liu | 5bbbcf7 | 2016-08-08 17:23:20 -0700 | [diff] [blame] | 1343 | if (args.length > 0 && Analytics.ANALYTICS_DUMPSYS_ARG.equals(args[0])) { |
| 1344 | Analytics.dumpToEncodedProto(writer, args); |
| 1345 | return; |
| 1346 | } |
Tyler Gunn | 897e851 | 2017-05-18 15:46:51 -0700 | [diff] [blame] | 1347 | boolean isTimeLineView = (args.length > 0 && TIME_LINE_ARG.equalsIgnoreCase(args[0])); |
Hall Liu | 5bbbcf7 | 2016-08-08 17:23:20 -0700 | [diff] [blame] | 1348 | |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 1349 | final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " "); |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 1350 | if (mCallsManager != null) { |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 1351 | pw.println("CallsManager: "); |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 1352 | pw.increaseIndent(); |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 1353 | mCallsManager.dump(pw); |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 1354 | pw.decreaseIndent(); |
| 1355 | |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 1356 | pw.println("PhoneAccountRegistrar: "); |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 1357 | pw.increaseIndent(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1358 | mPhoneAccountRegistrar.dump(pw); |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 1359 | pw.decreaseIndent(); |
Hall Liu | 3258720 | 2015-11-18 11:10:08 -0800 | [diff] [blame] | 1360 | |
| 1361 | pw.println("Analytics:"); |
| 1362 | pw.increaseIndent(); |
| 1363 | Analytics.dump(pw); |
| 1364 | pw.decreaseIndent(); |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 1365 | } |
Tyler Gunn | 897e851 | 2017-05-18 15:46:51 -0700 | [diff] [blame] | 1366 | if (isTimeLineView) { |
| 1367 | Log.dumpEventsTimeline(pw); |
| 1368 | } else { |
| 1369 | Log.dumpEvents(pw); |
| 1370 | } |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 1371 | } |
Abhijith Shastry | 7a846f5 | 2016-02-01 16:49:27 -0800 | [diff] [blame] | 1372 | |
Mohamed | c926185 | 2016-02-05 14:10:17 -0800 | [diff] [blame] | 1373 | /** |
Abhijith Shastry | b1308ec | 2016-02-29 16:26:09 -0800 | [diff] [blame] | 1374 | * @see android.telecom.TelecomManager#createManageBlockedNumbersIntent |
| 1375 | */ |
Abhijith Shastry | ebe7bbe | 2016-02-29 11:16:30 -0800 | [diff] [blame] | 1376 | @Override |
| 1377 | public Intent createManageBlockedNumbersIntent() { |
Abhijith Shastry | b1308ec | 2016-02-29 16:26:09 -0800 | [diff] [blame] | 1378 | return BlockedNumbersActivity.getIntentForStartingActivity(); |
Abhijith Shastry | ebe7bbe | 2016-02-29 11:16:30 -0800 | [diff] [blame] | 1379 | } |
Tyler Gunn | acb3bc8 | 2017-01-09 09:43:56 -0800 | [diff] [blame] | 1380 | |
| 1381 | /** |
| 1382 | * @see android.telecom.TelecomManager#isIncomingCallPermitted(PhoneAccountHandle) |
| 1383 | */ |
| 1384 | @Override |
| 1385 | public boolean isIncomingCallPermitted(PhoneAccountHandle phoneAccountHandle) { |
| 1386 | try { |
| 1387 | Log.startSession("TSI.iICP"); |
| 1388 | enforcePermission(android.Manifest.permission.MANAGE_OWN_CALLS); |
| 1389 | synchronized (mLock) { |
| 1390 | long token = Binder.clearCallingIdentity(); |
| 1391 | try { |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1392 | return mCallsManager.isIncomingCallPermitted(phoneAccountHandle); |
Tyler Gunn | acb3bc8 | 2017-01-09 09:43:56 -0800 | [diff] [blame] | 1393 | } finally { |
| 1394 | Binder.restoreCallingIdentity(token); |
| 1395 | } |
| 1396 | } |
| 1397 | } finally { |
| 1398 | Log.endSession(); |
| 1399 | } |
Tyler Gunn | acb3bc8 | 2017-01-09 09:43:56 -0800 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | /** |
| 1403 | * @see android.telecom.TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle) |
| 1404 | */ |
| 1405 | @Override |
| 1406 | public boolean isOutgoingCallPermitted(PhoneAccountHandle phoneAccountHandle) { |
| 1407 | try { |
| 1408 | Log.startSession("TSI.iOCP"); |
| 1409 | enforcePermission(android.Manifest.permission.MANAGE_OWN_CALLS); |
| 1410 | synchronized (mLock) { |
| 1411 | long token = Binder.clearCallingIdentity(); |
| 1412 | try { |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1413 | return mCallsManager.isOutgoingCallPermitted(phoneAccountHandle); |
Tyler Gunn | acb3bc8 | 2017-01-09 09:43:56 -0800 | [diff] [blame] | 1414 | } finally { |
| 1415 | Binder.restoreCallingIdentity(token); |
| 1416 | } |
| 1417 | } |
| 1418 | } finally { |
| 1419 | Log.endSession(); |
| 1420 | } |
Tyler Gunn | acb3bc8 | 2017-01-09 09:43:56 -0800 | [diff] [blame] | 1421 | } |
Tyler Gunn | 9e806ee | 2017-02-06 20:49:24 -0800 | [diff] [blame] | 1422 | |
| 1423 | /** |
| 1424 | * Blocks until all Telecom handlers have completed their current work. |
| 1425 | * |
| 1426 | * See {@link com.android.commands.telecom.Telecom}. |
| 1427 | */ |
| 1428 | @Override |
| 1429 | public void waitOnHandlers() { |
| 1430 | try { |
| 1431 | Log.startSession("TSI.wOH"); |
| 1432 | enforceModifyPermission(); |
| 1433 | synchronized (mLock) { |
| 1434 | long token = Binder.clearCallingIdentity(); |
| 1435 | try { |
| 1436 | Log.i(this, "waitOnHandlers"); |
| 1437 | mCallsManager.waitOnHandlers(); |
| 1438 | } finally { |
| 1439 | Binder.restoreCallingIdentity(token); |
| 1440 | } |
| 1441 | } |
| 1442 | } finally { |
| 1443 | Log.endSession(); |
| 1444 | } |
| 1445 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1446 | }; |
| 1447 | |
Eugene Susla | ccba720 | 2017-02-10 10:56:53 -0800 | [diff] [blame] | 1448 | /** |
| 1449 | * @return whether to return early without doing the action/throwing |
| 1450 | * @throws SecurityException same as {@link Context#enforceCallingOrSelfPermission} |
| 1451 | */ |
| 1452 | private boolean enforceAnswerCallPermission(String packageName, int uid) { |
| 1453 | try { |
| 1454 | enforceModifyPermission(); |
| 1455 | } catch (SecurityException e) { |
| 1456 | final String permission = Manifest.permission.ANSWER_PHONE_CALLS; |
| 1457 | enforcePermission(permission); |
| 1458 | |
| 1459 | final int opCode = AppOpsManager.permissionToOpCode(permission); |
| 1460 | if (opCode != AppOpsManager.OP_NONE |
| 1461 | && mAppOpsManager.checkOp(opCode, uid, packageName) |
| 1462 | != AppOpsManager.MODE_ALLOWED) { |
| 1463 | return false; |
| 1464 | } |
| 1465 | } |
| 1466 | return true; |
| 1467 | } |
| 1468 | |
Tyler Gunn | 37a4dca | 2018-01-18 15:00:41 -0800 | [diff] [blame] | 1469 | /** |
| 1470 | * @return {@code true} if the app has the handover permission and has received runtime |
| 1471 | * permission to perform that operation, {@code false}. |
| 1472 | * @throws SecurityException same as {@link Context#enforceCallingOrSelfPermission} |
| 1473 | */ |
| 1474 | private boolean enforceAcceptHandoverPermission(String packageName, int uid) { |
| 1475 | mContext.enforceCallingOrSelfPermission(Manifest.permission.ACCEPT_HANDOVER, |
| 1476 | "App requires ACCEPT_HANDOVER permission to accept handovers."); |
| 1477 | |
| 1478 | final int opCode = AppOpsManager.permissionToOpCode(Manifest.permission.ACCEPT_HANDOVER); |
| 1479 | if (opCode != AppOpsManager.OP_ACCEPT_HANDOVER || ( |
| 1480 | mAppOpsManager.checkOp(opCode, uid, packageName) |
| 1481 | != AppOpsManager.MODE_ALLOWED)) { |
| 1482 | return false; |
| 1483 | } |
| 1484 | return true; |
| 1485 | } |
| 1486 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1487 | private Context mContext; |
| 1488 | private AppOpsManager mAppOpsManager; |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1489 | private PackageManager mPackageManager; |
| 1490 | private CallsManager mCallsManager; |
| 1491 | private final PhoneAccountRegistrar mPhoneAccountRegistrar; |
Hall Liu | ecda554 | 2015-12-04 11:31:31 -0800 | [diff] [blame] | 1492 | private final CallIntentProcessor.Adapter mCallIntentProcessorAdapter; |
| 1493 | private final UserCallIntentProcessorFactory mUserCallIntentProcessorFactory; |
Hall Liu | 7c92832 | 2016-12-06 18:15:39 -0800 | [diff] [blame] | 1494 | private final DefaultDialerCache mDefaultDialerCache; |
Hall Liu | 0a6dd30 | 2015-12-16 15:06:49 -0800 | [diff] [blame] | 1495 | private final SubscriptionManagerAdapter mSubscriptionManagerAdapter; |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1496 | private final TelecomSystem.SyncRoot mLock; |
| 1497 | |
| 1498 | public TelecomServiceImpl( |
| 1499 | Context context, |
| 1500 | CallsManager callsManager, |
| 1501 | PhoneAccountRegistrar phoneAccountRegistrar, |
Hall Liu | ecda554 | 2015-12-04 11:31:31 -0800 | [diff] [blame] | 1502 | CallIntentProcessor.Adapter callIntentProcessorAdapter, |
| 1503 | UserCallIntentProcessorFactory userCallIntentProcessorFactory, |
Hall Liu | 7c92832 | 2016-12-06 18:15:39 -0800 | [diff] [blame] | 1504 | DefaultDialerCache defaultDialerCache, |
Hall Liu | 0a6dd30 | 2015-12-16 15:06:49 -0800 | [diff] [blame] | 1505 | SubscriptionManagerAdapter subscriptionManagerAdapter, |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1506 | TelecomSystem.SyncRoot lock) { |
| 1507 | mContext = context; |
| 1508 | mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE); |
| 1509 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1510 | mPackageManager = mContext.getPackageManager(); |
| 1511 | |
| 1512 | mCallsManager = callsManager; |
| 1513 | mLock = lock; |
| 1514 | mPhoneAccountRegistrar = phoneAccountRegistrar; |
Hall Liu | ecda554 | 2015-12-04 11:31:31 -0800 | [diff] [blame] | 1515 | mUserCallIntentProcessorFactory = userCallIntentProcessorFactory; |
Hall Liu | 7c92832 | 2016-12-06 18:15:39 -0800 | [diff] [blame] | 1516 | mDefaultDialerCache = defaultDialerCache; |
Hall Liu | ecda554 | 2015-12-04 11:31:31 -0800 | [diff] [blame] | 1517 | mCallIntentProcessorAdapter = callIntentProcessorAdapter; |
Hall Liu | 0a6dd30 | 2015-12-16 15:06:49 -0800 | [diff] [blame] | 1518 | mSubscriptionManagerAdapter = subscriptionManagerAdapter; |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 1521 | public ITelecomService.Stub getBinder() { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1522 | return mBinderImpl; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | // |
| 1526 | // Supporting methods for the ITelecomService interface implementation. |
| 1527 | // |
| 1528 | |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 1529 | private boolean isPhoneAccountHandleVisibleToCallingUser( |
| 1530 | PhoneAccountHandle phoneAccountUserHandle, UserHandle callingUser) { |
| 1531 | return mPhoneAccountRegistrar.getPhoneAccount(phoneAccountUserHandle, callingUser) != null; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | private boolean isCallerSystemApp() { |
| 1535 | int uid = Binder.getCallingUid(); |
| 1536 | String[] packages = mPackageManager.getPackagesForUid(uid); |
| 1537 | for (String packageName : packages) { |
| 1538 | if (isPackageSystemApp(packageName)) { |
| 1539 | return true; |
| 1540 | } |
| 1541 | } |
| 1542 | return false; |
| 1543 | } |
| 1544 | |
| 1545 | private boolean isPackageSystemApp(String packageName) { |
| 1546 | try { |
| 1547 | ApplicationInfo applicationInfo = mPackageManager.getApplicationInfo(packageName, |
| 1548 | PackageManager.GET_META_DATA); |
| 1549 | if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 1550 | return true; |
| 1551 | } |
| 1552 | } catch (PackageManager.NameNotFoundException e) { |
| 1553 | } |
| 1554 | return false; |
| 1555 | } |
| 1556 | |
Tyler Gunn | 42ef808 | 2015-11-24 15:34:34 -0800 | [diff] [blame] | 1557 | private void acceptRingingCallInternal(int videoState) { |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 1558 | Call call = mCallsManager.getFirstCallWithState(CallState.RINGING); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1559 | if (call != null) { |
Tyler Gunn | 42ef808 | 2015-11-24 15:34:34 -0800 | [diff] [blame] | 1560 | if (videoState == DEFAULT_VIDEO_STATE || !isValidAcceptVideoState(videoState)) { |
| 1561 | videoState = call.getVideoState(); |
| 1562 | } |
| 1563 | call.answer(videoState); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1564 | } |
| 1565 | } |
| 1566 | |
Tyler Gunn | 587fc27 | 2018-02-07 16:07:29 -0800 | [diff] [blame] | 1567 | private boolean endCallInternal(String callingPackage) { |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1568 | // Always operate on the foreground call if one exists, otherwise get the first call in |
| 1569 | // priority order by call-state. |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 1570 | Call call = mCallsManager.getForegroundCall(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1571 | if (call == null) { |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 1572 | call = mCallsManager.getFirstCallWithState( |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1573 | CallState.ACTIVE, |
| 1574 | CallState.DIALING, |
Tyler Gunn | 1e37be5 | 2016-07-11 08:54:23 -0700 | [diff] [blame] | 1575 | CallState.PULLING, |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1576 | CallState.RINGING, |
| 1577 | CallState.ON_HOLD); |
| 1578 | } |
| 1579 | |
| 1580 | if (call != null) { |
| 1581 | if (call.getState() == CallState.RINGING) { |
Tyler Gunn | 587fc27 | 2018-02-07 16:07:29 -0800 | [diff] [blame] | 1582 | call.reject(false /* rejectWithMessage */, null, callingPackage); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1583 | } else { |
Tyler Gunn | 587fc27 | 2018-02-07 16:07:29 -0800 | [diff] [blame] | 1584 | call.disconnect(0 /* disconnectionTimeout */, callingPackage); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1585 | } |
| 1586 | return true; |
| 1587 | } |
| 1588 | |
| 1589 | return false; |
| 1590 | } |
| 1591 | |
Brad Ebinger | 62da8e1 | 2016-01-28 19:16:08 -0800 | [diff] [blame] | 1592 | // Enforce that the PhoneAccountHandle being passed in is both registered to the current user |
| 1593 | // and enabled. |
Tony Mak | 5851fa0 | 2016-02-23 19:41:52 +0000 | [diff] [blame] | 1594 | private void enforcePhoneAccountIsRegisteredEnabled(PhoneAccountHandle phoneAccountHandle, |
| 1595 | UserHandle callingUserHandle) { |
| 1596 | PhoneAccount phoneAccount = mPhoneAccountRegistrar.getPhoneAccount(phoneAccountHandle, |
| 1597 | callingUserHandle); |
Brad Ebinger | 62da8e1 | 2016-01-28 19:16:08 -0800 | [diff] [blame] | 1598 | if(phoneAccount == null) { |
| 1599 | EventLog.writeEvent(0x534e4554, "26864502", Binder.getCallingUid(), "R"); |
| 1600 | throw new SecurityException("This PhoneAccountHandle is not registered for this user!"); |
| 1601 | } |
| 1602 | if(!phoneAccount.isEnabled()) { |
| 1603 | EventLog.writeEvent(0x534e4554, "26864502", Binder.getCallingUid(), "E"); |
| 1604 | throw new SecurityException("This PhoneAccountHandle is not enabled for this user!"); |
| 1605 | } |
| 1606 | } |
| 1607 | |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1608 | private void enforcePhoneAccountModificationForPackage(String packageName) { |
| 1609 | // TODO: Use a new telecomm permission for this instead of reusing modify. |
| 1610 | |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1611 | int result = mContext.checkCallingOrSelfPermission(MODIFY_PHONE_STATE); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1612 | |
| 1613 | // Callers with MODIFY_PHONE_STATE can use the PhoneAccount mechanism to implement |
| 1614 | // built-in behavior even when PhoneAccounts are not exposed as a third-part API. They |
| 1615 | // may also modify PhoneAccounts on behalf of any 'packageName'. |
| 1616 | |
| 1617 | if (result != PackageManager.PERMISSION_GRANTED) { |
| 1618 | // Other callers are only allowed to modify PhoneAccounts if the relevant system |
| 1619 | // feature is enabled ... |
| 1620 | enforceConnectionServiceFeature(); |
| 1621 | // ... and the PhoneAccounts they refer to are for their own package. |
| 1622 | enforceCallingPackage(packageName); |
| 1623 | } |
| 1624 | } |
| 1625 | |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1626 | private void enforcePermissionOrPrivilegedDialer(String permission, String packageName) { |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 1627 | if (!isPrivilegedDialerCalling(packageName)) { |
| 1628 | try { |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1629 | enforcePermission(permission); |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 1630 | } catch (SecurityException e) { |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1631 | Log.e(this, e, "Caller must be the default or system dialer, or have the permission" |
| 1632 | + " %s to perform this operation.", permission); |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 1633 | throw e; |
| 1634 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1635 | } |
| 1636 | } |
| 1637 | |
| 1638 | private void enforceCallingPackage(String packageName) { |
| 1639 | mAppOpsManager.checkPackage(Binder.getCallingUid(), packageName); |
| 1640 | } |
| 1641 | |
| 1642 | private void enforceConnectionServiceFeature() { |
| 1643 | enforceFeature(PackageManager.FEATURE_CONNECTION_SERVICE); |
| 1644 | } |
| 1645 | |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1646 | private void enforceRegisterSimSubscriptionPermission() { |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1647 | enforcePermission(REGISTER_SIM_SUBSCRIPTION); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1648 | } |
| 1649 | |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1650 | private void enforceModifyPermission() { |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1651 | enforcePermission(MODIFY_PHONE_STATE); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1652 | } |
| 1653 | |
Tyler Gunn | 322480c | 2017-07-17 15:34:02 -0700 | [diff] [blame] | 1654 | private void enforceModifyPermission(String message) { |
| 1655 | mContext.enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, message); |
| 1656 | } |
| 1657 | |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1658 | private void enforcePermission(String permission) { |
| 1659 | mContext.enforceCallingOrSelfPermission(permission, null); |
| 1660 | } |
| 1661 | |
Tyler Gunn | acb3bc8 | 2017-01-09 09:43:56 -0800 | [diff] [blame] | 1662 | private void enforceRegisterSelfManaged() { |
| 1663 | mContext.enforceCallingPermission(android.Manifest.permission.MANAGE_OWN_CALLS, null); |
| 1664 | } |
| 1665 | |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1666 | private void enforceRegisterMultiUser() { |
| 1667 | if (!isCallerSystemApp()) { |
| 1668 | throw new SecurityException("CAPABILITY_MULTI_USER is only available to system apps."); |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | private void enforceUserHandleMatchesCaller(PhoneAccountHandle accountHandle) { |
| 1673 | if (!Binder.getCallingUserHandle().equals(accountHandle.getUserHandle())) { |
| 1674 | throw new SecurityException("Calling UserHandle does not match PhoneAccountHandle's"); |
| 1675 | } |
| 1676 | } |
| 1677 | |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 1678 | private void enforceCrossUserPermission(int callingUid) { |
| 1679 | if (callingUid != Process.SYSTEM_UID && callingUid != 0) { |
| 1680 | mContext.enforceCallingOrSelfPermission( |
| 1681 | android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, "Must be system or have" |
| 1682 | + " INTERACT_ACROSS_USERS_FULL permission"); |
| 1683 | } |
| 1684 | } |
| 1685 | |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1686 | private void enforceFeature(String feature) { |
| 1687 | PackageManager pm = mContext.getPackageManager(); |
| 1688 | if (!pm.hasSystemFeature(feature)) { |
| 1689 | throw new UnsupportedOperationException( |
| 1690 | "System does not support feature " + feature); |
| 1691 | } |
| 1692 | } |
| 1693 | |
Svet Ganov | 38f1a4d | 2015-04-17 15:28:03 -0700 | [diff] [blame] | 1694 | private boolean canReadPhoneState(String callingPackage, String message) { |
Yorke Lee | 57138a6 | 2015-05-18 18:18:08 -0700 | [diff] [blame] | 1695 | // The system/default dialer can always read phone state - so that emergency calls will |
| 1696 | // still work. |
| 1697 | if (isPrivilegedDialerCalling(callingPackage)) { |
| 1698 | return true; |
| 1699 | } |
| 1700 | |
Amit Mahajan | 3c29693 | 2015-07-14 10:23:15 -0700 | [diff] [blame] | 1701 | try { |
Amit Mahajan | 86b8e33 | 2015-07-30 16:02:52 -0700 | [diff] [blame] | 1702 | mContext.enforceCallingOrSelfPermission(READ_PRIVILEGED_PHONE_STATE, message); |
| 1703 | // SKIP checking run-time OP_READ_PHONE_STATE since caller or self has PRIVILEGED |
| 1704 | // permission |
Amit Mahajan | 3c29693 | 2015-07-14 10:23:15 -0700 | [diff] [blame] | 1705 | return true; |
| 1706 | } catch (SecurityException e) { |
| 1707 | // Accessing phone state is gated by a special permission. |
| 1708 | mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, message); |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 1709 | |
Amit Mahajan | 3c29693 | 2015-07-14 10:23:15 -0700 | [diff] [blame] | 1710 | // Some apps that have the permission can be restricted via app ops. |
| 1711 | return mAppOpsManager.noteOp(AppOpsManager.OP_READ_PHONE_STATE, |
| 1712 | Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED; |
| 1713 | } |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1716 | private boolean isSelfManagedConnectionService(PhoneAccountHandle phoneAccountHandle) { |
| 1717 | if (phoneAccountHandle != null) { |
| 1718 | PhoneAccount phoneAccount = mPhoneAccountRegistrar.getPhoneAccountUnchecked( |
| 1719 | phoneAccountHandle); |
Tyler Gunn | 9e806ee | 2017-02-06 20:49:24 -0800 | [diff] [blame] | 1720 | return phoneAccount != null && phoneAccount.isSelfManaged(); |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1721 | } |
| 1722 | return false; |
| 1723 | } |
| 1724 | |
Yorke Lee | a3a3adc | 2015-04-23 12:49:01 -0700 | [diff] [blame] | 1725 | private boolean canCallPhone(String callingPackage, String message) { |
Yorke Lee | 57138a6 | 2015-05-18 18:18:08 -0700 | [diff] [blame] | 1726 | // The system/default dialer can always read phone state - so that emergency calls will |
| 1727 | // still work. |
| 1728 | if (isPrivilegedDialerCalling(callingPackage)) { |
| 1729 | return true; |
| 1730 | } |
| 1731 | |
Yorke Lee | a3a3adc | 2015-04-23 12:49:01 -0700 | [diff] [blame] | 1732 | // Accessing phone state is gated by a special permission. |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1733 | mContext.enforceCallingOrSelfPermission(CALL_PHONE, message); |
Yorke Lee | a3a3adc | 2015-04-23 12:49:01 -0700 | [diff] [blame] | 1734 | |
| 1735 | // Some apps that have the permission can be restricted via app ops. |
| 1736 | return mAppOpsManager.noteOp(AppOpsManager.OP_CALL_PHONE, |
| 1737 | Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED; |
| 1738 | } |
| 1739 | |
Sailesh Nepal | 2a98c97 | 2015-03-04 15:43:15 -0800 | [diff] [blame] | 1740 | private boolean isCallerSimCallManager() { |
Yorke Lee | 9427c0f | 2015-06-27 11:01:58 -0700 | [diff] [blame] | 1741 | long token = Binder.clearCallingIdentity(); |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 1742 | PhoneAccountHandle accountHandle = null; |
Yorke Lee | 9427c0f | 2015-06-27 11:01:58 -0700 | [diff] [blame] | 1743 | try { |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 1744 | accountHandle = mPhoneAccountRegistrar.getSimCallManagerOfCurrentUser(); |
Yorke Lee | 9427c0f | 2015-06-27 11:01:58 -0700 | [diff] [blame] | 1745 | } finally { |
| 1746 | Binder.restoreCallingIdentity(token); |
| 1747 | } |
| 1748 | |
Sailesh Nepal | 2a98c97 | 2015-03-04 15:43:15 -0800 | [diff] [blame] | 1749 | if (accountHandle != null) { |
| 1750 | try { |
| 1751 | mAppOpsManager.checkPackage( |
| 1752 | Binder.getCallingUid(), accountHandle.getComponentName().getPackageName()); |
| 1753 | return true; |
| 1754 | } catch (SecurityException e) { |
| 1755 | } |
| 1756 | } |
| 1757 | return false; |
| 1758 | } |
| 1759 | |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 1760 | private boolean isPrivilegedDialerCalling(String callingPackage) { |
| 1761 | mAppOpsManager.checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | 7c92832 | 2016-12-06 18:15:39 -0800 | [diff] [blame] | 1762 | return mDefaultDialerCache.isDefaultOrSystemDialer( |
| 1763 | callingPackage, Binder.getCallingUserHandle().getIdentifier()); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | private TelephonyManager getTelephonyManager() { |
Hall Liu | ecda554 | 2015-12-04 11:31:31 -0800 | [diff] [blame] | 1767 | return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1768 | } |
Tyler Gunn | 42ef808 | 2015-11-24 15:34:34 -0800 | [diff] [blame] | 1769 | |
| 1770 | /** |
| 1771 | * Determines if a video state is valid for accepting an incoming call. |
| 1772 | * For the purpose of accepting a call, states {@link VideoProfile#STATE_AUDIO_ONLY}, and |
| 1773 | * any combination of {@link VideoProfile#STATE_RX_ENABLED} and |
| 1774 | * {@link VideoProfile#STATE_TX_ENABLED} are considered valid. |
| 1775 | * |
| 1776 | * @param videoState The video state. |
| 1777 | * @return {@code true} if the video state is valid, {@code false} otherwise. |
| 1778 | */ |
| 1779 | private boolean isValidAcceptVideoState(int videoState) { |
| 1780 | // Given a video state input, turn off TX and RX so that we can determine if those were the |
| 1781 | // only bits set. |
| 1782 | int remainingState = videoState & ~VideoProfile.STATE_TX_ENABLED; |
| 1783 | remainingState = remainingState & ~VideoProfile.STATE_RX_ENABLED; |
| 1784 | |
| 1785 | // If only TX or RX were set (or neither), the video state is valid. |
| 1786 | return remainingState == 0; |
| 1787 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1788 | } |