Save timezone when setting data cycle reset date.
Bug: 5938567 Change-Id: I9df8da9d030169952098efc04cfde79e3e42e1f8
This commit is contained in:
@@ -42,7 +42,6 @@ import static android.net.TrafficStats.UID_REMOVED;
|
||||
import static android.net.TrafficStats.UID_TETHERING;
|
||||
import static android.text.format.DateUtils.FORMAT_ABBREV_MONTH;
|
||||
import static android.text.format.DateUtils.FORMAT_SHOW_DATE;
|
||||
import static android.text.format.Time.TIMEZONE_UTC;
|
||||
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||
import static com.android.internal.util.Preconditions.checkNotNull;
|
||||
import static com.android.settings.Utils.prepareCustomPreferencesList;
|
||||
@@ -86,6 +85,7 @@ import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateUtils;
|
||||
import android.text.format.Formatter;
|
||||
import android.text.format.Time;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -1139,7 +1139,7 @@ public class DataUsageSummary extends Fragment {
|
||||
|
||||
final long totalBytes = entry != null ? entry.rxBytes + entry.txBytes : 0;
|
||||
final String totalPhrase = Formatter.formatFileSize(context, totalBytes);
|
||||
final String rangePhrase = formatDateRange(context, start, end, false);
|
||||
final String rangePhrase = formatDateRange(context, start, end);
|
||||
|
||||
mUsageSummary.setText(
|
||||
getString(R.string.data_usage_total_during_range, totalPhrase, rangePhrase));
|
||||
@@ -1264,7 +1264,7 @@ public class DataUsageSummary extends Fragment {
|
||||
}
|
||||
|
||||
public CycleItem(Context context, long start, long end) {
|
||||
this.label = formatDateRange(context, start, end, true);
|
||||
this.label = formatDateRange(context, start, end);
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
@@ -1293,14 +1293,13 @@ public class DataUsageSummary extends Fragment {
|
||||
private static final java.util.Formatter sFormatter = new java.util.Formatter(
|
||||
sBuilder, Locale.getDefault());
|
||||
|
||||
public static String formatDateRange(Context context, long start, long end, boolean utcTime) {
|
||||
public static String formatDateRange(Context context, long start, long end) {
|
||||
final int flags = FORMAT_SHOW_DATE | FORMAT_ABBREV_MONTH;
|
||||
final String timezone = utcTime ? TIMEZONE_UTC : null;
|
||||
|
||||
synchronized (sBuilder) {
|
||||
sBuilder.setLength(0);
|
||||
return DateUtils
|
||||
.formatDateRange(context, sFormatter, start, end, flags, timezone).toString();
|
||||
return DateUtils.formatDateRange(context, sFormatter, start, end, flags, null)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1641,7 +1640,8 @@ public class DataUsageSummary extends Fragment {
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
final int cycleDay = cycleDayPicker.getValue();
|
||||
editor.setPolicyCycleDay(template, cycleDay);
|
||||
final String cycleTimezone = new Time().timezone;
|
||||
editor.setPolicyCycleDay(template, cycleDay, cycleTimezone);
|
||||
target.updatePolicy(true);
|
||||
}
|
||||
});
|
||||
|
@@ -144,17 +144,20 @@ public class NetworkPolicyEditor {
|
||||
final Time time = new Time();
|
||||
time.setToNow();
|
||||
final int cycleDay = time.monthDay;
|
||||
final String cycleTimezone = time.timezone;
|
||||
|
||||
return new NetworkPolicy(template, cycleDay, WARNING_DISABLED, LIMIT_DISABLED, true);
|
||||
return new NetworkPolicy(
|
||||
template, cycleDay, cycleTimezone, WARNING_DISABLED, LIMIT_DISABLED, true);
|
||||
}
|
||||
|
||||
public int getPolicyCycleDay(NetworkTemplate template) {
|
||||
return getPolicy(template).cycleDay;
|
||||
}
|
||||
|
||||
public void setPolicyCycleDay(NetworkTemplate template, int cycleDay) {
|
||||
public void setPolicyCycleDay(NetworkTemplate template, int cycleDay, String cycleTimezone) {
|
||||
final NetworkPolicy policy = getOrCreatePolicy(template);
|
||||
policy.cycleDay = cycleDay;
|
||||
policy.cycleTimezone = cycleTimezone;
|
||||
policy.clearSnooze();
|
||||
writeAsync();
|
||||
}
|
||||
@@ -197,6 +200,7 @@ public class NetworkPolicyEditor {
|
||||
return modified;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isMobilePolicySplit(String subscriberId) {
|
||||
boolean has3g = false;
|
||||
boolean has4g = false;
|
||||
@@ -216,6 +220,7 @@ public class NetworkPolicyEditor {
|
||||
return has3g && has4g;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setMobilePolicySplit(String subscriberId, boolean split) {
|
||||
if (setMobilePolicySplitInternal(subscriberId, split)) {
|
||||
writeAsync();
|
||||
@@ -228,6 +233,7 @@ public class NetworkPolicyEditor {
|
||||
*
|
||||
* @return {@code true} when any {@link NetworkPolicy} was mutated.
|
||||
*/
|
||||
@Deprecated
|
||||
private boolean setMobilePolicySplitInternal(String subscriberId, boolean split) {
|
||||
final boolean beforeSplit = isMobilePolicySplit(subscriberId);
|
||||
|
||||
@@ -248,7 +254,8 @@ public class NetworkPolicyEditor {
|
||||
: policy4g;
|
||||
mPolicies.remove(policy3g);
|
||||
mPolicies.remove(policy4g);
|
||||
mPolicies.add(new NetworkPolicy(templateAll, restrictive.cycleDay,
|
||||
mPolicies.add(new NetworkPolicy(
|
||||
templateAll, restrictive.cycleDay, restrictive.cycleTimezone,
|
||||
restrictive.warningBytes, restrictive.limitBytes, restrictive.metered));
|
||||
return true;
|
||||
|
||||
@@ -256,9 +263,11 @@ public class NetworkPolicyEditor {
|
||||
// duplicate existing policy into two rules
|
||||
final NetworkPolicy policyAll = getPolicy(templateAll);
|
||||
mPolicies.remove(policyAll);
|
||||
mPolicies.add(new NetworkPolicy(template3g, policyAll.cycleDay, policyAll.warningBytes,
|
||||
mPolicies.add(new NetworkPolicy(
|
||||
template3g, policyAll.cycleDay, policyAll.cycleTimezone, policyAll.warningBytes,
|
||||
policyAll.limitBytes, policyAll.metered));
|
||||
mPolicies.add(new NetworkPolicy(template4g, policyAll.cycleDay, policyAll.warningBytes,
|
||||
mPolicies.add(new NetworkPolicy(
|
||||
template4g, policyAll.cycleDay, policyAll.cycleTimezone, policyAll.warningBytes,
|
||||
policyAll.limitBytes, policyAll.metered));
|
||||
return true;
|
||||
} else {
|
||||
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.widget;
|
||||
|
||||
import static com.android.settings.DataUsageSummary.formatDateRange;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
@@ -30,7 +32,6 @@ import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.settings.DataUsageSummary;
|
||||
import com.android.settings.R;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
@@ -82,8 +83,8 @@ public class ChartGridView extends View {
|
||||
|
||||
void setBounds(long start, long end) {
|
||||
final Context context = getContext();
|
||||
mLayoutStart = makeLayout(DataUsageSummary.formatDateRange(context, start, start, true));
|
||||
mLayoutEnd = makeLayout(DataUsageSummary.formatDateRange(context, end, end, true));
|
||||
mLayoutStart = makeLayout(formatDateRange(context, start, start));
|
||||
mLayoutEnd = makeLayout(formatDateRange(context, end, end));
|
||||
invalidate();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user