• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.servicestests.apps.suspendtestapp;
18 
19 import static com.android.server.pm.SuspendPackagesTest.ACTION_FINISH_TEST_ACTIVITY;
20 import static com.android.server.pm.SuspendPackagesTest.ACTION_REPORT_TEST_ACTIVITY_STARTED;
21 import static com.android.server.pm.SuspendPackagesTest.ACTION_REPORT_TEST_ACTIVITY_STOPPED;
22 import static com.android.server.pm.SuspendPackagesTest.INSTRUMENTATION_PACKAGE;
23 
24 import android.app.Activity;
25 import android.content.BroadcastReceiver;
26 import android.content.Context;
27 import android.content.Intent;
28 import android.content.IntentFilter;
29 import android.util.Log;
30 
31 public class SuspendTestActivity extends Activity {
32     private static final String TAG = SuspendTestActivity.class.getSimpleName();
33 
34     private BroadcastReceiver mFinishReceiver = new BroadcastReceiver() {
35         @Override
36         public void onReceive(Context context, Intent intent) {
37             Log.d(TAG, "Finishing test activity from receiver");
38             SuspendTestActivity.this.finish();
39         }
40     };
41 
42     @Override
onStart()43     public void onStart() {
44         Log.d(TAG, "onStart");
45         final Intent reportStart = new Intent(ACTION_REPORT_TEST_ACTIVITY_STARTED)
46                 .setPackage(INSTRUMENTATION_PACKAGE);
47         sendBroadcast(reportStart);
48         registerReceiver(mFinishReceiver, new IntentFilter(ACTION_FINISH_TEST_ACTIVITY));
49         super.onStart();
50     }
51     @Override
onStop()52     public void onStop() {
53         Log.d(TAG, "onStop");
54         final Intent reportStop = new Intent(ACTION_REPORT_TEST_ACTIVITY_STOPPED)
55                 .setPackage(INSTRUMENTATION_PACKAGE);
56         sendBroadcast(reportStop);
57         unregisterReceiver(mFinishReceiver);
58         super.onStop();
59     }
60 }
61