Search in sources :

Example 11 with PackageStats

use of android.content.pm.PackageStats in project android_frameworks_base by DirtyUnicorns.

the class PackageManagerService method getPackageSizeInfo.

@Override
public void getPackageSizeInfo(final String packageName, int userHandle, final IPackageStatsObserver observer) {
    mContext.enforceCallingOrSelfPermission(android.Manifest.permission.GET_PACKAGE_SIZE, null);
    if (packageName == null) {
        throw new IllegalArgumentException("Attempt to get size of null packageName");
    }
    PackageStats stats = new PackageStats(packageName, userHandle);
    /*
         * Queue up an async operation since the package measurement may take a
         * little while.
         */
    Message msg = mHandler.obtainMessage(INIT_COPY);
    msg.obj = new MeasureParams(stats, observer);
    mHandler.sendMessage(msg);
}
Also used : Message(android.os.Message) PackageStats(android.content.pm.PackageStats)

Example 12 with PackageStats

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

the class PackageManagerService method getPackageSizeInfo.

@Override
public void getPackageSizeInfo(final String packageName, int userHandle, final IPackageStatsObserver observer) {
    mContext.enforceCallingOrSelfPermission(android.Manifest.permission.GET_PACKAGE_SIZE, null);
    if (packageName == null) {
        throw new IllegalArgumentException("Attempt to get size of null packageName");
    }
    PackageStats stats = new PackageStats(packageName, userHandle);
    /*
         * Queue up an async operation since the package measurement may take a
         * little while.
         */
    Message msg = mHandler.obtainMessage(INIT_COPY);
    msg.obj = new MeasureParams(stats, observer);
    mHandler.sendMessage(msg);
}
Also used : Message(android.os.Message) PackageStats(android.content.pm.PackageStats)

Example 13 with PackageStats

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

the class DefaultPackageManager method getPackageSizeInfoAsUser.

@Override
public void getPackageSizeInfoAsUser(String pkgName, int uid, final IPackageStatsObserver callback) {
    final PackageStats packageStats = packageStatsMap.get(pkgName);
    new Handler(Looper.getMainLooper()).post(new Runnable() {

        @Override
        public void run() {
            try {
                callback.onGetStatsCompleted(packageStats, packageStats != null);
            } catch (RemoteException remoteException) {
                remoteException.rethrowFromSystemServer();
            }
        }
    });
}
Also used : PackageStats(android.content.pm.PackageStats) Handler(android.os.Handler) RemoteException(android.os.RemoteException)

Example 14 with PackageStats

use of android.content.pm.PackageStats in project android_frameworks_base by crdroidandroid.

the class AppCollectorTest method testOneValidApp.

@Test
public void testOneValidApp() throws Exception {
    addApplication("com.test.app", "testuuid");
    VolumeInfo volume = new VolumeInfo("testuuid", 0, null, null);
    volume.fsUuid = "testuuid";
    AppCollector collector = new AppCollector(mContext, volume);
    PackageStats stats = new PackageStats("com.test.app");
    // Set up this to handle the asynchronous call to the PackageManager. This returns the
    // package info for the specified package.
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) {
            try {
                ((IPackageStatsObserver.Stub) invocation.getArguments()[2]).onGetStatsCompleted(stats, true);
            } catch (Exception e) {
                // We fail instead of just letting the exception fly because throwing
                // out of the callback like this on the background thread causes the test
                // runner to crash, rather than reporting the failure.
                fail();
            }
            return null;
        }
    }).when(mPm).getPackageSizeInfoAsUser(eq("com.test.app"), eq(0), any());
    // Because getPackageStats is a blocking call, we block execution of the test until the
    // call finishes. In order to finish the call, we need the above answer to execute.
    List<PackageStats> myStats = new ArrayList<>();
    CountDownLatch latch = new CountDownLatch(1);
    new Thread(new Runnable() {

        @Override
        public void run() {
            myStats.addAll(collector.getPackageStats(TIMEOUT));
            latch.countDown();
        }
    }).start();
    latch.await();
    assertThat(myStats).containsExactly(stats);
}
Also used : ArrayList(java.util.ArrayList) VolumeInfo(android.os.storage.VolumeInfo) CountDownLatch(java.util.concurrent.CountDownLatch) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PackageStats(android.content.pm.PackageStats) IPackageStatsObserver(android.content.pm.IPackageStatsObserver) Test(org.junit.Test)

Example 15 with PackageStats

use of android.content.pm.PackageStats in project android_frameworks_base by crdroidandroid.

the class AppCollectorTest method testMultipleUsersOneApp.

@Test
public void testMultipleUsersOneApp() throws Exception {
    addApplication("com.test.app", "testuuid");
    ApplicationInfo otherUsersApp = new ApplicationInfo();
    otherUsersApp.packageName = "com.test.app";
    otherUsersApp.volumeUuid = "testuuid";
    otherUsersApp.uid = 1;
    mUsers.add(new UserInfo(1, "", 0));
    VolumeInfo volume = new VolumeInfo("testuuid", 0, null, null);
    volume.fsUuid = "testuuid";
    AppCollector collector = new AppCollector(mContext, volume);
    PackageStats stats = new PackageStats("com.test.app");
    PackageStats otherStats = new PackageStats("com.test.app");
    otherStats.userHandle = 1;
    // Set up this to handle the asynchronous call to the PackageManager. This returns the
    // package info for our packages.
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) {
            try {
                ((IPackageStatsObserver.Stub) invocation.getArguments()[2]).onGetStatsCompleted(stats, true);
                // Now callback for the other uid.
                ((IPackageStatsObserver.Stub) invocation.getArguments()[2]).onGetStatsCompleted(otherStats, true);
            } catch (Exception e) {
                // We fail instead of just letting the exception fly because throwing
                // out of the callback like this on the background thread causes the test
                // runner to crash, rather than reporting the failure.
                fail();
            }
            return null;
        }
    }).when(mPm).getPackageSizeInfoAsUser(eq("com.test.app"), eq(0), any());
    // Because getPackageStats is a blocking call, we block execution of the test until the
    // call finishes. In order to finish the call, we need the above answer to execute.
    List<PackageStats> myStats = new ArrayList<>();
    CountDownLatch latch = new CountDownLatch(1);
    new Thread(new Runnable() {

        @Override
        public void run() {
            myStats.addAll(collector.getPackageStats(TIMEOUT));
            latch.countDown();
        }
    }).start();
    latch.await();
    assertThat(myStats).containsAllOf(stats, otherStats);
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo) VolumeInfo(android.os.storage.VolumeInfo) CountDownLatch(java.util.concurrent.CountDownLatch) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PackageStats(android.content.pm.PackageStats) IPackageStatsObserver(android.content.pm.IPackageStatsObserver) Test(org.junit.Test)

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