1 /* 2 * Copyright (C) 2024 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.cts.host; 18 19 import static com.google.common.truth.Truth.assertWithMessage; 20 21 import static org.junit.Assume.assumeTrue; 22 23 import android.app.sdksandbox.hosttestutils.DeviceSupportHostUtils; 24 import android.platform.test.annotations.LargeTest; 25 26 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; 27 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; 28 29 import org.junit.Before; 30 import org.junit.Test; 31 import org.junit.runner.RunWith; 32 33 @RunWith(DeviceJUnit4ClassRunner.class) 34 public class SdkSandboxInstallationTest extends BaseHostJUnit4Test { 35 36 private static final String SDK_PACKAGE = "com.android.sdksandbox.cts.provider"; 37 38 private static final String SDK_PROVIDER1 = SDK_PACKAGE + ".dataisolationtest"; 39 private static final String SDK_PROVIDER2 = SDK_PACKAGE + ".storagetest"; 40 41 public static final int TIME_OUT = 600_000; 42 43 private final DeviceSupportHostUtils mDeviceSupportUtils = new DeviceSupportHostUtils(this); 44 45 @Before setUp()46 public void setUp() throws Exception { 47 assumeTrue("Device supports SdkSandbox", mDeviceSupportUtils.isSdkSandboxSupported()); 48 } 49 50 @Test 51 @LargeTest // Reboot device testSdkSandbox_deviceReboot_sdkInstalledAndDexopted()52 public void testSdkSandbox_deviceReboot_sdkInstalledAndDexopted() throws Exception { 53 54 assertInstalledAndDexopted( 55 getDevice().executeShellCommand("dumpsys package " + SDK_PROVIDER1), SDK_PROVIDER1); 56 57 assertInstalledAndDexopted( 58 getDevice().executeShellCommand("dumpsys package " + SDK_PROVIDER2), SDK_PROVIDER2); 59 60 getDevice().reboot(); 61 getDevice().waitForBootComplete(TIME_OUT); 62 63 assertInstalledAndDexopted( 64 getDevice().executeShellCommand("dumpsys package " + SDK_PROVIDER1), SDK_PROVIDER1); 65 assertInstalledAndDexopted( 66 getDevice().executeShellCommand("dumpsys package " + SDK_PROVIDER2), SDK_PROVIDER2); 67 } 68 assertInstalledAndDexopted(String str, String provider)69 private static void assertInstalledAndDexopted(String str, String provider) { 70 if (str == null || !str.contains("Package [" + provider + "]")) { 71 throw new AssertionError("Expected package [" + provider + "] not found at " + str); 72 } 73 assertWithMessage("Expected to have ODEX in Dexopt state").that(str).contains("base.odex"); 74 } 75 } 76