Merge "Added api to delete cache files for a given user" into nyc-dev

This commit is contained in:
TreeHugger Robot
2016-04-13 03:13:47 +00:00
committed by Android (Google) Code Review
6 changed files with 65 additions and 2 deletions

View File

@@ -1920,6 +1920,16 @@ public class ApplicationPackageManager extends PackageManager {
}
}
@Override
public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
IPackageDataObserver observer) {
try {
mPM.deleteApplicationCacheFilesAsUser(packageName, userId, observer);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
IPackageDataObserver observer) {

View File

@@ -387,6 +387,15 @@ interface IPackageManager {
*/
void deleteApplicationCacheFiles(in String packageName, IPackageDataObserver observer);
/**
* Delete all the cache files in an applications cache directory
* @param packageName The package name of the application whose cache
* files need to be deleted
* @param userId the user to delete application cache for
* @param observer a callback used to notify when the deletion is finished.
*/
void deleteApplicationCacheFilesAsUser(in String packageName, int userId, IPackageDataObserver observer);
/**
* Clear the user data directory of an application.
* @param packageName The package name of the application whose cache

View File

@@ -4971,6 +4971,27 @@ public abstract class PackageManager {
public abstract void deleteApplicationCacheFiles(String packageName,
IPackageDataObserver observer);
/**
* Attempts to delete the cache files associated with an application for a given user. Since
* this may take a little while, the result will be posted back to the given observer. A
* deletion will fail if the calling context lacks the
* {@link android.Manifest.permission#DELETE_CACHE_FILES} permission, if the named package
* cannot be found, or if the named package is a "system package". If {@code userId} does not
* belong to the calling user, the caller must have
* {@link android.Manifest.permission#INTERACT_ACROSS_USERS} permission.
*
* @param packageName The name of the package to delete
* @param userId the user for which the cache files needs to be deleted
* @param observer An observer callback to get notified when the cache file deletion is
* complete.
* {@link android.content.pm.IPackageDataObserver#onRemoveCompleted(String, boolean)}
* will be called when that happens. observer may be null to indicate that no
* callback is desired.
* @hide
*/
public abstract void deleteApplicationCacheFilesAsUser(String packageName, int userId,
IPackageDataObserver observer);
/**
* Free storage by deleting LRU sorted list of cache files across
* all applications. If the currently available free storage

View File

@@ -16033,16 +16033,25 @@ public class PackageManagerService extends IPackageManager.Stub {
@Override
public void deleteApplicationCacheFiles(final String packageName,
final IPackageDataObserver observer) {
final int userId = UserHandle.getCallingUserId();
deleteApplicationCacheFilesAsUser(packageName, userId, observer);
}
@Override
public void deleteApplicationCacheFilesAsUser(final String packageName, final int userId,
final IPackageDataObserver observer) {
mContext.enforceCallingOrSelfPermission(
android.Manifest.permission.DELETE_CACHE_FILES, null);
// Queue up an async operation since the package deletion may take a little while.
final int userId = UserHandle.getCallingUserId();
enforceCrossUserPermission(Binder.getCallingUid(), userId,
/* requireFullPermission= */ true, /* checkShell= */ false,
"delete application cache files");
final PackageParser.Package pkg;
synchronized (mPackages) {
pkg = mPackages.get(packageName);
}
// Queue up an async operation since the package deletion may take a little while.
mHandler.post(new Runnable() {
public void run() {
try (PackageFreezer freezer = freezePackage(packageName,

View File

@@ -691,6 +691,15 @@ public class MockPackageManager extends PackageManager {
throw new UnsupportedOperationException();
}
/**
* @hide - to match hiding in superclass
*/
@Override
public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
IPackageDataObserver observer) {
throw new UnsupportedOperationException();
}
/** {@hide} */
@Override
public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,

View File

@@ -644,6 +644,11 @@ public class BridgePackageManager extends PackageManager {
public void deleteApplicationCacheFiles(String packageName, IPackageDataObserver observer) {
}
@Override
public void deleteApplicationCacheFilesAsUser(String packageName, int userId,
IPackageDataObserver observer) {
}
@Override
public void freeStorageAndNotify(String volumeUuid, long freeStorageSize,
IPackageDataObserver observer) {