Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f3acebfb authored by Doris Ling's avatar Doris Ling
Browse files

Fix inconsistent data usage cycle start time.

- change the detail adapter start time to be 4 weeks before end time,
even if it is earlier than history start time, to be consistent with
other places that the cycle period is shown.

Change-Id: I62846022a10597f9e8618907500613357a1f6551
Fixes: 121045978
Test: make RunSettingsLibRoboTests
parent 5eb1fef3
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import static android.net.NetworkStatsHistory.FIELD_TX_BYTES;
import android.app.usage.NetworkStats;
import android.app.usage.NetworkStatsManager;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.INetworkStatsService;
import android.net.INetworkStatsSession;
import android.net.NetworkPolicy;
@@ -35,14 +34,14 @@ import android.os.ServiceManager;
import android.text.format.DateUtils;
import android.util.Pair;

import androidx.annotation.VisibleForTesting;
import androidx.loader.content.AsyncTaskLoader;

import com.android.settingslib.NetworkPolicyEditor;

import java.time.ZonedDateTime;
import java.util.Iterator;

import androidx.annotation.VisibleForTesting;
import androidx.loader.content.AsyncTaskLoader;

/**
 * Loader for network data usage history. It returns a list of usage data per billing cycle.
 */
@@ -121,8 +120,7 @@ public abstract class NetworkCycleDataLoader<D> extends AsyncTaskLoader<D> {

            long cycleEnd = historyEnd;
            while (cycleEnd > historyStart) {
                final long cycleStart = Math.max(
                    historyStart, cycleEnd - (DateUtils.WEEK_IN_MILLIS * 4));
                final long cycleStart = cycleEnd - (DateUtils.WEEK_IN_MILLIS * 4);
                recordUsage(cycleStart, cycleEnd);
                cycleEnd = cycleStart;
            }
+2 −1
Original line number Diff line number Diff line
@@ -130,7 +130,8 @@ public class NetworkCycleDataLoaderTest {
            .thenReturn(networkHistory);
        final long now = System.currentTimeMillis();
        final long fourWeeksAgo = now - (DateUtils.WEEK_IN_MILLIS * 4);
        when(networkHistory.getStart()).thenReturn(fourWeeksAgo);
        final long twoDaysAgo = now - (DateUtils.DAY_IN_MILLIS * 2);
        when(networkHistory.getStart()).thenReturn(twoDaysAgo);
        when(networkHistory.getEnd()).thenReturn(now);

        mLoader.loadFourWeeksData();