Search in sources :

Example 6 with BatteryStatsProxy

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;
}
Also used : Context(android.content.Context) SharedPreferences(android.content.SharedPreferences) StatElement(com.asksven.android.common.privateapiproxies.StatElement) Alarm(com.asksven.android.common.privateapiproxies.Alarm) ArrayList(java.util.ArrayList) BatteryStatsProxy(com.asksven.android.common.privateapiproxies.BatteryStatsProxy) SuppressLint(android.annotation.SuppressLint)

Example 7 with BatteryStatsProxy

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;
}
Also used : Context(android.content.Context) StatElement(com.asksven.android.common.privateapiproxies.StatElement) ArrayList(java.util.ArrayList) Process(com.asksven.android.common.privateapiproxies.Process) BatteryStatsProxy(com.asksven.android.common.privateapiproxies.BatteryStatsProxy) SuppressLint(android.annotation.SuppressLint)

Example 8 with BatteryStatsProxy

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;
}
Also used : Context(android.content.Context) SharedPreferences(android.content.SharedPreferences) StatElement(com.asksven.android.common.privateapiproxies.StatElement) NetworkUsage(com.asksven.android.common.privateapiproxies.NetworkUsage) ArrayList(java.util.ArrayList) BatteryStatsProxy(com.asksven.android.common.privateapiproxies.BatteryStatsProxy) SuppressLint(android.annotation.SuppressLint)

Example 9 with BatteryStatsProxy

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;
}
Also used : HistoryItem(com.asksven.android.common.privateapiproxies.HistoryItem) ArrayList(java.util.ArrayList) BatteryStatsProxy(com.asksven.android.common.privateapiproxies.BatteryStatsProxy)

Example 10 with BatteryStatsProxy

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;
}
Also used : HistoryItem(com.asksven.android.common.privateapiproxies.HistoryItem) ArrayList(java.util.ArrayList) BatteryStatsProxy(com.asksven.android.common.privateapiproxies.BatteryStatsProxy)

Aggregations

BatteryStatsProxy (com.asksven.android.common.privateapiproxies.BatteryStatsProxy)15 ArrayList (java.util.ArrayList)10 StatElement (com.asksven.android.common.privateapiproxies.StatElement)9 SuppressLint (android.annotation.SuppressLint)8 Context (android.content.Context)8 SharedPreferences (android.content.SharedPreferences)8 HistoryItem (com.asksven.android.common.privateapiproxies.HistoryItem)3 Misc (com.asksven.android.common.privateapiproxies.Misc)3 PendingIntent (android.app.PendingIntent)2 AppWidgetManager (android.appwidget.AppWidgetManager)2 Intent (android.content.Intent)2 ReceiverCallNotAllowedException (android.content.ReceiverCallNotAllowedException)2 PackageManager (android.content.pm.PackageManager)2 Bundle (android.os.Bundle)2 RemoteViews (android.widget.RemoteViews)2 BatteryInfoUnavailableException (com.asksven.android.common.privateapiproxies.BatteryInfoUnavailableException)2 NativeKernelWakelock (com.asksven.android.common.privateapiproxies.NativeKernelWakelock)2 Reference (com.asksven.betterbatterystats.data.Reference)2 StatsProvider (com.asksven.betterbatterystats.data.StatsProvider)2 DisplayMetrics (android.util.DisplayMetrics)1