use of com.asksven.android.common.privateapiproxies.Misc in project BetterBatteryStats by asksven.
the class UpdateWidgetService method onStart.
@SuppressLint("NewApi")
@Override
public void onStart(Intent intent, int startId) {
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.getInstance(this).invalidate();
for (int widgetId : allWidgetIds) {
RemoteViews remoteViews = new RemoteViews(this.getApplicationContext().getPackageName(), R.layout.widget);
final int cellSize = 40;
int width = 3;
int height = 2;
int widthDim = 0;
int heightDim = 0;
if (Build.VERSION.SDK_INT >= 16) {
Bundle widgetOptions = appWidgetManager.getAppWidgetOptions(widgetId);
// width = (widgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH)) / cellSize;
// height = (widgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT)) / cellSize;
width = AppWidget.sizeToCells(widgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH) - 10);
height = AppWidget.sizeToCells(widgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT) + 10);
widthDim = widgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH);
heightDim = widgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
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);
if ((height <= 2) && (width <= 2)) {
// switch to image only
Log.i(TAG, "[" + widgetId + "] using image-only layout");
remoteViews = new RemoteViews(this.getPackageName(), R.layout.widget);
} else if (height < width) {
// switch to horizontal
Log.i(TAG, "[" + widgetId + "] using horizontal layout");
remoteViews = new RemoteViews(this.getPackageName(), R.layout.widget_horz);
} else {
// switch to vertical
Log.i(TAG, "[" + widgetId + "] using vertical layout");
remoteViews = new RemoteViews(this.getPackageName(), R.layout.widget_vert);
}
}
// 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);
// remoteViews.setInt(R.id.layoutBackground, "setImageAlpha", opacity);
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);
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 {
// no proper reference found
// remoteViews.setInt(R.id.graph, "setVisibility", View.GONE);
}
} 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);
}
WidgetSummary graph = new WidgetSummary();
graph.setAwake(timeAwake);
graph.setScreenOn(timeScreenOn);
graph.setDeepSleep(timeDeepSleep);
graph.setDuration(timeSince);
graph.setKWL(timeKWL);
graph.setPWL(timePWL);
DisplayMetrics metrics = this.getResources().getDisplayMetrics();
// Float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, Math.min(width, height) * cellSize, metrics);
Log.i(TAG, "Widget Dimensions: height=" + heightDim + " width=" + widthDim);
Float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, Math.min(Math.max(Math.min(widthDim, heightDim), 80), 160), metrics);
Log.i(TAG, "BitmapDip=" + Math.min(Math.max(Math.min(widthDim, heightDim), 80), 160) + ", BitmapPx=" + px.intValue());
graph.setBitmapSizePx(px.intValue());
remoteViews.setImageViewBitmap(R.id.imageView1, graph.getBitmap(this));
// Show % depending on width and if vertical or horz
if ((width > height) && (width <= 4)) {
remoteViews.setTextViewText(R.id.textViewAwakeVal, AppWidget.formatDuration(timeAwake - timeScreenOn));
remoteViews.setTextViewText(R.id.textViewDeepSleepVal, AppWidget.formatDuration(timeDeepSleep));
remoteViews.setTextViewText(R.id.textViewScreenOnVal, AppWidget.formatDuration(timeScreenOn));
remoteViews.setTextViewText(R.id.textViewKWLVal, AppWidget.formatDuration(timeKWL));
remoteViews.setTextViewText(R.id.textViewPWLVal, AppWidget.formatDuration(timePWL));
} else {
remoteViews.setTextViewText(R.id.textViewAwakeVal, AppWidget.formatDuration(timeAwake - timeScreenOn) + " (" + StringUtils.formatRatio(timeAwake - timeScreenOn, timeSince) + ")");
remoteViews.setTextViewText(R.id.textViewDeepSleepVal, AppWidget.formatDuration(timeDeepSleep) + " (" + StringUtils.formatRatio(timeDeepSleep, timeSince) + ")");
remoteViews.setTextViewText(R.id.textViewScreenOnVal, AppWidget.formatDuration(timeScreenOn) + " (" + StringUtils.formatRatio(timeScreenOn, timeSince) + ")");
remoteViews.setTextViewText(R.id.textViewKWLVal, AppWidget.formatDuration(timeKWL) + " (" + StringUtils.formatRatio(timeKWL, timeSince) + ")");
remoteViews.setTextViewText(R.id.textViewPWLVal, AppWidget.formatDuration(timePWL) + " (" + StringUtils.formatRatio(timePWL, timeSince) + ")");
}
// 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);
}
}
stopSelf();
super.onStart(intent, startId);
}
use of com.asksven.android.common.privateapiproxies.Misc in project BetterBatteryStats by asksven.
the class StatsProvider method getOtherUsageStatList.
/**
* Get the Other Usage 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> getOtherUsageStatList(boolean bFilter, Reference refFrom, boolean bFilterView, boolean bWidget, Reference refTo) throws Exception {
Context ctx = BbsApplication.getAppContext();
ArrayList<StatElement> myStats = new ArrayList<StatElement>();
// if on of the refs is null return
if ((refFrom == null) || (refTo == null)) {
myStats.add(new Notification(ctx.getString(R.string.NO_REF_ERR)));
return myStats;
}
// List to store the other usages to
ArrayList<StatElement> myUsages = new ArrayList<StatElement>();
if ((refTo.m_refOther != null) && (!refTo.m_refOther.isEmpty())) {
myUsages = refTo.m_refOther;
} else {
myStats.add(new Notification(ctx.getString(R.string.NO_STATS)));
return myStats;
}
String strRefFrom = "";
String strRefTo = "";
String strRefFromDescr = "";
String strRefToDescr = "";
if (LogSettings.DEBUG) {
if (refFrom != null) {
strRefFromDescr = refFrom.whoAmI();
if (refFrom.m_refOther != null) {
strRefFrom = refFrom.m_refOther.toString();
} else {
strRefFrom = "Other is null";
}
}
if (refTo != null) {
strRefToDescr = refTo.whoAmI();
if (refTo.m_refOther != null) {
strRefTo = refTo.m_refOther.toString();
} else {
strRefTo = "Other is null";
}
}
Log.d(TAG, "Processing Other from " + refFrom.m_fileName + " to " + refTo.m_fileName);
Log.d(TAG, "Reference from: " + strRefFromDescr);
Log.d(TAG, "Reference to: " + strRefToDescr);
Log.d(TAG, "It is now " + DateUtils.now());
Log.d(TAG, "Substracting " + strRefFrom);
Log.d(TAG, "from " + strRefTo);
}
for (int i = 0; i < myUsages.size(); i++) {
Misc usage = ((Misc) myUsages.get(i)).clone();
if (LogSettings.DEBUG) {
Log.d(TAG, "Current value: " + usage.getName() + " " + usage.getData(StatsProvider.getInstance().getSince(refFrom, refTo)));
}
if ((!bFilter) || (usage.getTimeOn() > 0)) {
usage.substractFromRef(refFrom.m_refOther);
if ((!bFilter) || (usage.getTimeOn() > 0)) {
if (LogSettings.DEBUG) {
Log.d(TAG, "Result value: " + usage.getName() + " " + usage.getData(StatsProvider.getInstance().getSince(refFrom, refTo)));
}
myStats.add((StatElement) usage);
}
}
}
return myStats;
}
use of com.asksven.android.common.privateapiproxies.Misc 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.Misc 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.Misc in project BetterBatteryStats by asksven.
the class OtherStatsDumpsys method getOtherStats.
/**
* Returns a list of alarm value objects
* @return
* @throws Exception
*/
public static ArrayList<StatElement> getOtherStats(boolean showWifi, boolean showBt) {
final String START_PATTERN = "Statistics since last charge";
final String STOP_PATTERN = "Statistics since last unplugged";
ArrayList<StatElement> myOther = null;
long nTotalCount = 0;
List<String> res = null;
boolean useRoot = false;
res = NonRootShell.getInstance().run("dumpsys batterystats");
if ((res != null) && (res.size() != 0)) {
if (res.contains("Permission Denial")) {
Pattern begin = Pattern.compile(START_PATTERN);
Pattern end = Pattern.compile(STOP_PATTERN);
boolean bParsing = false;
// we are looking for single line entries in the format
// Screen on: 29s 297ms (99.7%), Input events: 0, Active phone call: 0ms (0.0%)
// Screen brightnesses: dark 29s 297ms (100.0%)
// Signal levels: none 21s 595ms (73.5%) 0x, poor 4s 447ms (15.1%) 3x, moderate 3s 295ms (11.2%) 1x, good 36ms (0.1%) 1x
// Radio types: none 22s 610ms (77.0%) 0x, hsdpa 4s 635ms (15.8%) 2x, other 2s 128ms (7.2%) 1x
// Wifi on: 0ms (0.0%), Wifi running: 0ms (0.0%), Bluetooth on: 0ms (0.0%)
Pattern patternScreenOn = Pattern.compile("\\s\\sScreen on:\\s(.*) \\(.*\\sActive phone call:\\s(.*)\\s\\(.*");
Pattern patternWifiOn = Pattern.compile("\\s\\sWifi on:\\s(.*) \\(.*\\sWifi running:\\s(.*)\\s\\(.*\\sBluetooth on:\\s(.*)\\s\\(.*");
myOther = new ArrayList<StatElement>();
Misc myMisc = null;
// process the file
long total = 0;
for (int i = 0; i < res.size(); i++) {
// skip till start mark found
if (bParsing) {
// look for end
Matcher endMatcher = end.matcher(res.get(i));
if (endMatcher.find()) {
break;
}
// parse the alarms by block
String line = res.get(i);
Matcher screenOnMatcher = patternScreenOn.matcher(line);
Matcher wifiOnMatcher = patternWifiOn.matcher(line);
// screen on line
if (screenOnMatcher.find()) {
try {
long durationScreenOn = DateUtils.durationToLong(screenOnMatcher.group(1));
long durationInCall = DateUtils.durationToLong(screenOnMatcher.group(2));
myMisc = new Misc("Screen On", durationScreenOn, SystemClock.elapsedRealtime());
myOther.add(myMisc);
myMisc = new Misc("Phone On", durationInCall, SystemClock.elapsedRealtime());
myOther.add(myMisc);
Log.i(TAG, "Adding partial wakelock: " + myMisc.toString());
} catch (Exception e) {
Log.e(TAG, "Error: parsing error in package line (" + line + ")");
}
}
// phone on line
if (wifiOnMatcher.find()) {
try {
long durationWifiOn = DateUtils.durationToLong(wifiOnMatcher.group(1));
long durationWifiRunning = DateUtils.durationToLong(wifiOnMatcher.group(2));
long durationBtRunning = DateUtils.durationToLong(wifiOnMatcher.group(3));
if (showWifi) {
myMisc = new Misc("Wifi On", durationWifiOn, SystemClock.elapsedRealtime());
myOther.add(myMisc);
myMisc = new Misc("Wifi Running", durationWifiRunning, SystemClock.elapsedRealtime());
myOther.add(myMisc);
}
if (showBt) {
myMisc = new Misc("Bluetooth On", durationBtRunning, SystemClock.elapsedRealtime());
myOther.add(myMisc);
}
Log.i(TAG, "Adding partial wakelock: " + myMisc.toString());
} catch (Exception e) {
Log.e(TAG, "Error: parsing error in package line (" + line + ")");
}
}
} else {
// look for beginning
Matcher line = begin.matcher(res.get(i));
if (line.find()) {
bParsing = true;
}
}
}
// set the total
for (int i = 0; i < myOther.size(); i++) {
myOther.get(i).setTotal(total);
}
} else {
myOther = new ArrayList<StatElement>();
Misc myWl = new Misc(PERMISSION_DENIED, 1, 1);
myOther.add(myWl);
}
} else {
myOther = new ArrayList<StatElement>();
Misc myWl = new Misc(PERMISSION_DENIED, 1, 1);
myOther.add(myWl);
}
return myOther;
}
Aggregations