@Override
 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
   boolean isCheckin = false;
   if (args != null) {
     for (String arg : args) {
       if ("--checkin".equals(arg)) {
         isCheckin = true;
       } else if ("--reset".equals(arg)) {
         synchronized (mStats) {
           mStats.resetAllStatsLocked();
           pw.println("Battery stats reset.");
         }
       }
     }
   }
   if (isCheckin) {
     List<ApplicationInfo> apps = mContext.getPackageManager().getInstalledApplications(0);
     synchronized (mStats) {
       mStats.dumpCheckinLocked(pw, args, apps);
     }
   } else {
     synchronized (mStats) {
       mStats.dumpLocked(pw);
     }
   }
 }
  @Override
  protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
        != PackageManager.PERMISSION_GRANTED) {
      pw.println(
          "Permission Denial: can't dump BatteryStats from from pid="
              + Binder.getCallingPid()
              + ", uid="
              + Binder.getCallingUid()
              + " without permission "
              + android.Manifest.permission.DUMP);
      return;
    }

    boolean isCheckin = false;
    boolean noOutput = false;
    if (args != null) {
      for (String arg : args) {
        if ("--checkin".equals(arg)) {
          isCheckin = true;
        } else if ("--reset".equals(arg)) {
          synchronized (mStats) {
            mStats.resetAllStatsLocked();
            pw.println("Battery stats reset.");
            noOutput = true;
          }
        } else if ("--write".equals(arg)) {
          synchronized (mStats) {
            mStats.writeSyncLocked();
            pw.println("Battery stats written.");
            noOutput = true;
          }
        } else if ("-h".equals(arg)) {
          dumpHelp(pw);
          return;
        } else if ("-a".equals(arg)) {
          // fall through
        } else {
          pw.println("Unknown option: " + arg);
          dumpHelp(pw);
        }
      }
    }
    if (noOutput) {
      return;
    }
    if (isCheckin) {
      List<ApplicationInfo> apps = mContext.getPackageManager().getInstalledApplications(0);
      synchronized (mStats) {
        mStats.dumpCheckinLocked(pw, args, apps);
      }
    } else {
      synchronized (mStats) {
        mStats.dumpLocked(pw);
      }
    }
  }