use of com.asksven.android.common.privateapiproxies.BatteryStatsProxy in project BetterBatteryStats by asksven.
the class StatsProvider method getCurrentAlarmsStatList.
public ArrayList<StatElement> getCurrentAlarmsStatList(boolean bFilter) throws Exception {
Context ctx = BbsApplication.getAppContext();
ArrayList<StatElement> myStats = new ArrayList<StatElement>();
// stop straight away of root features are disabled
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
boolean permsNotNeeded = sharedPrefs.getBoolean("ignore_system_app", false);
ArrayList<StatElement> myAlarms = null;
// use root if available as root delivers more data
if (SysUtils.hasBatteryStatsPermission(ctx) && SysUtils.hasDumpsysPermission(ctx)) {
myAlarms = AlarmsDumpsys.getAlarms();
} else if (permsNotNeeded || SysUtils.hasBatteryStatsPermission(ctx)) {
Log.i(TAG, "Accessing Alarms in API mode as dumpsys has failed");
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;
}
myAlarms = mStats.getWakeupStats(ctx, statsType);
} else {
return myStats;
}
ArrayList<Alarm> myRetAlarms = new ArrayList<Alarm>();
// if we are using custom ref. always retrieve "stats current"
// sort @see
// com.asksven.android.common.privateapiproxies.Walkelock.compareTo
long elapsedRealtime = SystemClock.elapsedRealtime();
for (int i = 0; i < myAlarms.size(); i++) {
Alarm alarm = (Alarm) myAlarms.get(i);
if (alarm != null) {
if ((!bFilter) || ((alarm.getWakeups()) > 0)) {
alarm.setTimeRunning(elapsedRealtime);
myRetAlarms.add(alarm);
}
}
}
Collections.sort(myRetAlarms);
for (int i = 0; i < myRetAlarms.size(); i++) {
myStats.add((StatElement) myRetAlarms.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 getCurrentProcessStatList.
public ArrayList<StatElement> getCurrentProcessStatList(boolean bFilter, int iSort) throws Exception {
Context ctx = BbsApplication.getAppContext();
ArrayList<StatElement> myProcesses = null;
ArrayList<Process> myRetProcesses = new ArrayList<Process>();
if (!SysUtils.hasBatteryStatsPermission(ctx)) {
myProcesses = ProcessStatsDumpsys.getProcesses(ctx);
} else {
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;
}
myProcesses = mStats.getProcessStats(ctx, statsType);
}
// add elements and recalculate the total
long total = 0;
for (int i = 0; i < myProcesses.size(); i++) {
Process ps = (Process) myProcesses.get(i);
if ((!bFilter) || ((ps.getSystemTime() + ps.getUserTime()) > 0)) {
total += ps.getSystemTime() + ps.getSystemTime();
myRetProcesses.add(ps);
}
}
// sort by Duration
Comparator<Process> myCompTime = new Process.ProcessTimeComparator();
Collections.sort(myRetProcesses, myCompTime);
if (LogSettings.DEBUG) {
Log.d(TAG, "Result " + myProcesses.toString());
}
myProcesses.clear();
for (int i = 0; i < myRetProcesses.size(); i++) {
myRetProcesses.get(i).setTotal(total);
myProcesses.add(myRetProcesses.get(i));
}
return myProcesses;
}
use of com.asksven.android.common.privateapiproxies.BatteryStatsProxy in project BetterBatteryStats by asksven.
the class StatsProvider method getCurrentNetworkUsageStatList.
public ArrayList<StatElement> getCurrentNetworkUsageStatList(boolean bFilter) throws Exception {
Context ctx = BbsApplication.getAppContext();
ArrayList<StatElement> myStats = new ArrayList<StatElement>();
// stop straight away of root features are disabled
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
ArrayList<StatElement> myNetworkStats = 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;
}
myNetworkStats = mStats.getNetworkUsageStats(ctx, statsType);
ArrayList<NetworkUsage> myRetNetworkStats = new ArrayList<NetworkUsage>();
for (int i = 0; i < myNetworkStats.size(); i++) {
NetworkUsage netStat = (NetworkUsage) myNetworkStats.get(i);
if ((!bFilter) || ((netStat.getTotalBytes()) > 0)) {
myRetNetworkStats.add(netStat);
}
}
// recalculate the total
long total = 0;
for (int i = 0; i < myRetNetworkStats.size(); i++) {
total += myRetNetworkStats.get(i).getTotalBytes();
}
Collections.sort(myRetNetworkStats);
for (int i = 0; i < myRetNetworkStats.size(); i++) {
myRetNetworkStats.get(i).setTotal(total);
myStats.add((StatElement) myRetNetworkStats.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 NewGraphActivity 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();
// Toast.makeText(this, getString(R.string.message_no_hist_froyo), Toast.LENGTH_SHORT).show();
}
ArrayList<HistoryItem> myRet = new ArrayList<HistoryItem>();
BatteryStatsProxy mStats = BatteryStatsProxy.getInstance(this);
try {
myRet = mStats.getHistory(this);
// mStats.dumpHistory(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 HistActivity 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();
// Toast.makeText(this, getString(R.string.message_no_hist_froyo), Toast.LENGTH_SHORT).show();
}
ArrayList<HistoryItem> myRet = new ArrayList<HistoryItem>();
BatteryStatsProxy mStats = BatteryStatsProxy.getInstance(this);
try {
myRet = mStats.getHistory(this);
// mStats.dumpHistory(this);
} catch (Exception e) {
Log.e(TAG, "An error occured while retrieving history. No result");
}
return myRet;
}
Aggregations