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:
Jeff Sharkey
2012-12-18 17:44:05 -08:00
parent 53f2855808
commit d54d34557a
2 changed files with 34 additions and 12 deletions

View File

@@ -119,7 +119,7 @@ public class DataUsageMeteredSettings extends SettingsPreferenceFragment {
setPersistent(false);
mBinding = true;
final NetworkPolicy policy = mPolicyEditor.getPolicy(template);
final NetworkPolicy policy = mPolicyEditor.getPolicyMaybeUnquoted(template);
if (policy != null) {
if (policy.limitBytes != LIMIT_DISABLED) {
setChecked(true);

View File

@@ -127,6 +127,15 @@ public class NetworkPolicyEditor {
return null;
}
public NetworkPolicy getPolicyMaybeUnquoted(NetworkTemplate template) {
NetworkPolicy policy = getPolicy(template);
if (policy != null) {
return policy;
} else {
return getPolicy(buildUnquotedNetworkTemplate(template));
}
}
@Deprecated
private static NetworkPolicy buildDefaultPolicy(NetworkTemplate template) {
// TODO: move this into framework to share with NetworkPolicyManagerService
@@ -188,7 +197,7 @@ public class NetworkPolicyEditor {
}
public boolean getPolicyMetered(NetworkTemplate template) {
final NetworkPolicy policy = getPolicy(template);
NetworkPolicy policy = getPolicy(template);
if (policy != null) {
return policy.metered;
} else {
@@ -223,17 +232,13 @@ public class NetworkPolicyEditor {
}
}
// Remove any oddly escaped policies while we're here
final String networkId = template.getNetworkId();
final String strippedNetworkId = WifiInfo.removeDoubleQuotes(networkId);
if (!TextUtils.equals(strippedNetworkId, networkId)) {
policy = getPolicy(new NetworkTemplate(
template.getMatchRule(), template.getSubscriberId(), strippedNetworkId));
if (policy != null) {
mPolicies.remove(policy);
// Remove legacy unquoted policies while we're here
final NetworkTemplate unquoted = buildUnquotedNetworkTemplate(template);
final NetworkPolicy unquotedPolicy = getPolicy(unquoted);
if (unquotedPolicy != null) {
mPolicies.remove(unquotedPolicy);
modified = true;
}
}
if (modified) writeAsync();
}
@@ -328,4 +333,21 @@ public class NetworkPolicyEditor {
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;
}
}
}