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());
}
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);
}
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);
}
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);
}
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;
}
}
Aggregations