Merge "NPMS lock improvement." am: 053893568a am: cada17643d am: 388fe5f626
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1480258 Change-Id: Ia0a79dc25e9bc08e572fa5a37fb5f821bd7bbfcf
This commit is contained in:
@@ -526,8 +526,9 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
private final SparseBooleanArray mRestrictBackgroundAllowlistRevokedUids =
|
private final SparseBooleanArray mRestrictBackgroundAllowlistRevokedUids =
|
||||||
new SparseBooleanArray();
|
new SparseBooleanArray();
|
||||||
|
|
||||||
|
final Object mMeteredIfacesLock = new Object();
|
||||||
/** Set of ifaces that are metered. */
|
/** Set of ifaces that are metered. */
|
||||||
@GuardedBy("mNetworkPoliciesSecondLock")
|
@GuardedBy("mMeteredIfacesLock")
|
||||||
private ArraySet<String> mMeteredIfaces = new ArraySet<>();
|
private ArraySet<String> mMeteredIfaces = new ArraySet<>();
|
||||||
/** Set of over-limit templates that have been notified. */
|
/** Set of over-limit templates that have been notified. */
|
||||||
@GuardedBy("mNetworkPoliciesSecondLock")
|
@GuardedBy("mNetworkPoliciesSecondLock")
|
||||||
@@ -1980,13 +1981,15 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove quota from any interfaces that are no longer metered.
|
// Remove quota from any interfaces that are no longer metered.
|
||||||
for (int i = mMeteredIfaces.size() - 1; i >= 0; i--) {
|
synchronized (mMeteredIfacesLock) {
|
||||||
final String iface = mMeteredIfaces.valueAt(i);
|
for (int i = mMeteredIfaces.size() - 1; i >= 0; i--) {
|
||||||
if (!newMeteredIfaces.contains(iface)) {
|
final String iface = mMeteredIfaces.valueAt(i);
|
||||||
removeInterfaceQuotaAsync(iface);
|
if (!newMeteredIfaces.contains(iface)) {
|
||||||
|
removeInterfaceQuotaAsync(iface);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
mMeteredIfaces = newMeteredIfaces;
|
||||||
}
|
}
|
||||||
mMeteredIfaces = newMeteredIfaces;
|
|
||||||
|
|
||||||
final ContentResolver cr = mContext.getContentResolver();
|
final ContentResolver cr = mContext.getContentResolver();
|
||||||
final boolean quotaEnabled = Settings.Global.getInt(cr,
|
final boolean quotaEnabled = Settings.Global.getInt(cr,
|
||||||
@@ -2038,7 +2041,10 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
mSubscriptionOpportunisticQuota.put(subId, quotaBytes);
|
mSubscriptionOpportunisticQuota.put(subId, quotaBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String[] meteredIfaces = mMeteredIfaces.toArray(new String[mMeteredIfaces.size()]);
|
final String[] meteredIfaces;
|
||||||
|
synchronized (mMeteredIfacesLock) {
|
||||||
|
meteredIfaces = mMeteredIfaces.toArray(new String[mMeteredIfaces.size()]);
|
||||||
|
}
|
||||||
mHandler.obtainMessage(MSG_METERED_IFACES_CHANGED, meteredIfaces).sendToTarget();
|
mHandler.obtainMessage(MSG_METERED_IFACES_CHANGED, meteredIfaces).sendToTarget();
|
||||||
|
|
||||||
mHandler.obtainMessage(MSG_ADVISE_PERSIST_THRESHOLD, lowestRule).sendToTarget();
|
mHandler.obtainMessage(MSG_ADVISE_PERSIST_THRESHOLD, lowestRule).sendToTarget();
|
||||||
@@ -3460,7 +3466,10 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
fout.print("Restrict background: "); fout.println(mRestrictBackground);
|
fout.print("Restrict background: "); fout.println(mRestrictBackground);
|
||||||
fout.print("Restrict power: "); fout.println(mRestrictPower);
|
fout.print("Restrict power: "); fout.println(mRestrictPower);
|
||||||
fout.print("Device idle: "); fout.println(mDeviceIdleMode);
|
fout.print("Device idle: "); fout.println(mDeviceIdleMode);
|
||||||
fout.print("Metered ifaces: "); fout.println(mMeteredIfaces);
|
synchronized (mMeteredIfacesLock) {
|
||||||
|
fout.print("Metered ifaces: ");
|
||||||
|
fout.println(mMeteredIfaces);
|
||||||
|
}
|
||||||
|
|
||||||
fout.println();
|
fout.println();
|
||||||
fout.print("mRestrictBackgroundLowPowerMode: " + mRestrictBackgroundLowPowerMode);
|
fout.print("mRestrictBackgroundLowPowerMode: " + mRestrictBackgroundLowPowerMode);
|
||||||
@@ -4654,7 +4663,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
}
|
}
|
||||||
case MSG_LIMIT_REACHED: {
|
case MSG_LIMIT_REACHED: {
|
||||||
final String iface = (String) msg.obj;
|
final String iface = (String) msg.obj;
|
||||||
synchronized (mNetworkPoliciesSecondLock) {
|
synchronized (mMeteredIfacesLock) {
|
||||||
// fast return if not needed.
|
// fast return if not needed.
|
||||||
if (!mMeteredIfaces.contains(iface)) {
|
if (!mMeteredIfaces.contains(iface)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -5296,7 +5305,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
isBackgroundRestricted = mRestrictBackground;
|
isBackgroundRestricted = mRestrictBackground;
|
||||||
}
|
}
|
||||||
final boolean isNetworkMetered;
|
final boolean isNetworkMetered;
|
||||||
synchronized (mNetworkPoliciesSecondLock) {
|
synchronized (mMeteredIfacesLock) {
|
||||||
isNetworkMetered = mMeteredIfaces.contains(ifname);
|
isNetworkMetered = mMeteredIfaces.contains(ifname);
|
||||||
}
|
}
|
||||||
final boolean ret = isUidNetworkingBlockedInternal(uid, uidRules, isNetworkMetered,
|
final boolean ret = isUidNetworkingBlockedInternal(uid, uidRules, isNetworkMetered,
|
||||||
|
|||||||
Reference in New Issue
Block a user