Merge "Fixes for sm and pm usage"

This commit is contained in:
Brian Carlstrom
2015-11-05 18:38:56 +00:00
committed by Gerrit Code Review
2 changed files with 27 additions and 52 deletions

View File

@@ -764,8 +764,7 @@ public final class Pm {
String optionData = nextOptionData(); String optionData = nextOptionData();
if (optionData == null || !isNumber(optionData)) { if (optionData == null || !isNumber(optionData)) {
System.err.println("Error: no USER_ID specified"); System.err.println("Error: no USER_ID specified");
showUsage(); return showUsage();
return 1;
} else { } else {
userId = Integer.parseInt(optionData); userId = Integer.parseInt(optionData);
} }
@@ -868,8 +867,7 @@ public final class Pm {
} }
} else { } else {
System.err.println("Error: unknown option: " + opt); System.err.println("Error: unknown option: " + opt);
showUsage(); return showUsage();
return 1;
} }
} }
@@ -877,16 +875,14 @@ public final class Pm {
final String pkg = nextArg(); final String pkg = nextArg();
if (pkg == null) { if (pkg == null) {
System.err.println("Error: no package specified."); System.err.println("Error: no package specified.");
showUsage(); return showUsage();
return 1;
} }
// State to apply; {always|ask|never|undefined}, required // State to apply; {always|ask|never|undefined}, required
final String modeString = nextArg(); final String modeString = nextArg();
if (modeString == null) { if (modeString == null) {
System.err.println("Error: no app link state specified."); System.err.println("Error: no app link state specified.");
showUsage(); return showUsage();
return 1;
} }
final int newMode; final int newMode;
@@ -955,8 +951,7 @@ public final class Pm {
} }
} else { } else {
System.err.println("Error: unknown option: " + opt); System.err.println("Error: unknown option: " + opt);
showUsage(); return showUsage();
return 1;
} }
} }
@@ -964,8 +959,7 @@ public final class Pm {
final String pkg = nextArg(); final String pkg = nextArg();
if (pkg == null) { if (pkg == null) {
System.err.println("Error: no package specified."); System.err.println("Error: no package specified.");
showUsage(); return showUsage();
return 1;
} }
try { try {
@@ -1370,8 +1364,7 @@ public final class Pm {
String optionData = nextOptionData(); String optionData = nextOptionData();
if (optionData == null || !isNumber(optionData)) { if (optionData == null || !isNumber(optionData)) {
System.err.println("Error: no USER_ID specified"); System.err.println("Error: no USER_ID specified");
showUsage(); return showUsage();
return 1;
} else { } else {
userId = Integer.parseInt(optionData); userId = Integer.parseInt(optionData);
} }
@@ -1379,8 +1372,7 @@ public final class Pm {
flags |= UserInfo.FLAG_MANAGED_PROFILE; flags |= UserInfo.FLAG_MANAGED_PROFILE;
} else { } else {
System.err.println("Error: unknown option " + opt); System.err.println("Error: unknown option " + opt);
showUsage(); return showUsage();
return 1;
} }
} }
String arg = nextArg(); String arg = nextArg();
@@ -1557,8 +1549,7 @@ public final class Pm {
String pkg = nextArg(); String pkg = nextArg();
if (pkg == null) { if (pkg == null) {
System.err.println("Error: no package specified"); System.err.println("Error: no package specified");
showUsage(); return showUsage();
return 1;
} }
if (userId == UserHandle.USER_ALL) { if (userId == UserHandle.USER_ALL) {
@@ -1626,8 +1617,7 @@ public final class Pm {
String optionData = nextOptionData(); String optionData = nextOptionData();
if (optionData == null || !isNumber(optionData)) { if (optionData == null || !isNumber(optionData)) {
System.err.println("Error: no USER_ID specified"); System.err.println("Error: no USER_ID specified");
showUsage(); return showUsage();
return 1;
} else { } else {
userId = Integer.parseInt(optionData); userId = Integer.parseInt(optionData);
} }
@@ -1636,8 +1626,7 @@ public final class Pm {
String pkg = nextArg(); String pkg = nextArg();
if (pkg == null) { if (pkg == null) {
System.err.println("Error: no package specified"); System.err.println("Error: no package specified");
showUsage(); return showUsage();
return 1;
} }
ClearDataObserver obs = new ClearDataObserver(); ClearDataObserver obs = new ClearDataObserver();
@@ -1698,8 +1687,7 @@ public final class Pm {
String optionData = nextOptionData(); String optionData = nextOptionData();
if (optionData == null || !isNumber(optionData)) { if (optionData == null || !isNumber(optionData)) {
System.err.println("Error: no USER_ID specified"); System.err.println("Error: no USER_ID specified");
showUsage(); return showUsage();
return 1;
} else { } else {
userId = Integer.parseInt(optionData); userId = Integer.parseInt(optionData);
} }
@@ -1708,8 +1696,7 @@ public final class Pm {
String pkg = nextArg(); String pkg = nextArg();
if (pkg == null) { if (pkg == null) {
System.err.println("Error: no package or component specified"); System.err.println("Error: no package or component specified");
showUsage(); return showUsage();
return 1;
} }
ComponentName cn = ComponentName.unflattenFromString(pkg); ComponentName cn = ComponentName.unflattenFromString(pkg);
if (cn == null) { if (cn == null) {
@@ -1747,8 +1734,7 @@ public final class Pm {
String optionData = nextOptionData(); String optionData = nextOptionData();
if (optionData == null || !isNumber(optionData)) { if (optionData == null || !isNumber(optionData)) {
System.err.println("Error: no USER_ID specified"); System.err.println("Error: no USER_ID specified");
showUsage(); return showUsage();
return 1;
} else { } else {
userId = Integer.parseInt(optionData); userId = Integer.parseInt(optionData);
} }
@@ -1757,8 +1743,7 @@ public final class Pm {
String pkg = nextArg(); String pkg = nextArg();
if (pkg == null) { if (pkg == null) {
System.err.println("Error: no package or component specified"); System.err.println("Error: no package or component specified");
showUsage(); return showUsage();
return 1;
} }
try { try {
mPm.setApplicationHiddenSettingAsUser(pkg, state, userId); mPm.setApplicationHiddenSettingAsUser(pkg, state, userId);
@@ -1785,14 +1770,12 @@ public final class Pm {
String pkg = nextArg(); String pkg = nextArg();
if (pkg == null) { if (pkg == null) {
System.err.println("Error: no package specified"); System.err.println("Error: no package specified");
showUsage(); return showUsage();
return 1;
} }
String perm = nextArg(); String perm = nextArg();
if (perm == null) { if (perm == null) {
System.err.println("Error: no permission specified"); System.err.println("Error: no permission specified");
showUsage(); return showUsage();
return 1;
} }
try { try {
@@ -1808,8 +1791,7 @@ public final class Pm {
return 1; return 1;
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
System.err.println("Bad argument: " + e.toString()); System.err.println("Bad argument: " + e.toString());
showUsage(); return showUsage();
return 1;
} catch (SecurityException e) { } catch (SecurityException e) {
System.err.println("Operation not allowed: " + e.toString()); System.err.println("Operation not allowed: " + e.toString());
return 1; return 1;
@@ -1826,8 +1808,7 @@ public final class Pm {
return 1; return 1;
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
System.err.println("Bad argument: " + e.toString()); System.err.println("Bad argument: " + e.toString());
showUsage(); return showUsage();
return 1;
} catch (SecurityException e) { } catch (SecurityException e) {
System.err.println("Operation not allowed: " + e.toString()); System.err.println("Operation not allowed: " + e.toString());
return 1; return 1;
@@ -1838,14 +1819,12 @@ public final class Pm {
final String permission = nextArg(); final String permission = nextArg();
if (permission == null) { if (permission == null) {
System.err.println("Error: no permission specified"); System.err.println("Error: no permission specified");
showUsage(); return showUsage();
return 1;
} }
final String enforcedRaw = nextArg(); final String enforcedRaw = nextArg();
if (enforcedRaw == null) { if (enforcedRaw == null) {
System.err.println("Error: no enforcement specified"); System.err.println("Error: no enforcement specified");
showUsage(); return showUsage();
return 1;
} }
final boolean enforced = Boolean.parseBoolean(enforcedRaw); final boolean enforced = Boolean.parseBoolean(enforcedRaw);
try { try {
@@ -1857,8 +1836,7 @@ public final class Pm {
return 1; return 1;
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
System.err.println("Bad argument: " + e.toString()); System.err.println("Bad argument: " + e.toString());
showUsage(); return showUsage();
return 1;
} catch (SecurityException e) { } catch (SecurityException e) {
System.err.println("Operation not allowed: " + e.toString()); System.err.println("Operation not allowed: " + e.toString());
return 1; return 1;
@@ -1884,8 +1862,7 @@ public final class Pm {
String size = nextArg(); String size = nextArg();
if (size == null) { if (size == null) {
System.err.println("Error: no size specified"); System.err.println("Error: no size specified");
showUsage(); return showUsage();
return 1;
} }
int len = size.length(); int len = size.length();
long multiplier = 1; long multiplier = 1;
@@ -1899,8 +1876,7 @@ public final class Pm {
multiplier = 1024L*1024L*1024L; multiplier = 1024L*1024L*1024L;
} else { } else {
System.err.println("Invalid suffix: " + c); System.err.println("Invalid suffix: " + c);
showUsage(); return showUsage();
return 1;
} }
size = size.substring(0, len-1); size = size.substring(0, len-1);
} }
@@ -1909,8 +1885,7 @@ public final class Pm {
sizeVal = Long.parseLong(size) * multiplier; sizeVal = Long.parseLong(size) * multiplier;
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
System.err.println("Error: expected number at: " + size); System.err.println("Error: expected number at: " + size);
showUsage(); return showUsage();
return 1;
} }
String volumeUuid = nextArg(); String volumeUuid = nextArg();
if ("internal".equals(volumeUuid)) { if ("internal".equals(volumeUuid)) {
@@ -1934,8 +1909,7 @@ public final class Pm {
return 1; return 1;
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
System.err.println("Bad argument: " + e.toString()); System.err.println("Bad argument: " + e.toString());
showUsage(); return showUsage();
return 1;
} catch (SecurityException e) { } catch (SecurityException e) {
System.err.println("Operation not allowed: " + e.toString()); System.err.println("Operation not allowed: " + e.toString());
return 1; return 1;

View File

@@ -42,6 +42,7 @@ public final class Sm {
} catch (Exception e) { } catch (Exception e) {
if (e instanceof IllegalArgumentException) { if (e instanceof IllegalArgumentException) {
showUsage(); showUsage();
System.exit(1);
} }
Log.e(TAG, "Error", e); Log.e(TAG, "Error", e);
System.err.println("Error: " + e); System.err.println("Error: " + e);