use of com.asksven.android.common.privateapiproxies.StatElement in project BetterBatteryStats by asksven.
the class StatsProvider method getStatList.
/**
* Get the Stat to be displayed
*
* @return a List of StatElements sorted (descending)
*/
public ArrayList<StatElement> getStatList(int iStat, String refFromName, int iSort, String refToName) throws Exception {
Context ctx = BbsApplication.getAppContext();
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(BbsApplication.getAppContext());
boolean bFilterStats = sharedPrefs.getBoolean("filter_data", true);
boolean developerMode = sharedPrefs.getBoolean("developer", false);
Reference refFrom = ReferenceStore.getReferenceByName(refFromName, ctx);
Reference refTo = ReferenceStore.getReferenceByName(refToName, ctx);
if ((refFrom == null) || (refTo == null) || (refFromName == null) || (refToName == null) || (refFromName.equals("")) || (refToName.equals(""))) {
Log.e(TAG, "Reference from or to are empty: (" + refFromName + ", " + refToName + ")");
return null;
}
if (refFrom.equals(refToName)) {
Toast.makeText(ctx, ctx.getString(R.string.message_identical_references, refFromName, refToName), Toast.LENGTH_LONG).show();
}
int iPctType = 0;
if ((!developerMode) && (this.getIsCharging(ctx))) {
ArrayList<StatElement> myRet = new ArrayList<StatElement>();
myRet.add(new Notification(ctx.getString(R.string.NO_STATS_WHEN_CHARGING)));
return myRet;
}
switch(iStat) {
case 0:
return getOtherUsageStatList(bFilterStats, refFrom, true, false, refTo);
case 1:
return getKernelWakelockStatList(bFilterStats, refFrom, iPctType, iSort, refTo);
case 2:
return getWakelockStatList(bFilterStats, refFrom, iPctType, iSort, refTo);
case 3:
return getAlarmsStatList(bFilterStats, refFrom, refTo);
case 4:
return getNetworkUsageStatList(bFilterStats, refFrom, refTo);
case 5:
return getCpuStateList(refFrom, refTo, bFilterStats);
case 6:
return getProcessStatList(bFilterStats, refFrom, iSort, refTo);
case 7:
return getSensorStatList(bFilterStats, refFrom, refTo);
}
return new ArrayList<StatElement>();
}
use of com.asksven.android.common.privateapiproxies.StatElement in project BetterBatteryStats by asksven.
the class StatsProvider method getAlarmsStatList.
/**
* 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> getAlarmsStatList(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> myAlarms = null;
// get the current value
if ((refTo.m_refAlarms != null) && (!refTo.m_refAlarms.isEmpty())) {
myAlarms = refTo.m_refAlarms;
} else {
myStats.add(new Notification(ctx.getString(R.string.NO_STATS)));
return myStats;
}
// Collections.sort(myAlarms);
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
String strCurrent = myAlarms.toString();
String strRef = "";
String strRefDescr = "";
if (LogSettings.DEBUG) {
if (refFrom != null) {
strRefDescr = refFrom.whoAmI();
if (refFrom.m_refAlarms != null) {
strRef = refFrom.m_refAlarms.toString();
} else {
strRef = "Alarms is null";
}
} else {
strRefDescr = "Reference is null";
}
Log.d(TAG, "Processing alarms 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 < myAlarms.size(); i++) {
Alarm alarm = ((Alarm) myAlarms.get(i)).clone();
if ((!bFilter) || ((alarm.getWakeups()) > 0)) {
alarm.substractFromRef(refFrom.m_refAlarms);
// threshold
if ((!bFilter) || ((alarm.getWakeups()) > 0)) {
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.StatElement in project BetterBatteryStats by asksven.
the class StatsAdapter method getView.
public View getView(int position, View convertView, ViewGroup viewGroup) {
StatElement entry = m_listData.get(position);
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.m_context);
if (LogSettings.DEBUG) {
Log.i(TAG, "Values: " + entry.getVals());
}
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) m_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.stat_row, null);
}
final float scale = this.m_context.getResources().getDisplayMetrics().density;
TextView tvName = (TextView) convertView.findViewById(R.id.TextViewName);
// ///////////////////////////////////////
// we do some stuff here to handle settings about font size and thumbnail size
String fontSize = sharedPrefs.getString("medium_font_size", "16");
int mediumFontSize = Integer.parseInt(fontSize);
// we need to change "since" fontsize
tvName.setTextSize(TypedValue.COMPLEX_UNIT_SP, mediumFontSize);
// We need to handle an exception here: Sensors do not have a name so we use the fqn instead
if (entry instanceof SensorUsage) {
tvName.setText(entry.getFqn(UidNameResolver.getInstance()));
} else {
tvName.setText(entry.getName());
}
TextView tvFqn = (TextView) convertView.findViewById(R.id.TextViewFqn);
tvFqn.setText(entry.getFqn(UidNameResolver.getInstance()));
TextView tvData = (TextView) convertView.findViewById(R.id.TextViewData);
// for alarms the values is wakeups per hour so we need to take the time as reference for the text
if (entry instanceof Alarm) {
tvData.setText(entry.getData((long) m_timeSince));
} else {
tvData.setText(entry.getData((long) m_maxValue));
}
LinearLayout myFqnLayout = (LinearLayout) convertView.findViewById(R.id.LinearLayoutFqn);
LinearLayout myRow = (LinearLayout) convertView.findViewById(R.id.LinearLayoutEntry);
// long press for "copy to clipboard"
convertView.setOnLongClickListener(new OnItemLongClickListener(position));
GraphablePie gauge = (GraphablePie) convertView.findViewById(R.id.Gauge);
if (entry instanceof NetworkUsage) {
gauge.setValue(entry.getValues()[0], ((NetworkUsage) entry).getTotal());
} else {
double max = m_maxValue;
// avoid rounding errors leading to values > 100 %
if (entry.getValues()[0] > max) {
max = entry.getValues()[0];
Log.i(TAG, "Upping gauge max to " + max);
}
gauge.setValue(entry.getValues()[0], max);
}
ImageView iconView = (ImageView) convertView.findViewById(R.id.icon);
LinearLayout iconLayout = (LinearLayout) convertView.findViewById(R.id.LayoutIcon);
// show / hide fqn text
if ((entry instanceof Process) || (entry instanceof State) || (entry instanceof Misc) || (entry instanceof NativeKernelWakelock) || (entry instanceof Alarm) || (entry instanceof SensorUsage)) {
myFqnLayout.setVisibility(View.GONE);
} else {
myFqnLayout.setVisibility(View.VISIBLE);
}
// show / hide package icons (we show / hide the whole layout as it contains a margin that must be hidded as well
if ((entry instanceof NativeKernelWakelock) || (entry instanceof State) || (entry instanceof Misc)) {
iconView.setVisibility(View.GONE);
} else {
iconView.setVisibility(View.VISIBLE);
iconView.setImageDrawable(entry.getIcon(UidNameResolver.getInstance()));
// set a click listener for the list
iconView.setOnClickListener(new OnPackageClickListener(position));
}
// add on click listener for the list entry if details are availble
if ((entry instanceof Alarm) || (entry instanceof NativeKernelWakelock) || (entry instanceof SensorUsage)) {
convertView.setOnClickListener(new OnItemClickListener(position));
}
return convertView;
}
use of com.asksven.android.common.privateapiproxies.StatElement in project BetterBatteryStats by asksven.
the class AlarmsDumpsys method getAlarmsPriorTo_4_2_2.
/**
* Returns a list of alarm value objects
* @return
* @throws Exception
*/
protected static ArrayList<StatElement> getAlarmsPriorTo_4_2_2(List<String> res) {
ArrayList<StatElement> myAlarms = null;
long nTotalCount = 0;
// if (res.getSuccess())
if ((res != null) && (res.size() != 0)) {
// String strRes = res.getResultLine();
if (!res.contains("Permission Denial")) {
Pattern begin = Pattern.compile("Alarm Stats");
boolean bParsing = false;
// ArrayList<String> myRes = res.getResult(); // getTestData();
// we are looking for multiline entries in the format
// ' <package name>
// ' <time> ms running, <number> wakeups
// ' <number> alarms: act=<intent name> flg=<flag> (repeating 1..n times)
Pattern packagePattern = Pattern.compile("\\s\\s([a-z][a-zA-Z0-9\\.]+)");
Pattern timePattern = Pattern.compile("\\s\\s(\\d+)ms running, (\\d+) wakeups");
Pattern numberPattern = Pattern.compile("\\s\\s(\\d+) alarms: (flg=[a-z0-9]+\\s){0,1}(act|cmp)=([A-Za-z0-9\\-\\_\\.\\{\\}\\/\\{\\}\\$]+)");
myAlarms = new ArrayList<StatElement>();
Alarm myAlarm = null;
// process the file
for (int i = 0; i < res.size(); i++) {
// skip till start mark found
if (bParsing) {
// parse the alarms by block
String line = res.get(i);
Matcher mPackage = packagePattern.matcher(line);
Matcher mTime = timePattern.matcher(line);
Matcher mNumber = numberPattern.matcher(line);
// first line
if (mPackage.find()) {
try {
// if there was a previous Alarm populated store it
if (myAlarm != null) {
myAlarms.add(myAlarm);
}
// we are interested in the first token
String strPackageName = mPackage.group(1);
myAlarm = new Alarm(strPackageName);
} catch (Exception e) {
Log.e(TAG, "Error: parsing error in package line (" + line + ")");
}
}
// second line
if (mTime.find()) {
try {
// we are interested in the second token
String strWakeups = mTime.group(2);
long nWakeups = Long.parseLong(strWakeups);
if (myAlarm == null) {
Log.e(TAG, "Error: time line found but without alarm object (" + line + ")");
} else {
myAlarm.setWakeups(nWakeups);
nTotalCount += nWakeups;
}
} catch (Exception e) {
Log.e(TAG, "Error: parsing error in time line (" + line + ")");
}
}
// third line (and following till next package
if (mNumber.find()) {
try {
// we are interested in the first and second token
String strNumber = mNumber.group(1);
String strIntent = mNumber.group(4);
long nNumber = Long.parseLong(strNumber);
if (myAlarm == null) {
Log.e(TAG, "Error: number line found but without alarm object (" + line + ")");
} else {
myAlarm.addItem(nNumber, strIntent);
}
} catch (Exception e) {
Log.e(TAG, "Error: parsing error in number line (" + line + ")");
}
}
} else {
// look for beginning
Matcher line = begin.matcher(res.get(i));
if (line.find()) {
bParsing = true;
}
}
}
// the last populated alarms has not been added to the list yet
myAlarms.add(myAlarm);
} else {
myAlarms = new ArrayList<StatElement>();
Alarm myAlarm = new Alarm(PERMISSION_DENIED);
myAlarm.setWakeups(1);
myAlarms.add(myAlarm);
}
} else {
myAlarms = new ArrayList<StatElement>();
Alarm myAlarm = new Alarm(PERMISSION_DENIED);
myAlarm.setWakeups(1);
myAlarms.add(myAlarm);
}
for (int i = 0; i < myAlarms.size(); i++) {
((Alarm) myAlarms.get(i)).setTotalCount(nTotalCount);
}
return myAlarms;
}
use of com.asksven.android.common.privateapiproxies.StatElement in project BetterBatteryStats by asksven.
the class AlarmsDumpsys method getAlarmsFrom_4_3.
protected static ArrayList<StatElement> getAlarmsFrom_4_3(List<String> res) {
ArrayList<StatElement> myAlarms = null;
long nTotalCount = 0;
if ((res != null) && (res.size() != 0)) {
Pattern begin = Pattern.compile("Alarm Stats");
boolean bParsing = false;
// we are looking for multiline entries in the format
// ' <package name> +<time>ms running, <number> wakeups
// ' +<time>ms <number> wakes <number> alarms: act=<intern> (repeating 1..n times)
Pattern packagePattern = Pattern.compile("\\s\\s([a-z][a-zA-Z0-9\\.]+)\\s\\+(.*), (\\d+) wakeups:");
Pattern numberPattern = Pattern.compile("\\s\\s\\s\\s\\+([0-9a-z]+)ms (\\d+) wakes (\\d+) alarms: (act|cmp)=(.*)");
myAlarms = new ArrayList<StatElement>();
Alarm myAlarm = null;
// process the file
for (int i = 0; i < res.size(); i++) {
// skip till start mark found
if (bParsing) {
// parse the alarms by block
String line = res.get(i);
Matcher mPackage = packagePattern.matcher(line);
Matcher mNumber = numberPattern.matcher(line);
// first line
if (mPackage.find()) {
try {
// if there was a previous Alarm populated store it
if (myAlarm != null) {
myAlarms.add(myAlarm);
}
// we are interested in the first token
String strPackageName = mPackage.group(1);
myAlarm = new Alarm(strPackageName);
String strWakeups = mPackage.group(3);
long nWakeups = Long.parseLong(strWakeups);
myAlarm.setWakeups(nWakeups);
nTotalCount += nWakeups;
} catch (Exception e) {
Log.e(TAG, "Error: parsing error in package line (" + line + ")");
}
}
// second line (and following till next package)
if (mNumber.find()) {
try {
// we are interested in the first and second token
String strNumber = mNumber.group(2);
String strIntent = mNumber.group(5);
long nNumber = Long.parseLong(strNumber);
if (myAlarm == null) {
Log.e(TAG, "Error: number line found but without alarm object (" + line + ")");
} else {
myAlarm.addItem(nNumber, strIntent);
}
} catch (Exception e) {
Log.e(TAG, "Error: parsing error in number line (" + line + ")");
}
}
} else {
// look for beginning
Matcher line = begin.matcher(res.get(i));
if (line.find()) {
bParsing = true;
}
}
}
// the last populated alarms has not been added to the list yet
myAlarms.add(myAlarm);
} else {
myAlarms = new ArrayList<StatElement>();
Alarm myAlarm = new Alarm(PERMISSION_DENIED);
myAlarm.setWakeups(1);
myAlarms.add(myAlarm);
}
for (int i = 0; i < myAlarms.size(); i++) {
Alarm myAlarm = (Alarm) myAlarms.get(i);
if (myAlarm != null) {
myAlarm.setTotalCount(nTotalCount);
}
}
return myAlarms;
}
Aggregations