Search in sources :

Example 1 with NetworkCycleDataForUid

use of com.android.settingslib.net.NetworkCycleDataForUid in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppDataUsageTest method bindData_hasAppUsageData_shouldShowCycleSpinnerAndUpdateUsageSummary.

@Test
public void bindData_hasAppUsageData_shouldShowCycleSpinnerAndUpdateUsageSummary() {
    mFragment = spy(new AppDataUsage());
    final Context context = RuntimeEnvironment.application;
    ReflectionHelpers.setField(mFragment, "mContext", context);
    final long backgroundBytes = 1234L;
    final long foregroundBytes = 5678L;
    final List<NetworkCycleDataForUid> appUsage = new ArrayList<>();
    appUsage.add(new NetworkCycleDataForUid.Builder().setBackgroundUsage(backgroundBytes).setForegroundUsage(foregroundBytes).build());
    ReflectionHelpers.setField(mFragment, "mUsageData", appUsage);
    final Preference backgroundPref = mock(Preference.class);
    ReflectionHelpers.setField(mFragment, "mBackgroundUsage", backgroundPref);
    final Preference foregroundPref = mock(Preference.class);
    ReflectionHelpers.setField(mFragment, "mForegroundUsage", foregroundPref);
    final Preference totalPref = mock(Preference.class);
    ReflectionHelpers.setField(mFragment, "mTotalUsage", totalPref);
    final SpinnerPreference cycle = mock(SpinnerPreference.class);
    ReflectionHelpers.setField(mFragment, "mCycle", cycle);
    mFragment.bindData(0);
    verify(cycle).setVisible(true);
    verify(totalPref).setSummary(DataUsageUtils.formatDataUsage(context, backgroundBytes + foregroundBytes));
    verify(backgroundPref).setSummary(DataUsageUtils.formatDataUsage(context, backgroundBytes));
    verify(foregroundPref).setSummary(DataUsageUtils.formatDataUsage(context, foregroundBytes));
}
Also used : Context(android.content.Context) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Preference(androidx.preference.Preference) ArrayList(java.util.ArrayList) NetworkCycleDataForUid(com.android.settingslib.net.NetworkCycleDataForUid) Test(org.junit.Test)

Example 2 with NetworkCycleDataForUid

use of com.android.settingslib.net.NetworkCycleDataForUid in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppDataUsage method bindData.

@VisibleForTesting
void bindData(int position) {
    final long backgroundBytes, foregroundBytes;
    if (mUsageData == null || position >= mUsageData.size()) {
        backgroundBytes = foregroundBytes = 0;
        mCycle.setVisible(false);
    } else {
        mCycle.setVisible(true);
        final NetworkCycleDataForUid data = mUsageData.get(position);
        backgroundBytes = data.getBackgroudUsage();
        foregroundBytes = data.getForegroudUsage();
    }
    final long totalBytes = backgroundBytes + foregroundBytes;
    mTotalUsage.setSummary(DataUsageUtils.formatDataUsage(mContext, totalBytes));
    mForegroundUsage.setSummary(DataUsageUtils.formatDataUsage(mContext, foregroundBytes));
    mBackgroundUsage.setSummary(DataUsageUtils.formatDataUsage(mContext, backgroundBytes));
}
Also used : NetworkCycleDataForUid(com.android.settingslib.net.NetworkCycleDataForUid) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 3 with NetworkCycleDataForUid

use of com.android.settingslib.net.NetworkCycleDataForUid in project android_packages_apps_Settings by omnirom.

the class AppDataUsage method bindData.

