Search in sources :

Example 1 with Notification

use of com.asksven.android.common.privateapiproxies.Notification in project BetterBatteryStats by asksven.

the class StatsActivity method setListViewAdapter.

/**
 * In order to refresh the ListView we need to re-create the Adapter
 * (should be the case but notifyDataSetChanged doesn't work so
 * we recreate and set a new one)
 */
private void setListViewAdapter() throws Exception {
    LinearLayout notificationPanel = (LinearLayout) findViewById(R.id.Notification);
    ListView listView = (ListView) findViewById(android.R.id.list);
    ArrayList<StatElement> myStats = StatsProvider.getInstance().getStatList(m_iStat, m_refFromName, m_iSorting, m_refToName);
    if ((myStats != null) && (!myStats.isEmpty())) {
        // check if notification
        if (myStats.get(0) instanceof Notification) {
            // Show Panel
            notificationPanel.setVisibility(View.VISIBLE);
            // Hide list
            listView.setVisibility(View.GONE);
            // set Text
            TextView tvNotification = (TextView) findViewById(R.id.TextViewNotification);
            tvNotification.setText(myStats.get(0).getName());
        } else {
            // hide Panel
            notificationPanel.setVisibility(View.GONE);
            // Show list
            listView.setVisibility(View.VISIBLE);
        }
    }
    // make sure we only instanciate when the reference does not exist
    if (m_listViewAdapter == null) {
        m_listViewAdapter = new StatsAdapter(this, myStats, StatsActivity.this);
        Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName, StatsActivity.this);
        Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName, StatsActivity.this);
        long sinceMs = StatsProvider.getInstance().getSince(myReferenceFrom, myReferenceTo);
        m_listViewAdapter.setTotalTime(sinceMs);
        setListAdapter(m_listViewAdapter);
    }
}
Also used : ListView(android.widget.ListView) Reference(com.asksven.betterbatterystats.data.Reference) StatElement(com.asksven.android.common.privateapiproxies.StatElement) TextView(android.widget.TextView) StatsAdapter(com.asksven.betterbatterystats.adapters.StatsAdapter) LinearLayout(android.widget.LinearLayout) Notification(com.asksven.android.common.privateapiproxies.Notification)

Example 2 with Notification

use of com.asksven.android.common.privateapiproxies.Notification in project BetterBatteryStats by asksven.

the class StatsProvider method getKernelWakelockStatList.

/**
 * 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> getKernelWakelockStatList(boolean bFilter, Reference refFrom, int iPctType, int iSort, Reference refTo) throws Exception {
    Context ctx = BbsApplication.getAppContext();
    ArrayList<StatElement> myStats = new ArrayList<StatElement>();
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    if (!(Wakelocks.fileIsWorldReadableExists() || WakeupSources.fileIsWorldReadableExists() || SysUtils.hasBatteryStatsPermission(ctx))) {
        myStats.add(new Notification(ctx.getString(R.string.KWL_ACCESS_ERROR)));
        return myStats;
    }
    if ((refFrom == null) || (refTo == null)) {
        myStats.add(new Notification(ctx.getString(R.string.NO_REF_ERR)));
        return myStats;
    }
    ArrayList<StatElement> myKernelWakelocks = null;
    if ((refTo.m_refKernelWakelocks != null) && (!refTo.m_refKernelWakelocks.isEmpty())) {
        myKernelWakelocks = refTo.m_refKernelWakelocks;
    } else {
        myStats.add(new Notification(ctx.getString(R.string.NO_STATS)));
        return myStats;
    }
    ArrayList<NativeKernelWakelock> myRetKernelWakelocks = new ArrayList<NativeKernelWakelock>();
    // if we are using custom ref. always retrieve "stats current"
    // sort @see
    // com.asksven.android.common.privateapiproxies.Walkelock.compareTo
    // Collections.sort(myKernelWakelocks);
    String strCurrent = myKernelWakelocks.toString();
    String strRef = "";
    String strRefDescr = "";
    if (LogSettings.DEBUG) {
        if (refFrom != null) {
            strRefDescr = refFrom.whoAmI();
            if (refFrom.m_refKernelWakelocks != null) {
                strRef = refFrom.m_refKernelWakelocks.toString();
            } else {
                strRef = "kernel wakelocks is null";
            }
        } else {
            strRefDescr = "Reference is null";
        }
        Log.d(TAG, "Processing kernel wakelocks 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 < myKernelWakelocks.size(); i++) {
        NativeKernelWakelock wl = ((NativeKernelWakelock) myKernelWakelocks.get(i)).clone();
        if ((!bFilter) || ((wl.getDuration()) > 0)) {
            wl.substractFromRef(refFrom.m_refKernelWakelocks);
            // threshold
            if ((!bFilter) || ((wl.getDuration()) > 0)) {
                myRetKernelWakelocks.add(wl);
            }
        }
    }
    // com.asksven.android.common.privateapiproxies.Walkelock.compareTo
    switch(iSort) {
        case 0:
            // by Duration
            Comparator<NativeKernelWakelock> myCompTime = new NativeKernelWakelock.TimeComparator();
            Collections.sort(myRetKernelWakelocks, myCompTime);
            break;
        case 1:
            // by Count
            Comparator<NativeKernelWakelock> myCompCount = new NativeKernelWakelock.CountComparator();
            Collections.sort(myRetKernelWakelocks, myCompCount);
            break;
    }
    for (int i = 0; i < myRetKernelWakelocks.size(); i++) {
        myStats.add((StatElement) myRetKernelWakelocks.get(i));
    }
    if (LogSettings.DEBUG) {
        Log.d(TAG, "Result " + myStats.toString());
    }
    return myStats;
}
Also used : Context(android.content.Context) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) Notification(com.asksven.android.common.privateapiproxies.Notification) SuppressLint(android.annotation.SuppressLint) NativeKernelWakelock(com.asksven.android.common.privateapiproxies.NativeKernelWakelock) StatElement(com.asksven.android.common.privateapiproxies.StatElement)

Example 3 with Notification

use of com.asksven.android.common.privateapiproxies.Notification 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;
}
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) Notification(com.asksven.android.common.privateapiproxies.Notification) SuppressLint(android.annotation.SuppressLint)

Example 4 with Notification

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

Example 5 with Notification

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

Aggregations

Notification (com.asksven.android.common.privateapiproxies.Notification)10 StatElement (com.asksven.android.common.privateapiproxies.StatElement)10 SuppressLint (android.annotation.SuppressLint)9 Context (android.content.Context)9 ArrayList (java.util.ArrayList)9 SharedPreferences (android.content.SharedPreferences)7 NativeKernelWakelock (com.asksven.android.common.privateapiproxies.NativeKernelWakelock)2 LinearLayout (android.widget.LinearLayout)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 State (com.asksven.android.common.kernelutils.State)1 Alarm (com.asksven.android.common.privateapiproxies.Alarm)1 Misc (com.asksven.android.common.privateapiproxies.Misc)1 NetworkUsage (com.asksven.android.common.privateapiproxies.NetworkUsage)1 Process (com.asksven.android.common.privateapiproxies.Process)1 SensorUsage (com.asksven.android.common.privateapiproxies.SensorUsage)1 Wakelock (com.asksven.android.common.privateapiproxies.Wakelock)1 StatsAdapter (com.asksven.betterbatterystats.adapters.StatsAdapter)1 Reference (com.asksven.betterbatterystats.data.Reference)1