Program: 192366
Project: 192366
Buggy source:
static int onShellCommand(Shell shell,String cmd){
  if (cmd == null) {
    return shell.handleDefaultCommands(cmd);
  }
  PrintWriter pw=shell.getOutPrintWriter();
  PrintWriter err=shell.getErrPrintWriter();
  try {
switch (cmd) {
case "String_Node_Str":
{
        int res=shell.parseUserPackageOp(true,err);
        if (res < 0) {
          return res;
        }
        String modeStr=shell.getNextArg();
        if (modeStr == null) {
          err.println("String_Node_Str");
          return -1;
        }
        final int mode;
switch (modeStr) {
case "String_Node_Str":
          mode=AppOpsManager.MODE_ALLOWED;
        break;
case "String_Node_Str":
      mode=AppOpsManager.MODE_ERRORED;
    break;
case "String_Node_Str":
  mode=AppOpsManager.MODE_IGNORED;
break;
case "String_Node_Str":
mode=AppOpsManager.MODE_DEFAULT;
break;
default :
err.println("String_Node_Str" + modeStr + "String_Node_Str");
return -1;
}
shell.mInterface.setMode(shell.op,shell.packageUid,shell.packageName,mode);
return 0;
}
case "String_Node_Str":
{
int res=shell.parseUserPackageOp(false,err);
if (res < 0) {
return res;
}
List<AppOpsManager.PackageOps> ops=shell.mInterface.getOpsForPackage(shell.packageUid,shell.packageName,shell.op != AppOpsManager.OP_NONE ? new int[]{shell.op} : null);
if (ops == null || ops.size() <= 0) {
pw.println("String_Node_Str");
return 0;
}
final long now=System.currentTimeMillis();
for (int i=0; i < ops.size(); i++) {
List<AppOpsManager.OpEntry> entries=ops.get(i).getOps();
for (int j=0; j < entries.size(); j++) {
AppOpsManager.OpEntry ent=entries.get(j);
pw.print(AppOpsManager.opToName(ent.getOp()));
pw.print("String_Node_Str");
switch (ent.getMode()) {
case AppOpsManager.MODE_ALLOWED:
pw.print("String_Node_Str");
break;
case AppOpsManager.MODE_IGNORED:
pw.print("String_Node_Str");
break;
case AppOpsManager.MODE_ERRORED:
pw.print("String_Node_Str");
break;
case AppOpsManager.MODE_DEFAULT:
pw.print("String_Node_Str");
break;
default :
pw.print("String_Node_Str");
pw.print(ent.getMode());
break;
}
if (ent.getTime() != 0) {
pw.print("String_Node_Str");
TimeUtils.formatDuration(now - ent.getTime(),pw);
pw.print("String_Node_Str");
}
if (ent.getRejectTime() != 0) {
pw.print("String_Node_Str");
TimeUtils.formatDuration(now - ent.getRejectTime(),pw);
pw.print("String_Node_Str");
}
if (ent.getDuration() == -1) {
pw.print("String_Node_Str");
}
 else if (ent.getDuration() != 0) {
pw.print("String_Node_Str");
TimeUtils.formatDuration(ent.getDuration(),pw);
}
pw.println();
}
}
return 0;
}
case "String_Node_Str":
{
String packageName=null;
int userId=UserHandle.USER_CURRENT;
for (String argument; (argument=shell.getNextArg()) != null; ) {
if ("String_Node_Str".equals(argument)) {
String userStr=shell.getNextArgRequired();
userId=UserHandle.parseUserArg(userStr);
}
 else {
if (packageName == null) {
packageName=argument;
}
 else {
err.println("String_Node_Str" + argument);
return -1;
}
}
}
if (userId == UserHandle.USER_CURRENT) {
userId=ActivityManager.getCurrentUser();
}
shell.mInterface.resetAllModes(userId,packageName);
pw.print("String_Node_Str");
if (userId == UserHandle.USER_ALL) {
pw.print("String_Node_Str");
}
 else {
pw.print("String_Node_Str");
pw.print(userId);
}
pw.print("String_Node_Str");
if (packageName == null) {
pw.println("String_Node_Str");
}
 else {
pw.print("String_Node_Str");
pw.println(packageName);
}
return 0;
}
case "String_Node_Str":
{
shell.mInternal.mContext.enforcePermission(android.Manifest.permission.UPDATE_APP_OPS_STATS,Binder.getCallingPid(),Binder.getCallingUid(),null);
long token=Binder.clearCallingIdentity();
try {
synchronized (shell.mInternal) {
shell.mInternal.mHandler.removeCallbacks(shell.mInternal.mWriteRunner);
}
shell.mInternal.writeState();
pw.println("String_Node_Str");
}
  finally {
Binder.restoreCallingIdentity(token);
}
return 0;
}
case "String_Node_Str":
{
shell.mInternal.mContext.enforcePermission(android.Manifest.permission.UPDATE_APP_OPS_STATS,Binder.getCallingPid(),Binder.getCallingUid(),null);
long token=Binder.clearCallingIdentity();
try {
shell.mInternal.readState();
pw.println("String_Node_Str");
}
  finally {
Binder.restoreCallingIdentity(token);
}
return 0;
}
default :
return shell.handleDefaultCommands(cmd);
}
}
 catch (RemoteException e) {
pw.println("String_Node_Str" + e);
}
return -1;
}

