Search in sources :

Example 1 with ModuleInfo

use of android.content.pm.ModuleInfo in project robolectric by robolectric.

the class ShadowPackageManagerTest method deleteModule.

@Test
@Config(minSdk = android.os.Build.VERSION_CODES.Q)
public void deleteModule() throws Exception {
    ModuleInfo sentModuleInfo = ModuleInfoBuilder.newBuilder().setName("test.module.name").setPackageName("test.module.package.name").setHidden(false).build();
    shadowOf(packageManager).installModule(sentModuleInfo);
    ModuleInfo receivedModuleInfo = packageManager.getModuleInfo(sentModuleInfo.getPackageName(), 0);
    assertThat(receivedModuleInfo.getPackageName().equals(sentModuleInfo.getPackageName())).isTrue();
    ModuleInfo deletedModuleInfo = (ModuleInfo) shadowOf(packageManager).deleteModule(sentModuleInfo.getPackageName());
    assertThat(deletedModuleInfo.getName().toString().contentEquals(sentModuleInfo.getName())).isTrue();
    assertThat(deletedModuleInfo.getPackageName().equals(sentModuleInfo.getPackageName())).isTrue();
    assertThat(deletedModuleInfo.isHidden()).isSameInstanceAs(sentModuleInfo.isHidden());
}
Also used : ModuleInfo(android.content.pm.ModuleInfo) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 2 with ModuleInfo

use of android.content.pm.ModuleInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class RecentAppStatsMixinTest method loadDisplayableRecentApps_hiddenSystemModuleSet_shouldNotHaveHiddenSystemModule.

@Test
public void loadDisplayableRecentApps_hiddenSystemModuleSet_shouldNotHaveHiddenSystemModule() {
    final List<UsageStats> stats = new ArrayList<>();
    // Regular app.
    final UsageStats stat1 = new UsageStats();
    stat1.mLastTimeUsed = System.currentTimeMillis();
    stat1.mPackageName = "com.foo.bar";
    stats.add(stat1);
    // Hidden system module.
    final UsageStats stat2 = new UsageStats();
    stat2.mLastTimeUsed = System.currentTimeMillis() + 200;
    stat2.mPackageName = "com.foo.hidden";
    stats.add(stat2);
    ApplicationsState.AppEntry stat1Entry = mock(ApplicationsState.AppEntry.class);
    ApplicationsState.AppEntry stat2Entry = mock(ApplicationsState.AppEntry.class);
    stat1Entry.info = mApplicationInfo;
    stat2Entry.info = mApplicationInfo;
    when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId())).thenReturn(stat1Entry);
    when(mAppState.getEntry(stat2.mPackageName, UserHandle.myUserId())).thenReturn(stat2Entry);
    final ModuleInfo moduleInfo1 = new ModuleInfo();
    moduleInfo1.setPackageName(stat1.mPackageName);
    moduleInfo1.setHidden(false);
    final ModuleInfo moduleInfo2 = new ModuleInfo();
    moduleInfo2.setPackageName(stat2.mPackageName);
    moduleInfo2.setHidden(true);
    ReflectionHelpers.setStaticField(ApplicationsState.class, "sInstance", null);
    final List<ModuleInfo> modules = new ArrayList<>();
    modules.add(moduleInfo2);
    when(mPackageManager.getInstalledModules(anyInt())).thenReturn(modules);
    when(mPackageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(new ResolveInfo());
    when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong())).thenReturn(stats);
    mRecentAppStatsMixin.loadDisplayableRecentApps(3);
    assertThat(mRecentAppStatsMixin.mRecentApps.size()).isEqualTo(1);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ModuleInfo(android.content.pm.ModuleInfo) ApplicationsState(com.android.settingslib.applications.ApplicationsState) ArrayList(java.util.ArrayList) Intent(android.content.Intent) UsageStats(android.app.usage.UsageStats) Test(org.junit.Test)

Example 3 with ModuleInfo

use of android.content.pm.ModuleInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ModuleLicensesListPreferenceControllerTest method getAvailabilityStatus_validLicenses_returnsAvailable.

