Search in sources :

Example 6 with NetworkCycleDataForUid

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

the class AppDataUsageTest method onLoadFinished_hasSelectedCycleSpecified_shouldSelectSpecifiedCycle.

@Test
public void onLoadFinished_hasSelectedCycleSpecified_shouldSelectSpecifiedCycle() {
    final long now = System.currentTimeMillis();
    final long tenDaysAgo = now - (DateUtils.DAY_IN_MILLIS * 10);
    final long twentyDaysAgo = now - (DateUtils.DAY_IN_MILLIS * 20);
    final long thirtyDaysAgo = now - (DateUtils.DAY_IN_MILLIS * 30);
    final List<NetworkCycleDataForUid> data = new ArrayList<>();
    NetworkCycleDataForUid.Builder builder = new NetworkCycleDataForUid.Builder();
    builder.setStartTime(thirtyDaysAgo).setEndTime(twentyDaysAgo).setTotalUsage(9876L);
    data.add(builder.build());
    builder = new NetworkCycleDataForUid.Builder();
    builder.setStartTime(twentyDaysAgo).setEndTime(tenDaysAgo).setTotalUsage(5678L);
    data.add(builder.build());
    builder = new NetworkCycleDataForUid.Builder();
    builder.setStartTime(tenDaysAgo).setEndTime(now).setTotalUsage(1234L);
    data.add(builder.build());
    mFragment = new AppDataUsage();
    ReflectionHelpers.setField(mFragment, "mContext", RuntimeEnvironment.application);
    ReflectionHelpers.setField(mFragment, "mCycleAdapter", mock(CycleAdapter.class));
    ReflectionHelpers.setField(mFragment, "mSelectedCycle", tenDaysAgo);
    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.mUidDataCallbacks.onLoadFinished(null, /* loader */
    data);
    verify(cycle).setSelection(1);
}
Also used : RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Preference(androidx.preference.Preference) ArrayList(java.util.ArrayList) NetworkCycleDataForUid(com.android.settingslib.net.NetworkCycleDataForUid) Test(org.junit.Test)

Example 7 with NetworkCycleDataForUid

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

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)

Example 8 with NetworkCycleDataForUid

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

the class AppDataUsageTest method onLoadFinished_hasSelectedCycleSpecified_shouldSelectSpecifiedCycle.

@Test
public void onLoadFinished_hasSelectedCycleSpecified_shouldSelectSpecifiedCycle() {
    final long now = System.currentTimeMillis();
    final long tenDaysAgo = now - (DateUtils.DAY_IN_MILLIS * 10);
    final long twentyDaysAgo = now - (DateUtils.DAY_IN_MILLIS * 20);
    final long thirtyDaysAgo = now - (DateUtils.DAY_IN_MILLIS * 30);
    final List<NetworkCycleDataForUid> data = new ArrayList<>();
    NetworkCycleDataForUid.Builder builder = new NetworkCycleDataForUid.Builder();
    builder.setStartTime(thirtyDaysAgo).setEndTime(twentyDaysAgo).setTotalUsage(9876L);
    data.add(builder.build());
    builder = new NetworkCycleDataForUid.Builder();
    builder.setStartTime(twentyDaysAgo).setEndTime(tenDaysAgo).setTotalUsage(5678L);
    data.add(builder.build());
    builder = new NetworkCycleDataForUid.Builder();
    builder.setStartTime(tenDaysAgo).setEndTime(now).setTotalUsage(1234L);
    data.add(builder.build());
    mFragment = new AppDataUsage();
    ReflectionHelpers.setField(mFragment, "mContext", RuntimeEnvironment.application);
    ReflectionHelpers.setField(mFragment, "mCycleAdapter", mock(CycleAdapter.class));
    ReflectionHelpers.setField(mFragment, "mSelectedCycle", tenDaysAgo);
    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.mUidDataCallbacks.onLoadFinished(null, /* loader */
    data);
    verify(cycle).setSelection(1);
}
Also used : RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Preference(androidx.preference.Preference) ArrayList(java.util.ArrayList) NetworkCycleDataForUid(com.android.settingslib.net.NetworkCycleDataForUid) Test(org.junit.Test)

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