Fixed version (ground truth):
static int onShellCommand(Shell shell,String cmd){
  if (cmd == null) {
    return shell.handleDefaultCommands(cmd);
  }
  PrintWriter pw=shell.getOutPrintWriter();
  PrintWriter err=shell.getErrPrintWriter();
  try {
switch (cmd) {
case "String_Node_Str":
{
        int res=shell.parseUserPackageOp(true,err);
        if (res < 0) {
          return res;
        }
        String modeStr=shell.getNextArg();
        if (modeStr == null) {
          err.println("String_Node_Str");
          return -1;
        }
        final int mode=shell.strModeToMode(modeStr,err);
        if (mode < 0) {
          return -1;
        }
        shell.mInterface.setMode(shell.op,shell.packageUid,shell.packageName,mode);
        return 0;
      }
case "String_Node_Str":
{
      int res=shell.parseUserPackageOp(false,err);
      if (res < 0) {
        return res;
      }
      List<AppOpsManager.PackageOps> ops=shell.mInterface.getOpsForPackage(shell.packageUid,shell.packageName,shell.op != AppOpsManager.OP_NONE ? new int[]{shell.op} : null);
      if (ops == null || ops.size() <= 0) {
        pw.println("String_Node_Str");
        return 0;
      }
      final long now=System.currentTimeMillis();
      for (int i=0; i < ops.size(); i++) {
        List<AppOpsManager.OpEntry> entries=ops.get(i).getOps();
        for (int j=0; j < entries.size(); j++) {
          AppOpsManager.OpEntry ent=entries.get(j);
          pw.print(AppOpsManager.opToName(ent.getOp()));
          pw.print("String_Node_Str");
switch (ent.getMode()) {
case AppOpsManager.MODE_ALLOWED:
            pw.print("String_Node_Str");
          break;
case AppOpsManager.MODE_IGNORED:
        pw.print("String_Node_Str");
      break;
case AppOpsManager.MODE_ERRORED:
    pw.print("String_Node_Str");
  break;
case AppOpsManager.MODE_DEFAULT:
pw.print("String_Node_Str");
break;
default :
pw.print("String_Node_Str");
pw.print(ent.getMode());
break;
}
if (ent.getTime() != 0) {
pw.print("String_Node_Str");
TimeUtils.formatDuration(now - ent.getTime(),pw);
pw.print("String_Node_Str");
}
if (ent.getRejectTime() != 0) {
pw.print("String_Node_Str");
TimeUtils.formatDuration(now - ent.getRejectTime(),pw);
pw.print("String_Node_Str");
}
if (ent.getDuration() == -1) {
pw.print("String_Node_Str");
}
 else if (ent.getDuration() != 0) {
pw.print("String_Node_Str");
TimeUtils.formatDuration(ent.getDuration(),pw);
}
pw.println();
}
}
return 0;
}
case "String_Node_Str":
{
int res=shell.parseUserOpMode(AppOpsManager.MODE_IGNORED,err);
if (res < 0) {
return res;
}
List<AppOpsManager.PackageOps> ops=shell.mInterface.getPackagesForOps(new int[]{shell.op});
if (ops == null || ops.size() <= 0) {
pw.println("String_Node_Str");
return 0;
}
for (int i=0; i < ops.size(); i++) {
final AppOpsManager.PackageOps pkg=ops.get(i);
boolean hasMatch=false;
final List<AppOpsManager.OpEntry> entries=ops.get(i).getOps();
for (int j=0; j < entries.size(); j++) {
AppOpsManager.OpEntry ent=entries.get(j);
if (ent.getOp() == shell.op && ent.getMode() == shell.mode) {
hasMatch=true;
break;
}
}
if (hasMatch) {
pw.println(pkg.getPackageName());
}
}
return 0;
}
case "String_Node_Str":
{
String packageName=null;
int userId=UserHandle.USER_CURRENT;
for (String argument; (argument=shell.getNextArg()) != null; ) {
if ("String_Node_Str".equals(argument)) {
String userStr=shell.getNextArgRequired();
userId=UserHandle.parseUserArg(userStr);
}
 else {
if (packageName == null) {
packageName=argument;
}
 else {
err.println("String_Node_Str" + argument);
return -1;
}
}
}
if (userId == UserHandle.USER_CURRENT) {
userId=ActivityManager.getCurrentUser();
}
shell.mInterface.resetAllModes(userId,packageName);
pw.print("String_Node_Str");
if (userId == UserHandle.USER_ALL) {
pw.print("String_Node_Str");
}
 else {
pw.print("String_Node_Str");
pw.print(userId);
}
pw.print("String_Node_Str");
if (packageName == null) {
pw.println("String_Node_Str");
}
 else {
pw.print("String_Node_Str");
pw.println(packageName);
}
return 0;
}
case "String_Node_Str":
{
shell.mInternal.mContext.enforcePermission(android.Manifest.permission.UPDATE_APP_OPS_STATS,Binder.getCallingPid(),Binder.getCallingUid(),null);
long token=Binder.clearCallingIdentity();
try {
synchronized (shell.mInternal) {
shell.mInternal.mHandler.removeCallbacks(shell.mInternal.mWriteRunner);
}
shell.mInternal.writeState();
pw.println("String_Node_Str");
}
  finally {
Binder.restoreCallingIdentity(token);
}
return 0;
}
case "String_Node_Str":
{
shell.mInternal.mContext.enforcePermission(android.Manifest.permission.UPDATE_APP_OPS_STATS,Binder.getCallingPid(),Binder.getCallingUid(),null);
long token=Binder.clearCallingIdentity();
try {
shell.mInternal.readState();
pw.println("String_Node_Str");
}
  finally {
Binder.restoreCallingIdentity(token);
}
return 0;
}
default :
return shell.handleDefaultCommands(cmd);
}
}
 catch (RemoteException e) {
pw.println("String_Node_Str" + e);
}
return -1;
}