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