Exemplo n.º 1
0
 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());
   }
 }