summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAhmed ElArabawy <arabawy@google.com>2017-11-28 14:08:49 -0800
committerAhmed ElArabawy <arabawy@google.com>2018-08-10 13:46:49 -0700
commitbd4ae452150a3605d8a592905ae843516aff4ec5 (patch)
tree550da0697e36e0113016dc62ef86f981d54afda0 /tests
parentbdf34cb8d78cf2a3eaf28568fade917a1e955746 (diff)
Release the correct WiFi Multicast Wakelock
In current implementation, when the same UID allocates, and acquires multiple WiFi Multicast wakelocks the tag associated with the lock is passed in the acquire method, and stored in the multicasters list. However, when the UID tries to release the lock, the tag is not included in the method call, and hence all the wakelocks found in the list of multicasters for this UID are released. This behavior does not reflect what the user app expects since only one multicast wakelock should be released and the others should still be acquired. This commit fixes this situation by releasing only the proper wakelock. Bug: 70691435 Test: ./frameworks/opt/net/wifi/tests/wifitests/runtests.sh Change-Id: I25c5ec0e03cd2a0572f4275005b205900a649ba7
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiMulticastLockManagerTest.java96
1 files changed, 93 insertions, 3 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMulticastLockManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMulticastLockManagerTest.java
index 8939636af..1c560a146 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiMulticastLockManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiMulticastLockManagerTest.java
@@ -27,6 +27,7 @@ import com.android.internal.app.IBatteryStats;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -35,6 +36,9 @@ import org.mockito.MockitoAnnotations;
*/
@SmallTest
public class WifiMulticastLockManagerTest {
+ private static final String WL_1_TAG = "Wakelock-1";
+ private static final String WL_2_TAG = "Wakelock-2";
+
@Mock WifiMulticastLockManager.FilterController mHandler;
@Mock IBatteryStats mBatteryStats;
WifiMulticastLockManager mManager;
@@ -64,7 +68,7 @@ public class WifiMulticastLockManagerTest {
@Test
public void oneLock() throws RemoteException {
IBinder binder = mock(IBinder.class);
- mManager.acquireLock(binder, "Test");
+ mManager.acquireLock(binder, WL_1_TAG);
assertTrue(mManager.isMulticastEnabled());
verify(mHandler).stopFilteringMulticastPackets();
mManager.initializeFiltering();
@@ -72,9 +76,95 @@ public class WifiMulticastLockManagerTest {
verify(mBatteryStats).noteWifiMulticastEnabled(anyInt());
verify(mBatteryStats, times(0)).noteWifiMulticastDisabled(anyInt());
- mManager.releaseLock();
+ mManager.releaseLock(WL_1_TAG);
verify(mBatteryStats).noteWifiMulticastDisabled(anyInt());
assertFalse(mManager.isMulticastEnabled());
}
-}
+ /**
+ * Test behavior when one lock is aquired then released with the wrong tag.
+ */
+ @Test
+ public void oneLock_wrongName() throws RemoteException {
+ IBinder binder = mock(IBinder.class);
+ mManager.acquireLock(binder, WL_1_TAG);
+ assertTrue(mManager.isMulticastEnabled());
+ verify(mHandler).stopFilteringMulticastPackets();
+ mManager.initializeFiltering();
+ verify(mHandler, never()).startFilteringMulticastPackets();
+ verify(mBatteryStats).noteWifiMulticastEnabled(anyInt());
+ verify(mBatteryStats, never()).noteWifiMulticastDisabled(anyInt());
+
+ mManager.releaseLock(WL_2_TAG);
+ verify(mBatteryStats, never()).noteWifiMulticastDisabled(anyInt());
+ assertTrue(mManager.isMulticastEnabled());
+ }
+
+ /**
+ * Test behavior when multiple locks are aquired then released in nesting order.
+ */
+ @Test
+ public void multipleLocksInOrder() throws RemoteException {
+ IBinder binder = mock(IBinder.class);
+
+ InOrder inOrderHandler = inOrder(mHandler);
+ InOrder inOrderBatteryStats = inOrder(mBatteryStats);
+
+ mManager.acquireLock(binder, WL_1_TAG);
+ inOrderHandler.verify(mHandler).stopFilteringMulticastPackets();
+ inOrderBatteryStats.verify(mBatteryStats).noteWifiMulticastEnabled(anyInt());
+ assertTrue(mManager.isMulticastEnabled());
+
+ mManager.acquireLock(binder, WL_2_TAG);
+ inOrderHandler.verify(mHandler).stopFilteringMulticastPackets();
+ inOrderBatteryStats.verify(mBatteryStats).noteWifiMulticastEnabled(anyInt());
+ assertTrue(mManager.isMulticastEnabled());
+
+ mManager.initializeFiltering();
+ inOrderHandler.verify(mHandler, never()).startFilteringMulticastPackets();
+
+ mManager.releaseLock(WL_2_TAG);
+ inOrderHandler.verify(mHandler, never()).startFilteringMulticastPackets();
+ inOrderBatteryStats.verify(mBatteryStats).noteWifiMulticastDisabled(anyInt());
+ assertTrue(mManager.isMulticastEnabled());
+
+ mManager.releaseLock(WL_1_TAG);
+ inOrderHandler.verify(mHandler).startFilteringMulticastPackets();
+ inOrderBatteryStats.verify(mBatteryStats).noteWifiMulticastDisabled(anyInt());
+ assertFalse(mManager.isMulticastEnabled());
+ }
+
+ /**
+ * Test behavior when multiple locks are aquired then released out of nesting order.
+ */
+ @Test
+ public void multipleLocksOutOfOrder() throws RemoteException {
+ IBinder binder = mock(IBinder.class);
+
+ InOrder inOrderHandler = inOrder(mHandler);
+ InOrder inOrderBatteryStats = inOrder(mBatteryStats);
+
+ mManager.acquireLock(binder, WL_1_TAG);
+ inOrderHandler.verify(mHandler).stopFilteringMulticastPackets();
+ inOrderBatteryStats.verify(mBatteryStats).noteWifiMulticastEnabled(anyInt());
+ assertTrue(mManager.isMulticastEnabled());
+
+ mManager.acquireLock(binder, WL_2_TAG);
+ inOrderHandler.verify(mHandler).stopFilteringMulticastPackets();
+ inOrderBatteryStats.verify(mBatteryStats).noteWifiMulticastEnabled(anyInt());
+ assertTrue(mManager.isMulticastEnabled());
+
+ mManager.initializeFiltering();
+ inOrderHandler.verify(mHandler, never()).startFilteringMulticastPackets();
+
+ mManager.releaseLock(WL_1_TAG);
+ inOrderHandler.verify(mHandler, never()).startFilteringMulticastPackets();
+ inOrderBatteryStats.verify(mBatteryStats).noteWifiMulticastDisabled(anyInt());
+ assertTrue(mManager.isMulticastEnabled());
+
+ mManager.releaseLock(WL_2_TAG);
+ inOrderHandler.verify(mHandler).startFilteringMulticastPackets();
+ inOrderBatteryStats.verify(mBatteryStats).noteWifiMulticastDisabled(anyInt());
+ assertFalse(mManager.isMulticastEnabled());
+ }
+}