Home | History | Annotate | Download | only in managedprofile
      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 package com.android.cts.managedprofile;
     17 
     18 import android.app.Activity;
     19 import android.content.Intent;
     20 import android.util.Log;
     21 
     22 import java.util.concurrent.Semaphore;
     23 import java.util.concurrent.TimeUnit;
     24 
     25 /**
     26  * Dummy activity necessary for the tests.
     27  */
     28 public class TestActivity extends Activity {
     29     private static final String TAG = TestActivity.class.getName();
     30 
     31     private final Semaphore mActivityStartedSemaphore = new Semaphore(0);
     32 
     33     public void startActivity(String action) {
     34         startActivityForResult(new Intent(action), /* requestCode= */ 0);
     35     }
     36 
     37     public boolean checkActivityStarted() {
     38         Log.i(TAG, "Waiting to see if an activity was started");
     39         try {
     40             return mActivityStartedSemaphore.tryAcquire(5, TimeUnit.SECONDS);
     41         } catch (InterruptedException e) {
     42            return false;
     43         }
     44     }
     45 
     46     @Override
     47     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     48         Log.i(TAG, "An activity sent a result");
     49         if (resultCode != RESULT_OK) {
     50             Log.w(TAG, "Activity returned error code: " + resultCode);
     51         }
     52         mActivityStartedSemaphore.release();
     53     }
     54 }
     55