1 /* 2 * Copyright (C) 2023 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.test.app; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.content.Context; 22 import android.content.pm.IBackgroundInstallControlService; 23 import android.content.pm.PackageInfo; 24 import android.content.pm.PackageManager; 25 import android.content.pm.ParceledListSlice; 26 import android.os.RemoteException; 27 import android.os.ServiceManager; 28 import android.os.UserHandle; 29 30 import androidx.test.runner.AndroidJUnit4; 31 32 import org.junit.Before; 33 import org.junit.Test; 34 import org.junit.runner.RunWith; 35 36 import java.util.Set; 37 import java.util.stream.Collectors; 38 39 @RunWith(AndroidJUnit4.class) 40 public class BackgroundInstallControlServiceTest { 41 private static final String TAG = "BackgroundInstallControlServiceTest"; 42 43 private IBackgroundInstallControlService mIBics; 44 45 @Before setUp()46 public void setUp() { 47 mIBics = IBackgroundInstallControlService.Stub.asInterface( 48 ServiceManager.getService(Context.BACKGROUND_INSTALL_CONTROL_SERVICE)); 49 assertThat(mIBics).isNotNull(); 50 } 51 52 @Test testGetMockBackgroundInstalledPackages()53 public void testGetMockBackgroundInstalledPackages() throws RemoteException { 54 ParceledListSlice<PackageInfo> slice = mIBics.getBackgroundInstalledPackages( 55 PackageManager.MATCH_ALL, 56 UserHandle.USER_ALL); 57 assertThat(slice).isNotNull(); 58 59 var packageList = slice.getList(); 60 assertThat(packageList).isNotNull(); 61 assertThat(packageList).hasSize(2); 62 63 var expectedPackageNames = Set.of("com.android.servicestests.apps.bicmockapp1", 64 "com.android.servicestests.apps.bicmockapp2"); 65 var actualPackageNames = packageList.stream().map((packageInfo) -> packageInfo.packageName) 66 .collect(Collectors.toSet()); 67 assertThat(actualPackageNames).containsExactlyElementsIn(expectedPackageNames); 68 } 69 } 70