PackageManagerServiceTest.java revision e400c441c2669b7b3643d70ecc5a637ecf8d2b54
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 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); 74 pri.removedUsers = new int[] {1, 2, 3, 4, 5}; 75 pri.populateUsers(pri.removedUsers, setting); 76 assertNotNull(pri.broadcastUsers); 77 assertEquals(pri.removedUsers.length, pri.broadcastUsers.length); 78 79 // Exclude a user 80 pri.broadcastUsers = null; 81 setting.setInstantApp(true, 4); 82 pri.populateUsers(pri.removedUsers, setting); 83 assertNotNull(pri.broadcastUsers); 84 assertEquals(pri.removedUsers.length - 1, pri.broadcastUsers.length); 85 86 // TODO: test that sendApplicationHiddenForUser() actually fills in 87 // broadcastUsers 88 } 89} 90