Search in sources :

Example 41 with PackageStats

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

the class ShadowPackageManager method addPackageNoDefaults.

/**
 * Adds a package to the {@link PackageManager}, but doesn't set any default values on it.
 *
 * Right now it will not set {@link ApplicationInfo#FLAG_INSTALLED} flag on its application, so
 * if not set explicitly, it will be treated as not installed.
 */
public void addPackageNoDefaults(PackageInfo packageInfo) {
    PackageStats packageStats = new PackageStats(packageInfo.packageName);
    addPackage(packageInfo, packageStats);
}
Also used : PackageStats(android.content.pm.PackageStats)

Example 42 with PackageStats

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

the class ShadowPackageManagerTest method whenPreconfiguredForAnotherPackage_getPackageSizeInfo_callsBackWithConfiguredValues.

@Test
// Functionality removed in O
@Config(minSdk = N, maxSdk = N_MR1)
public void whenPreconfiguredForAnotherPackage_getPackageSizeInfo_callsBackWithConfiguredValues() throws Exception {
    PackageInfo packageInfo = new PackageInfo();
    packageInfo.packageName = "org.other";
    PackageStats packageStats = new PackageStats("org.other");
    shadowOf(packageManager).addPackage(packageInfo, packageStats);
    IPackageStatsObserver packageStatsObserver = mock(IPackageStatsObserver.class);
    packageManager.getPackageSizeInfo("org.other", packageStatsObserver);
    shadowMainLooper().idle();
    verify(packageStatsObserver).onGetStatsCompleted(packageStatsCaptor.capture(), eq(true));
    assertThat(packageStatsCaptor.getValue().packageName).isEqualTo("org.other");
    assertThat(packageStatsCaptor.getValue().toString()).isEqualTo(packageStats.toString());
}
Also used : PackageInfo(android.content.pm.PackageInfo) PackageStats(android.content.pm.PackageStats) IPackageStatsObserver(android.content.pm.IPackageStatsObserver) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 43 with PackageStats

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

the class ShadowPackageManagerTest method whenPreconfigured_getPackageSizeInfo_callsBackWithConfiguredValues.

@Test
// Functionality removed in O
@Config(minSdk = N, maxSdk = N_MR1)
public void whenPreconfigured_getPackageSizeInfo_callsBackWithConfiguredValues() throws Exception {
    PackageInfo packageInfo = new PackageInfo();
    packageInfo.packageName = "org.robolectric";
    PackageStats packageStats = new PackageStats("org.robolectric");
    shadowOf(packageManager).addPackage(packageInfo, packageStats);
    IPackageStatsObserver packageStatsObserver = mock(IPackageStatsObserver.class);
    packageManager.getPackageSizeInfo("org.robolectric", packageStatsObserver);
    shadowMainLooper().idle();
    verify(packageStatsObserver).onGetStatsCompleted(packageStatsCaptor.capture(), eq(true));
    assertThat(packageStatsCaptor.getValue().packageName).isEqualTo("org.robolectric");
    assertThat(packageStatsCaptor.getValue().toString()).isEqualTo(packageStats.toString());
}
Also used : PackageInfo(android.content.pm.PackageInfo) PackageStats(android.content.pm.PackageStats) IPackageStatsObserver(android.content.pm.IPackageStatsObserver) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

PackageStats (android.content.pm.PackageStats)43 Test (org.junit.Test)20 IPackageStatsObserver (android.content.pm.IPackageStatsObserver)13 JSONArray (org.json.JSONArray)12 JSONObject (org.json.JSONObject)12 ArrayList (java.util.ArrayList)11 RemoteException (android.os.RemoteException)8 VolumeInfo (android.os.storage.VolumeInfo)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 PackageManager (android.content.pm.PackageManager)6 ArrayMap (android.util.ArrayMap)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 ApplicationInfo (android.content.pm.ApplicationInfo)5 Message (android.os.Message)5 PackageInfo (android.content.pm.PackageInfo)4 UserInfo (android.content.pm.UserInfo)3 Handler (android.os.Handler)3 ArraySet (android.util.ArraySet)3 LogRunnable (com.android.server.storage.DiskStatsLoggingService.LogRunnable)3 Method (java.lang.reflect.Method)3