summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Gabriel Biren <gbiren@google.com> 2025-03-21 00:16:10 +0000
committer Gabriel Biren <gbiren@google.com> 2025-03-21 17:21:35 +0000
commit8729cd99ddb429aeb79fcff6671ae84e028d71d9 (patch)
treee63bb2c5ca0605e067bd7e2c9c7ee4d85aa4a7a4
parent23bfefa7959a38bc48c8b9838885c247dfdedbea (diff)
Log WifiMulticastLockManager active sessions
in WifiMetrics when filtering is re-enabled. Bug: 391378901 Flag: EXEMPT minor metrics feature Test: atest WifiMulticastLockManagerTest Change-Id: Ie79a3d67bdab271c8d2aba3be20fb60b2b7f2077
-rw-r--r--service/java/com/android/server/wifi/WifiMulticastLockManager.java31
-rw-r--r--service/tests/wifitests/src/com/android/server/wifi/WifiMulticastLockManagerTest.java66
2 files changed, 88 insertions, 9 deletions
diff --git a/service/java/com/android/server/wifi/WifiMulticastLockManager.java b/service/java/com/android/server/wifi/WifiMulticastLockManager.java
index f02efc3d74..598bf5716d 100644
--- a/service/java/com/android/server/wifi/WifiMulticastLockManager.java
+++ b/service/java/com/android/server/wifi/WifiMulticastLockManager.java
@@ -50,6 +50,8 @@ public class WifiMulticastLockManager {
private final Map<Integer, Integer> mNumLocksPerInactiveOwner = new HashMap<>();
private int mMulticastEnabled = 0;
private int mMulticastDisabled = 0;
+ private boolean mIsFilterDisableSessionActive = false;
+ private long mFilterDisableSessionStartTime;
private final Handler mHandler;
private final Object mLock = new Object();
private boolean mVerboseLoggingEnabled = false;
@@ -235,17 +237,32 @@ public class WifiMulticastLockManager {
public void startFilteringMulticastPackets() {
synchronized (mLock) {
if (!isMulticastEnabled()) {
+ if (mIsFilterDisableSessionActive) {
+ // Log the end of the filtering disabled session,
+ // since we're about to re-enable multicast packet filtering
+ mWifiMetrics.addMulticastLockManagerActiveSession(
+ mClock.getElapsedSinceBootMillis() - mFilterDisableSessionStartTime);
+ }
mActiveModeWarden.getPrimaryClientModeManager()
.getMcastLockManagerFilterController()
.startFilteringMulticastPackets();
+ mIsFilterDisableSessionActive = false;
}
}
}
private void stopFilteringMulticastPackets() {
- mActiveModeWarden.getPrimaryClientModeManager()
- .getMcastLockManagerFilterController()
- .stopFilteringMulticastPackets();
+ synchronized (mLock) {
+ if (!mIsFilterDisableSessionActive) {
+ // Mark the beginning of a filtering disabled session,
+ // since we're about to disable multicast packet filtering
+ mFilterDisableSessionStartTime = mClock.getElapsedSinceBootMillis();
+ }
+ mActiveModeWarden.getPrimaryClientModeManager()
+ .getMcastLockManagerFilterController()
+ .stopFilteringMulticastPackets();
+ mIsFilterDisableSessionActive = true;
+ }
}
/**
@@ -273,9 +290,7 @@ public class WifiMulticastLockManager {
// our new size == 1 (first call), but this function won't
// be called often and by making the stopPacket call each
// time we're less fragile and self-healing.
- mActiveModeWarden.getPrimaryClientModeManager()
- .getMcastLockManagerFilterController()
- .stopFilteringMulticastPackets();
+ stopFilteringMulticastPackets();
}
final long ident = Binder.clearCallingIdentity();
@@ -328,9 +343,7 @@ public class WifiMulticastLockManager {
}
if (!isMulticastEnabled()) {
- mActiveModeWarden.getPrimaryClientModeManager()
- .getMcastLockManagerFilterController()
- .startFilteringMulticastPackets();
+ startFilteringMulticastPackets();
}
final long ident = Binder.clearCallingIdentity();
diff --git a/service/tests/wifitests/src/com/android/server/wifi/WifiMulticastLockManagerTest.java b/service/tests/wifitests/src/com/android/server/wifi/WifiMulticastLockManagerTest.java
index eb290241b1..8ce4a8d191 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/WifiMulticastLockManagerTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/WifiMulticastLockManagerTest.java
@@ -406,4 +406,70 @@ public class WifiMulticastLockManagerTest extends WifiBaseTest {
verify(mWifiMetrics).addMulticastLockManagerAcqSession(
eq(TEST_UID), eq(TEST_ATTRIBUTION_TAG), anyInt(), eq(10L) /* duration */);
}
+
+ /**
+ * Verify that an active session is logged when multicast filtering is re-enabled,
+ * and that an acquire session is logged when a multicast lock is released.
+ */
+ @Test
+ public void testSingleLockActiveSessionMetrics() {
+ IBinder binder = mock(IBinder.class);
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(START_TIME);
+ mManager.acquireLock(TEST_UID, binder, WL_1_TAG, TEST_ATTRIBUTION_TAG, TEST_PACKAGE_NAME);
+
+ // Transition the UID to low importance at t=10
+ // Since this is the only lock, this should re-enable packet filtering
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(START_TIME + 10);
+ mUidImportanceListenerCaptor.getValue().onUidImportance(
+ TEST_UID, ActivityManager.RunningAppProcessInfo.IMPORTANCE_CACHED);
+ mLooper.dispatchAll();
+
+ // Release the lock at t=20
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(START_TIME + 20);
+ mManager.releaseLock(TEST_UID, binder, WL_1_TAG);
+
+ // Verify that the active session was logged during the priority switch (t=10)
+ // and that the lock acquire session was logged during the lock release (t=20)
+ verify(mWifiMetrics).addMulticastLockManagerActiveSession(eq(10L));
+ verify(mWifiMetrics).addMulticastLockManagerAcqSession(
+ eq(TEST_UID), eq(TEST_ATTRIBUTION_TAG), anyInt(), eq(20L));
+ }
+
+ /**
+ * See comment for {@link #testSingleLockActiveSessionMetrics()}.
+ * This case considers a multi-lock scenario.
+ */
+ @Test
+ public void testMultiLockActiveSessionMetrics() {
+ int uid1 = TEST_UID;
+ int uid2 = TEST_UID + 1;
+ String attributionTag1 = "attribution-tag-1";
+ String attributionTag2 = "attribution-tag-2";
+ String packageName1 = "package-name-1";
+ String packageName2 = "package-name-2";
+ IBinder binder1 = mock(IBinder.class);
+ IBinder binder2 = mock(IBinder.class);
+
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(START_TIME);
+ mManager.acquireLock(uid1, binder1, WL_1_TAG, attributionTag1, packageName1);
+ mManager.acquireLock(uid2, binder2, WL_2_TAG, attributionTag2, packageName2);
+
+ // Release lock 1 at t=10. Multicast filtering is still disabled.
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(START_TIME + 10);
+ mManager.releaseLock(uid1, binder1, WL_1_TAG);
+
+ // Release lock 2 at t=20. Multicast filtering should be re-enabled.
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(START_TIME + 20);
+ mManager.releaseLock(uid2, binder2, WL_2_TAG);
+
+ // An acquire session should have been logged when each lock was released
+ verify(mWifiMetrics).addMulticastLockManagerAcqSession(
+ eq(uid1), eq(attributionTag1), anyInt(), eq(10L));
+ verify(mWifiMetrics).addMulticastLockManagerAcqSession(
+ eq(uid2), eq(attributionTag2), anyInt(), eq(20L));
+
+ // A single active session should have been logged when the final lock was released (t=20)
+ verify(mWifiMetrics, times(1)).addMulticastLockManagerActiveSession(anyLong());
+ verify(mWifiMetrics).addMulticastLockManagerActiveSession(eq(20L));
+ }
}