• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import android.util.Log;
27 
28 import java.util.concurrent.CountDownLatch;
29 import java.util.concurrent.TimeUnit;
30 
31 public class CtsPostCallActivity extends Activity {
32     private static final String TAG = CtsPostCallActivity.class.getSimpleName();
33     private static final String ACTION_POST_CALL = "android.telecom.action.POST_CALL";
34     private static final int DEFAULT_DISCONNECT_CAUSE = -1;
35     private static final long TEST_TIMEOUT = 5000;
36 
37     private static Uri cachedHandle;
38     private static int cachedDisconnectCause;
39     private static CountDownLatch sLatch = new CountDownLatch(1);
40 
41     @Override
onCreate(Bundle bundle)42     protected void onCreate(Bundle bundle) {
43         super.onCreate(bundle);
44         final Intent intent = getIntent();
45         Log.i(TAG, "onCreate: intent= " + intent);
46         final String action = intent != null ? intent.getAction() : null;
47         if (ACTION_POST_CALL.equals(action)) {
48             cachedHandle = intent.getParcelableExtra(EXTRA_HANDLE);
49             cachedDisconnectCause = intent
50                     .getIntExtra(EXTRA_DISCONNECT_CAUSE, DEFAULT_DISCONNECT_CAUSE);
51             sLatch.countDown();
52             //  The activity should be immediately destroyed after the latch is decremented.
53             //  Otherwise, the activity will fail to be created again when another test is
54             //  executed leading to flake.
55             finish();
56         }
57     }
58 
59     @Override
onStart()60     protected void onStart() {
61         super.onStart();
62         Log.i(TAG, "onStart: Activity becoming visible");
63     }
64 
65     @Override
onResume()66     protected void onResume() {
67         super.onResume();
68         Log.i(TAG, "onResume: Activity in foreground and interactive");
69     }
70 
71     @Override
onPause()72     protected void onPause() {
73         super.onPause();
74         Log.i(TAG, "onPause: Activity losing focus");
75     }
76 
77     @Override
onStop()78     protected void onStop() {
79         super.onStop();
80         Log.i(TAG, "onStop: Activity no longer visible");
81     }
82 
83     @Override
onDestroy()84     protected void onDestroy() {
85         super.onDestroy();
86         Log.i(TAG, "onDestroy: Activity is being destroyed");
87     }
88 
89     @Override
onRestart()90     protected void onRestart() {
91         super.onRestart();
92         Log.i(TAG, "onRestart: Activity restarting after being stopped");
93     }
94 
getCachedHandle()95     public static Uri getCachedHandle() {
96         return cachedHandle;
97     }
98 
getCachedDisconnectCause()99     public static int getCachedDisconnectCause() {
100         return cachedDisconnectCause;
101     }
102 
resetPostCallActivity()103     public static void resetPostCallActivity() {
104         Log.i(TAG, "resetPostCallActivity:");
105         sLatch = new CountDownLatch(1);
106         cachedHandle = null;
107         cachedDisconnectCause = DEFAULT_DISCONNECT_CAUSE;
108     }
109 
waitForActivity()110     public static boolean waitForActivity() {
111         Log.i(TAG, "waitForActivity:");
112         try {
113             return sLatch.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS);
114         } catch (InterruptedException e) {
115             return false;
116         }
117     }
118 }
119