Iterate NetworkPolicy towards SubscriptionPlan.

As part of getting Settings ready to roll towards SubscriptionPlan,
reduce references to NetworkPolicy internal fields.  All usage cycle
details are now obtained from an Iterator which converts to
SubscriptionPlan under the hood.

Bug: 63391323
Test: bit FrameworksServicesTests:com.android.server.NetworkPolicyManagerServiceTest
Exempt-From-Owner-Approval: Bug 63673347
Change-Id: I0e1357eef092a328c05f6a709aba0f106554631e
This commit is contained in:
Jeff Sharkey
2017-07-13 16:47:51 -06:00
parent dc09269c81
commit 47f51fac35
3 changed files with 41 additions and 31 deletions

View File

@@ -15,17 +15,21 @@ package com.android.settings.datausage;
import android.content.Context;
import android.net.NetworkPolicy;
import android.net.NetworkPolicyManager;
import android.net.NetworkStatsHistory;
import android.text.format.DateUtils;
import android.util.Pair;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settingslib.net.ChartData;
import libcore.util.Objects;
import static android.net.NetworkPolicyManager.computeLastCycleBoundary;
import static android.net.NetworkPolicyManager.computeNextCycleBoundary;
import java.time.ZonedDateTime;
import java.util.Iterator;
public class CycleAdapter extends ArrayAdapter<CycleAdapter.CycleItem> {
@@ -61,9 +65,9 @@ public class CycleAdapter extends ArrayAdapter<CycleAdapter.CycleItem> {
}
/**
* Rebuild list based on {@link NetworkPolicy#cycleDay}
* and available {@link NetworkStatsHistory} data. Always selects the newest
* item, updating the inspection range on chartData.
* Rebuild list based on {@link NetworkPolicy} and available
* {@link NetworkStatsHistory} data. Always selects the newest item,
* updating the inspection range on chartData.
*/
public boolean updateCycleList(NetworkPolicy policy, ChartData chartData) {
// stash away currently selected cycle to try restoring below
@@ -87,12 +91,12 @@ public class CycleAdapter extends ArrayAdapter<CycleAdapter.CycleItem> {
boolean hasCycles = false;
if (policy != null) {
// find the next cycle boundary
long cycleEnd = computeNextCycleBoundary(historyEnd, policy);
// walk backwards, generating all valid cycle ranges
while (cycleEnd > historyStart) {
final long cycleStart = computeLastCycleBoundary(cycleEnd, policy);
final Iterator<Pair<ZonedDateTime, ZonedDateTime>> it = NetworkPolicyManager
.cycleIterator(policy);
while (it.hasNext()) {
final Pair<ZonedDateTime, ZonedDateTime> cycle = it.next();
final long cycleStart = cycle.first.toInstant().toEpochMilli();
final long cycleEnd = cycle.second.toInstant().toEpochMilli();
final boolean includeCycle;
if (chartData != null) {
@@ -106,7 +110,6 @@ public class CycleAdapter extends ArrayAdapter<CycleAdapter.CycleItem> {
add(new CycleAdapter.CycleItem(context, cycleStart, cycleEnd));
hasCycles = true;
}
cycleEnd = cycleStart;
}
}