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);
}
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);
}
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);
}
Aggregations