1 /* 2 * Copyright (C) 2023 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 android.telecom.cts.cuj; 18 19 import static android.telecom.cts.apps.AttributesUtil.getExtrasWithPhoneAccount; 20 import static android.telecom.cts.apps.AttributesUtil.isOutgoing; 21 import static android.telecom.cts.apps.TelecomTestApp.MANAGED_ADDRESS; 22 import static android.telecom.cts.apps.TelecomTestApp.MANAGED_APP_CLONE_LABEL; 23 import static android.telecom.cts.apps.TelecomTestApp.MANAGED_APP_CN; 24 import static android.telecom.cts.apps.TelecomTestApp.MANAGED_APP_ID; 25 import static android.telecom.cts.apps.TelecomTestApp.MANAGED_APP_LABEL; 26 import static android.telecom.cts.apps.TelecomTestApp.MANAGED_CLONE_ADDRESS; 27 import static android.telecom.cts.apps.TelecomTestApp.MANAGED_CLONE_APP_CN; 28 import static android.telecom.cts.apps.TelecomTestApp.MANAGED_CLONE_APP_ID; 29 30 import static junit.framework.Assert.assertNotNull; 31 32 import android.content.Context; 33 import android.graphics.Color; 34 import android.net.Uri; 35 import android.os.RemoteException; 36 import android.platform.test.flag.junit.CheckFlagsRule; 37 import android.platform.test.flag.junit.DeviceFlagsValueProvider; 38 import android.telecom.Call; 39 import android.telecom.CallAttributes; 40 import android.telecom.CallEndpoint; 41 import android.telecom.CallException; 42 import android.telecom.PhoneAccount; 43 import android.telecom.PhoneAccountHandle; 44 import android.telecom.TelecomManager; 45 import android.telecom.cts.apps.AppControlWrapper; 46 import android.telecom.cts.apps.BaseAppVerifierImpl; 47 import android.telecom.cts.apps.CallStateTransitionOperation; 48 import android.telecom.cts.apps.InCallServiceMethods; 49 import android.telecom.cts.apps.TelecomTestApp; 50 51 import androidx.test.platform.app.InstrumentationRegistry; 52 53 import org.junit.After; 54 import org.junit.Before; 55 import org.junit.Rule; 56 57 import java.util.Arrays; 58 import java.util.HashMap; 59 import java.util.List; 60 import java.util.Map; 61 import java.util.Set; 62 import java.util.function.Consumer; 63 64 /** 65 * BaseAppVerifier should be extended by any test class that wants to bind to the test apps in the 66 * cts/tests/tests/telecomApps directory. 67 */ 68 public class BaseAppVerifier { 69 @Rule 70 public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule(); 71 public static final boolean S_IS_TEST_DISABLED = true; 72 public boolean mShouldTestTelecom = true; 73 public boolean mSupportsManagedCalls = false; 74 private BaseAppVerifierImpl mBaseAppVerifierImpl; 75 private TelecomManager mTelecomManager; 76 protected Context mContext = null; 77 /*********************************************************** 78 / ManagedConnectionServiceApp/ ManagedConnectionServiceAppClone - The PhoneAccountHandle and 79 / PhoneAccount must reside in the CTS test process. 80 /***********************************************************/ 81 public static final PhoneAccountHandle MANAGED_HANDLE_1 = 82 new PhoneAccountHandle(MANAGED_APP_CN, MANAGED_APP_ID); 83 84 private static final PhoneAccount MANAGED_DEFAULT_ACCOUNT_1 = 85 PhoneAccount.builder(MANAGED_HANDLE_1, MANAGED_APP_LABEL) 86 .setAddress(Uri.parse(MANAGED_ADDRESS)) 87 .setSubscriptionAddress(Uri.parse(MANAGED_ADDRESS)) 88 .setCapabilities( 89 PhoneAccount.CAPABILITY_VIDEO_CALLING 90 /* needed in order to be default sub */ 91 | PhoneAccount.CAPABILITY_CALL_PROVIDER 92 /* needed to place ECC */ 93 | PhoneAccount.CAPABILITY_PLACE_EMERGENCY_CALLS) 94 .setHighlightColor(Color.RED) 95 .addSupportedUriScheme(PhoneAccount.SCHEME_SIP) 96 .addSupportedUriScheme(PhoneAccount.SCHEME_TEL) 97 .addSupportedUriScheme(PhoneAccount.SCHEME_VOICEMAIL) 98 .build(); 99 100 public static final PhoneAccountHandle MANAGED_HANDLE_2 = 101 new PhoneAccountHandle(MANAGED_APP_CN, MANAGED_APP_ID + "_2"); 102 private static final PhoneAccount MANAGED_DEFAULT_ACCOUNT_2 = 103 PhoneAccount.builder(MANAGED_HANDLE_2, MANAGED_APP_LABEL) 104 .setAddress(Uri.parse(MANAGED_ADDRESS + "_2")) 105 .setSubscriptionAddress(Uri.parse(MANAGED_ADDRESS + "_2")) 106 .setCapabilities( 107 PhoneAccount.CAPABILITY_VIDEO_CALLING 108 /* needed in order to be default sub */ 109 | PhoneAccount.CAPABILITY_CALL_PROVIDER 110 /* needed to place ECC */ 111 | PhoneAccount.CAPABILITY_PLACE_EMERGENCY_CALLS) 112 .setHighlightColor(Color.RED) 113 .addSupportedUriScheme(PhoneAccount.SCHEME_TEL) 114 .build(); 115 116 public static final PhoneAccountHandle MANAGED_CLONE_HANDLE_1 = 117 new PhoneAccountHandle(MANAGED_CLONE_APP_CN, MANAGED_CLONE_APP_ID); 118 private static final PhoneAccount MANAGED_CLONE_DEFAULT_ACCOUNT_1 = 119 PhoneAccount.builder(MANAGED_CLONE_HANDLE_1, MANAGED_APP_CLONE_LABEL) 120 .setAddress(Uri.parse(MANAGED_CLONE_ADDRESS)) 121 .setSubscriptionAddress(Uri.parse(MANAGED_CLONE_ADDRESS)) 122 .setCapabilities( 123 PhoneAccount.CAPABILITY_VIDEO_CALLING 124 /* needed in order to be default sub */ 125 | PhoneAccount.CAPABILITY_CALL_PROVIDER 126 /* needed to place ECC */ 127 | PhoneAccount.CAPABILITY_PLACE_EMERGENCY_CALLS) 128 .setHighlightColor(Color.RED) 129 .addSupportedUriScheme(PhoneAccount.SCHEME_SIP) 130 .addSupportedUriScheme(PhoneAccount.SCHEME_TEL) 131 .addSupportedUriScheme(PhoneAccount.SCHEME_VOICEMAIL) 132 .build(); 133 134 private static final Map<PhoneAccountHandle, PhoneAccount> MANAGED_PHONE_ACCOUNTS = 135 new HashMap<>(); 136 static { MANAGED_PHONE_ACCOUNTS.put(MANAGED_HANDLE_1, MANAGED_DEFAULT_ACCOUNT_1)137 MANAGED_PHONE_ACCOUNTS.put(MANAGED_HANDLE_1, MANAGED_DEFAULT_ACCOUNT_1); MANAGED_PHONE_ACCOUNTS.put(MANAGED_HANDLE_2, MANAGED_DEFAULT_ACCOUNT_2)138 MANAGED_PHONE_ACCOUNTS.put(MANAGED_HANDLE_2, MANAGED_DEFAULT_ACCOUNT_2); 139 } 140 141 /*********************************************************** 142 / setUp and tearDown methods 143 /***********************************************************/ 144 @Before setUp()145 public void setUp() throws Exception { 146 mContext = InstrumentationRegistry.getInstrumentation().getContext(); 147 mShouldTestTelecom = BaseAppVerifierImpl.shouldTestTelecom(mContext); 148 mSupportsManagedCalls = TestUtils.hasDialerRole(mContext) 149 && TestUtils.hasTelephonyFeature(mContext); 150 if (!mShouldTestTelecom) { 151 return; 152 } 153 mBaseAppVerifierImpl = new BaseAppVerifierImpl( 154 InstrumentationRegistry.getInstrumentation(), 155 Arrays.asList(MANAGED_DEFAULT_ACCOUNT_1, MANAGED_DEFAULT_ACCOUNT_2), 156 Arrays.asList(MANAGED_CLONE_DEFAULT_ACCOUNT_1), 157 new InCallServiceMethods() { 158 159 @Override 160 public boolean isBound() { 161 return CujInCallService.isServiceBound(); 162 } 163 164 @Override 165 public List<Call> getOngoingCalls() { 166 return CujInCallService.getOngoingCalls(); 167 } 168 169 @Override 170 public Call getLastAddedCall() { 171 return CujInCallService.getLastAddedCall(); 172 } 173 174 @Override 175 public int getCurrentCallCount() { 176 return CujInCallService.getCurrentCallCount(); 177 } 178 }); 179 mBaseAppVerifierImpl.setUp(); 180 mTelecomManager = mContext.getSystemService(TelecomManager.class); 181 } 182 183 @After tearDown()184 public void tearDown() throws Exception { 185 if (!mShouldTestTelecom || mBaseAppVerifierImpl == null) { 186 return; 187 } 188 mBaseAppVerifierImpl.tearDown(); 189 } 190 191 /*********************************************************** 192 / setUp and tearDown methods 193 /***********************************************************/ 194 195 /** 196 * This method will check TelecomManager#isInCall to determine if there is an ongoing call at 197 * the test start. If there is a call, the Telecom command to disconnect all ongoing calls will 198 * run and attempt to put the test class in a good state. Also, the method will log any bound 199 * test apps. 200 */ maybeCleanupTelecom()201 public void maybeCleanupTelecom() { 202 mBaseAppVerifierImpl.maybeCleanupTelecom(); 203 } 204 bindToApp(TelecomTestApp applicationName)205 public AppControlWrapper bindToApp(TelecomTestApp applicationName) throws Exception { 206 return mBaseAppVerifierImpl.bindToApp(applicationName); 207 } 208 bindToApps(List<TelecomTestApp> applicationNames)209 public List<AppControlWrapper> bindToApps(List<TelecomTestApp> applicationNames) 210 throws Exception { 211 return mBaseAppVerifierImpl.bindToApps(applicationNames); 212 } 213 tearDownApp(AppControlWrapper appControl)214 public void tearDownApp(AppControlWrapper appControl) { 215 mBaseAppVerifierImpl.tearDownApp(appControl); 216 } 217 tearDownApps(List<AppControlWrapper> appControls)218 public void tearDownApps(List<AppControlWrapper> appControls) { 219 mBaseAppVerifierImpl.tearDownApps(appControls); 220 } 221 getDefaultAttributes(TelecomTestApp name, boolean isOutgoing)222 public CallAttributes getDefaultAttributes(TelecomTestApp name, boolean isOutgoing) 223 throws Exception { 224 return mBaseAppVerifierImpl.getDefaultAttributes(name, isOutgoing); 225 } 226 getDefaultAttributes(TelecomTestApp name, PhoneAccountHandle pAH, boolean isOutgoing)227 public CallAttributes getDefaultAttributes(TelecomTestApp name, PhoneAccountHandle pAH, 228 boolean isOutgoing) 229 throws Exception { 230 return mBaseAppVerifierImpl.getDefaultAttributes(name, pAH, isOutgoing); 231 } 232 getDefaultMmiAttributes(TelecomTestApp name, boolean inCallMmi)233 public CallAttributes getDefaultMmiAttributes(TelecomTestApp name, boolean inCallMmi) 234 throws Exception { 235 return mBaseAppVerifierImpl.getDefaultMmiAttributes(name, inCallMmi); 236 } 237 getRandomAttributes( TelecomTestApp name, boolean isOutgoing, boolean isHoldable)238 public CallAttributes getRandomAttributes( 239 TelecomTestApp name, boolean isOutgoing, boolean isHoldable) throws Exception { 240 return mBaseAppVerifierImpl.getRandomAttributes(name, isOutgoing, isHoldable); 241 } 242 addOutgoingCallAndVerify(AppControlWrapper appControl)243 public String addOutgoingCallAndVerify(AppControlWrapper appControl) 244 throws Exception { 245 CallAttributes outgoingAttributes = mBaseAppVerifierImpl.getRandomAttributes( 246 appControl.getTelecomApps(), 247 true /*isOutgoing*/, 248 true /* isHoldable */); 249 return mBaseAppVerifierImpl.addCallAndVerify(appControl, outgoingAttributes); 250 } 251 addEmergencyCallAndVerify( AppControlWrapper appControl, Consumer<CallStateTransitionOperation> consumer, int numDisconnectDueToEcc)252 public String addEmergencyCallAndVerify( 253 AppControlWrapper appControl, 254 Consumer<CallStateTransitionOperation> consumer, 255 int numDisconnectDueToEcc) 256 throws Exception { 257 CallAttributes emergencyCallAttrs = 258 mBaseAppVerifierImpl.getDefaultAttributesForEmergency(appControl.getTelecomApps()); 259 // ECC has to be placed in the same package as the system dialer (CujInCallService). 260 if (isOutgoing(emergencyCallAttrs)) { 261 mTelecomManager.placeCall( 262 emergencyCallAttrs.getAddress(), getExtrasWithPhoneAccount(emergencyCallAttrs)); 263 } else { 264 mTelecomManager.addNewIncomingCall( 265 emergencyCallAttrs.getPhoneAccountHandle(), 266 getExtrasWithPhoneAccount(emergencyCallAttrs)); 267 } 268 return mBaseAppVerifierImpl.verifyAddEmergencyCall( 269 appControl, emergencyCallAttrs, consumer, numDisconnectDueToEcc); 270 } 271 addIncomingCallAndVerify(AppControlWrapper appControl)272 public String addIncomingCallAndVerify(AppControlWrapper appControl) 273 throws Exception { 274 CallAttributes incomingAttributes = mBaseAppVerifierImpl.getRandomAttributes( 275 appControl.getTelecomApps(), 276 false /*isOutgoing*/, 277 true /* isHoldable */); 278 return mBaseAppVerifierImpl.addCallAndVerify(appControl, incomingAttributes); 279 } 280 addOutgoingCallAndVerify(AppControlWrapper appControl, boolean isHoldable)281 public String addOutgoingCallAndVerify(AppControlWrapper appControl, boolean isHoldable) 282 throws Exception { 283 CallAttributes outgoingAttributes = mBaseAppVerifierImpl.getRandomAttributes( 284 appControl.getTelecomApps(), 285 true /*isOutgoing*/, 286 isHoldable /* isHoldable */); 287 return mBaseAppVerifierImpl.addCallAndVerify(appControl, outgoingAttributes); 288 } 289 addIncomingCallAndVerify(AppControlWrapper appControl, boolean isHoldable)290 public String addIncomingCallAndVerify(AppControlWrapper appControl, boolean isHoldable) 291 throws Exception { 292 CallAttributes incomingAttributes = mBaseAppVerifierImpl.getRandomAttributes( 293 appControl.getTelecomApps(), 294 false /*isOutgoing*/, 295 isHoldable /* isHoldable */); 296 return mBaseAppVerifierImpl.addCallAndVerify(appControl, incomingAttributes); 297 } 298 addCallAndVerify(AppControlWrapper appControl, CallAttributes attributes)299 public String addCallAndVerify(AppControlWrapper appControl, CallAttributes attributes) 300 throws Exception { 301 return mBaseAppVerifierImpl.addCallAndVerify(appControl, attributes); 302 } 303 addCallAndVerify(AppControlWrapper appControl, CallAttributes attributes, Consumer<CallStateTransitionOperation> consumer)304 public String addCallAndVerify(AppControlWrapper appControl, CallAttributes attributes, 305 Consumer<CallStateTransitionOperation> consumer) 306 throws Exception { 307 return mBaseAppVerifierImpl.addCallAndVerify(appControl, attributes, consumer); 308 } 309 addCallAndVerifyNewCall(AppControlWrapper appControl, CallAttributes attributes, String idToExclude, Consumer<CallStateTransitionOperation> consumer )310 public String addCallAndVerifyNewCall(AppControlWrapper appControl, CallAttributes attributes, 311 String idToExclude, Consumer<CallStateTransitionOperation> consumer 312 ) throws Exception { 313 return mBaseAppVerifierImpl.addAndGetNewCall(appControl, attributes, idToExclude, consumer); 314 } 315 addOutgoingCallAndVerifyFailure(AppControlWrapper appControl)316 public void addOutgoingCallAndVerifyFailure(AppControlWrapper appControl) throws Exception { 317 CallAttributes outgoingAttributes = 318 mBaseAppVerifierImpl.getRandomAttributes( 319 appControl.getTelecomApps(), true /*isOutgoing*/, true /* isHoldable */); 320 mBaseAppVerifierImpl.addCallAndVerifyFailure(appControl, outgoingAttributes); 321 } 322 addOutgoingCallAndVerifyFailure( AppControlWrapper appControl, CallAttributes attributes)323 public void addOutgoingCallAndVerifyFailure( 324 AppControlWrapper appControl, CallAttributes attributes) throws Exception { 325 mBaseAppVerifierImpl.addCallAndVerifyFailure(appControl, attributes); 326 } 327 addFailedCallWithCreateConnectionVerify( AppControlWrapper appControl, CallAttributes attributes)328 public void addFailedCallWithCreateConnectionVerify( 329 AppControlWrapper appControl, CallAttributes attributes) throws Exception { 330 mBaseAppVerifierImpl.addFailedCallWithCreateConnectionVerify(appControl, attributes); 331 } 332 waitUntilExpectedCallCount(int expectedCallCount)333 public void waitUntilExpectedCallCount(int expectedCallCount) { 334 mBaseAppVerifierImpl.waitUntilExpectedCallCount(expectedCallCount); 335 } 336 setCallState(AppControlWrapper appControl, String id, int callState)337 public void setCallState(AppControlWrapper appControl, String id, int callState) 338 throws Exception { 339 mBaseAppVerifierImpl.setCallState(appControl, id, callState); 340 } setCallStateAndVerify(AppControlWrapper appControl, String id, int callState)341 public void setCallStateAndVerify(AppControlWrapper appControl, String id, int callState) 342 throws Exception { 343 mBaseAppVerifierImpl.setCallStateAndVerify(appControl, id, callState); 344 } 345 setCallStateAndVerify(AppControlWrapper appControl, String id, int targetCallState, int arg)346 public void setCallStateAndVerify(AppControlWrapper appControl, String id, int targetCallState, 347 int arg) throws Exception { 348 mBaseAppVerifierImpl.setCallStateAndVerify(appControl, id, targetCallState, arg); 349 } 350 answerViaInCallService(String id, int videoState)351 public void answerViaInCallService(String id, int videoState) throws Exception { 352 mBaseAppVerifierImpl.answerViaInCallService(id, videoState); 353 } 354 answerViaInCallServiceAndVerify(String id, int videoState)355 public void answerViaInCallServiceAndVerify(String id, int videoState) throws Exception { 356 mBaseAppVerifierImpl.answerViaInCallServiceAndVerify(id, videoState); 357 } 358 holdCallViaInCallService(String id)359 public void holdCallViaInCallService(String id) { 360 mBaseAppVerifierImpl.holdCallViaInCallService(id); 361 } 362 unholdCallViaInCallService(String id)363 public void unholdCallViaInCallService(String id) { 364 mBaseAppVerifierImpl.unholdCallViaInCallService(id); 365 } 366 disconnectCallViaInCallService(String id)367 public void disconnectCallViaInCallService(String id) { 368 mBaseAppVerifierImpl.disconnectCallViaInCallService(id); 369 } 370 isCallHoldable(String id)371 public boolean isCallHoldable(String id) { 372 return mBaseAppVerifierImpl.isCallHoldable(id); 373 } 374 setCallStateButExpectOnError(AppControlWrapper appControl, String id, int targetCallState)375 public CallException setCallStateButExpectOnError(AppControlWrapper appControl, 376 String id, 377 int targetCallState) 378 throws Exception { 379 return mBaseAppVerifierImpl.setCallStateButExpectOnError(appControl, id, targetCallState); 380 } 381 382 setCallControlActionButExpectOnError(AppControlWrapper appControl, String id, int targetCallState, int arg)383 public CallException setCallControlActionButExpectOnError(AppControlWrapper appControl, 384 String id, 385 int targetCallState, 386 int arg) throws Exception { 387 return mBaseAppVerifierImpl.setCallStateButExpectOnError( 388 appControl, id, targetCallState, arg); 389 } 390 verifyCallIsInState(String id, int state)391 public void verifyCallIsInState(String id, int state) throws Exception { 392 mBaseAppVerifierImpl.verifyCallIsInState(id, state); 393 } 394 verifyCallExtraPresent(String id, String extraToVerify, boolean expected)395 public void verifyCallExtraPresent(String id, String extraToVerify, boolean expected) 396 throws Exception { 397 mBaseAppVerifierImpl.verifyCallExtraPresent(id, extraToVerify, expected); 398 } 399 getAnotherCallEndpoint(AppControlWrapper appControl, String id)400 public CallEndpoint getAnotherCallEndpoint(AppControlWrapper appControl, String id) 401 throws Exception { 402 return mBaseAppVerifierImpl.getAnotherCallEndpoint(appControl, id); 403 } 404 setAudioRouteStateAndVerify(AppControlWrapper appControl, String id, CallEndpoint newCallEndpoint)405 public void setAudioRouteStateAndVerify(AppControlWrapper appControl, String id, 406 CallEndpoint newCallEndpoint) throws Exception { 407 mBaseAppVerifierImpl.setAudioRouteStateAndVerify(appControl, id, newCallEndpoint); 408 } 409 isMuted(AppControlWrapper appControl, String id)410 public boolean isMuted(AppControlWrapper appControl, String id) throws RemoteException { 411 return mBaseAppVerifierImpl.isMuted(appControl, id); 412 } 413 setMuteState(AppControlWrapper appControl, String id, boolean isMuted)414 public void setMuteState(AppControlWrapper appControl, String id, boolean isMuted) 415 throws RemoteException { 416 mBaseAppVerifierImpl.setMuteState(appControl, id, isMuted); 417 } 418 sendConnectionEvent(AppControlWrapper appControl, String id, String event)419 public void sendConnectionEvent(AppControlWrapper appControl, String id, String event) 420 throws RemoteException { 421 mBaseAppVerifierImpl.sendConnectionEvent(appControl, id, event); 422 } 423 getCurrentCallEndpoint(AppControlWrapper appControl, String id)424 public CallEndpoint getCurrentCallEndpoint(AppControlWrapper appControl, String id) 425 throws Exception { 426 return mBaseAppVerifierImpl.getCurrentCallEndpoint(appControl, id); 427 } 428 getAvailableCallEndpoints(AppControlWrapper appControl, String id)429 public List<CallEndpoint> getAvailableCallEndpoints(AppControlWrapper appControl, String id) 430 throws Exception { 431 return mBaseAppVerifierImpl.getAvailableCallEndpoints(appControl, id); 432 } 433 registerDefaultPhoneAccount(AppControlWrapper appControl)434 public void registerDefaultPhoneAccount(AppControlWrapper appControl) throws RemoteException { 435 mBaseAppVerifierImpl.registerDefaultPhoneAccount(appControl); 436 } 437 registerCustomPhoneAccount(AppControlWrapper appControl, PhoneAccount account)438 public void registerCustomPhoneAccount(AppControlWrapper appControl, PhoneAccount account) 439 throws Exception { 440 mBaseAppVerifierImpl.registerCustomPhoneAccount(appControl, account); 441 } 442 unregisterPhoneAccountWithHandle(AppControlWrapper appControl, PhoneAccountHandle handle)443 public void unregisterPhoneAccountWithHandle(AppControlWrapper appControl, 444 PhoneAccountHandle handle) throws Exception { 445 mBaseAppVerifierImpl.unregisterPhoneAccountWithHandle(appControl, handle); 446 } 447 getAccountHandlesForApp(AppControlWrapper appControl)448 public List<PhoneAccountHandle> getAccountHandlesForApp(AppControlWrapper appControl) 449 throws Exception { 450 return mBaseAppVerifierImpl.getAccountHandlesForApp(appControl); 451 } 452 verifyCallPhoneAccount(String id, PhoneAccountHandle handle)453 public void verifyCallPhoneAccount(String id, PhoneAccountHandle handle) { 454 mBaseAppVerifierImpl.verifyCallPhoneAccount(id, handle); 455 } 456 /** 457 * Fetch the PhoneAccount associated with the given PhoneAccountHandle 458 */ getRegisteredPhoneAccounts(AppControlWrapper appControl)459 public List<PhoneAccount> getRegisteredPhoneAccounts(AppControlWrapper appControl) 460 throws Exception { 461 return appControl.getRegisteredPhoneAccounts(); 462 } 463 setUserDefaultPhoneAccountOverride(PhoneAccountHandle handle)464 public void setUserDefaultPhoneAccountOverride(PhoneAccountHandle handle) throws Exception { 465 mBaseAppVerifierImpl.setUserDefaultPhoneAccountOverride(handle); 466 } 467 isPhoneAccountRegistered(PhoneAccountHandle handle)468 public boolean isPhoneAccountRegistered(PhoneAccountHandle handle) { 469 return mBaseAppVerifierImpl.isPhoneAccountRegistered(handle); 470 } 471 switchToAnotherCallEndpoint(AppControlWrapper appControl, String callId)472 public void switchToAnotherCallEndpoint(AppControlWrapper appControl, String callId) 473 throws Exception { 474 CallEndpoint originalCallEndpoint = getCurrentCallEndpoint(appControl, callId); 475 CallEndpoint anotherCallEndpoint = getAnotherCallEndpoint(appControl, callId); 476 if (anotherCallEndpoint != null && !originalCallEndpoint.equals(anotherCallEndpoint)) { 477 setAudioRouteStateAndVerify(appControl, callId, anotherCallEndpoint); 478 // reset the DUT to the original endpoint for cleanup purposes 479 setAudioRouteStateAndVerify(appControl, callId, originalCallEndpoint); 480 } 481 } 482 assertAudioMode(final int expectedMode)483 public void assertAudioMode(final int expectedMode) { 484 mBaseAppVerifierImpl.assertAudioMode(expectedMode); 485 } 486 487 /** 488 * NOTIFICATION STUFF 489 */ 490 verifyNotificationIsPostedForCall(AppControlWrapper appControl, String callId)491 public void verifyNotificationIsPostedForCall(AppControlWrapper appControl, String callId) { 492 mBaseAppVerifierImpl.verifyNotificationPostedForCall(appControl, callId); 493 } 494 removeNotificationForCall(AppControlWrapper appControl, String callId)495 public void removeNotificationForCall(AppControlWrapper appControl, String callId) 496 throws RemoteException { 497 appControl.removeNotificationForCall(callId); 498 } 499 500 /** 501 * Checks if foreground service delegation is active for a specific phone account a call was 502 * created on. 503 * 504 * <p>This method determines whether the given phone account is currently delegating its 505 * foreground service capabilities to another application. Foreground service delegation allows 506 * an app to manage calls and perform call-related operations even when it's not in the 507 * foreground. 508 * 509 * @param appControl The {@link AppControlWrapper} instance representing the application whose 510 * foreground service delegation status is being checked. 511 * @param handle The {@link PhoneAccountHandle} identifying the phone account to check. 512 * @return {@code true} if foreground service delegation is active for the specified phone 513 * account that is owned by the application, {@code false} otherwise. 514 * @throws RemoteException if there is an error communicating with the remote application. 515 */ isForegroundServiceDelegationActive( AppControlWrapper appControl, PhoneAccountHandle handle)516 public boolean isForegroundServiceDelegationActive( 517 AppControlWrapper appControl, PhoneAccountHandle handle) throws RemoteException { 518 return appControl.isForegroundServiceDelegationActive(handle); 519 } 520 521 /** 522 * Modifies the existing managed PhoneAccount to include a new PhoneAccount restriction. Must be 523 * called after the PhoneAccount was registered as part of {@link #bindToApp(TelecomTestApp)}. 524 */ updateManagedPhoneAccountWithRestriction( PhoneAccountHandle handle, Set<PhoneAccountHandle> restrictions)525 public void updateManagedPhoneAccountWithRestriction( 526 PhoneAccountHandle handle, Set<PhoneAccountHandle> restrictions) throws Exception { 527 PhoneAccount acctToUpdate = MANAGED_PHONE_ACCOUNTS.get(handle); 528 assertNotNull("setManagedPhoneAccountRestriction: test error, couldn't find PA " 529 + "from PAH: " + handle, acctToUpdate); 530 PhoneAccount.Builder newAcct = new PhoneAccount.Builder(acctToUpdate); 531 if (restrictions == null) { 532 newAcct.clearSimultaneousCallingRestriction(); 533 } else { 534 newAcct.setSimultaneousCallingRestriction(restrictions); 535 } 536 mBaseAppVerifierImpl.registerManagedPhoneAccount(newAcct.build()); 537 } 538 539 /** 540 * Audio focus stuff 541 */ 542 543 /** 544 * Acquire media focus for music playback; pretend we are listening to music so that we can 545 * verify that focus is lost during a call and restored later. 546 */ acquireAudioFocusForMusic()547 public void acquireAudioFocusForMusic() { 548 mBaseAppVerifierImpl.acquireAudioFocusForMusic(); 549 } 550 551 /** Waits to ensure that the music audio focus was one of the expected values */ waitForAndVerifyMusicFocus(boolean verifyPresence, int... expectedValues)552 public boolean waitForAndVerifyMusicFocus(boolean verifyPresence, int... expectedValues) { 553 return mBaseAppVerifierImpl.waitForAndVerifyMusicFocus(verifyPresence, expectedValues); 554 } 555 556 /** 557 * Release media focus for media playback; pretend we are not listening to music any longer. 558 */ releaseAudioFocusForMusic()559 public void releaseAudioFocusForMusic() { 560 mBaseAppVerifierImpl.releaseAudioFocusForMusic(); 561 } 562 563 /** Setup required to test emergency calling in CUJ. */ setupForEmergencyCalling()564 public void setupForEmergencyCalling() throws Exception { 565 if (mBaseAppVerifierImpl == null) { 566 return; 567 } 568 mBaseAppVerifierImpl.setupForEmergencyCalling(); 569 } 570 571 /** Cleanup setup procedure done to test emergency calling. d */ tearDownEmergencyCalling()572 public void tearDownEmergencyCalling() throws Exception { 573 if (mBaseAppVerifierImpl == null) { 574 return; 575 } 576 mBaseAppVerifierImpl.tearDownEmergencyCalling(); 577 } 578 } 579