use of com.asksven.android.common.privateapiproxies.StatElement in project BetterBatteryStats by asksven.
the class StatsProvider method getNetworkUsageStatList.
/**
* Get the Kernel Wakelock Stat to be displayed
*
* @param bFilter
* defines if zero-values should be filtered out
* @return a List of Wakelocks sorted by duration (descending)
* @throws Exception
* if the API call failed
*/
public ArrayList<StatElement> getNetworkUsageStatList(boolean bFilter, Reference refFrom, Reference refTo) throws Exception {
Context ctx = BbsApplication.getAppContext();
ArrayList<StatElement> myStats = new ArrayList<StatElement>();
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
// stop straight away if no root permissions or no perms to access data directly
if (!SysUtils.hasBatteryStatsPermission(ctx)) {
myStats.add(new Notification(ctx.getString(R.string.NO_PERM_ERR)));
return myStats;
}
if ((refFrom == null) || (refTo == null)) {
myStats.add(new Notification(ctx.getString(R.string.NO_REF_ERR)));
return myStats;
}
ArrayList<StatElement> myNetworkStats = null;
if ((refTo.m_refNetworkStats != null) && (!refTo.m_refNetworkStats.isEmpty())) {
myNetworkStats = refTo.m_refNetworkStats;
} else {
myStats.add(new Notification(ctx.getString(R.string.NO_STATS)));
return myStats;
}
ArrayList<NetworkUsage> myRetNetworkStats = new ArrayList<NetworkUsage>();
// if we are using custom ref. always retrieve "stats current"
// sort @see
// com.asksven.android.common.privateapiproxies.Walkelock.compareTo
// Collections.sort(myNetworkStats);
String strCurrent = "";
String strRef = "";
String strRefDescr = "";
if (LogSettings.DEBUG) {
if (refFrom != null) {
strRefDescr = refFrom.whoAmI();
if (refFrom.m_refNetworkStats != null) {
strRef = refFrom.m_refNetworkStats.toString();
} else {
strRef = "Network stats is null";
}
} else {
strRefDescr = "Reference is null";
}
Log.d(TAG, "Processing network stats from " + refFrom.m_fileName + " to " + refTo.m_fileName);
Log.d(TAG, "Reference used: " + strRefDescr);
Log.d(TAG, "It is now " + DateUtils.now());
Log.d(TAG, "Substracting " + strRef);
Log.d(TAG, "from " + strCurrent);
}
for (int i = 0; i < myNetworkStats.size(); i++) {
NetworkUsage netStat = ((NetworkUsage) myNetworkStats.get(i)).clone();
if ((!bFilter) || ((netStat.getTotalBytes()) > 0)) {
netStat.substractFromRef(refFrom.m_refNetworkStats);
// threshold
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.StatElement in project BetterBatteryStats by asksven.
the class StatsProvider method sum.
public long sum(ArrayList<StatElement> myList) {
long ret = 0;
if (myList == null) {
Log.d(TAG, "sum was called with a null list");
return 0;
}
if (myList.size() == 0) {
Log.d(TAG, "sum was called with an empty list");
return 0;
}
for (int i = 0; i < myList.size(); i++) {
// make sure nothing goes wrong
try {
StatElement item = myList.get(i);
ret += item.getValues()[0];
} catch (Exception e) {
Log.e(TAG, "An error occcured " + e.getMessage());
GenericLogger.stackTrace(TAG, e.getStackTrace());
}
}
return ret;
}
use of com.asksven.android.common.privateapiproxies.StatElement in project BetterBatteryStats by asksven.
the class StatsProvider method getCpuStateList.
/**
* Get the CPU states to be displayed
*
* @param bFilter
* defines if zero-values should be filtered out
* @return a List of Other usages sorted by duration (descending)
* @throws Exception
* if the API call failed
*/
public ArrayList<StatElement> getCpuStateList(Reference refFrom, Reference refTo, boolean bFilter) throws Exception {
Context ctx = BbsApplication.getAppContext();
// List to store the other usages to
ArrayList<StatElement> myStates = refTo.m_refCpuStates;
ArrayList<StatElement> myStats = new ArrayList<StatElement>();
if ((refFrom == null) || (refTo == null)) {
myStats.add(new Notification(ctx.getString(R.string.NO_REF_ERR)));
return myStats;
}
if (refTo.m_refCpuStates == null) {
myStats.add(new Notification(ctx.getString(R.string.NO_STATS)));
return myStats;
}
String strCurrent = myStates.toString();
String strRef = "";
String strRefDescr = "";
if (LogSettings.DEBUG) {
if (refFrom != null) {
strRefDescr = refFrom.whoAmI();
if (refFrom.m_refCpuStates != null) {
strRef = refFrom.m_refCpuStates.toString();
} else {
strRef = "CPU States is null";
}
}
Log.d(TAG, "Processing CPU States from " + refFrom.m_fileName + " to " + refTo.m_fileName);
Log.d(TAG, "Reference used: " + strRefDescr);
Log.d(TAG, "It is now " + DateUtils.now());
Log.d(TAG, "Substracting " + strRef);
Log.d(TAG, "from " + strCurrent);
}
ArrayList<State> myResultStates = new ArrayList<State>();
for (int i = 0; i < myStates.size(); i++) {
State state = ((State) myStates.get(i)).clone();
state.substractFromRef(refFrom.m_refCpuStates);
if ((!bFilter) || ((state.m_duration) > 0)) {
myResultStates.add(state);
}
}
Collections.sort(myResultStates);
for (int i = 0; i < myResultStates.size(); i++) {
myStats.add(myResultStates.get(i));
}
return myStats;
}
use of com.asksven.android.common.privateapiproxies.StatElement in project BetterBatteryStats by asksven.
the class StatsProvider method getSensorStatList.
// 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);
//
// ArrayList<StatElement> myAlarms = 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;
// }
//
// myAlarms = mStats.getWakeupStats(ctx, statsType);
//
// 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;
//
// }
/**
* Get the Alarm Stat to be displayed
*
* @param bFilter
* defines if zero-values should be filtered out
* @return a List of Other usages sorted by duration (descending)
* @throws Exception
* if the API call failed
*/
public ArrayList<StatElement> getSensorStatList(boolean bFilter, Reference refFrom, Reference refTo) throws Exception {
Context ctx = BbsApplication.getAppContext();
ArrayList<StatElement> myStats = new ArrayList<StatElement>();
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
// to process alarms we need either root or the perms to access the private API
if (!SysUtils.hasBatteryStatsPermission(ctx)) {
myStats.add(new Notification(ctx.getString(R.string.NO_PERM_ERR)));
return myStats;
}
if ((refFrom == null) || (refTo == null)) {
myStats.add(new Notification(ctx.getString(R.string.NO_REF_ERR)));
return myStats;
}
ArrayList<StatElement> mySensorStats = null;
if ((refTo.m_refSensorUsage != null) && (!refTo.m_refSensorUsage.isEmpty())) {
mySensorStats = refTo.m_refSensorUsage;
} else {
myStats.add(new Notification(ctx.getString(R.string.NO_STATS)));
return myStats;
}
ArrayList<SensorUsage> myRetSensorStats = new ArrayList<SensorUsage>();
// if we are using custom ref. always retrieve "stats current"
// sort @see
// com.asksven.android.common.privateapiproxies.Walkelock.compareTo
String strCurrent = mySensorStats.toString();
String strRef = "";
String strRefDescr = "";
if (LogSettings.DEBUG) {
if (refFrom != null) {
strRefDescr = refFrom.whoAmI();
if (refFrom.m_refSensorUsage != null) {
strRef = refFrom.m_refSensorUsage.toString();
} else {
strRef = "SensorUsage is null";
}
} else {
strRefDescr = "Reference is null";
}
Log.d(TAG, "Processing sensor stats from " + refFrom.m_fileName + " to " + refTo.m_fileName);
Log.d(TAG, "Reference used: " + strRefDescr);
Log.d(TAG, "It is now " + DateUtils.now());
Log.d(TAG, "Substracting " + strRef);
Log.d(TAG, "from " + strCurrent);
}
for (int i = 0; i < mySensorStats.size(); i++) {
SensorUsage sensor = ((SensorUsage) mySensorStats.get(i)).clone();
if ((!bFilter) || ((sensor.getTotal()) > 0)) {
sensor.substractFromRef(refFrom.m_refSensorUsage);
// threshold
if ((!bFilter) || ((sensor.getTotal()) > 0)) {
myRetSensorStats.add(sensor);
}
}
}
Collections.sort(myRetSensorStats);
for (int i = 0; i < myRetSensorStats.size(); i++) {
myStats.add((StatElement) myRetSensorStats.get(i));
}
if (LogSettings.DEBUG) {
Log.d(TAG, "Result " + myStats.toString());
}
return myStats;
}
use of com.asksven.android.common.privateapiproxies.StatElement 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;
}
Aggregations