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