1 /* 2 * Copyright (C) 2009 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 android.app.stubs; 18 19 import android.app.Activity; 20 import android.os.Bundle; 21 import android.os.SystemClock; 22 23 public class PendingIntentStubActivity extends Activity { 24 25 public static final int INVALIDATE = -1; 26 public static final int ON_CREATE = 0; 27 public static int status = INVALIDATE; 28 29 private static boolean sCreated = false; 30 private static Object sBlocker = new Object(); 31 32 @Override onCreate(Bundle icicle)33 public void onCreate(Bundle icicle) { 34 super.onCreate(icicle); 35 synchronized (sBlocker) { 36 status = ON_CREATE; 37 sCreated = true; 38 sBlocker.notifyAll(); 39 } 40 } 41 42 prepare()43 public static void prepare() { 44 synchronized (sBlocker) { 45 status = INVALIDATE; 46 sCreated = false; 47 } 48 } 49 waitForCreate(long timeout)50 public static boolean waitForCreate(long timeout) { 51 long now = SystemClock.elapsedRealtime(); 52 final long endTime = now + timeout; 53 synchronized (sBlocker) { 54 while (!sCreated && now < endTime) { 55 try { 56 sBlocker.wait(endTime - now); 57 } catch (InterruptedException e) { 58 } 59 now = SystemClock.elapsedRealtime(); 60 } 61 return sCreated; 62 } 63 } 64 } 65