Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 661daf9b authored by junyulai's avatar junyulai Committed by markchien
Browse files

[SP08] re-calculate interface quota when limit reached

Some providers might hit the limit reached event prior to
others. Thus, re-calculate and update interface quota for
every provider is needed.

This change also removes the lock that held by NPMS while
requesting NSS force update, which seems unnecessary and
might cause potential deadlock in future.

Test: atest NetworkStatsServiceTest
Test: atest NetworkPolicyManagerServiceTest

Bug: 130855321
Change-Id: I84a08ecfb14c61023fa9f1c98af73d3ee90acef6
parent e3f4143d
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -4547,7 +4547,11 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
                }
                case MSG_STATS_PROVIDER_LIMIT_REACHED: {
                    mNetworkStats.forceUpdate();

                    synchronized (mNetworkPoliciesSecondLock) {
                        // Some providers might hit the limit reached event prior to others. Thus,
                        // re-calculate and update interface quota for every provider is needed.
                        updateNetworkRulesNL();
                        updateNetworkEnabledNL();
                        updateNotificationsNL();
                    }
@@ -4555,17 +4559,22 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
                }
                case MSG_LIMIT_REACHED: {
                    final String iface = (String) msg.obj;

                    synchronized (mNetworkPoliciesSecondLock) {
                        if (mMeteredIfaces.contains(iface)) {
                            // force stats update to make sure we have
                            // numbers that caused alert to trigger.
                        // fast return if not needed.
                        if (!mMeteredIfaces.contains(iface)) {
                            return true;
                        }
                    }

                    // force stats update to make sure the service have the numbers that caused
                    // alert to trigger.
                    mNetworkStats.forceUpdate();

                    synchronized (mNetworkPoliciesSecondLock) {
                        updateNetworkRulesNL();
                        updateNetworkEnabledNL();
                        updateNotificationsNL();
                    }
                    }
                    return true;
                }
                case MSG_RESTRICT_BACKGROUND_CHANGED: {
+3 −1
Original line number Diff line number Diff line
@@ -1729,9 +1729,11 @@ public class NetworkPolicyManagerServiceTest {
                .getService(NetworkPolicyManagerInternal.class);
        npmi.onStatsProviderLimitReached("TEST");

        // Verifies that the limit reached leads to a force update.
        // Verifies that the limit reached leads to a force update and new limit should be set.
        postMsgAndWaitForCompletion();
        verify(mStatsService).forceUpdate();
        postMsgAndWaitForCompletion();
        verify(mStatsService).setStatsProviderLimit(TEST_IFACE, 10000L - 4999L - 1999L);
    }

    /**