1 /* 2 * Copyright (C) 2022 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.sdksandbox.testutils; 18 19 import android.app.sdksandbox.SdkSandboxManager; 20 21 import java.util.concurrent.CountDownLatch; 22 import java.util.concurrent.TimeUnit; 23 24 public class FakeSdkSandboxProcessDeathCallback 25 implements SdkSandboxManager.SdkSandboxProcessDeathCallback { 26 private CountDownLatch mLatch = new CountDownLatch(1); 27 28 @Override onSdkSandboxDied()29 public void onSdkSandboxDied() { 30 mLatch.countDown(); 31 } 32 33 /** 34 * Returns {@code true} if the sandbox death callback is invoked within 5 seconds, {@code false} 35 * otherwise. 36 */ waitForSandboxDeath()37 public boolean waitForSandboxDeath() throws InterruptedException { 38 return mLatch.await(5, TimeUnit.SECONDS); 39 } 40 41 /** 42 * Resets the latch used to wait for death callbacks, to enable testing multiple death events 43 * for the same callback object. 44 */ resetLatch()45 public void resetLatch() { 46 mLatch = new CountDownLatch(1); 47 } 48 } 49