Commit 3476e978 authored by Sam Mortimer's avatar Sam Mortimer

Settings: Prevent DataSaverBackend from overwriting uid policies

* Lineage assigns additional network policy values for restrict on
  data and wlan etc.

* DataSaverBackend was assuming that only allow background
  and allow unrestricted background exist and therefore could both:
  i) overwrite other uid policies and ii) incorrectly think there were
  changes when there weren't.

* Change setUidPolicy to appropriate add/remove sequences and filter
  the newPolicy value in the callback to ignore everything except
  background data related policies.

Change-Id: I4c81d7fa2199441674a4176eb78b29facd0b799e
parent 5e8502de
......@@ -82,12 +82,15 @@ public class DataSaverBackend {
public void setIsWhitelisted(int uid, String packageName, boolean whitelisted) {
final int policy = whitelisted ? POLICY_ALLOW_METERED_BACKGROUND : POLICY_NONE;
mPolicyManager.setUidPolicy(uid, policy);
mUidPolicies.put(uid, policy);
if (whitelisted) {
mPolicyManager.addUidPolicy(uid, POLICY_ALLOW_METERED_BACKGROUND);
mMetricsFeatureProvider.action(
mContext, MetricsEvent.ACTION_DATA_SAVER_WHITELIST, packageName);
} else {
mPolicyManager.removeUidPolicy(uid, POLICY_ALLOW_METERED_BACKGROUND);
}
mPolicyManager.removeUidPolicy(uid, POLICY_REJECT_METERED_BACKGROUND);
}
public boolean isWhitelisted(int uid) {
......@@ -121,12 +124,15 @@ public class DataSaverBackend {
public void setIsBlacklisted(int uid, String packageName, boolean blacklisted) {
final int policy = blacklisted ? POLICY_REJECT_METERED_BACKGROUND : POLICY_NONE;
mPolicyManager.setUidPolicy(uid, policy);
mUidPolicies.put(uid, policy);
if (blacklisted) {
mPolicyManager.addUidPolicy(uid, POLICY_REJECT_METERED_BACKGROUND);
mMetricsFeatureProvider.action(
mContext, MetricsEvent.ACTION_DATA_SAVER_BLACKLIST, packageName);
} else {
mPolicyManager.removeUidPolicy(uid, POLICY_REJECT_METERED_BACKGROUND);
}
mPolicyManager.removeUidPolicy(uid, POLICY_ALLOW_METERED_BACKGROUND);
}
public boolean isBlacklisted(int uid) {
......@@ -164,6 +170,10 @@ public class DataSaverBackend {
loadWhitelist();
loadBlacklist();
// We only care about allow/reject metered background policy here.
newPolicy &= (POLICY_ALLOW_METERED_BACKGROUND
| POLICY_REJECT_METERED_BACKGROUND);
final int oldPolicy = mUidPolicies.get(uid, POLICY_NONE);
if (newPolicy == POLICY_NONE) {
mUidPolicies.delete(uid);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment