1 /*
2  * Copyright (C) 2016 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.documentsui;
18 
19 import static com.android.documentsui.base.Shared.EXTRA_BENCHMARK;
20 
21 import android.app.Activity;
22 import android.content.Intent;
23 import android.os.SystemClock;
24 
25 import java.util.concurrent.CountDownLatch;
26 import java.util.concurrent.TimeUnit;
27 
28 public class LauncherActivity extends Activity {
29     private static final int BENCHMARK_REQUEST_CODE = 1986;
30 
31     static final Intent OPEN_DOCUMENT_INTENT = new Intent(Intent.ACTION_OPEN_DOCUMENT);
32     static {
33         OPEN_DOCUMENT_INTENT.addCategory(Intent.CATEGORY_OPENABLE);
OPEN_DOCUMENT_INTENT.putExtra(EXTRA_BENCHMARK, true)34         OPEN_DOCUMENT_INTENT.putExtra(EXTRA_BENCHMARK, true);
35         OPEN_DOCUMENT_INTENT.setType("*/*");
36     }
37 
38     private CountDownLatch mTestCaseLatch;
39 
40     /** Starts DocumentsUi and returns the duration until the result is received. */
startAndWaitDocumentsUi()41     long startAndWaitDocumentsUi() throws InterruptedException {
42         mTestCaseLatch = new CountDownLatch(1);
43         final long startTime = SystemClock.elapsedRealtime();
44         startActivityForResult(OPEN_DOCUMENT_INTENT, BENCHMARK_REQUEST_CODE);
45         if (!mTestCaseLatch.await(10, TimeUnit.SECONDS)) {
46             throw new RuntimeException("DocumentsUi is not responding");
47         }
48         return SystemClock.elapsedRealtime() - startTime;
49     }
50 
51     @Override
onActivityResult(int requestCode, int resultCode, Intent data)52     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
53         if (requestCode == BENCHMARK_REQUEST_CODE) {
54             mTestCaseLatch.countDown();
55         }
56     }
57 }
58