@Test
public void getAvailabilityStatus_validLicenses_returnsAvailable() throws PackageManager.NameNotFoundException, IOException {
    Context context = mock(Context.class);
    PackageManager packageManager = mock(PackageManager.class);
    when(context.getPackageManager()).thenReturn(packageManager);
    ModuleInfo moduleInfo = new ModuleInfo();
    moduleInfo.setPackageName(PACKAGE_NAME);
    when(packageManager.getInstalledModules(0)).thenReturn(Collections.singletonList(moduleInfo));
    PackageInfo packageInfo = new PackageInfo();
    ApplicationInfo applicationInfo = new ApplicationInfo();
    packageInfo.applicationInfo = applicationInfo;
    when(packageManager.getPackageInfo(PACKAGE_NAME, PackageManager.MATCH_APEX)).thenReturn(packageInfo);
    Resources resources = mock(Resources.class);
    when(packageManager.getResourcesForApplication(applicationInfo)).thenReturn(resources);
    AssetManager manager = mock(AssetManager.class);
    when(resources.getAssets()).thenReturn(manager);
    when(manager.list("")).thenReturn(new String[] { GZIPPED_LICENSE_FILE_NAME });
    ModuleLicensesListPreferenceController controller = new ModuleLicensesListPreferenceController(context, PREFERENCE_KEY);
    assertThat(controller.getAvailabilityStatus()).isEqualTo(BasePreferenceController.AVAILABLE);
}
Also used : Context(android.content.Context) AssetManager(android.content.res.AssetManager) PackageManager(android.content.pm.PackageManager) ModuleInfo(android.content.pm.ModuleInfo) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) Resources(android.content.res.Resources) Test(org.junit.Test)

Example 4 with ModuleInfo

use of android.content.pm.ModuleInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ModuleLicensesPreferenceControllerTest method setUp.

@Before
public void setUp() {
    mModuleOne = new ModuleInfo();
    mModuleOne.setName(MODULE_1_NAME);
    mModuleOne.setPackageName(MODULE_1_PACKAGE_NAME);
    mModuleTwo = new ModuleInfo();
    mModuleTwo.setName(MODULE_2_NAME);
    mModuleTwo.setPackageName(MODULE_2_PACKAGE_NAME);
}
Also used : ModuleInfo(android.content.pm.ModuleInfo) Before(org.junit.Before)

Example 5 with ModuleInfo

use of android.content.pm.ModuleInfo in project robolectric by robolectric.

the class ShadowApplicationPackageManager method getInstalledModules.

@Implementation(minSdk = Q)
protected List<ModuleInfo> getInstalledModules(int flags) {
    synchronized (lock) {
        List<ModuleInfo> result = new ArrayList<>();
        for (String moduleName : moduleInfos.keySet()) {
            try {
                ModuleInfo moduleInfo = (ModuleInfo) getModuleInfo(moduleName, flags);
                result.add(moduleInfo);
            } catch (NameNotFoundException e) {
                Log.i(TAG, String.format("Module %s filtered out: %s", moduleName, e.getMessage()));
            }
        }
        return result;
    }
}
Also used : ModuleInfo(android.content.pm.ModuleInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ArrayList(java.util.ArrayList) Implementation(org.robolectric.annotation.Implementation)

Aggregations

ModuleInfo (android.content.pm.ModuleInfo)16 Test (org.junit.Test)8 PackageManager (android.content.pm.PackageManager)6 Context (android.content.Context)5 ApplicationInfo (android.content.pm.ApplicationInfo)3 PackageInfo (android.content.pm.PackageInfo)3 ArrayList (java.util.ArrayList)3 Before (org.junit.Before)3 Config (org.robolectric.annotation.Config)3 AssetManager (android.content.res.AssetManager)2 Resources (android.content.res.Resources)2 Activity (android.app.Activity)1 UsageStats (android.app.usage.UsageStats)1 Intent (android.content.Intent)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 ResolveInfo (android.content.pm.ResolveInfo)1 Preference (androidx.preference.Preference)1 PreferenceGroup (androidx.preference.PreferenceGroup)1 PreferenceScreen (androidx.preference.PreferenceScreen)1 ArrayUtils (com.android.internal.util.ArrayUtils)1