@VisibleForTesting
void bindData(int position) {
    final long backgroundBytes, foregroundBytes;
    if (mUsageData == null || position >= mUsageData.size()) {
        backgroundBytes = foregroundBytes = 0;
        mCycle.setVisible(false);
    } else {
        mCycle.setVisible(true);
        final NetworkCycleDataForUid data = mUsageData.get(position);
        backgroundBytes = data.getBackgroudUsage();
        foregroundBytes = data.getForegroudUsage();
    }
    final long totalBytes = backgroundBytes + foregroundBytes;
    mTotalUsage.setSummary(DataUsageUtils.formatDataUsage(mContext, totalBytes));
    mForegroundUsage.setSummary(DataUsageUtils.formatDataUsage(mContext, foregroundBytes));
    mBackgroundUsage.setSummary(DataUsageUtils.formatDataUsage(mContext, backgroundBytes));
}
Also used : NetworkCycleDataForUid(com.android.settingslib.net.NetworkCycleDataForUid) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 4 with NetworkCycleDataForUid

use of com.android.settingslib.net.NetworkCycleDataForUid in project android_packages_apps_Settings by omnirom.

the class AppDataUsageTest method bindData_hasAppUsageData_shouldShowCycleSpinnerAndUpdateUsageSummary.

@Test
public void bindData_hasAppUsageData_shouldShowCycleSpinnerAndUpdateUsageSummary() {
    mFragment = spy(new AppDataUsage());
    final Context context = RuntimeEnvironment.application;
    ReflectionHelpers.setField(mFragment, "mContext", context);
    final long backgroundBytes = 1234L;
    final long foregroundBytes = 5678L;
    final List<NetworkCycleDataForUid> appUsage = new ArrayList<>();
    appUsage.add(new NetworkCycleDataForUid.Builder().setBackgroundUsage(backgroundBytes).setForegroundUsage(foregroundBytes).build());
    ReflectionHelpers.setField(mFragment, "mUsageData", appUsage);
    final Preference backgroundPref = mock(Preference.class);
    ReflectionHelpers.setField(mFragment, "mBackgroundUsage", backgroundPref);
    final Preference foregroundPref = mock(Preference.class);
    ReflectionHelpers.setField(mFragment, "mForegroundUsage", foregroundPref);
    final Preference totalPref = mock(Preference.class);
    ReflectionHelpers.setField(mFragment, "mTotalUsage", totalPref);
    final SpinnerPreference cycle = mock(SpinnerPreference.class);
    ReflectionHelpers.setField(mFragment, "mCycle", cycle);
    mFragment.bindData(0);
    verify(cycle).setVisible(true);
    verify(totalPref).setSummary(DataUsageUtils.formatDataUsage(context, backgroundBytes + foregroundBytes));
    verify(backgroundPref).setSummary(DataUsageUtils.formatDataUsage(context, backgroundBytes));
    verify(foregroundPref).setSummary(DataUsageUtils.formatDataUsage(context, foregroundBytes));
}
Also used : Context(android.content.Context) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Preference(androidx.preference.Preference) ArrayList(java.util.ArrayList) NetworkCycleDataForUid(com.android.settingslib.net.NetworkCycleDataForUid) Test(org.junit.Test)

Example 5 with NetworkCycleDataForUid

use of com.android.settingslib.net.NetworkCycleDataForUid in project android_packages_apps_Settings by omnirom.

the class AppDataUsagePreferenceController method getDataSummary.

private CharSequence getDataSummary() {
    if (mAppUsageData != null) {
        long totalBytes = 0;
        long startTime = System.currentTimeMillis();
        for (NetworkCycleDataForUid data : mAppUsageData) {
            totalBytes += data.getTotalUsage();
            final long cycleStart = data.getStartTime();
            if (cycleStart < startTime) {
                startTime = cycleStart;
            }
        }
        if (totalBytes == 0) {
            return mContext.getString(R.string.no_data_usage);
        }
        return mContext.getString(R.string.data_summary_format, Formatter.formatFileSize(mContext, totalBytes, Formatter.FLAG_IEC_UNITS), DateUtils.formatDateTime(mContext, startTime, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH));
    }
    return mContext.getString(R.string.computing_size);
}
Also used : NetworkCycleDataForUid(com.android.settingslib.net.NetworkCycleDataForUid)

Aggregations

NetworkCycleDataForUid (com.android.settingslib.net.NetworkCycleDataForUid)8 Preference (androidx.preference.Preference)4 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Context (android.content.Context)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2