1 /*
2  * Copyright (C) 2020 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.suspendapps.suspendtestapp;
18 
19 import static com.android.suspendapps.suspendtestapp.Constants.PACKAGE_NAME;
20 
21 import android.app.Activity;
22 import android.content.Intent;
23 import android.os.Bundle;
24 import android.util.Log;
25 
26 import androidx.annotation.GuardedBy;
27 
28 public class SuspendTestActivity extends Activity {
29     private static final String TAG = SuspendTestActivity.class.getSimpleName();
30     private static final String ACTION_FINISH_TEST_ACTIVITY =
31             PACKAGE_NAME + ".action.FINISH_TEST_ACTIVITY";
32 
33     static final Object sLock = new Object();
34     @GuardedBy("sLock")
35     static Intent sStartedIntent;
36 
37     @Override
onCreate(Bundle savedInstanceState)38     protected void onCreate(Bundle savedInstanceState) {
39         Log.d(TAG, "onCreate");
40         super.onCreate(savedInstanceState);
41         if (ACTION_FINISH_TEST_ACTIVITY.equals(getIntent().getAction())) {
42             finish();
43         }
44     }
45 
46     @Override
onStart()47     protected void onStart() {
48         Log.d(TAG, "onStart");
49         super.onStart();
50         synchronized (sLock) {
51             sStartedIntent = getIntent();
52             sLock.notifyAll();
53         }
54     }
55 
56     @Override
onStop()57     public void onStop() {
58         Log.d(TAG, "onStop");
59         super.onStop();
60         synchronized (sLock) {
61             sStartedIntent = null;
62             sLock.notifyAll();
63         }
64     }
65 }
66