use of com.asksven.android.common.privateapiproxies.BatteryStatsProxy in project BetterBatteryStats by asksven.
the class StatsProvider method getCurrentOtherUsageStatList.
public ArrayList<StatElement> getCurrentOtherUsageStatList(boolean bFilter, boolean bFilterView, boolean bWidget) throws Exception {
Context ctx = BbsApplication.getAppContext();
ArrayList<StatElement> myStats = new ArrayList<StatElement>();
// List to store the other usages to
ArrayList<StatElement> myUsages = new ArrayList<StatElement>();
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
BatteryStatsProxy mStats = BatteryStatsProxy.getInstance(ctx);
long rawRealtime = SystemClock.elapsedRealtime() * 1000;
long uptime = SystemClock.uptimeMillis();
long elaspedRealtime = rawRealtime / 1000;
long batteryRealtime = 0;
try {
batteryRealtime = mStats.getBatteryRealtime(rawRealtime);
} catch (Exception e) {
Log.e(TAG, "An exception occured processing battery realtime. Message: " + e.getMessage());
Log.e(TAG, "Exception: " + Log.getStackTraceString(e));
}
int statsType = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
statsType = BatteryStatsTypesLolipop.STATS_CURRENT;
} else {
statsType = BatteryStatsTypes.STATS_CURRENT;
}
long whichRealtime = mStats.computeBatteryRealtime(rawRealtime, statsType) / 1000;
long timeBatteryUp = mStats.computeBatteryUptime(SystemClock.uptimeMillis() * 1000, statsType) / 1000;
if (CommonLogSettings.DEBUG) {
Log.i(TAG, "whichRealtime = " + whichRealtime + " batteryRealtime = " + batteryRealtime + " timeBatteryUp=" + timeBatteryUp);
}
long timeScreenOn = mStats.getScreenOnTime(batteryRealtime, statsType) / 1000;
long timePhoneOn = mStats.getPhoneOnTime(batteryRealtime, statsType) / 1000;
long timeWifiOn = 0;
long timeWifiRunning = 0;
if (sharedPrefs.getBoolean("show_other_wifi", true) && !bWidget) {
try {
timeWifiOn = mStats.getWifiOnTime(batteryRealtime, statsType) / 1000;
timeWifiRunning = mStats.getGlobalWifiRunningTime(batteryRealtime, statsType) / 1000;
} catch (BatteryInfoUnavailableException e) {
timeWifiOn = 0;
timeWifiRunning = 0;
Log.e(TAG, "A batteryinfo error occured while retrieving Wifi data");
}
}
long timeBluetoothOn = 0;
if (sharedPrefs.getBoolean("show_other_bt", true) && !bWidget) {
try {
if (Build.VERSION.SDK_INT >= 21) {
timeBluetoothOn = mStats.getBluetoothInStateTime(ctx, statsType) / 1000;
} else {
timeBluetoothOn = mStats.getBluetoothOnTime(batteryRealtime, statsType) / 1000;
}
} catch (BatteryInfoUnavailableException e) {
timeBluetoothOn = 0;
Log.e(TAG, "A batteryinfo error occured while retrieving BT data");
}
}
long interactiveTime = 0;
long powerSaveModeEnabledTime = 0;
long deviceIdleModeEnabledTime = 0;
long getDeviceIdlingTime = 0;
if (sharedPrefs.getBoolean("show_other_doze", true) && !bWidget) {
try {
if (Build.VERSION.SDK_INT >= 21) {
interactiveTime = mStats.getInteractiveTime(batteryRealtime, statsType) / 1000;
powerSaveModeEnabledTime = mStats.getPowerSaveModeEnabledTime(batteryRealtime, statsType) / 1000;
deviceIdleModeEnabledTime = mStats.getDeviceIdleModeEnabledTime(batteryRealtime, statsType) / 1000;
// these are not available anymore from SDK24 on
if (Build.VERSION.SDK_INT <= 23) {
getDeviceIdlingTime = mStats.getDeviceIdlingTime(batteryRealtime, statsType) / 1000;
} else {
// we need to switch to getDeviceIdleModeTime
}
}
} catch (BatteryInfoUnavailableException e) {
timeBluetoothOn = 0;
Log.e(TAG, "A batteryinfo error occured while retrieving doze mode data");
}
}
long syncTime = 0;
try {
if ((Build.VERSION.SDK_INT >= 21) && (Build.VERSION.SDK_INT < 27)) {
syncTime = mStats.getSyncOnTime(ctx, batteryRealtime, statsType) / 1000;
}
} catch (BatteryInfoUnavailableException e) {
Log.e(TAG, "A batteryinfo error occured while retrieving sensor and sync stats");
}
long timeNoDataConnection = 0;
long timeSignalNone = 0;
long timeSignalPoor = 0;
long timeSignalModerate = 0;
long timeSignalGood = 0;
long timeSignalGreat = 0;
if (sharedPrefs.getBoolean("show_other_signal", true)) {
try {
timeNoDataConnection = mStats.getPhoneDataConnectionTime(BatteryStatsTypes.DATA_CONNECTION_NONE, batteryRealtime, statsType) / 1000;
timeSignalNone = mStats.getPhoneSignalStrengthTime(BatteryStatsTypes.SIGNAL_STRENGTH_NONE_OR_UNKNOWN, batteryRealtime, statsType) / 1000;
timeSignalPoor = mStats.getPhoneSignalStrengthTime(BatteryStatsTypes.SIGNAL_STRENGTH_POOR, batteryRealtime, statsType) / 1000;
timeSignalModerate = mStats.getPhoneSignalStrengthTime(BatteryStatsTypes.SIGNAL_STRENGTH_MODERATE, batteryRealtime, statsType) / 1000;
timeSignalGood = mStats.getPhoneSignalStrengthTime(BatteryStatsTypes.SIGNAL_STRENGTH_GOOD, batteryRealtime, statsType) / 1000;
timeSignalGreat = mStats.getPhoneSignalStrengthTime(BatteryStatsTypes.SIGNAL_STRENGTH_GREAT, batteryRealtime, statsType) / 1000;
} catch (BatteryInfoUnavailableException e) {
timeNoDataConnection = 0;
timeSignalNone = 0;
timeSignalPoor = 0;
timeSignalModerate = 0;
timeSignalGood = 0;
timeSignalGreat = 0;
Log.e(TAG, "A batteryinfo error occured while retrieving Signal data");
}
}
long timeScreenDark = 0;
long timeScreenDim = 0;
long timeScreenMedium = 0;
long timeScreenLight = 0;
long timeScreenBright = 0;
if (sharedPrefs.getBoolean("show_other_screen_brightness", true)) {
try {
timeScreenDark = mStats.getScreenBrightnessTime(BatteryStatsTypes.SCREEN_BRIGHTNESS_DARK, batteryRealtime, statsType) / 1000;
timeScreenDim = mStats.getScreenBrightnessTime(BatteryStatsTypes.SCREEN_BRIGHTNESS_DIM, batteryRealtime, statsType) / 1000;
timeScreenMedium = mStats.getScreenBrightnessTime(BatteryStatsTypes.SCREEN_BRIGHTNESS_MEDIUM, batteryRealtime, statsType) / 1000;
timeScreenLight = mStats.getScreenBrightnessTime(BatteryStatsTypes.SCREEN_BRIGHTNESS_LIGHT, batteryRealtime, statsType) / 1000;
timeScreenBright = mStats.getScreenBrightnessTime(BatteryStatsTypes.SCREEN_BRIGHTNESS_BRIGHT, batteryRealtime, statsType) / 1000;
} catch (BatteryInfoUnavailableException e) {
timeScreenDark = 0;
timeScreenDim = 0;
timeScreenMedium = 0;
timeScreenLight = 0;
timeScreenBright = 0;
Log.e(TAG, "A batteryinfo error occured while retrieving Screen brightness data");
}
}
// deep sleep times are independent of stat type
long timeDeepSleep = (SystemClock.elapsedRealtime() - SystemClock.uptimeMillis());
Misc deepSleepUsage = new Misc("Deep Sleep", timeDeepSleep, elaspedRealtime);
if (LogSettings.DEBUG) {
Log.d(TAG, "Added Deep sleep:" + deepSleepUsage.toString());
}
if ((!bFilter) || (deepSleepUsage.getTimeOn() > 0)) {
myUsages.add(deepSleepUsage);
}
if (timeBatteryUp > 0) {
myUsages.add(new Misc(LABEL_MISC_AWAKE, timeBatteryUp - timeScreenOn, elaspedRealtime));
}
if (timeScreenOn > 0) {
myUsages.add(new Misc("Screen On", timeScreenOn, elaspedRealtime));
}
if (timePhoneOn > 0) {
myUsages.add(new Misc("Phone On", timePhoneOn, elaspedRealtime));
}
if ((timeWifiOn > 0) && (!bFilterView || sharedPrefs.getBoolean("show_other_wifi", true))) {
myUsages.add(new Misc("Wifi On", timeWifiOn, elaspedRealtime));
}
if ((timeWifiRunning > 0) && (!bFilterView || sharedPrefs.getBoolean("show_other_wifi", true))) {
myUsages.add(new Misc("Wifi Running", timeWifiRunning, elaspedRealtime));
}
if ((timeBluetoothOn > 0) && (!bFilterView || sharedPrefs.getBoolean("show_other_bt", true))) {
myUsages.add(new Misc("Bluetooth On", timeBluetoothOn, elaspedRealtime));
}
if (Build.VERSION.SDK_INT >= 6) {
if ((interactiveTime > 0) && (!bFilterView || sharedPrefs.getBoolean("show_other_doze", true))) {
myUsages.add(new Misc("Doze Interactive Time", interactiveTime, elaspedRealtime));
}
if ((powerSaveModeEnabledTime > 0) && (!bFilterView || sharedPrefs.getBoolean("show_other_doze", true))) {
myUsages.add(new Misc("Doze Powersave Time", powerSaveModeEnabledTime, elaspedRealtime));
}
if ((deviceIdleModeEnabledTime > 0) && (!bFilterView || sharedPrefs.getBoolean("show_other_doze", true))) {
myUsages.add(new Misc("Doze Idle Mode Time", deviceIdleModeEnabledTime, elaspedRealtime));
}
if ((getDeviceIdlingTime > 0) && (!bFilterView || sharedPrefs.getBoolean("show_other_doze", true))) {
myUsages.add(new Misc("Doze Idling Time", getDeviceIdlingTime, elaspedRealtime));
}
if (syncTime > 0) {
myUsages.add(new Misc("Sync", syncTime, elaspedRealtime));
}
}
if ((timeNoDataConnection > 0) && (!bFilterView || sharedPrefs.getBoolean("show_other_connection", true))) {
myUsages.add(new Misc("No Data Connection", timeNoDataConnection, elaspedRealtime));
}
if ((timeSignalNone > 0) && (!bFilterView || sharedPrefs.getBoolean("show_other_signal", true))) {
myUsages.add(new Misc("No or Unknown Signal", timeSignalNone, elaspedRealtime));
}
if ((timeSignalPoor > 0) && (!bFilterView || sharedPrefs.getBoolean("show_other_signal", true))) {
myUsages.add(new Misc("Poor Signal", timeSignalPoor, elaspedRealtime));
}
if ((timeSignalModerate > 0) && (!bFilterView || sharedPrefs.getBoolean("show_other_signal", true))) {
myUsages.add(new Misc("Moderate Signal", timeSignalModerate, elaspedRealtime));
}
if ((timeSignalGood > 0) && (!bFilterView || sharedPrefs.getBoolean("show_other_signal", true))) {
myUsages.add(new Misc("Good Signal", timeSignalGood, elaspedRealtime));
}
if ((timeSignalGreat > 0) && (!bFilterView || sharedPrefs.getBoolean("show_other_signal", true))) {
myUsages.add(new Misc("Great Signal", timeSignalGreat, elaspedRealtime));
}
if ((timeScreenDark > 0) && (!bFilterView || sharedPrefs.getBoolean("show_other_screen_brightness", true))) {
myUsages.add(new Misc("Screen dark", timeScreenDark, elaspedRealtime));
}
if ((timeScreenDim > 0) && (!bFilterView || sharedPrefs.getBoolean("show_other_screen_brightness", true))) {
myUsages.add(new Misc("Screen dimmed", timeScreenDim, elaspedRealtime));
}
if ((timeScreenMedium > 0) && (!bFilterView || sharedPrefs.getBoolean("show_other_screen_brightness", true))) {
myUsages.add(new Misc("Screen medium", timeScreenMedium, elaspedRealtime));
}
if ((timeScreenLight > 0) && (!bFilterView || sharedPrefs.getBoolean("show_other_screen_brightness", true))) {
myUsages.add(new Misc("Screen light", timeScreenLight, elaspedRealtime));
}
if ((timeScreenBright > 0) && (!bFilterView || sharedPrefs.getBoolean("show_other_screen_brightness", true))) {
myUsages.add(new Misc("Screen bright", timeScreenBright, elaspedRealtime));
}
for (int i = 0; i < myUsages.size(); i++) {
Misc usage = (Misc) myUsages.get(i);
if (LogSettings.DEBUG) {
Log.d(TAG, "Current value: " + usage.getName() + " " + usage.toString());
}
if ((!bFilter) || (usage.getTimeOn() > 0)) {
myStats.add((StatElement) usage);
}
}
return myStats;
}
use of com.asksven.android.common.privateapiproxies.BatteryStatsProxy in project BetterBatteryStats by asksven.
the class GraphActivity method getHistList.
/**
* Get the Stat to be displayed
*
* @return a List of StatElements sorted (descending)
*/
protected ArrayList<HistoryItem> getHistList() {
if (AndroidVersion.isFroyo()) {
Snackbar.make(findViewById(android.R.id.content), R.string.message_no_hist_froyo, Snackbar.LENGTH_LONG).show();
}
ArrayList<HistoryItem> myRet = new ArrayList<HistoryItem>();
BatteryStatsProxy mStats = BatteryStatsProxy.getInstance(this);
try {
myRet = mStats.getHistory(this);
} catch (Exception e) {
Log.e(TAG, "An error occured while retrieving history. No result");
}
return myRet;
}
use of com.asksven.android.common.privateapiproxies.BatteryStatsProxy in project BetterBatteryStats by asksven.
the class UpdateTextWidgetService method onHandleWork.
@Override
protected void onHandleWork(Intent intent) {
// We have received work to do. The system or framework is already
// holding a wake lock for us at this point, so we can just go.
Log.i(TAG, "onHandleWork: " + intent);
if (LogSettings.DEBUG) {
Log.d(TAG, "Service started");
}
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this.getApplicationContext());
int[] allWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
StatsProvider stats = StatsProvider.getInstance();
// make sure to flush cache
BatteryStatsProxy proxy = BatteryStatsProxy.getInstance(this);
if (proxy != null) {
proxy.invalidate();
}
if (allWidgetIds != null) {
if (allWidgetIds.length == 0) {
Log.i(TAG, "allWidgetIds was empty");
}
for (int widgetId : allWidgetIds) {
Log.i(TAG, "Update widget " + widgetId);
RemoteViews remoteViews = new RemoteViews(this.getApplicationContext().getPackageName(), R.layout.widget);
final int cellSize = 40;
int width = 3;
int height = 2;
if (Build.VERSION.SDK_INT >= 16) {
Bundle widgetOptions = appWidgetManager.getAppWidgetOptions(widgetId);
width = AppWidget.sizeToCells(widgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH) - 10);
height = AppWidget.sizeToCells(widgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT) + 10);
Log.i(TAG, "[" + widgetId + "] height=" + height + " (" + widgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT) + ")");
Log.i(TAG, "[" + widgetId + "] width=" + width + "(" + widgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH) + ")");
remoteViews = new RemoteViews(this.getPackageName(), R.layout.widget_horz);
Log.i(TAG, "[" + widgetId + "] using horizontal layout");
remoteViews = new RemoteViews(this.getPackageName(), R.layout.text_widget_horz);
}
// we change the bg color of the layout based on alpha from prefs
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
int opacity = sharedPrefs.getInt("new_widget_bg_opacity", 20);
opacity = (255 * opacity) / 100;
remoteViews.setInt(R.id.background, "setBackgroundColor", (opacity << 24) & android.graphics.Color.BLACK);
long timeAwake = 0;
long timeSince = 0;
long timeScreenOn = 0;
long timeDeepSleep = 0;
long timePWL = 0;
long timeKWL = 0;
String refFrom = sharedPrefs.getString("new_widget_default_stat_type", Reference.UNPLUGGED_REF_FILENAME);
try {
// retrieve stats
Reference currentRef = StatsProvider.getInstance().getUncachedPartialReference(0);
Reference fromRef = ReferenceStore.getReferenceByName(refFrom, this);
remoteViews.setTextViewText(R.id.stat_type, fromRef.getLabel());
ArrayList<StatElement> otherStats = stats.getOtherUsageStatList(true, fromRef, false, true, currentRef);
if ((otherStats == null) || (otherStats.size() == 1)) {
// the desired stat type is unavailable, pick the alternate one and go on with that one
refFrom = sharedPrefs.getString("widget_fallback_stat_type", Reference.UNPLUGGED_REF_FILENAME);
fromRef = ReferenceStore.getReferenceByName(refFrom, this);
otherStats = stats.getOtherUsageStatList(true, fromRef, false, true, currentRef);
}
timeSince = StatsProvider.getInstance().getSince(fromRef, currentRef);
if ((otherStats != null) && (otherStats.size() > 1)) {
Misc timeAwakeStat = (Misc) stats.getElementByKey(otherStats, StatsProvider.LABEL_MISC_AWAKE);
if (timeAwakeStat != null) {
timeAwake = timeAwakeStat.getTimeOn();
} else {
timeAwake = 0;
}
Misc timeScreenOnStat = (Misc) stats.getElementByKey(otherStats, "Screen On");
if (timeScreenOnStat != null) {
timeScreenOn = timeScreenOnStat.getTimeOn();
} else {
timeScreenOn = 0;
}
Misc deepSleepStat = ((Misc) stats.getElementByKey(otherStats, "Deep Sleep"));
if (deepSleepStat != null) {
timeDeepSleep = deepSleepStat.getTimeOn();
} else {
timeDeepSleep = 0;
}
ArrayList<StatElement> pWakelockStats = stats.getWakelockStatList(true, fromRef, 0, 0, currentRef);
timePWL = stats.sum(pWakelockStats);
ArrayList<StatElement> kWakelockStats = stats.getKernelWakelockStatList(true, fromRef, 0, 0, currentRef);
timeKWL = stats.sum(kWakelockStats);
} else {
}
} catch (Exception e) {
Log.e(TAG, "Exception: " + Log.getStackTraceString(e));
} finally {
if (LogSettings.DEBUG) {
Log.d(TAG, "Reference: " + refFrom);
Log.d(TAG, "Since: " + DateUtils.formatShort(timeSince) + " " + AppWidget.formatDuration(timeSince) + " " + timeSince);
Log.d(TAG, "Awake: " + DateUtils.formatShort(timeAwake) + " " + AppWidget.formatDuration(timeAwake) + " " + timeAwake);
Log.d(TAG, "Screen on: " + DateUtils.formatShort(timeScreenOn) + " " + AppWidget.formatDuration(timeScreenOn) + " " + timeScreenOn);
Log.d(TAG, "Deep sleep: " + DateUtils.formatShort(timeDeepSleep) + " " + AppWidget.formatDuration(timeDeepSleep) + " " + timeDeepSleep);
Log.d(TAG, "KWL: " + DateUtils.formatShort(timeKWL) + " " + AppWidget.formatDuration(timeKWL) + " " + timeKWL);
Log.d(TAG, "PWL: " + DateUtils.formatShort(timePWL) + " " + AppWidget.formatDuration(timePWL) + " " + timePWL);
}
remoteViews.setTextViewText(R.id.textViewSinceVal, AppWidget.formatDuration(timeSince));
// Show % depending on width and preferences
boolean show_pwc_only = sharedPrefs.getBoolean("widget_show_pct", false);
if (show_pwc_only) {
UpdateWidgetService.setValuesToPct(remoteViews, timeAwake, timeSince, timeScreenOn, timeDeepSleep, timePWL, timeKWL);
} else {
if (width <= 2) {
UpdateWidgetService.setValuesToDuration(remoteViews, timeAwake, timeSince, timeScreenOn, timeDeepSleep, timePWL, timeKWL);
} else {
UpdateWidgetService.setValuesToDurationAndPct(remoteViews, timeAwake, timeSince, timeScreenOn, timeDeepSleep, timePWL, timeKWL);
}
}
boolean showColor = sharedPrefs.getBoolean("text_widget_color", true);
UpdateWidgetService.setTextColor(remoteViews, showColor, this);
// tap zones
// Register an onClickListener for the graph -> refresh
Intent clickIntentRefresh = new Intent(this.getApplicationContext(), AppWidget.class);
clickIntentRefresh.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
clickIntentRefresh.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, allWidgetIds);
PendingIntent pendingIntentRefresh = PendingIntent.getBroadcast(getApplicationContext(), 0, clickIntentRefresh, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.imageViewRefresh, pendingIntentRefresh);
// Register an onClickListener for the widget -> call main activity
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage(getPackageName());
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
int stat = Integer.valueOf(sharedPrefs.getString("widget_default_stat", "0"));
i.putExtra(StatsActivity.STAT, stat);
i.putExtra(StatsActivity.STAT_TYPE_FROM, refFrom);
i.putExtra(StatsActivity.STAT_TYPE_TO, Reference.CURRENT_REF_FILENAME);
PendingIntent clickPI = PendingIntent.getActivity(this.getApplicationContext(), PI_CODE, i, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.imageView1, clickPI);
appWidgetManager.updateAppWidget(widgetId, remoteViews);
}
}
} else {
Log.i(TAG, "allWidgetIds was null");
}
Log.i(TAG, "Completed service @ " + DateUtils.formatDurationLong(SystemClock.elapsedRealtime()));
}
use of com.asksven.android.common.privateapiproxies.BatteryStatsProxy in project BetterBatteryStats by asksven.
the class StatsProvider method getCurrentWakelockStatList.
public ArrayList<StatElement> getCurrentWakelockStatList(boolean bFilter, int iPctType, int iSort) throws Exception {
Context ctx = BbsApplication.getAppContext();
ArrayList<StatElement> myStats = new ArrayList<StatElement>();
ArrayList<StatElement> myWakelocks = null;
BatteryStatsProxy mStats = BatteryStatsProxy.getInstance(ctx);
int statsType = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
statsType = BatteryStatsTypesLolipop.STATS_CURRENT;
} else {
statsType = BatteryStatsTypes.STATS_CURRENT;
}
myWakelocks = mStats.getWakelockStats(ctx, BatteryStatsTypes.WAKE_TYPE_PARTIAL, statsType, iPctType);
ArrayList<Wakelock> myRetWakelocks = new ArrayList<Wakelock>();
for (int i = 0; i < myWakelocks.size(); i++) {
Wakelock wl = (Wakelock) myWakelocks.get(i);
if ((!bFilter) || ((wl.getDuration() / 1000) > 0)) {
myRetWakelocks.add(wl);
}
}
if (LogSettings.DEBUG) {
Log.i(TAG, "Result has " + myRetWakelocks.size() + " entries");
}
// com.asksven.android.common.privateapiproxies.Walkelock.compareTo
switch(iSort) {
case 0:
// by Duration
Comparator<Wakelock> myCompTime = new Wakelock.WakelockTimeComparator();
Collections.sort(myRetWakelocks, myCompTime);
break;
case 1:
// by Count
Comparator<Wakelock> myCompCount = new Wakelock.WakelockCountComparator();
Collections.sort(myRetWakelocks, myCompCount);
break;
}
for (int i = 0; i < myRetWakelocks.size(); i++) {
myStats.add((StatElement) myRetWakelocks.get(i));
}
if (LogSettings.DEBUG) {
Log.d(TAG, "Result " + myStats.toString());
}
return myStats;
}
use of com.asksven.android.common.privateapiproxies.BatteryStatsProxy in project BetterBatteryStats by asksven.
the class StatsProvider method getCurrentSensorStatList.
public ArrayList<StatElement> getCurrentSensorStatList(boolean bFilter) throws Exception {
Context ctx = BbsApplication.getAppContext();
ArrayList<StatElement> myRetStats = new ArrayList<StatElement>();
// stop straight away of root features are disabled
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
BatteryStatsProxy mStats = BatteryStatsProxy.getInstance(ctx);
int statsType = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
statsType = BatteryStatsTypesLolipop.STATS_CURRENT;
} else {
statsType = BatteryStatsTypes.STATS_CURRENT;
}
long elapsedRealtime = SystemClock.elapsedRealtime();
ArrayList<SensorUsage> mySensorStats = mStats.getSensorStats(ctx, elapsedRealtime, statsType);
ArrayList<SensorUsage> myStats = new ArrayList<SensorUsage>();
for (int i = 0; i < mySensorStats.size(); i++) {
SensorUsage sensor = (SensorUsage) mySensorStats.get(i);
if (sensor != null) {
if ((!bFilter) || ((sensor.getTotal()) > 0)) {
myStats.add(sensor);
}
}
}
Collections.sort(myStats);
for (int i = 0; i < myStats.size(); i++) {
myRetStats.add((StatElement) myStats.get(i));
}
if (LogSettings.DEBUG) {
Log.d(TAG, "Result " + myStats.toString());
}
return myRetStats;
}
Aggregations