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