1 /* 2 * Copyright (C) 2011 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 android.app.stubs; 17 18 import android.app.Activity; 19 import android.content.Intent; 20 import android.os.Bundle; 21 22 import java.util.concurrent.CountDownLatch; 23 import java.util.concurrent.TimeUnit; 24 25 /** 26 * {@link Activity} that just launches {@link ActivityManagerMemoryClassTestActivity} and 27 * returns the result of that activity. 28 */ 29 public class ActivityManagerMemoryClassLaunchActivity extends Activity { 30 31 public static final String MEMORY_CLASS_EXTRA = "activityMemoryClass"; 32 33 private static final int TEST_ACTIVITY_REQUEST_CODE = 1337; 34 35 private final CountDownLatch mLatch = new CountDownLatch(1); 36 37 private int mChildResult = RESULT_CANCELED; 38 39 @Override 40 protected void onCreate(Bundle savedInstanceState) { 41 super.onCreate(savedInstanceState); 42 43 // Start the activity that runs in a separate process to do the actual testing, 44 // since the test itself cannot start an activity in a separate process. A separate 45 // process is used to avoid including the overhead of the test instrumentation process. 46 47 Intent intent = getIntent(); 48 int memoryClass = intent.getIntExtra(MEMORY_CLASS_EXTRA, -1); 49 50 Intent testIntent = new Intent(this, ActivityManagerMemoryClassTestActivity.class); 51 testIntent.putExtra(MEMORY_CLASS_EXTRA, memoryClass); 52 startActivityForResult(testIntent, TEST_ACTIVITY_REQUEST_CODE); 53 } 54 55 @Override 56 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 57 super.onActivityResult(requestCode, resultCode, data); 58 if (requestCode == 1337) { 59 synchronized (this) { 60 mChildResult = resultCode; 61 } 62 } else { 63 throw new IllegalStateException("Request code: " + requestCode); 64 } 65 } 66 67 public int getResult() throws InterruptedException { 68 mLatch.await(5, TimeUnit.SECONDS); 69 synchronized (this) { 70 return mChildResult; 71 } 72 } 73 } 74