Java Examples for com.android.internal.os.PowerProfile
The following java examples will help you to understand the usage of com.android.internal.os.PowerProfile. These source code samples are taken from different open source projects.
Example 1
| Project: KernelAdiutor-master File: Battery.java View source code |
public static int getCapacity(Context context) {
if (sCapacity == null) {
try {
Class<?> powerProfile = Class.forName("com.android.internal.os.PowerProfile");
Constructor constructor = powerProfile.getDeclaredConstructor(Context.class);
Object powerProInstance = constructor.newInstance(context);
Method batteryCap = powerProfile.getMethod("getBatteryCapacity");
sCapacity = Math.round((long) (double) batteryCap.invoke(powerProInstance));
} catch (Exception e) {
e.printStackTrace();
sCapacity = 0;
}
}
return sCapacity;
}Example 2
| Project: android-imf-ext-master File: BatteryStatsService.java View source code |
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);
}Example 3
| Project: Open-Battery-Saver-master File: BatteryStatsHelper.java View source code |
public void create(Bundle icicle) throws Exception {
if (icicle != null) {
mStats = sStatsXfer;
}
IBinder batteryStatsService = (IBinder) ReflectionUtils.getClassMethod("android.os.ServiceManager", "getService", String.class).invoke(null, "batterystats");
Class<?> IBatteryStats = ReflectionUtils.getClass("com.android.internal.app.IBatteryStats$Stub");
mBatteryInfo = IBatteryStats.getMethod("asInterface", IBinder.class).invoke(null, batteryStatsService);
for (Method method : mBatteryInfo.getClass().getMethods()) {
System.out.println(mBatteryInfo.getClass().getSimpleName() + " Method: " + method.getName());
}
//mBatteryInfo = IBatteryStats.Stub.asInterface(ServiceManager.getService("batterystats"));
mUm = (UserManager) mActivity.getSystemService(Context.USER_SERVICE);
mPowerProfile = ReflectionUtils.getClassConstructor("com.android.internal.os.PowerProfile", Context.class).newInstance(mActivity);
for (Method m : mPowerProfile.getClass().getMethods()) {
System.out.print(mPowerProfile.getClass().getSimpleName() + " Method: " + m.getName() + "(");
for (Class c : m.getParameterTypes()) {
System.out.print(c.getSimpleName());
System.out.print(", ");
}
System.out.println(")");
}
//mPowerProfile = new PowerProfile(mActivity);
}Example 4
| Project: sandro-master File: PowerProfileProxy.java View source code |
private void reflectPowerProfile(Context context) {
try {
powerProfileClass = Class.forName("com.android.internal.os.PowerProfile");
} catch (Exception e) {
Log.e(TAG, "reflectPowerProfile powerProfileClass Exception : " + e.toString());
return;
}
// 取得全部的构造函数
Constructor<?> cons[] = powerProfileClass.getConstructors();
try {
for (Constructor<?> con : cons) {
powerProfileInstance = (Object) con.newInstance(context);
break;
}
} catch (IllegalArgumentException e) {
Log.e(TAG, "reflectPowerProfile.newInstance.IllegalArgumentException : " + e.toString());
return;
} catch (InstantiationException e) {
Log.e(TAG, "reflectPowerProfile.newInstance.InstantiationException : " + e.toString());
return;
} catch (IllegalAccessException e) {
Log.e(TAG, "reflectPowerProfile.newInstance.IllegalAccessException : " + e.toString());
return;
} catch (InvocationTargetException e) {
Log.e(TAG, "reflectPowerProfile.newInstance.InvocationTargetException : " + e.toString());
return;
}
}Example 5
| Project: TwsPluginFramework-master File: TwsPowerSaveManagerService.java View source code |
/* init */
private void Init() {
/*
* IBinder binder = ServiceManager.getService("rootstub"); if(binder ==
* null){ Log.e(TAG, "rootstub service not exist"); } else{
* mrootCmdBinder = IRootStub.Stub.asInterface(binder); }
*/
getAvailableGovernor();
mAmm = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
mwifimgr = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
mCmgr = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
mBtAdapter = BluetoothAdapter.getDefaultAdapter();
HandlerThread hthread = new HandlerThread("TwsPowerSaveManagerService");
hthread.start();
mHandler = new ScreenStateChangeHandler(hthread.getLooper());
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
filter.addAction("tx_bluetooth_setting_state_change");
filter.addAction("BLUETOOTH_TRANSFER_FILE_REQUEST_ACTION");
filter.addAction("BLUETOOTH_TRANSFER_COMPLETED_ACTION");
filter.addAction("WIFI_DEVICE_IDLE");
filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
mContext.registerReceiver(mIntentReceiver, filter);
PowerProfile myPowerProfile = new PowerProfile(mContext);
mbatteryCapacity = Math.round(myPowerProfile.getBatteryCapacity());
filter = new IntentFilter();
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
mContext.registerReceiver(new BatteryReceiver(), filter);
filter = new IntentFilter();
filter.addAction(POWER_SAVE_ACTION);
mContext.registerReceiver(new PowerSaveRecevier(), filter);
mbPowerSaveModeEnabled = TwsSettings.System.getInt(mContext.getContentResolver(), TWS_POWER_SAVE_MODE_SETTING, 0) > 0;
mbCpuFreqEnabled = TwsSettings.System.getInt(mContext.getContentResolver(), TwsSettings.System.TWS_CPU_SETTING, 0) > 0;
mbMobiledataPowerSaveEnabled = TwsSettings.System.getInt(mContext.getContentResolver(), TwsSettings.System.TWS_POWER_SAVE_AUTO_DISABLE_MOBILEDATA, 0) > 0;
mbMobiledataUserSet = isMobileDataEnable(mContext);
mbBluetoothPowerSaveEnabled = TwsSettings.System.getInt(mContext.getContentResolver(), TwsSettings.System.TWS_AUTO_CLOSE_BT_EBABLE, 0) > 0;
mbSyncAutoSetting = ContentResolver.getMasterSyncAutomatically();
mSleepModeStatus = TwsSettings.System.getInt(mContext.getContentResolver(), TwsSettings.System.TWS_SLEEP_MODE_STATUS, 0);
updatePowerSaveModeLocked(mbPowerSaveModeEnabled);
Uri PowerSaveModeUri = TwsSettings.System.getUriFor(TwsSettings.System.TWS_POWER_SAVE_MODE_SETTING);
Uri CpuFreqUri = TwsSettings.System.getUriFor(TwsSettings.System.TWS_CPU_SETTING);
Uri AutoDisableWiFiUri = TwsSettings.System.getUriFor(TwsSettings.System.TWS_AUTO_CLOSE_WIFI_EBABLE);
Uri AutoDisableMobileDataUri = TwsSettings.System.getUriFor(TwsSettings.System.TWS_POWER_SAVE_AUTO_DISABLE_MOBILEDATA);
Uri AutoDisableBluetoothUri = TwsSettings.System.getUriFor(TwsSettings.System.TWS_AUTO_CLOSE_BT_EBABLE);
mContext.getContentResolver().registerContentObserver(PowerSaveModeUri, false, mPowerSaveModeObserver);
Uri sleepModeUri = TwsSettings.System.getUriFor(TwsSettings.System.TWS_SLEEP_MODE_STATUS);
mContext.getContentResolver().registerContentObserver(CpuFreqUri, false, mCpuFreqObserver);
mContext.getContentResolver().registerContentObserver(AutoDisableMobileDataUri, false, mAutoDisableMobileDataObserver);
mContext.getContentResolver().registerContentObserver(AutoDisableBluetoothUri, false, mAutoDisableBtObserver);
mContext.getContentResolver().registerContentObserver(sleepModeUri, false, mSleepModeObserver);
}Example 6
| Project: Cafe-master File: SystemLib.java View source code |
/**
* Battery capacity in milliAmpHour (mAh).
*/
public void processAppBatteryUsage() {
create();
SensorManager sensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
final int which = mStatsType;
final int speedSteps = mPowerProfile.getNumSpeedSteps();
final double[] powerCpuNormal = new double[speedSteps];
final long[] cpuSpeedStepTimes = new long[speedSteps];
for (int p = 0; p < speedSteps; p++) {
powerCpuNormal[p] = mPowerProfile.getAveragePower(PowerProfile.POWER_CPU_ACTIVE, p);
}
final double averageCostPerByte = getAverageDataCost();
long uSecTime = mStats.computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which);
long appWakelockTime = 0;
// BatterySipper osApp = null;
mStatsPeriod = uSecTime;
SparseArray<? extends Uid> uidStats = mStats.getUidStats();
final int NU = uidStats.size();
for (int iu = 0; iu < NU; iu++) {
Uid u = uidStats.valueAt(iu);
double power = 0;
double highestDrain = 0;
String packageWithHighestDrain = null;
//mUsageList.add(new AppUsage(u.getUid(), new double[] {power}));
Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
long cpuTime = 0;
long cpuFgTime = 0;
long wakelockTime = 0;
long gpsTime = 0;
if (processStats.size() > 0) {
// Process CPU time
for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent : processStats.entrySet()) {
Log.print("Process name = " + ent.getKey());
Uid.Proc ps = ent.getValue();
final long userTime = ps.getUserTime(which);
final long systemTime = ps.getSystemTime(which);
final long foregroundTime = ps.getForegroundTime(which);
// convert to millis
cpuFgTime += foregroundTime * 10;
// convert to millis
final long tmpCpuTime = (userTime + systemTime) * 10;
int totalTimeAtSpeeds = 0;
// Get the total first
for (int step = 0; step < speedSteps; step++) {
cpuSpeedStepTimes[step] = ps.getTimeAtCpuSpeedStep(step, which);
totalTimeAtSpeeds += cpuSpeedStepTimes[step];
}
if (totalTimeAtSpeeds == 0)
totalTimeAtSpeeds = 1;
// Then compute the ratio of time spent at each speed
double processPower = 0;
for (int step = 0; step < speedSteps; step++) {
double ratio = (double) cpuSpeedStepTimes[step] / totalTimeAtSpeeds;
processPower += ratio * tmpCpuTime * powerCpuNormal[step];
}
cpuTime += tmpCpuTime;
power += processPower;
if (packageWithHighestDrain == null || packageWithHighestDrain.startsWith("*")) {
highestDrain = processPower;
packageWithHighestDrain = ent.getKey();
} else if (highestDrain < processPower && !ent.getKey().startsWith("*")) {
highestDrain = processPower;
packageWithHighestDrain = ent.getKey();
}
}
Log.print("Max drain of " + highestDrain + " by " + packageWithHighestDrain);
}
if (cpuFgTime > cpuTime) {
if (cpuFgTime > cpuTime + 10000) {
Log.print("WARNING! Cputime is more than 10 seconds behind Foreground time");
}
// Statistics may not have been gathered yet.
cpuTime = cpuFgTime;
}
power /= 1000;
// Process wake lock usage
Map<String, ? extends BatteryStats.Uid.Wakelock> wakelockStats = u.getWakelockStats();
for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> wakelockEntry : wakelockStats.entrySet()) {
Uid.Wakelock wakelock = wakelockEntry.getValue();
// Only care about partial wake locks since full wake locks
// are canceled when the user turns the screen off.
BatteryStats.Timer timer = wakelock.getWakeTime(BatteryStats.WAKE_TYPE_PARTIAL);
if (timer != null) {
wakelockTime += timer.getTotalTimeLocked(uSecTime, which);
}
}
// convert to millis
wakelockTime /= 1000;
appWakelockTime += wakelockTime;
// Add cost of holding a wake lock
power += (wakelockTime * mPowerProfile.getAveragePower(PowerProfile.POWER_CPU_AWAKE)) / 1000;
// Add cost of data traffic
long tcpBytesReceived = u.getTcpBytesReceived(mStatsType);
long tcpBytesSent = u.getTcpBytesSent(mStatsType);
power += (tcpBytesReceived + tcpBytesSent) * averageCostPerByte;
// Add cost of keeping WIFI running.
long wifiRunningTimeMs = u.getWifiRunningTime(uSecTime, which) / 1000;
mAppWifiRunning += wifiRunningTimeMs;
power += (wifiRunningTimeMs * mPowerProfile.getAveragePower(PowerProfile.POWER_WIFI_ON)) / 1000;
// Process Sensor usage
Map<Integer, ? extends BatteryStats.Uid.Sensor> sensorStats = u.getSensorStats();
for (Map.Entry<Integer, ? extends BatteryStats.Uid.Sensor> sensorEntry : sensorStats.entrySet()) {
Uid.Sensor sensor = sensorEntry.getValue();
int sensorType = sensor.getHandle();
BatteryStats.Timer timer = sensor.getSensorTime();
long sensorTime = timer.getTotalTimeLocked(uSecTime, which) / 1000;
double multiplier = 0;
switch(sensorType) {
case Uid.Sensor.GPS:
multiplier = mPowerProfile.getAveragePower(PowerProfile.POWER_GPS_ON);
gpsTime = sensorTime;
break;
default:
android.hardware.Sensor sensorData = sensorManager.getDefaultSensor(sensorType);
if (sensorData != null) {
multiplier = sensorData.getPower();
Log.print("Got sensor " + sensorData.getName() + " with power = " + multiplier);
}
}
power += (multiplier * sensorTime) / 1000;
}
// Log.print("UID " + u.getUid() + ": power=" + power);
Log.print("PACKAGE " + packageWithHighestDrain + ": power=" + power);
// // Add the app to the list if it is consuming power
// if (power != 0 || u.getUid() == 0) {
// BatterySipper app = new BatterySipper(getActivity(), mRequestQueue, mHandler,
// packageWithHighestDrain, DrainType.APP, 0, u,
// new double[] {power});
// app.cpuTime = cpuTime;
// app.gpsTime = gpsTime;
// app.wifiRunningTime = wifiRunningTimeMs;
// app.cpuFgTime = cpuFgTime;
// app.wakeLockTime = wakelockTime;
// app.tcpBytesReceived = tcpBytesReceived;
// app.tcpBytesSent = tcpBytesSent;
// if (u.getUid() == Process.WIFI_UID) {
// mWifiSippers.add(app);
// } else if (u.getUid() == Process.BLUETOOTH_GID) {
// mBluetoothSippers.add(app);
// } else {
// mUsageList.add(app);
// }
// if (u.getUid() == 0) {
// osApp = app;
// }
// }
// if (u.getUid() == Process.WIFI_UID) {
// mWifiPower += power;
// } else if (u.getUid() == Process.BLUETOOTH_GID) {
// mBluetoothPower += power;
// } else {
// if (power > mMaxPower) mMaxPower = power;
// mTotalPower += power;
// }
// if (DEBUG) Log.i(TAG, "Added power = " + power);
}
// The device has probably been awake for longer than the screen on
// time and application wake lock time would account for. Assign
// this remainder to the OS, if possible.
// if (osApp != null) {
// long wakeTimeMillis = mStats.computeBatteryUptime(
// SystemClock.uptimeMillis() * 1000, which) / 1000;
// wakeTimeMillis -= appWakelockTime - (mStats.getScreenOnTime(
// SystemClock.elapsedRealtime(), which) / 1000);
// if (wakeTimeMillis > 0) {
// double power = (wakeTimeMillis
// * mPowerProfile.getAveragePower(PowerProfile.POWER_CPU_AWAKE)) / 1000;
// osApp.wakeLockTime += wakeTimeMillis;
// osApp.value += power;
// osApp.values[0] += power;
// if (osApp.value > mMaxPower) mMaxPower = osApp.value;
// mTotalPower += power;
// }
// }
}Example 7
| Project: folio100_frameworks_base-master File: BatteryStatsService.java View source code |
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);
}Example 8
| Project: cnAndroidDocs-master File: BatteryStatsService.java View source code |
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);
}Example 9
| Project: property-db-master File: BatteryStatsService.java View source code |
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);
}Example 10
| Project: frameworks_base_disabled-master File: BatteryStatsService.java View source code |
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);
}Example 11
| Project: android-15-master File: BatteryStatsService.java View source code |
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);
}Example 12
| Project: packages_apps_settings-master File: PowerUsageSummary.java View source code |
protected void refreshStats() {
super.refreshStats();
updatePreference(mHistPref);
cacheRemoveAllPrefs(mAppListGroup);
mAppListGroup.setOrderingAsAdded(false);
boolean addedSome = false;
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
final boolean showUnacAndOvercounted = sp.getBoolean(DevelopmentSettings.SHOW_UNAC_AND_OVERCOUNTED_STATS, false);
final PowerProfile powerProfile = mStatsHelper.getPowerProfile();
final BatteryStats stats = mStatsHelper.getStats();
final double averagePower = powerProfile.getAveragePower(PowerProfile.POWER_SCREEN_FULL);
TypedValue value = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.colorControlNormal, value, true);
int colorControl = getContext().getColor(value.resourceId);
if (averagePower >= MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP || USE_FAKE_DATA) {
final List<BatterySipper> usageList = getCoalescedUsageList(USE_FAKE_DATA ? getFakeStats() : mStatsHelper.getUsageList());
final int dischargeAmount = USE_FAKE_DATA ? 5000 : stats != null ? stats.getDischargeAmount(mStatsType) : 0;
final int numSippers = usageList.size();
for (int i = 0; i < numSippers; i++) {
final BatterySipper sipper = usageList.get(i);
if ((sipper.totalPowerMah * SECONDS_IN_HOUR) < MIN_POWER_THRESHOLD_MILLI_AMP) {
continue;
}
double totalPower = USE_FAKE_DATA ? 4000 : mStatsHelper.getTotalPower();
final double percentOfTotal = ((sipper.totalPowerMah / totalPower) * dischargeAmount);
if (((int) (percentOfTotal + .5)) < 1) {
continue;
}
if (sipper.drainType == BatterySipper.DrainType.OVERCOUNTED) {
// the largest real entry, and its percent of total is more significant
if (sipper.totalPowerMah < ((mStatsHelper.getMaxRealPower() * 2) / 3)) {
continue;
}
if (percentOfTotal < 10) {
continue;
}
if (!showUnacAndOvercounted) {
continue;
}
}
if (sipper.drainType == BatterySipper.DrainType.UNACCOUNTED) {
// the largest real entry, and its percent of total is more significant
if (sipper.totalPowerMah < (mStatsHelper.getMaxRealPower() / 2)) {
continue;
}
if (percentOfTotal < 5) {
continue;
}
if (!showUnacAndOvercounted) {
continue;
}
}
final UserHandle userHandle = new UserHandle(UserHandle.getUserId(sipper.getUid()));
final BatteryEntry entry = new BatteryEntry(getActivity(), mHandler, mUm, sipper);
final Drawable badgedIcon = mUm.getBadgedIconForUser(entry.getIcon(), userHandle);
final CharSequence contentDescription = mUm.getBadgedLabelForUser(entry.getLabel(), userHandle);
final String key = sipper.drainType == DrainType.APP ? sipper.getPackages() != null ? TextUtils.concat(sipper.getPackages()).toString() : String.valueOf(sipper.getUid()) : sipper.drainType.toString();
PowerGaugePreference pref = (PowerGaugePreference) getCachedPreference(key);
if (pref == null) {
pref = new PowerGaugePreference(getPrefContext(), badgedIcon, contentDescription, entry);
pref.setKey(key);
}
final double percentOfMax = (sipper.totalPowerMah * 100) / mStatsHelper.getMaxPower();
sipper.percent = percentOfTotal;
pref.setTitle(entry.getLabel());
pref.setOrder(i + 1);
pref.setPercent(percentOfMax, percentOfTotal);
if (sipper.uidObj != null) {
pref.setKey(Integer.toString(sipper.uidObj.getUid()));
}
if ((sipper.drainType != DrainType.APP || sipper.uidObj.getUid() == 0) && sipper.drainType != DrainType.USER) {
pref.setTint(colorControl);
}
addedSome = true;
mAppListGroup.addPreference(pref);
if (mAppListGroup.getPreferenceCount() - getCachedCount() > (MAX_ITEMS_TO_LIST + 1)) {
break;
}
}
}
if (!addedSome) {
addNotAvailableMessage();
}
removeCachedPrefs(mAppListGroup);
BatteryEntry.startRequestQueue();
}Example 13
| Project: platform_packages_apps_settings-master File: PowerUsageSummary.java View source code |
protected void refreshStats() {
super.refreshStats();
updatePreference(mHistPref);
cacheRemoveAllPrefs(mAppListGroup);
mAppListGroup.setOrderingAsAdded(false);
boolean addedSome = false;
final PowerProfile powerProfile = mStatsHelper.getPowerProfile();
final BatteryStats stats = mStatsHelper.getStats();
final double averagePower = powerProfile.getAveragePower(PowerProfile.POWER_SCREEN_FULL);
TypedValue value = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.colorControlNormal, value, true);
int colorControl = getContext().getColor(value.resourceId);
if (averagePower >= MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP || USE_FAKE_DATA) {
final List<BatterySipper> usageList = getCoalescedUsageList(USE_FAKE_DATA ? getFakeStats() : mStatsHelper.getUsageList());
final int dischargeAmount = USE_FAKE_DATA ? 5000 : stats != null ? stats.getDischargeAmount(mStatsType) : 0;
final int numSippers = usageList.size();
for (int i = 0; i < numSippers; i++) {
final BatterySipper sipper = usageList.get(i);
if ((sipper.totalPowerMah * SECONDS_IN_HOUR) < MIN_POWER_THRESHOLD_MILLI_AMP) {
continue;
}
double totalPower = USE_FAKE_DATA ? 4000 : mStatsHelper.getTotalPower();
final double percentOfTotal = ((sipper.totalPowerMah / totalPower) * dischargeAmount);
if (((int) (percentOfTotal + .5)) < 1) {
continue;
}
if (sipper.drainType == BatterySipper.DrainType.OVERCOUNTED) {
// the largest real entry, and its percent of total is more significant
if (sipper.totalPowerMah < ((mStatsHelper.getMaxRealPower() * 2) / 3)) {
continue;
}
if (percentOfTotal < 10) {
continue;
}
if ("user".equals(Build.TYPE)) {
continue;
}
}
if (sipper.drainType == BatterySipper.DrainType.UNACCOUNTED) {
// the largest real entry, and its percent of total is more significant
if (sipper.totalPowerMah < (mStatsHelper.getMaxRealPower() / 2)) {
continue;
}
if (percentOfTotal < 5) {
continue;
}
if ("user".equals(Build.TYPE)) {
continue;
}
}
final UserHandle userHandle = new UserHandle(UserHandle.getUserId(sipper.getUid()));
final BatteryEntry entry = new BatteryEntry(getActivity(), mHandler, mUm, sipper);
final Drawable badgedIcon = mUm.getBadgedIconForUser(entry.getIcon(), userHandle);
final CharSequence contentDescription = mUm.getBadgedLabelForUser(entry.getLabel(), userHandle);
final String key = sipper.drainType == DrainType.APP ? sipper.getPackages() != null ? TextUtils.concat(sipper.getPackages()).toString() : String.valueOf(sipper.getUid()) : sipper.drainType.toString();
PowerGaugePreference pref = (PowerGaugePreference) getCachedPreference(key);
if (pref == null) {
pref = new PowerGaugePreference(getPrefContext(), badgedIcon, contentDescription, entry);
pref.setKey(key);
}
final double percentOfMax = (sipper.totalPowerMah * 100) / mStatsHelper.getMaxPower();
sipper.percent = percentOfTotal;
pref.setTitle(entry.getLabel());
pref.setOrder(i + 1);
pref.setPercent(percentOfMax, percentOfTotal);
if (sipper.uidObj != null) {
pref.setKey(Integer.toString(sipper.uidObj.getUid()));
}
if ((sipper.drainType != DrainType.APP || sipper.uidObj.getUid() == 0) && sipper.drainType != DrainType.USER) {
pref.setTint(colorControl);
}
addedSome = true;
mAppListGroup.addPreference(pref);
if (mAppListGroup.getPreferenceCount() - getCachedCount() > (MAX_ITEMS_TO_LIST + 1)) {
break;
}
}
}
if (!addedSome) {
addNotAvailableMessage();
}
removeCachedPrefs(mAppListGroup);
BatteryEntry.startRequestQueue();
}Example 14
| Project: android_packages_apps_settings-master File: PowerUsageSummary.java View source code |
private void processAppUsage() {
SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
final int which = mStatsType;
final int speedSteps = mPowerProfile.getNumSpeedSteps();
final double[] powerCpuNormal = new double[speedSteps];
final long[] cpuSpeedStepTimes = new long[speedSteps];
for (int p = 0; p < speedSteps; p++) {
powerCpuNormal[p] = mPowerProfile.getAveragePower(PowerProfile.POWER_CPU_ACTIVE, p);
}
final double averageCostPerByte = getAverageDataCost();
long uSecTime = mStats.computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which);
mStatsPeriod = uSecTime;
updateStatsPeriod(uSecTime);
SparseArray<? extends Uid> uidStats = mStats.getUidStats();
final int NU = uidStats.size();
for (int iu = 0; iu < NU; iu++) {
Uid u = uidStats.valueAt(iu);
double power = 0;
double highestDrain = 0;
String packageWithHighestDrain = null;
//mUsageList.add(new AppUsage(u.getUid(), new double[] {power}));
Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
long cpuTime = 0;
long cpuFgTime = 0;
long gpsTime = 0;
if (processStats.size() > 0) {
// Process CPU time
for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent : processStats.entrySet()) {
if (DEBUG)
Log.i(TAG, "Process name = " + ent.getKey());
Uid.Proc ps = ent.getValue();
final long userTime = ps.getUserTime(which);
final long systemTime = ps.getSystemTime(which);
final long foregroundTime = ps.getForegroundTime(which);
// convert to millis
cpuFgTime += foregroundTime * 10;
// convert to millis
final long tmpCpuTime = (userTime + systemTime) * 10;
int totalTimeAtSpeeds = 0;
// Get the total first
for (int step = 0; step < speedSteps; step++) {
cpuSpeedStepTimes[step] = ps.getTimeAtCpuSpeedStep(step, which);
totalTimeAtSpeeds += cpuSpeedStepTimes[step];
}
if (totalTimeAtSpeeds == 0)
totalTimeAtSpeeds = 1;
// Then compute the ratio of time spent at each speed
double processPower = 0;
for (int step = 0; step < speedSteps; step++) {
double ratio = (double) cpuSpeedStepTimes[step] / totalTimeAtSpeeds;
processPower += ratio * tmpCpuTime * powerCpuNormal[step];
}
cpuTime += tmpCpuTime;
power += processPower;
if (highestDrain < processPower) {
highestDrain = processPower;
packageWithHighestDrain = ent.getKey();
}
}
if (DEBUG)
Log.i(TAG, "Max drain of " + highestDrain + " by " + packageWithHighestDrain);
}
if (cpuFgTime > cpuTime) {
if (DEBUG && cpuFgTime > cpuTime + 10000) {
Log.i(TAG, "WARNING! Cputime is more than 10 seconds behind Foreground time");
}
// Statistics may not have been gathered yet.
cpuTime = cpuFgTime;
}
power /= 1000;
// Add cost of data traffic
power += (u.getTcpBytesReceived(mStatsType) + u.getTcpBytesSent(mStatsType)) * averageCostPerByte;
// Process Sensor usage
Map<Integer, ? extends BatteryStats.Uid.Sensor> sensorStats = u.getSensorStats();
for (Map.Entry<Integer, ? extends BatteryStats.Uid.Sensor> sensorEntry : sensorStats.entrySet()) {
Uid.Sensor sensor = sensorEntry.getValue();
int sensorType = sensor.getHandle();
BatteryStats.Timer timer = sensor.getSensorTime();
long sensorTime = timer.getTotalTimeLocked(uSecTime, which) / 1000;
double multiplier = 0;
switch(sensorType) {
case Uid.Sensor.GPS:
multiplier = mPowerProfile.getAveragePower(PowerProfile.POWER_GPS_ON);
gpsTime = sensorTime;
break;
default:
android.hardware.Sensor sensorData = sensorManager.getDefaultSensor(sensorType);
if (sensorData != null) {
multiplier = sensorData.getPower();
if (DEBUG) {
Log.i(TAG, "Got sensor " + sensorData.getName() + " with power = " + multiplier);
}
}
}
power += (multiplier * sensorTime) / 1000;
}
// Add the app to the list if it is consuming power
if (power != 0) {
BatterySipper app = new BatterySipper(packageWithHighestDrain, DrainType.APP, 0, u, new double[] { power });
app.cpuTime = cpuTime;
app.gpsTime = gpsTime;
app.cpuFgTime = cpuFgTime;
mUsageList.add(app);
}
if (power > mMaxPower)
mMaxPower = power;
mTotalPower += power;
if (DEBUG)
Log.i(TAG, "Added power = " + power);
}
}Example 15
| Project: new_test-master File: PowerUsageSummary.java View source code |
private void processAppUsage() {
SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
final int which = mStatsType;
final int speedSteps = mPowerProfile.getNumSpeedSteps();
final double[] powerCpuNormal = new double[speedSteps];
final long[] cpuSpeedStepTimes = new long[speedSteps];
for (int p = 0; p < speedSteps; p++) {
powerCpuNormal[p] = mPowerProfile.getAveragePower(PowerProfile.POWER_CPU_ACTIVE, p);
}
final double averageCostPerByte = getAverageDataCost();
long uSecTime = mStats.computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which);
mStatsPeriod = uSecTime;
updateStatsPeriod(uSecTime);
SparseArray<? extends Uid> uidStats = mStats.getUidStats();
final int NU = uidStats.size();
for (int iu = 0; iu < NU; iu++) {
Uid u = uidStats.valueAt(iu);
double power = 0;
double highestDrain = 0;
String packageWithHighestDrain = null;
//mUsageList.add(new AppUsage(u.getUid(), new double[] {power}));
Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
long cpuTime = 0;
long cpuFgTime = 0;
long gpsTime = 0;
if (processStats.size() > 0) {
// Process CPU time
for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent : processStats.entrySet()) {
if (DEBUG)
Log.i(TAG, "Process name = " + ent.getKey());
Uid.Proc ps = ent.getValue();
final long userTime = ps.getUserTime(which);
final long systemTime = ps.getSystemTime(which);
final long foregroundTime = ps.getForegroundTime(which);
// convert to millis
cpuFgTime += foregroundTime * 10;
// convert to millis
final long tmpCpuTime = (userTime + systemTime) * 10;
int totalTimeAtSpeeds = 0;
// Get the total first
for (int step = 0; step < speedSteps; step++) {
cpuSpeedStepTimes[step] = ps.getTimeAtCpuSpeedStep(step, which);
totalTimeAtSpeeds += cpuSpeedStepTimes[step];
}
if (totalTimeAtSpeeds == 0)
totalTimeAtSpeeds = 1;
// Then compute the ratio of time spent at each speed
double processPower = 0;
for (int step = 0; step < speedSteps; step++) {
double ratio = (double) cpuSpeedStepTimes[step] / totalTimeAtSpeeds;
processPower += ratio * tmpCpuTime * powerCpuNormal[step];
}
cpuTime += tmpCpuTime;
power += processPower;
if (highestDrain < processPower) {
highestDrain = processPower;
packageWithHighestDrain = ent.getKey();
}
}
if (DEBUG)
Log.i(TAG, "Max drain of " + highestDrain + " by " + packageWithHighestDrain);
}
if (cpuFgTime > cpuTime) {
if (DEBUG && cpuFgTime > cpuTime + 10000) {
Log.i(TAG, "WARNING! Cputime is more than 10 seconds behind Foreground time");
}
// Statistics may not have been gathered yet.
cpuTime = cpuFgTime;
}
power /= 1000;
// Add cost of data traffic
power += (u.getTcpBytesReceived(mStatsType) + u.getTcpBytesSent(mStatsType)) * averageCostPerByte;
// Process Sensor usage
Map<Integer, ? extends BatteryStats.Uid.Sensor> sensorStats = u.getSensorStats();
for (Map.Entry<Integer, ? extends BatteryStats.Uid.Sensor> sensorEntry : sensorStats.entrySet()) {
Uid.Sensor sensor = sensorEntry.getValue();
int sensorType = sensor.getHandle();
BatteryStats.Timer timer = sensor.getSensorTime();
long sensorTime = timer.getTotalTimeLocked(uSecTime, which) / 1000;
double multiplier = 0;
switch(sensorType) {
case Uid.Sensor.GPS:
multiplier = mPowerProfile.getAveragePower(PowerProfile.POWER_GPS_ON);
gpsTime = sensorTime;
break;
default:
android.hardware.Sensor sensorData = sensorManager.getDefaultSensor(sensorType);
if (sensorData != null) {
multiplier = sensorData.getPower();
if (DEBUG) {
Log.i(TAG, "Got sensor " + sensorData.getName() + " with power = " + multiplier);
}
}
}
power += (multiplier * sensorTime) / 1000;
}
// Add the app to the list if it is consuming power
if (power != 0) {
BatterySipper app = new BatterySipper(packageWithHighestDrain, DrainType.APP, 0, u, new double[] { power });
app.cpuTime = cpuTime;
app.gpsTime = gpsTime;
app.cpuFgTime = cpuFgTime;
mUsageList.add(app);
}
if (power > mMaxPower)
mMaxPower = power;
mTotalPower += power;
if (DEBUG)
Log.i(TAG, "Added power = " + power);
}
}Example 16
| Project: Project-M-1-master File: PowerUsageSummary.java View source code |
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
if (icicle != null) {
mStats = sStatsXfer;
}
addPreferencesFromResource(R.xml.power_usage_summary);
mBatteryInfo = IBatteryStats.Stub.asInterface(ServiceManager.getService("batteryinfo"));
mUm = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
mAppListGroup = (PreferenceGroup) findPreference(KEY_APP_LIST);
mBatteryStatusPref = mAppListGroup.findPreference(KEY_BATTERY_STATUS);
mPowerProfile = new PowerProfile(getActivity());
setHasOptionsMenu(true);
}Example 17
| Project: android_device_softwinner_cubieboard1-master File: PowerUsageSummary.java View source code |
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
if (icicle != null) {
mStats = sStatsXfer;
}
addPreferencesFromResource(R.xml.power_usage_summary);
mBatteryInfo = IBatteryStats.Stub.asInterface(ServiceManager.getService("batteryinfo"));
mUm = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
mAppListGroup = (PreferenceGroup) findPreference(KEY_APP_LIST);
mBatteryStatusPref = mAppListGroup.findPreference(KEY_BATTERY_STATUS);
mPowerProfile = new PowerProfile(getActivity());
setHasOptionsMenu(true);
}Example 18
| Project: android_packages_apps-master File: PowerUsageSummary.java View source code |
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
if (icicle != null) {
mStats = sStatsXfer;
}
addPreferencesFromResource(R.xml.power_usage_summary);
mBatteryInfo = IBatteryStats.Stub.asInterface(ServiceManager.getService("batteryinfo"));
mAppListGroup = (PreferenceGroup) findPreference(KEY_APP_LIST);
mBatteryStatusPref = mAppListGroup.findPreference(KEY_BATTERY_STATUS);
mPowerProfile = new PowerProfile(getActivity());
setHasOptionsMenu(true);
}Example 19
| Project: android-sdk-sources-for-api-level-23-master File: BatteryStatsService.java View source code |
public void publish(Context context) {
mContext = context;
ServiceManager.addService(BatteryStats.SERVICE_NAME, asBinder());
mStats.setNumSpeedSteps(new PowerProfile(mContext).getNumSpeedSteps());
mStats.setRadioScanningTimeout(mContext.getResources().getInteger(com.android.internal.R.integer.config_radioScanningTimeout) * 1000L);
mStats.setPowerProfile(new PowerProfile(context));
}Example 20
| Project: platform_frameworks_base-master File: BatteryStatsService.java View source code |
public void publish(Context context) {
mContext = context;
mStats.setRadioScanningTimeout(mContext.getResources().getInteger(com.android.internal.R.integer.config_radioScanningTimeout) * 1000L);
mStats.setPowerProfile(new PowerProfile(context));
ServiceManager.addService(BatteryStats.SERVICE_NAME, asBinder());
}Example 21
| Project: android_frameworks_base-master File: BatteryStatsService.java View source code |
public void publish(Context context) {
mContext = context;
mStats.setRadioScanningTimeout(mContext.getResources().getInteger(com.android.internal.R.integer.config_radioScanningTimeout) * 1000L);
mStats.setPowerProfile(new PowerProfile(context));
ServiceManager.addService(BatteryStats.SERVICE_NAME, asBinder());
}