Mike Tsao | cfe4ffe | 2017-04-11 13:57:31 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.pm; |
| 18 | |
| 19 | import android.content.IIntentReceiver; |
| 20 | |
| 21 | import android.os.Bundle; |
| 22 | |
| 23 | import android.test.AndroidTestCase; |
| 24 | import android.test.suitebuilder.annotation.SmallTest; |
| 25 | |
| 26 | import java.io.File; |
| 27 | |
| 28 | // runtest -c com.android.server.pm.PackageManagerServiceTest frameworks-services |
| 29 | |
| 30 | @SmallTest |
| 31 | public 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 Tsao | 338d332 | 2017-04-13 16:19:28 -0700 | [diff] [blame] | 74 | pri.populateUsers(new int[] {1, 2, 3, 4, 5}, setting); |
Mike Tsao | cfe4ffe | 2017-04-11 13:57:31 -0700 | [diff] [blame] | 75 | assertNotNull(pri.broadcastUsers); |
Mike Tsao | 338d332 | 2017-04-13 16:19:28 -0700 | [diff] [blame] | 76 | assertEquals(5, pri.broadcastUsers.length); |
Mike Tsao | cfe4ffe | 2017-04-11 13:57:31 -0700 | [diff] [blame] | 77 | |
| 78 | // Exclude a user |
| 79 | pri.broadcastUsers = null; |
Mike Tsao | 338d332 | 2017-04-13 16:19:28 -0700 | [diff] [blame] | 80 | 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 Tsao | cfe4ffe | 2017-04-11 13:57:31 -0700 | [diff] [blame] | 83 | assertNotNull(pri.broadcastUsers); |
Mike Tsao | 338d332 | 2017-04-13 16:19:28 -0700 | [diff] [blame] | 84 | assertEquals(5 - 1, pri.broadcastUsers.length); |
Mike Tsao | cfe4ffe | 2017-04-11 13:57:31 -0700 | [diff] [blame] | 85 | |
| 86 | // TODO: test that sendApplicationHiddenForUser() actually fills in |
| 87 | // broadcastUsers |
| 88 | } |
| 89 | } |