use of android.content.pm.ModuleInfo in project robolectric by robolectric.
the class ShadowPackageManager method installModule.
/**
* Installs a module with the {@link PackageManager} as long as it is not {@code null}
*
* <p>In order to create ModuleInfo objects in a valid state please use {@link ModuleInfoBuilder}.
*/
public void installModule(Object moduleInfoObject) {
synchronized (lock) {
ModuleInfo moduleInfo = (ModuleInfo) moduleInfoObject;
if (moduleInfo != null) {
moduleInfos.put(moduleInfo.getPackageName(), moduleInfo);
// Checking to see if package exists in the system
if (packageInfos.get(moduleInfo.getPackageName()) == null) {
ApplicationInfo applicationInfo = new ApplicationInfo();
applicationInfo.packageName = moduleInfo.getPackageName();
applicationInfo.name = moduleInfo.getName().toString();
PackageInfo packageInfo = new PackageInfo();
packageInfo.applicationInfo = applicationInfo;
packageInfo.packageName = moduleInfo.getPackageName();
installPackage(packageInfo);
}
}
}
}
use of android.content.pm.ModuleInfo in project robolectric by robolectric.
the class ShadowPackageManagerTest method getInstalledModules.
@Test
@Config(minSdk = android.os.Build.VERSION_CODES.Q)
public void getInstalledModules() {
List<ModuleInfo> sentModuleInfos = new ArrayList<>();
sentModuleInfos.add(ModuleInfoBuilder.newBuilder().setName("test.module.name.one").setPackageName("test.module.package.name.one").setHidden(false).build());
sentModuleInfos.add(ModuleInfoBuilder.newBuilder().setName("test.module.name.two").setPackageName("test.module.package.name.two").setHidden(false).build());
for (ModuleInfo sentModuleInfo : sentModuleInfos) {
shadowOf(packageManager).installModule(sentModuleInfo);
}
List<ModuleInfo> receivedModuleInfos = packageManager.getInstalledModules(0);
for (int i = 0; i < receivedModuleInfos.size(); i++) {
assertThat(receivedModuleInfos.get(i).getName().toString().contentEquals(sentModuleInfos.get(i).getName())).isTrue();
assertThat(receivedModuleInfos.get(i).getPackageName().equals(sentModuleInfos.get(i).getPackageName())).isTrue();
assertThat(receivedModuleInfos.get(i).isHidden()).isSameInstanceAs(sentModuleInfos.get(i).isHidden());
}
}
use of android.content.pm.ModuleInfo in project robolectric by robolectric.
the class ShadowPackageManagerTest method getModule.
@Test
@Config(minSdk = android.os.Build.VERSION_CODES.Q)
public void getModule() 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.getName().toString().contentEquals(sentModuleInfo.getName())).isTrue();
assertThat(receivedModuleInfo.getPackageName().equals(sentModuleInfo.getPackageName())).isTrue();
assertThat(receivedModuleInfo.isHidden()).isSameInstanceAs(sentModuleInfo.isHidden());
}
use of android.content.pm.ModuleInfo in project robolectric by robolectric.
the class ModuleInfoBuilder method build.
/**
* Returns a {@link ModuleInfo} with the data that was given. Both name and packageName are
* mandatory to build, but hidden is optional, if no value was given will default to false
*/
public ModuleInfo build() {
// Check mandatory fields.
checkNotNull(name, "Mandatory field 'name' missing.");
checkNotNull(packageName, "Mandatory field 'packageName' missing.");
ModuleInfo moduleInfo = new ModuleInfo();
moduleInfo.setName(name);
moduleInfo.setPackageName(packageName);
moduleInfo.setHidden(hidden);
return moduleInfo;
}
use of android.content.pm.ModuleInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SpecialAppAccessPreferenceControllerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mContext.getApplicationContext()).thenReturn(mContext);
ShadowUserManager.getShadow().setProfileIdsWithDisabled(new int[] { 0 });
doReturn(mPackageManager).when(mContext).getPackageManager();
doReturn(new ArrayList<ModuleInfo>()).when(mPackageManager).getInstalledModules(anyInt());
mController = new SpecialAppAccessPreferenceController(mContext, "test_key");
mPreference = new Preference(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.mSession = mSession;
}
Aggregations