blob: e67ed9136f61e8dd30024e3d1e2569280fa17adb [file] [log] [blame]
Tomasz Mikolajewskib8373c22016-03-15 17:41:31 +09001/*
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
17package com.android.documentsui;
18
Steve McKayd9caa6a2016-09-15 16:36:45 -070019import static com.android.documentsui.base.Shared.EXTRA_BENCHMARK;
Tomasz Mikolajewskib8373c22016-03-15 17:41:31 +090020
21import android.app.Activity;
22import android.content.Intent;
Riddle Hsu619a2252022-12-19 21:19:04 +080023import android.os.SystemClock;
Tomasz Mikolajewskib8373c22016-03-15 17:41:31 +090024
25import java.util.concurrent.CountDownLatch;
Riddle Hsu619a2252022-12-19 21:19:04 +080026import java.util.concurrent.TimeUnit;
Tomasz Mikolajewskib8373c22016-03-15 17:41:31 +090027
28public class LauncherActivity extends Activity {
Tomasz Mikolajewskib8373c22016-03-15 17:41:31 +090029 private static final int BENCHMARK_REQUEST_CODE = 1986;
30
Riddle Hsu619a2252022-12-19 21:19:04 +080031 static final Intent OPEN_DOCUMENT_INTENT = new Intent(Intent.ACTION_OPEN_DOCUMENT);
32 static {
33 OPEN_DOCUMENT_INTENT.addCategory(Intent.CATEGORY_OPENABLE);
34 OPEN_DOCUMENT_INTENT.putExtra(EXTRA_BENCHMARK, true);
35 OPEN_DOCUMENT_INTENT.setType("*/*");
36 }
Tomasz Mikolajewskib8373c22016-03-15 17:41:31 +090037
Riddle Hsu619a2252022-12-19 21:19:04 +080038 private CountDownLatch mTestCaseLatch;
Tomasz Mikolajewskib8373c22016-03-15 17:41:31 +090039
Riddle Hsu619a2252022-12-19 21:19:04 +080040 /** Starts DocumentsUi and returns the duration until the result is received. */
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;
Tomasz Mikolajewskib8373c22016-03-15 17:41:31 +090049 }
50
51 @Override
52 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
53 if (requestCode == BENCHMARK_REQUEST_CODE) {
Riddle Hsu619a2252022-12-19 21:19:04 +080054 mTestCaseLatch.countDown();
Tomasz Mikolajewskib8373c22016-03-15 17:41:31 +090055 }
56 }
57}