Exemplo n.º 1
0
 @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);
     }
   }
 }
Exemplo n.º 2
0
 public void noteBluetoothOn() {
   enforceCallingPermission();
   BluetoothHeadset headset = new BluetoothHeadset(mContext, null);
   synchronized (mStats) {
     mStats.noteBluetoothOnLocked();
     mStats.setBtHeadset(headset);
   }
 }
  @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);
      }
    }
  }
 public void onServiceConnected(int profile, BluetoothProfile proxy) {
   mBluetoothHeadset = (BluetoothHeadset) proxy;
   synchronized (mStats) {
     if (mBluetoothPendingStats) {
       mStats.noteBluetoothOnLocked();
       mStats.setBtHeadset(mBluetoothHeadset);
       mBluetoothPendingStats = false;
     }
   }
 }
 public void publish(Context context) {
   mContext = context;
   ServiceManager.addService("batteryinfo", asBinder());
   mStats.setNumSpeedSteps(new PowerProfile(mContext).getNumSpeedSteps());
   mStats.setRadioScanningTimeout(
       mContext
               .getResources()
               .getInteger(com.android.internal.R.integer.config_radioScanningTimeout)
           * 1000L);
 }
 public void noteBluetoothOn() {
   enforceCallingPermission();
   mAdapter = BluetoothAdapter.getDefaultAdapter();
   if (mAdapter != null) {
     mAdapter.getProfileProxy(
         mContext, mBluetoothProfileServiceListener, BluetoothProfile.HEADSET);
   }
   synchronized (mStats) {
     if (mBluetoothHeadset != null) {
       mStats.noteBluetoothOnLocked();
       mStats.setBtHeadset(mBluetoothHeadset);
     } else {
       mBluetoothPendingStats = true;
     }
   }
 }
 public void notePhoneState(int state) {
   enforceCallingPermission();
   int simState = TelephonyManager.getDefault().getSimState();
   synchronized (mStats) {
     mStats.notePhoneStateLocked(state, simState);
   }
 }
 public void noteBluetoothOff() {
   enforceCallingPermission();
   synchronized (mStats) {
     mBluetoothPendingStats = false;
     mStats.noteBluetoothOffLocked();
   }
   mAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
 }
 public byte[] getStatistics() {
   mContext.enforceCallingPermission(android.Manifest.permission.BATTERY_STATS, null);
   // Slog.i("foo", "SENDING BATTERY INFO:");
   // mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM));
   Parcel out = Parcel.obtain();
   mStats.writeToParcel(out, 0);
   byte[] data = out.marshall();
   out.recycle();
   return data;
 }
 public boolean isOnBattery() {
   return mStats.isOnBattery();
 }
 public void noteNetworkInterfaceType(String iface, int type) {
   enforceCallingPermission();
   synchronized (mStats) {
     mStats.noteNetworkInterfaceTypeLocked(iface, type);
   }
 }
 public void noteWifiMulticastDisabledFromSource(WorkSource ws) {
   enforceCallingPermission();
   synchronized (mStats) {
     mStats.noteWifiMulticastDisabledFromSourceLocked(ws);
   }
 }
 public void noteScanWifiLockReleasedFromSource(WorkSource ws) {
   enforceCallingPermission();
   synchronized (mStats) {
     mStats.noteScanWifiLockReleasedFromSourceLocked(ws);
   }
 }
 public void noteStartAudio(int uid) {
   enforceCallingPermission();
   synchronized (mStats) {
     mStats.noteAudioOnLocked(uid);
   }
 }
 public void shutdown() {
   Slog.w("BatteryStats", "Writing battery stats before shutdown...");
   synchronized (mStats) {
     mStats.shutdownLocked();
   }
 }
 public void noteUserActivity(int uid, int event) {
   enforceCallingPermission();
   synchronized (mStats) {
     mStats.noteUserActivityLocked(uid, event);
   }
 }
 public void noteFullWifiLockAcquired(int uid) {
   enforceCallingPermission();
   synchronized (mStats) {
     mStats.noteFullWifiLockAcquiredLocked(uid);
   }
 }
 public void notePhoneOn() {
   enforceCallingPermission();
   synchronized (mStats) {
     mStats.notePhoneOnLocked();
   }
 }
 public void notePhoneSignalStrength(SignalStrength signalStrength) {
   enforceCallingPermission();
   synchronized (mStats) {
     mStats.notePhoneSignalStrengthLocked(signalStrength);
   }
 }
 public void notePhoneDataConnectionState(int dataType, boolean hasData) {
   enforceCallingPermission();
   synchronized (mStats) {
     mStats.notePhoneDataConnectionStateLocked(dataType, hasData);
   }
 }
 public void noteWifiStopped(WorkSource ws) {
   enforceCallingPermission();
   synchronized (mStats) {
     mStats.noteWifiStoppedLocked(ws);
   }
 }
 public void noteWifiRunningChanged(WorkSource oldWs, WorkSource newWs) {
   enforceCallingPermission();
   synchronized (mStats) {
     mStats.noteWifiRunningChangedLocked(oldWs, newWs);
   }
 }
 public void noteStopVideo(int uid) {
   enforceCallingPermission();
   synchronized (mStats) {
     mStats.noteVideoOffLocked(uid);
   }
 }
 public void setBatteryState(int status, int health, int plugType, int level, int temp, int volt) {
   enforceCallingPermission();
   mStats.setBatteryState(status, health, plugType, level, temp, volt);
 }
 public long getAwakeTimePlugged() {
   mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BATTERY_STATS, null);
   return mStats.getAwakeTimePlugged();
 }
 public void noteScanWifiLockReleased(int uid) {
   enforceCallingPermission();
   synchronized (mStats) {
     mStats.noteScanWifiLockReleasedLocked(uid);
   }
 }
 public void noteInputEvent() {
   enforceCallingPermission();
   mStats.noteInputEventAtomic();
 }
 public void noteWifiMulticastDisabled(int uid) {
   enforceCallingPermission();
   synchronized (mStats) {
     mStats.noteWifiMulticastDisabledLocked(uid);
   }
 }
 public void noteFullWifiLockAcquiredFromSource(WorkSource ws) {
   enforceCallingPermission();
   synchronized (mStats) {
     mStats.noteFullWifiLockAcquiredFromSourceLocked(ws);
   }
 }
 public void noteWifiOff() {
   enforceCallingPermission();
   synchronized (mStats) {
     mStats.noteWifiOffLocked();
   }
 }