1 /*
2  * Copyright (C) 2014 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.cts.deviceowner;
18 
19 import android.app.Activity;
20 import android.content.Intent;
21 
22 public class LockTaskUtilityActivity extends Activity {
23 
24     public static final String START_LOCK_TASK = "startLockTask";
25     public static final String STOP_LOCK_TASK = "stopLockTask";
26     public static final String START_ACTIVITY = "startActivity";
27     public static final String FINISH = "finish";
28 
29     public static final String CREATE_ACTION = "com.android.cts.deviceowner.LOCK_TASK_CREATE";
30     public static final String DESTROY_ACTION = "com.android.cts.deviceowner.LOCK_TASK_DESTROY";
31     public static final String PAUSE_ACTION = "com.android.cts.deviceowner.LOCK_TASK_PAUSE";
32     public static final String RESUME_ACTION = "com.android.cts.deviceowner.LOCK_TASK_RESUME";
33     public static final String INTENT_ACTION = "com.android.cts.deviceowner.LOCK_TASK_INTENT";
34 
35     @Override
onNewIntent(Intent intent)36     protected void onNewIntent(Intent intent) {
37         super.onNewIntent(intent);
38         handleIntent(intent);
39     }
40 
41     @Override
onCreate(android.os.Bundle savedInstanceState)42     protected void onCreate(android.os.Bundle savedInstanceState) {
43         super.onCreate(savedInstanceState);
44         sendBroadcast(new Intent(CREATE_ACTION));
45         handleIntent(getIntent());
46     }
47 
48     @Override
onDestroy()49     protected void onDestroy() {
50         sendBroadcast(new Intent(DESTROY_ACTION));
51         super.onDestroy();
52     }
53 
54     @Override
onResume()55     protected void onResume() {
56         sendBroadcast(new Intent(RESUME_ACTION));
57         super.onResume();
58     }
59 
60     @Override
onPause()61     protected void onPause() {
62         sendBroadcast(new Intent(PAUSE_ACTION));
63         super.onPause();
64     }
65 
handleIntent(Intent intent)66     private void handleIntent(Intent intent) {
67         if (intent.getBooleanExtra(START_LOCK_TASK, false)) {
68             startLockTask();
69         }
70         if (intent.getBooleanExtra(STOP_LOCK_TASK, false)) {
71             stopLockTask();
72         }
73         if (intent.hasExtra(START_ACTIVITY)) {
74             Intent i = intent.getParcelableExtra(START_ACTIVITY);
75             startActivity(i);
76         }
77         if (intent.getBooleanExtra(FINISH, false)) {
78             finish();
79         }
80         sendBroadcast(new Intent(INTENT_ACTION));
81     }
82 
83 }
84