1 /* 2 * Copyright (C) 2019 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.screeningtestapp; 18 19 import static android.telecom.TelecomManager.EXTRA_DISCONNECT_CAUSE; 20 import static android.telecom.TelecomManager.EXTRA_HANDLE; 21 22 import android.app.Activity; 23 import android.content.Intent; 24 import android.net.Uri; 25 import android.os.Bundle; 26 27 import java.util.concurrent.CountDownLatch; 28 import java.util.concurrent.TimeUnit; 29 30 public class CtsPostCallActivity extends Activity { 31 private static final String ACTION_POST_CALL = "android.telecom.action.POST_CALL"; 32 private static final int DEFAULT_DISCONNECT_CAUSE = -1; 33 private static final long TEST_TIMEOUT = 5000; 34 35 private static Uri cachedHandle; 36 private static int cachedDisconnectCause; 37 private static CountDownLatch sLatch = new CountDownLatch(1); 38 39 @Override onCreate(Bundle bundle)40 protected void onCreate(Bundle bundle) { 41 super.onCreate(bundle); 42 final Intent intent = getIntent(); 43 final String action = intent != null ? intent.getAction() : null; 44 if (ACTION_POST_CALL.equals(action)) { 45 cachedHandle = intent.getParcelableExtra(EXTRA_HANDLE); 46 cachedDisconnectCause = intent 47 .getIntExtra(EXTRA_DISCONNECT_CAUSE, DEFAULT_DISCONNECT_CAUSE); 48 sLatch.countDown(); 49 } 50 } 51 getCachedHandle()52 public static Uri getCachedHandle() { 53 return cachedHandle; 54 } 55 getCachedDisconnectCause()56 public static int getCachedDisconnectCause() { 57 return cachedDisconnectCause; 58 } 59 resetPostCallActivity()60 public static void resetPostCallActivity() { 61 sLatch = new CountDownLatch(1); 62 cachedHandle = null; 63 cachedDisconnectCause = DEFAULT_DISCONNECT_CAUSE; 64 } 65 waitForActivity()66 public static boolean waitForActivity() { 67 try { 68 return sLatch.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS); 69 } catch (InterruptedException e) { 70 return false; 71 } 72 } 73 } 74