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()); } }
private void runClear() { int userId = 0; String option = nextOption(); if (option != null && option.equals("--user")) { String optionData = nextOptionData(); if (optionData == null || !isNumber(optionData)) { System.err.println("Error: no USER_ID specified"); showUsage(); return; } else { userId = Integer.parseInt(optionData); } } String pkg = nextArg(); if (pkg == null) { System.err.println("Error: no package specified"); showUsage(); return; } ClearDataObserver obs = new ClearDataObserver(); try { if (!ActivityManagerNative.getDefault().clearApplicationUserData(pkg, obs, userId)) { System.err.println("Failed"); } synchronized (obs) { while (!obs.finished) { try { obs.wait(); } catch (InterruptedException e) { } } } if (obs.result) { System.err.println("Success"); } else { System.err.println("Failed"); } } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(PM_NOT_RUNNING_ERR); } }