One final pass at unquoted NetworkPolicies.
Correctly shows the metered status of legacy policies in UI. Bug: 7695807 Change-Id: I13c9f4c1716d8457343c41433afac0b5f00e02fe
This commit is contained in:
@@ -119,7 +119,7 @@ public class DataUsageMeteredSettings extends SettingsPreferenceFragment {
|
|||||||
setPersistent(false);
|
setPersistent(false);
|
||||||
|
|
||||||
mBinding = true;
|
mBinding = true;
|
||||||
final NetworkPolicy policy = mPolicyEditor.getPolicy(template);
|
final NetworkPolicy policy = mPolicyEditor.getPolicyMaybeUnquoted(template);
|
||||||
if (policy != null) {
|
if (policy != null) {
|
||||||
if (policy.limitBytes != LIMIT_DISABLED) {
|
if (policy.limitBytes != LIMIT_DISABLED) {
|
||||||
setChecked(true);
|
setChecked(true);
|
||||||
|
@@ -127,6 +127,15 @@ public class NetworkPolicyEditor {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NetworkPolicy getPolicyMaybeUnquoted(NetworkTemplate template) {
|
||||||
|
NetworkPolicy policy = getPolicy(template);
|
||||||
|
if (policy != null) {
|
||||||
|
return policy;
|
||||||
|
} else {
|
||||||
|
return getPolicy(buildUnquotedNetworkTemplate(template));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
private static NetworkPolicy buildDefaultPolicy(NetworkTemplate template) {
|
private static NetworkPolicy buildDefaultPolicy(NetworkTemplate template) {
|
||||||
// TODO: move this into framework to share with NetworkPolicyManagerService
|
// TODO: move this into framework to share with NetworkPolicyManagerService
|
||||||
@@ -188,7 +197,7 @@ public class NetworkPolicyEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean getPolicyMetered(NetworkTemplate template) {
|
public boolean getPolicyMetered(NetworkTemplate template) {
|
||||||
final NetworkPolicy policy = getPolicy(template);
|
NetworkPolicy policy = getPolicy(template);
|
||||||
if (policy != null) {
|
if (policy != null) {
|
||||||
return policy.metered;
|
return policy.metered;
|
||||||
} else {
|
} else {
|
||||||
@@ -223,16 +232,12 @@ public class NetworkPolicyEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove any oddly escaped policies while we're here
|
// Remove legacy unquoted policies while we're here
|
||||||
final String networkId = template.getNetworkId();
|
final NetworkTemplate unquoted = buildUnquotedNetworkTemplate(template);
|
||||||
final String strippedNetworkId = WifiInfo.removeDoubleQuotes(networkId);
|
final NetworkPolicy unquotedPolicy = getPolicy(unquoted);
|
||||||
if (!TextUtils.equals(strippedNetworkId, networkId)) {
|
if (unquotedPolicy != null) {
|
||||||
policy = getPolicy(new NetworkTemplate(
|
mPolicies.remove(unquotedPolicy);
|
||||||
template.getMatchRule(), template.getSubscriberId(), strippedNetworkId));
|
modified = true;
|
||||||
if (policy != null) {
|
|
||||||
mPolicies.remove(policy);
|
|
||||||
modified = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modified) writeAsync();
|
if (modified) writeAsync();
|
||||||
@@ -328,4 +333,21 @@ public class NetworkPolicyEditor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a revised {@link NetworkTemplate} that matches the same rule, but
|
||||||
|
* with an unquoted {@link NetworkTemplate#getNetworkId()}. Used to work
|
||||||
|
* around legacy bugs.
|
||||||
|
*/
|
||||||
|
private static NetworkTemplate buildUnquotedNetworkTemplate(NetworkTemplate template) {
|
||||||
|
if (template == null) return null;
|
||||||
|
final String networkId = template.getNetworkId();
|
||||||
|
final String strippedNetworkId = WifiInfo.removeDoubleQuotes(networkId);
|
||||||
|
if (!TextUtils.equals(strippedNetworkId, networkId)) {
|
||||||
|
return new NetworkTemplate(
|
||||||
|
template.getMatchRule(), template.getSubscriberId(), strippedNetworkId);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user