Tomasz Mikolajewski | b8373c2 | 2016-03-15 17:41:31 +0900 | [diff] [blame] | 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 | |
Steve McKay | d9caa6a | 2016-09-15 16:36:45 -0700 | [diff] [blame] | 19 | import static com.android.documentsui.base.Shared.EXTRA_BENCHMARK; |
Tomasz Mikolajewski | b8373c2 | 2016-03-15 17:41:31 +0900 | [diff] [blame] | 20 | |
| 21 | import android.app.Activity; |
| 22 | import android.content.Intent; |
Riddle Hsu | 619a225 | 2022-12-19 21:19:04 +0800 | [diff] [blame] | 23 | import android.os.SystemClock; |
Tomasz Mikolajewski | b8373c2 | 2016-03-15 17:41:31 +0900 | [diff] [blame] | 24 | |
| 25 | import java.util.concurrent.CountDownLatch; |
Riddle Hsu | 619a225 | 2022-12-19 21:19:04 +0800 | [diff] [blame] | 26 | import java.util.concurrent.TimeUnit; |
Tomasz Mikolajewski | b8373c2 | 2016-03-15 17:41:31 +0900 | [diff] [blame] | 27 | |
| 28 | public class LauncherActivity extends Activity { |
Tomasz Mikolajewski | b8373c2 | 2016-03-15 17:41:31 +0900 | [diff] [blame] | 29 | private static final int BENCHMARK_REQUEST_CODE = 1986; |
| 30 | |
Riddle Hsu | 619a225 | 2022-12-19 21:19:04 +0800 | [diff] [blame] | 31 | 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 Mikolajewski | b8373c2 | 2016-03-15 17:41:31 +0900 | [diff] [blame] | 37 | |
Riddle Hsu | 619a225 | 2022-12-19 21:19:04 +0800 | [diff] [blame] | 38 | private CountDownLatch mTestCaseLatch; |
Tomasz Mikolajewski | b8373c2 | 2016-03-15 17:41:31 +0900 | [diff] [blame] | 39 | |
Riddle Hsu | 619a225 | 2022-12-19 21:19:04 +0800 | [diff] [blame] | 40 | /** 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 Mikolajewski | b8373c2 | 2016-03-15 17:41:31 +0900 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | @Override |
| 52 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 53 | if (requestCode == BENCHMARK_REQUEST_CODE) { |
Riddle Hsu | 619a225 | 2022-12-19 21:19:04 +0800 | [diff] [blame] | 54 | mTestCaseLatch.countDown(); |
Tomasz Mikolajewski | b8373c2 | 2016-03-15 17:41:31 +0900 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | } |