• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.app.sdksandbox.hosttestutils.SdkSandboxDeviceSupportedHostRule;
22 import android.platform.test.annotations.LargeTest;
23 
24 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
25 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
26 
27 import org.junit.Rule;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 
31 @RunWith(DeviceJUnit4ClassRunner.class)
32 public class SdkSandboxInstallationTest extends BaseHostJUnit4Test {
33 
34     @Rule(order = 0)
35     public final SdkSandboxDeviceSupportedHostRule deviceSupportRule =
36             new SdkSandboxDeviceSupportedHostRule(this);
37 
38     private static final String SDK_PACKAGE = "com.android.sdksandbox.cts.provider";
39 
40     private static final String SDK_PROVIDER1 = SDK_PACKAGE + ".dataisolationtest";
41     private static final String SDK_PROVIDER2 = SDK_PACKAGE + ".storagetest";
42 
43     public static final int TIME_OUT = 600_000;
44 
45     @Test
46     @LargeTest // Reboot device
testSdkSandbox_deviceReboot_sdkInstalledAndDexopted()47     public void testSdkSandbox_deviceReboot_sdkInstalledAndDexopted() throws Exception {
48 
49         assertInstalledAndDexopted(
50                 getDevice().executeShellCommand("dumpsys package " + SDK_PROVIDER1), SDK_PROVIDER1);
51 
52         assertInstalledAndDexopted(
53                 getDevice().executeShellCommand("dumpsys package " + SDK_PROVIDER2), SDK_PROVIDER2);
54 
55         getDevice().reboot();
56         getDevice().waitForBootComplete(TIME_OUT);
57 
58         assertInstalledAndDexopted(
59                 getDevice().executeShellCommand("dumpsys package " + SDK_PROVIDER1), SDK_PROVIDER1);
60         assertInstalledAndDexopted(
61                 getDevice().executeShellCommand("dumpsys package " + SDK_PROVIDER2), SDK_PROVIDER2);
62     }
63 
assertInstalledAndDexopted(String str, String provider)64     private static void assertInstalledAndDexopted(String str, String provider) {
65         if (str == null || !str.contains("Package [" + provider + "]")) {
66             throw new AssertionError("Expected package [" + provider + "] not found at " + str);
67         }
68         assertWithMessage("Expected to have ODEX in Dexopt state").that(str).contains("base.odex");
69     }
70 }
71