• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.net.hostside;
18 
19 import android.app.Activity;
20 import android.app.KeyguardManager;
21 import android.content.Intent;
22 import android.os.Bundle;
23 import android.view.WindowManager;
24 
25 import java.util.concurrent.LinkedBlockingQueue;
26 import java.util.concurrent.TimeUnit;
27 
28 public class MyActivity extends Activity {
29     private final LinkedBlockingQueue<Integer> mResult = new LinkedBlockingQueue<>(1);
30 
31     @Override
onCreate(Bundle savedInstanceState)32     protected void onCreate(Bundle savedInstanceState) {
33         super.onCreate(savedInstanceState);
34 
35         getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
36                 | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
37                 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
38 
39         // Dismiss the keyguard so that the tests can click on the VPN confirmation dialog.
40         // FLAG_DISMISS_KEYGUARD is not sufficient to do this because as soon as the dialog appears,
41         // this activity goes into the background and the keyguard reappears.
42         getSystemService(KeyguardManager.class).requestDismissKeyguard(this, null /* callback */);
43     }
44 
45     @Override
onActivityResult(int requestCode, int resultCode, Intent data)46     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
47         if (mResult.offer(resultCode) == false) {
48             throw new RuntimeException("Queue is full! This should never happen");
49         }
50     }
51 
getResult(int timeoutMs)52     public Integer getResult(int timeoutMs) throws InterruptedException {
53         return mResult.poll(timeoutMs, TimeUnit.MILLISECONDS);
54     }
55 }
56