summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSohani Rao <sohanirao@google.com>2017-02-03 14:11:10 -0800
committerSohani Rao <sohanirao@google.com>2017-02-17 16:02:09 -0800
commit3c0eb618a6398926893508f9d05fa39a99cf4894 (patch)
tree86cbb0f5e097e0f66bf166596f8e1a460c523b3d /tests
parent53f278b6fed422a18d763b07216a21e96d9445f9 (diff)
Note WifiState in BatteryStats
BatteryStats has APIs which can be used to keep it posted about the WifiStateMachine state . This can help correlate power usage with different WifiStates. A helper class WifiStateTracker will convert WifiStateMachine states to the states of interest in BatteryStats. Bug: 28908455 Test: Unit tests Change-Id: I18db4496c1d7388f57e249d7dbdc0115134c1b3b
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java2
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateTrackerTest.java80
2 files changed, 82 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index 91862296e..06fa43094 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -323,6 +323,7 @@ public class WifiStateMachineTest {
@Mock WifiNative mWifiNative;
@Mock WifiConnectivityManager mWifiConnectivityManager;
@Mock SoftApManager mSoftApManager;
+ @Mock WifiStateTracker mWifiStateTracker;
public WifiStateMachineTest() throws Exception {
}
@@ -362,6 +363,7 @@ public class WifiStateMachineTest {
when(mWifiNative.setupDriverForClientMode()).thenReturn(mClientInterface);
when(mWifiNative.setupDriverForSoftApMode()).thenReturn(mApInterface);
+ when(mWifiInjector.getWifiStateTracker()).thenReturn(mWifiStateTracker);
when(mWifiNative.getInterfaceName()).thenReturn("mockWlan");
when(mWifiNative.enableSupplicant()).thenReturn(true);
when(mWifiNative.disableSupplicant()).thenReturn(true);
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateTrackerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateTrackerTest.java
new file mode 100644
index 000000000..428364dbe
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateTrackerTest.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wifi;
+
+import com.android.internal.app.IBatteryStats;
+
+import static org.mockito.Mockito.anyInt;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+/*
+ * Unit tests for {@link com.android.server.wifi.WifiStateTracker}.
+ */
+@SmallTest
+public class WifiStateTrackerTest {
+
+ private static final String TAG = "WifiStateTrackerTest";
+ @Mock IBatteryStats mBatteryStats;
+ private WifiStateTracker mWifiStateTracker;
+
+ /**
+ * Setup test.
+ */
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mWifiStateTracker = new WifiStateTracker(mBatteryStats);
+ }
+
+ /**
+ * Ensure BatteryStats's noteWifiState() is called when the method
+ * updateState() is invoked on WifiStateTracker for relevant states.
+ */
+ @Test
+ public void testBatteryStatsUpdated() throws Exception {
+ int[] relevantStates = new int[] { WifiStateTracker.SCAN_MODE,
+ WifiStateTracker.CONNECTED, WifiStateTracker.DISCONNECTED,
+ WifiStateTracker.SOFT_AP};
+ for (int i = 0; i < relevantStates.length; i++) {
+ mWifiStateTracker.updateState(relevantStates[i]);
+ }
+ verify(mBatteryStats, times(relevantStates.length)).noteWifiState(anyInt(), anyString());
+ }
+
+ /**
+ * Ensure BatteryStats's noteWifiState() is not called when the method
+ * updateState() is invoked on WifiStateTracker for irrelevant states.
+ */
+ @Test
+ public void testBatteryStatsNotUpdated() throws Exception {
+ int[] irrelevantStates = new int[] { WifiStateTracker.SCAN_MODE - 1,
+ WifiStateTracker.SOFT_AP + 1};
+ for (int i = 0; i < irrelevantStates.length; i++) {
+ mWifiStateTracker.updateState(irrelevantStates[i]);
+ }
+ verify(mBatteryStats, times(0)).noteWifiState(anyInt(), anyString());
+ }
+}