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 com.android.sdksandbox.app; 18 19 import android.app.Activity; 20 import android.app.sdksandbox.SdkSandboxManager; 21 import android.app.sdksandbox.testutils.FakeLoadSdkCallback; 22 import android.app.sdksandbox.testutils.FakeSdkSandboxProcessDeathCallback; 23 import android.os.Bundle; 24 25 public class SdkSandboxTestActivity extends Activity { 26 27 private static final String SDK_NAME = "com.android.testcode"; 28 private static final String SDK_NAME_2 = "com.android.testcode2"; 29 30 @Override onCreate(Bundle icicle)31 public void onCreate(Bundle icicle) { 32 super.onCreate(icicle); 33 if (icicle != null) { 34 // Only load SDKs when Activity created, not restored. 35 return; 36 } 37 38 SdkSandboxManager sdkSandboxManager = 39 getApplicationContext().getSystemService(SdkSandboxManager.class); 40 assert sdkSandboxManager != null; 41 42 // Add a callback so that this app does not die when the sandbox dies. 43 sdkSandboxManager.addSdkSandboxProcessDeathCallback( 44 Runnable::run, new FakeSdkSandboxProcessDeathCallback()); 45 46 Bundle params = new Bundle(); 47 FakeLoadSdkCallback callback = new FakeLoadSdkCallback(); 48 FakeLoadSdkCallback callback2 = new FakeLoadSdkCallback(); 49 sdkSandboxManager.loadSdk(SDK_NAME, params, Runnable::run, callback); 50 sdkSandboxManager.loadSdk(SDK_NAME_2, params, Runnable::run, callback2); 51 callback.assertLoadSdkIsSuccessful(); 52 callback2.assertLoadSdkIsSuccessful(); 53 } 54 } 55