summaryrefslogtreecommitdiffstats
path: root/cmds/pm
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2012-07-12 14:46:04 -0700
committerDianne Hackborn <hackbod@google.com>2012-07-12 14:46:04 -0700
commit197a0c82a1fbf337ec0a85d36b6b89c3d6e8a0ac (patch)
tree91ddac285a05fd389615ed6fab622d65b4bf2cee /cmds/pm
parent9c469ca0ff92ffa533faed9416d725be2204ed55 (diff)
downloadframeworks_base-197a0c82a1fbf337ec0a85d36b6b89c3d6e8a0ac.zip
frameworks_base-197a0c82a1fbf337ec0a85d36b6b89c3d6e8a0ac.tar.gz
frameworks_base-197a0c82a1fbf337ec0a85d36b6b89c3d6e8a0ac.tar.bz2
Improve cleanup of file caches.
This rewrites installd's code for deleting cache files to be better: - Isn't really stupid about just deleting directories in the order they are found on the filesytem; now collects all cache files and sorts them by mod time to determine which to delete. - Also deletes cache files in /data/media and for all users. This also tweaks DeviceStorageMonitor to be a little smarter about deciding when to flush cache files, having upper and lower limits that it allows memory to get down to and then flash files to reach the higher free storage limit. This should reduce the amount that we perform flushing when starting to reach the storage limit. Finally add a new pm command to force a cache flush. Change-Id: I02229038e1ad553d1168393e5cb6d5025933271d
Diffstat (limited to 'cmds/pm')
-rw-r--r--cmds/pm/src/com/android/commands/pm/Pm.java79
1 files changed, 78 insertions, 1 deletions
diff --git a/cmds/pm/src/com/android/commands/pm/Pm.java b/cmds/pm/src/com/android/commands/pm/Pm.java
index 88a025e..4cb5270 100644
--- a/cmds/pm/src/com/android/commands/pm/Pm.java
+++ b/cmds/pm/src/com/android/commands/pm/Pm.java
@@ -157,6 +157,11 @@ public final class Pm {
return;
}
+ if ("trim-caches".equals(op)) {
+ runTrimCaches();
+ return;
+ }
+
if ("create-user".equals(op)) {
runCreateUser();
return;
@@ -1098,7 +1103,7 @@ public final class Pm {
return obs.result;
}
- class ClearDataObserver extends IPackageDataObserver.Stub {
+ static class ClearDataObserver extends IPackageDataObserver.Stub {
boolean finished;
boolean result;
@@ -1272,6 +1277,75 @@ public final class Pm {
}
}
+ static class ClearCacheObserver extends IPackageDataObserver.Stub {
+ boolean finished;
+ boolean result;
+
+ @Override
+ public void onRemoveCompleted(String packageName, boolean succeeded) throws RemoteException {
+ synchronized (this) {
+ finished = true;
+ result = succeeded;
+ notifyAll();
+ }
+ }
+
+ }
+
+ private void runTrimCaches() {
+ String size = nextArg();
+ if (size == null) {
+ System.err.println("Error: no size specified");
+ showUsage();
+ return;
+ }
+ int len = size.length();
+ long multiplier = 1;
+ if (len > 1) {
+ char c = size.charAt(len-1);
+ if (c == 'K' || c == 'k') {
+ multiplier = 1024L;
+ } else if (c == 'M' || c == 'm') {
+ multiplier = 1024L*1024L;
+ } else if (c == 'G' || c == 'g') {
+ multiplier = 1024L*1024L*1024L;
+ } else {
+ System.err.println("Invalid suffix: " + c);
+ showUsage();
+ return;
+ }
+ size = size.substring(0, len-1);
+ }
+ long sizeVal;
+ try {
+ sizeVal = Long.parseLong(size) * multiplier;
+ } catch (NumberFormatException e) {
+ System.err.println("Error: expected number at: " + size);
+ showUsage();
+ return;
+ }
+ ClearDataObserver obs = new ClearDataObserver();
+ try {
+ mPm.freeStorageAndNotify(sizeVal, obs);
+ synchronized (obs) {
+ while (!obs.finished) {
+ try {
+ obs.wait();
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ } catch (RemoteException e) {
+ System.err.println(e.toString());
+ System.err.println(PM_NOT_RUNNING_ERR);
+ } catch (IllegalArgumentException e) {
+ System.err.println("Bad argument: " + e.toString());
+ showUsage();
+ } catch (SecurityException e) {
+ System.err.println("Operation not allowed: " + e.toString());
+ }
+ }
+
/**
* Displays the package file for a package.
* @param pckg
@@ -1373,6 +1447,7 @@ public final class Pm {
System.err.println(" pm set-install-location [0/auto] [1/internal] [2/external]");
System.err.println(" pm get-install-location");
System.err.println(" pm set-permission-enforced PERMISSION [true|false]");
+ System.err.println(" pm trim-caches DESIRED_FREE_SPACE");
System.err.println("");
System.err.println("pm list packages: prints all packages, optionally only");
System.err.println(" those whose package name contains the text in FILTER. Options:");
@@ -1434,5 +1509,7 @@ public final class Pm {
System.err.println(" 0 [auto]: Let system decide the best location");
System.err.println(" 1 [internal]: Install on internal device storage");
System.err.println(" 2 [external]: Install on external media");
+ System.err.println("");
+ System.err.println("pm trim-caches: trim cache files to reach the given free space.");
}
}