blob: 5093710850551e958e5f571142352527ae30d386 [file] [log] [blame]
Adam Lesinskib67fc5f2018-01-19 16:15:11 -08001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy
6 * 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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
14 * under the License.
15 */
16package com.android.server.om.hosttest;
17
18import static org.junit.Assert.assertEquals;
19import static org.junit.Assert.assertFalse;
20import static org.junit.Assert.assertTrue;
21import static org.junit.Assert.fail;
22
23import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
24import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
25
26import org.junit.Test;
27import org.junit.runner.RunWith;
28
29@RunWith(DeviceJUnit4ClassRunner.class)
30public class InstallOverlayTests extends BaseHostJUnit4Test {
31
32 private static final String OVERLAY_PACKAGE_NAME =
33 "com.android.server.om.hosttest.signature_overlay";
34
35 @Test
36 public void failToInstallNonPlatformSignedOverlay() throws Exception {
37 try {
38 installPackage("OverlayHostTests_BadSignatureOverlay.apk");
39 fail("installed a non-platform signed overlay");
40 } catch (Exception e) {
41 // Expected.
42 }
43 assertFalse(overlayManagerContainsPackage());
44 }
45
46 @Test
47 public void failToInstallPlatformSignedStaticOverlay() throws Exception {
48 try {
49 installPackage("OverlayHostTests_PlatformSignatureStaticOverlay.apk");
50 fail("installed a static overlay");
51 } catch (Exception e) {
52 // Expected.
53 }
54 assertFalse(overlayManagerContainsPackage());
55 }
56
57 @Test
58 public void succeedToInstallPlatformSignedOverlay() throws Exception {
59 installPackage("OverlayHostTests_PlatformSignatureOverlay.apk");
60 assertTrue(overlayManagerContainsPackage());
61 }
62
63 @Test
64 public void succeedToInstallPlatformSignedOverlayAndUpdate() throws Exception {
65 installPackage("OverlayHostTests_PlatformSignatureOverlay.apk");
66 assertTrue(overlayManagerContainsPackage());
67 assertEquals("v1", getDevice().getAppPackageInfo(OVERLAY_PACKAGE_NAME).getVersionName());
68
69 installPackage("OverlayHostTests_PlatformSignatureOverlayV2.apk");
70 assertTrue(overlayManagerContainsPackage());
71 assertEquals("v2", getDevice().getAppPackageInfo(OVERLAY_PACKAGE_NAME).getVersionName());
72 }
73
74 private boolean overlayManagerContainsPackage() throws Exception {
75 return getDevice().executeShellCommand("cmd overlay list")
76 .contains(OVERLAY_PACKAGE_NAME);
77 }
78}