Search in sources :

Example 11 with ModuleInfo

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

the class ModuleLicensePreferenceTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    mContext = Robolectric.setupActivity(Activity.class);
    mModuleInfo = new ModuleInfo();
    mModuleInfo.setPackageName(PACKAGE_NAME);
    mModuleInfo.setName(NAME);
}
Also used : ModuleInfo(android.content.pm.ModuleInfo) Activity(android.app.Activity) Before(org.junit.Before)

Example 12 with ModuleInfo

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

the class ModuleLicensesListPreferenceControllerTest method getAvailabilityStatus_noLicenses_returnsConditionallyUnavailable.

@Test
public void getAvailabilityStatus_noLicenses_returnsConditionallyUnavailable() 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[] {});
    ModuleLicensesListPreferenceController controller = new ModuleLicensesListPreferenceController(context, PREFERENCE_KEY);
    assertThat(controller.getAvailabilityStatus()).isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
}
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 13 with ModuleInfo

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

the class ModuleLicenseProviderTest method openFile_validUri_notReadMode_throwsIllegalArgumentException.

@Test(expected = IllegalArgumentException.class)
public void openFile_validUri_notReadMode_throwsIllegalArgumentException() throws PackageManager.NameNotFoundException {
    ModuleLicenseProvider provider = spy(new ModuleLicenseProvider());
    Context context = mock(Context.class);
    PackageManager packageManager = mock(PackageManager.class);
    when(provider.getContext()).thenReturn(context);
    when(context.getPackageManager()).thenReturn(packageManager);
    when(packageManager.getModuleInfo(PACKAGE_NAME, 0)).thenReturn(new ModuleInfo());
    provider.openFile(new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(ModuleLicenseProvider.AUTHORITY).appendPath(PACKAGE_NAME).appendPath(LICENSE_FILE_NAME).build(), "badmode");
}
Also used : Context(android.content.Context) PackageManager(android.content.pm.PackageManager) ModuleInfo(android.content.pm.ModuleInfo) Test(org.junit.Test)

Example 14 with ModuleInfo

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

the class ModuleLicenseProviderTest method getType_validUri_returnsHtmlMimeType.

@Test
public void getType_validUri_returnsHtmlMimeType() throws PackageManager.NameNotFoundException {
    ModuleLicenseProvider provider = spy(new ModuleLicenseProvider());
    Context context = mock(Context.class);
    PackageManager packageManager = mock(PackageManager.class);
    when(provider.getContext()).thenReturn(context);
    when(context.getPackageManager()).thenReturn(packageManager);
    when(packageManager.getModuleInfo(PACKAGE_NAME, 0)).thenReturn(new ModuleInfo());
    assertThat(provider.getType(new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(ModuleLicenseProvider.AUTHORITY).appendPath(PACKAGE_NAME).appendPath(LICENSE_FILE_NAME).build())).isEqualTo(ModuleLicenseProvider.LICENSE_FILE_MIME_TYPE);
}
Also used : Context(android.content.Context) PackageManager(android.content.pm.PackageManager) ModuleInfo(android.content.pm.ModuleInfo) Test(org.junit.Test)

Example 15 with ModuleInfo

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

the class ModuleLicensesListPreferenceController method getAvailabilityStatus.

@Override
public int getAvailabilityStatus() {
    PackageManager packageManager = mContext.getPackageManager();
    List<ModuleInfo> modules = packageManager.getInstalledModules(0);
    return modules.stream().anyMatch(new ModuleLicensesPreferenceController.Predicate(mContext)) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
Also used : PackageManager(android.content.pm.PackageManager) ModuleInfo(android.content.pm.ModuleInfo)

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