Home | History | Annotate | Download | only in documentsui
      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.Bundle;
     24 import android.os.Handler;
     25 
     26 import java.util.concurrent.CountDownLatch;
     27 
     28 public class LauncherActivity extends Activity {
     29     private static final String TARGET_PACKAGE = "com.android.documentsui";
     30     private static final int BENCHMARK_REQUEST_CODE = 1986;
     31 
     32     public static CountDownLatch testCaseLatch = null;
     33     public static long measurement = -1;
     34 
     35     private long mStartTime = -1;
     36 
     37     @Override
     38     protected void onCreate(Bundle savedInstanceState) {
     39         super.onCreate(savedInstanceState);
     40 
     41         new Handler().post(new Runnable() {
     42             @Override public void run() {
     43                 final Intent intent = new Intent("android.intent.action.OPEN_DOCUMENT");
     44                 intent.addCategory(Intent.CATEGORY_OPENABLE);
     45                 intent.putExtra(EXTRA_BENCHMARK, true);
     46                 intent.setType("*/*");
     47 
     48                 mStartTime = System.currentTimeMillis();
     49                 startActivityForResult(intent, BENCHMARK_REQUEST_CODE);
     50             }
     51         });
     52     }
     53 
     54     @Override
     55     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     56         if (requestCode == BENCHMARK_REQUEST_CODE) {
     57             measurement = System.currentTimeMillis() - mStartTime;
     58             testCaseLatch.countDown();
     59             finish();
     60         }
     61     }
     62 }
     63