Search in sources :

Example 6 with ModuleInfo

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);
            }
        }
    }
}
Also used : ModuleInfo(android.content.pm.ModuleInfo) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 7 with ModuleInfo

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());
    }
}
Also used : ModuleInfo(android.content.pm.ModuleInfo) ArrayList(java.util.ArrayList) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 8 with ModuleInfo

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());
}
Also used : ModuleInfo(android.content.pm.ModuleInfo) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 9 with ModuleInfo

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;
}
Also used : ModuleInfo(android.content.pm.ModuleInfo)

Example 10 with 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;
}
Also used : ModuleInfo(android.content.pm.ModuleInfo) Preference(androidx.preference.Preference) Before(org.junit.Before)

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