blob: 8f2f34ee77d9ab7c946b467d3540ec5020c03951 [file] [log] [blame]
Mike Tsaocfe4ffe2017-04-11 13:57:31 -07001/*
2 * Copyright (C) 2017 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
17package com.android.server.pm;
18
19import android.content.IIntentReceiver;
20
21import android.os.Bundle;
22
23import android.test.AndroidTestCase;
24import android.test.suitebuilder.annotation.SmallTest;
25
26import java.io.File;
27
28// runtest -c com.android.server.pm.PackageManagerServiceTest frameworks-services
29
30@SmallTest
31public class PackageManagerServiceTest extends AndroidTestCase {
32 @Override
33 protected void setUp() throws Exception {
34 super.setUp();
35 }
36
37 @Override
38 protected void tearDown() throws Exception {
39 super.tearDown();
40 }
41
42 public void testPackageRemoval() throws Exception {
43 class PackageSenderImpl implements PackageSender {
44 public void sendPackageBroadcast(final String action, final String pkg,
45 final Bundle extras, final int flags, final String targetPkg,
46 final IIntentReceiver finishedReceiver, final int[] userIds) {
47 }
48
49 public void sendPackageAddedForNewUsers(String packageName,
50 boolean isSystem, int appId, int... userIds) {
51 }
52 }
53
54 PackageSenderImpl sender = new PackageSenderImpl();
55 PackageSetting setting = null;
56 PackageManagerService.PackageRemovedInfo pri =
57 new PackageManagerService.PackageRemovedInfo(sender);
58
59 // Initial conditions: nothing there
60 assertNull(pri.removedUsers);
61 assertNull(pri.broadcastUsers);
62
63 // populateUsers with nothing leaves nothing
64 pri.populateUsers(null, setting);
65 assertNull(pri.broadcastUsers);
66
67 // Create a real (non-null) PackageSetting and confirm that the removed
68 // users are copied properly
69 setting = new PackageSetting("name", "realName", new File("codePath"),
70 new File("resourcePath"), "legacyNativeLibraryPathString",
71 "primaryCpuAbiString", "secondaryCpuAbiString",
72 "cpuAbiOverrideString", 0, 0, 0, "parentPackageName", null, 0,
73 null, null);
Mike Tsao338d3322017-04-13 16:19:28 -070074 pri.populateUsers(new int[] {1, 2, 3, 4, 5}, setting);
Mike Tsaocfe4ffe2017-04-11 13:57:31 -070075 assertNotNull(pri.broadcastUsers);
Mike Tsao338d3322017-04-13 16:19:28 -070076 assertEquals(5, pri.broadcastUsers.length);
Mike Tsaocfe4ffe2017-04-11 13:57:31 -070077
78 // Exclude a user
79 pri.broadcastUsers = null;
Mike Tsao338d3322017-04-13 16:19:28 -070080 final int EXCLUDED_USER_ID = 4;
81 setting.setInstantApp(true, EXCLUDED_USER_ID);
82 pri.populateUsers(new int[] {1, 2, 3, EXCLUDED_USER_ID, 5}, setting);
Mike Tsaocfe4ffe2017-04-11 13:57:31 -070083 assertNotNull(pri.broadcastUsers);
Mike Tsao338d3322017-04-13 16:19:28 -070084 assertEquals(5 - 1, pri.broadcastUsers.length);
Mike Tsaocfe4ffe2017-04-11 13:57:31 -070085
86 // TODO: test that sendApplicationHiddenForUser() actually fills in
87 // broadcastUsers
88 }
89}