Search in sources :

Example 76 with ProviderInfo

use of android.content.pm.ProviderInfo in project robolectric by robolectric.

the class ShadowPackageManagerTest method removeProvider.

@Test
public void removeProvider() {
    ComponentName componentName = new ComponentName(context, "org.robolectric.shadows.testing.TestContentProvider1");
    ProviderInfo removed = shadowOf(packageManager).removeProvider(componentName);
    assertThat(removed).isNotNull();
    try {
        packageManager.getProviderInfo(componentName, 0);
        fail();
    } catch (NameNotFoundException e) {
    // expected
    }
}
Also used : ProviderInfo(android.content.pm.ProviderInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ComponentName(android.content.ComponentName) Test(org.junit.Test)

Example 77 with ProviderInfo

use of android.content.pm.ProviderInfo in project robolectric by robolectric.

the class ShadowPackageManagerTest method getProviderInfo_shouldPopulatePermissionsInProviderInfos.

@Test
public void getProviderInfo_shouldPopulatePermissionsInProviderInfos() throws Exception {
    ProviderInfo providerInfo = packageManager.getProviderInfo(new ComponentName(context, "org.robolectric.shadows.testing.TestContentProvider1"), 0);
    assertThat(providerInfo.authority).isEqualTo("org.robolectric.authority1");
    assertThat(providerInfo.readPermission).isEqualTo("READ_PERMISSION");
    assertThat(providerInfo.writePermission).isEqualTo("WRITE_PERMISSION");
    assertThat(providerInfo.pathPermissions).asList().hasSize(1);
    assertThat(providerInfo.pathPermissions[0].getType()).isEqualTo(PathPermission.PATTERN_SIMPLE_GLOB);
    assertThat(providerInfo.pathPermissions[0].getPath()).isEqualTo("/path/*");
    assertThat(providerInfo.pathPermissions[0].getReadPermission()).isEqualTo("PATH_READ_PERMISSION");
    assertThat(providerInfo.pathPermissions[0].getWritePermission()).isEqualTo("PATH_WRITE_PERMISSION");
}
Also used : ProviderInfo(android.content.pm.ProviderInfo) ComponentName(android.content.ComponentName) Test(org.junit.Test)

Example 78 with ProviderInfo

use of android.content.pm.ProviderInfo in project robolectric by robolectric.

the class ShadowPackageManagerTest method addProvider.

@Test
public void addProvider() throws Exception {
    ProviderInfo providerInfo = new ProviderInfo();
    providerInfo.name = "name";
    providerInfo.packageName = "package";
    shadowOf(packageManager).addOrUpdateProvider(providerInfo);
    assertThat(packageManager.getProviderInfo(new ComponentName("package", "name"), 0)).isNotNull();
}
Also used : ProviderInfo(android.content.pm.ProviderInfo) ComponentName(android.content.ComponentName) Test(org.junit.Test)

Example 79 with ProviderInfo

use of android.content.pm.ProviderInfo in project robolectric by robolectric.

the class ContentProviderController method create.

/**
 * Create and register {@link ContentProvider} using {@link ProviderInfo} found from manifest.
 */
public ContentProviderController<T> create() {
    Context baseContext = RuntimeEnvironment.getApplication().getBaseContext();
    ComponentName componentName = createRelative(baseContext.getPackageName(), contentProvider.getClass().getName());
    ProviderInfo providerInfo = null;
    try {
        providerInfo = baseContext.getPackageManager().getProviderInfo(componentName, PackageManager.MATCH_DISABLED_COMPONENTS);
    } catch (PackageManager.NameNotFoundException e) {
        Logger.strict("Unable to find provider info for " + componentName, e);
    }
    return create(providerInfo);
}
Also used : Context(android.content.Context) ProviderInfo(android.content.pm.ProviderInfo) PackageManager(android.content.pm.PackageManager) ComponentName(android.content.ComponentName)

Example 80 with ProviderInfo

use of android.content.pm.ProviderInfo in project robolectric by robolectric.

the class ShadowContentResolverTest method registerProvider_shouldAttachProviderInfo.

@Test
public void registerProvider_shouldAttachProviderInfo() {
    ContentProvider mock = mock(ContentProvider.class);
    ProviderInfo providerInfo0 = new ProviderInfo();
    // todo: support multiple authorities
    providerInfo0.authority = "the-authority";
    providerInfo0.grantUriPermissions = true;
    mock.attachInfo(ApplicationProvider.getApplicationContext(), providerInfo0);
    mock.onCreate();
    ArgumentCaptor<ProviderInfo> captor = ArgumentCaptor.forClass(ProviderInfo.class);
    verify(mock).attachInfo(same((Application) ApplicationProvider.getApplicationContext()), captor.capture());
    ProviderInfo providerInfo = captor.getValue();
    assertThat(providerInfo.authority).isEqualTo("the-authority");
    assertThat(providerInfo.grantUriPermissions).isEqualTo(true);
}
Also used : ProviderInfo(android.content.pm.ProviderInfo) ContentProvider(android.content.ContentProvider) Application(android.app.Application) Test(org.junit.Test)

Aggregations

ProviderInfo (android.content.pm.ProviderInfo)200 ComponentName (android.content.ComponentName)43 RemoteException (android.os.RemoteException)36 ArrayList (java.util.ArrayList)33 PackageManager (android.content.pm.PackageManager)27 ResolveInfo (android.content.pm.ResolveInfo)23 ApplicationInfo (android.content.pm.ApplicationInfo)22 ServiceInfo (android.content.pm.ServiceInfo)16 Point (android.graphics.Point)16 VPackage (com.lody.virtual.server.pm.parser.VPackage)15 PackageInfo (android.content.pm.PackageInfo)14 Map (java.util.Map)14 Test (org.junit.Test)14 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)13 Uri (android.net.Uri)13 File (java.io.File)13 IPackageManager (android.content.pm.IPackageManager)12 ActivityInfo (android.content.pm.ActivityInfo)10 Before (org.junit.Before)10 Intent (android.content.Intent)8