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

Commit 1bbc8a56 authored by Doris Ling's avatar Doris Ling Committed by Android (Google) Code Review
Browse files

Merge "Fix inconsistent data usage cycle start time."

parents 9dfb10ce f3acebfb
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();