summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEtan Cohen <etancohen@google.com>2017-04-25 06:50:22 -0700
committerEtan Cohen <etancohen@google.com>2017-05-11 14:45:43 -0700
commitc760a66378bbd844eb421658799b4d55c76b98fa (patch)
tree1d0fb57432d2b00ee8dec1ee5f77f90fedb50a4b /tests
parent82313852d1b6408d01cb2445ddfa3cadb8a59206 (diff)
[AWARE] Initial power optimization framework - hooks & config
Create hooks in Wi-Fi Aware service to respond to power state change events: interactive on/off (aka screen on/off) and idle (doze). Initial implementation transitions to higher latency (assumed to be lower power) discovery duty cycles. Bug: 35457252 Test: unit tests Change-Id: I3a2a67db3e0b47ab982d7c67326e7fa20e429fad
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java21
-rw-r--r--tests/wifitests/src/com/android/server/wifi/aware/WifiAwareNativeApiTest.java218
-rw-r--r--tests/wifitests/src/com/android/server/wifi/aware/WifiAwareServiceImplTest.java4
-rw-r--r--tests/wifitests/src/com/android/server/wifi/aware/WifiAwareStateManagerTest.java268
4 files changed, 467 insertions, 44 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java
index a2e7c77cf..2b744af46 100644
--- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java
@@ -55,8 +55,10 @@ import android.net.wifi.aware.WifiAwareNetworkSpecifier;
import android.net.wifi.aware.WifiAwareSession;
import android.os.Handler;
import android.os.INetworkManagementService;
+import android.os.IPowerManager;
import android.os.Message;
import android.os.Messenger;
+import android.os.PowerManager;
import android.os.Process;
import android.os.test.TestLooper;
import android.test.suitebuilder.annotation.SmallTest;
@@ -97,6 +99,7 @@ public class WifiAwareDataPathStateManagerTest {
@Mock private IWifiAwareEventCallback mMockCallback;
@Mock IWifiAwareDiscoverySessionCallback mMockSessionCallback;
TestAlarmManager mAlarmManager;
+ private PowerManager mMockPowerManager;
@Rule
public ErrorCollector collector = new ErrorCollector();
@@ -112,11 +115,18 @@ public class WifiAwareDataPathStateManagerTest {
when(mMockContext.getSystemService(Context.ALARM_SERVICE))
.thenReturn(mAlarmManager.getAlarmManager());
- when(mMockContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(mMockCm);
-
mMockLooper = new TestLooper();
mMockLooperHandler = new Handler(mMockLooper.getLooper());
+ IPowerManager powerManagerService = mock(IPowerManager.class);
+ mMockPowerManager = new PowerManager(mMockContext, powerManagerService,
+ new Handler(mMockLooper.getLooper()));
+
+ when(mMockContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(mMockCm);
+ when(mMockContext.getSystemServiceName(PowerManager.class)).thenReturn(
+ Context.POWER_SERVICE);
+ when(mMockContext.getSystemService(PowerManager.class)).thenReturn(mMockPowerManager);
+
mDut = new WifiAwareStateManager();
mDut.setNative(mMockNative);
mDut.start(mMockContext, mMockLooper.getLooper());
@@ -124,7 +134,7 @@ public class WifiAwareDataPathStateManagerTest {
when(mMockNative.getCapabilities(anyShort())).thenReturn(true);
when(mMockNative.enableAndConfigure(anyShort(), any(), anyBoolean(),
- anyBoolean())).thenReturn(true);
+ anyBoolean(), anyBoolean(), anyBoolean())).thenReturn(true);
when(mMockNative.disable(anyShort())).thenReturn(true);
when(mMockNative.publish(anyShort(), anyInt(), any())).thenReturn(true);
when(mMockNative.subscribe(anyShort(), anyInt(), any()))
@@ -145,6 +155,9 @@ public class WifiAwareDataPathStateManagerTest {
when(mMockNetworkInterface.configureAgentProperties(any(), any(), anyInt(), any(), any(),
any())).thenReturn(true);
+ when(mMockPowerManager.isDeviceIdleMode()).thenReturn(false);
+ when(mMockPowerManager.isInteractive()).thenReturn(true);
+
installDataPathStateManagerMocks();
}
@@ -884,7 +897,7 @@ public class WifiAwareDataPathStateManagerTest {
false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(),
- eq(configRequest), eq(false), eq(true));
+ eq(configRequest), eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mMockCallback).onConnectSuccess(clientId);
diff --git a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareNativeApiTest.java b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareNativeApiTest.java
new file mode 100644
index 000000000..956418997
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareNativeApiTest.java
@@ -0,0 +1,218 @@
+/*
+ * Copyright (C) 2017 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.aware;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyShort;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.hardware.wifi.V1_0.IWifiNanIface;
+import android.hardware.wifi.V1_0.NanBandIndex;
+import android.hardware.wifi.V1_0.NanConfigRequest;
+import android.hardware.wifi.V1_0.NanEnableRequest;
+import android.hardware.wifi.V1_0.WifiStatus;
+import android.hardware.wifi.V1_0.WifiStatusCode;
+import android.net.wifi.aware.ConfigRequest;
+import android.os.RemoteException;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ErrorCollector;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import java.io.PrintWriter;
+
+/**
+ * Unit test harness for WifiAwareNativeApi
+ */
+public class WifiAwareNativeApiTest {
+ @Mock WifiAwareNativeManager mWifiAwareNativeManagerMock;
+ @Mock IWifiNanIface mIWifiNanIfaceMock;
+
+ @Rule public ErrorCollector collector = new ErrorCollector();
+
+ private WifiAwareNativeApi mDut;
+
+ /**
+ * Initializes mocks.
+ */
+ @Before
+ public void setup() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ when(mWifiAwareNativeManagerMock.getWifiNanIface()).thenReturn(mIWifiNanIfaceMock);
+
+ WifiStatus status = new WifiStatus();
+ status.code = WifiStatusCode.SUCCESS;
+ when(mIWifiNanIfaceMock.enableRequest(anyShort(), any())).thenReturn(status);
+ when(mIWifiNanIfaceMock.configRequest(anyShort(), any())).thenReturn(status);
+
+ mDut = new WifiAwareNativeApi(mWifiAwareNativeManagerMock);
+ }
+
+ /**
+ * Test that the set parameter shell command executor works when parameters are valid.
+ */
+ @Test
+ public void testSetParameterShellCommandSuccess() {
+ setSettableParam(WifiAwareNativeApi.PARAM_DW_ON_IDLE_5GHZ, Integer.toString(1), true);
+ }
+
+ /**
+ * Test that the set parameter shell command executor fails on incorrect name.
+ */
+ @Test
+ public void testSetParameterShellCommandInvalidParameterName() {
+ setSettableParam("XXX", Integer.toString(1), false);
+ }
+
+ /**
+ * Test that the set parameter shell command executor fails on invalid value (not convertible
+ * to an int).
+ */
+ @Test
+ public void testSetParameterShellCommandInvalidValue() {
+ setSettableParam(WifiAwareNativeApi.PARAM_DW_ON_IDLE_5GHZ, "garbage", false);
+ }
+
+ /**
+ * Validate that the configuration parameters used to manage power state behavior is
+ * using default values at the default power state.
+ */
+ @Test
+ public void testEnableAndConfigPowerSettingsDefaults() throws RemoteException {
+ NanConfigRequest config = validateEnableAndConfigure((short) 10,
+ new ConfigRequest.Builder().build(), true, true, true, false);
+
+ collector.checkThat("validDiscoveryWindowIntervalVal-5", false,
+ equalTo(config.bandSpecificConfig[NanBandIndex.NAN_BAND_5GHZ]
+ .validDiscoveryWindowIntervalVal));
+ collector.checkThat("validDiscoveryWindowIntervalVal-24", false,
+ equalTo(config.bandSpecificConfig[NanBandIndex.NAN_BAND_24GHZ]
+ .validDiscoveryWindowIntervalVal));
+ }
+
+ /**
+ * Validate that the configuration parameters used to manage power state behavior is
+ * using the specified non-interactive values when in that power state.
+ */
+ @Test
+ public void testEnableAndConfigPowerSettingsNoneInteractive() throws RemoteException {
+ byte interactive5 = 2;
+ byte interactive24 = 3;
+
+ setPowerConfigurationParams(interactive5, interactive24, (byte) -1, (byte) -1);
+ NanConfigRequest config = validateEnableAndConfigure((short) 10,
+ new ConfigRequest.Builder().build(), false, false, false, false);
+
+ collector.checkThat("validDiscoveryWindowIntervalVal-5", true,
+ equalTo(config.bandSpecificConfig[NanBandIndex.NAN_BAND_5GHZ]
+ .validDiscoveryWindowIntervalVal));
+ collector.checkThat("discoveryWindowIntervalVal-5", interactive5,
+ equalTo(config.bandSpecificConfig[NanBandIndex.NAN_BAND_5GHZ]
+ .discoveryWindowIntervalVal));
+ collector.checkThat("validDiscoveryWindowIntervalVal-24", true,
+ equalTo(config.bandSpecificConfig[NanBandIndex.NAN_BAND_24GHZ]
+ .validDiscoveryWindowIntervalVal));
+ collector.checkThat("discoveryWindowIntervalVal-24", interactive24,
+ equalTo(config.bandSpecificConfig[NanBandIndex.NAN_BAND_24GHZ]
+ .discoveryWindowIntervalVal));
+ }
+
+ /**
+ * Validate that the configuration parameters used to manage power state behavior is
+ * using the specified idle (doze) values when in that power state.
+ */
+ @Test
+ public void testEnableAndConfigPowerSettingsIdle() throws RemoteException {
+ byte idle5 = 2;
+ byte idle24 = -1;
+
+ setPowerConfigurationParams((byte) -1, (byte) -1, idle5, idle24);
+ NanConfigRequest config = validateEnableAndConfigure((short) 10,
+ new ConfigRequest.Builder().build(), false, true, false, true);
+
+ collector.checkThat("validDiscoveryWindowIntervalVal-5", true,
+ equalTo(config.bandSpecificConfig[NanBandIndex.NAN_BAND_5GHZ]
+ .validDiscoveryWindowIntervalVal));
+ collector.checkThat("discoveryWindowIntervalVal-5", idle5,
+ equalTo(config.bandSpecificConfig[NanBandIndex.NAN_BAND_5GHZ]
+ .discoveryWindowIntervalVal));
+ collector.checkThat("validDiscoveryWindowIntervalVal-24", false,
+ equalTo(config.bandSpecificConfig[NanBandIndex.NAN_BAND_24GHZ]
+ .validDiscoveryWindowIntervalVal));
+ }
+
+ // utilities
+
+ private void setPowerConfigurationParams(byte interactive5, byte interactive24, byte idle5,
+ byte idle24) {
+ setSettableParam(WifiAwareNativeApi.PARAM_DW_ON_INACTIVE_5GHZ,
+ Integer.toString(interactive5), true);
+ setSettableParam(WifiAwareNativeApi.PARAM_DW_ON_INACTIVE_24GHZ,
+ Integer.toString(interactive24), true);
+ setSettableParam(WifiAwareNativeApi.PARAM_DW_ON_IDLE_5GHZ, Integer.toString(idle5), true);
+ setSettableParam(WifiAwareNativeApi.PARAM_DW_ON_IDLE_24GHZ, Integer.toString(idle24), true);
+ }
+
+ private void setSettableParam(String name, String value, boolean expectSuccess) {
+ PrintWriter pwMock = mock(PrintWriter.class);
+ WifiAwareShellCommand parentShellMock = mock(WifiAwareShellCommand.class);
+ when(parentShellMock.getNextArgRequired()).thenReturn("set").thenReturn(name).thenReturn(
+ value);
+ when(parentShellMock.getErrPrintWriter()).thenReturn(pwMock);
+
+ collector.checkThat(mDut.onCommand(parentShellMock), equalTo(expectSuccess ? 0 : -1));
+ }
+
+ private NanConfigRequest validateEnableAndConfigure(short transactionId,
+ ConfigRequest configRequest, boolean notifyIdentityChange, boolean initialConfiguration,
+ boolean isInteractive, boolean isIdle) throws RemoteException {
+ mDut.enableAndConfigure(transactionId, configRequest, notifyIdentityChange,
+ initialConfiguration, isInteractive, isIdle);
+
+ ArgumentCaptor<NanEnableRequest> enableReqCaptor = ArgumentCaptor.forClass(
+ NanEnableRequest.class);
+ ArgumentCaptor<NanConfigRequest> configReqCaptor = ArgumentCaptor.forClass(
+ NanConfigRequest.class);
+ NanConfigRequest config;
+
+ if (initialConfiguration) {
+ verify(mIWifiNanIfaceMock).enableRequest(eq(transactionId), enableReqCaptor.capture());
+ config = enableReqCaptor.getValue().configParams;
+ } else {
+ verify(mIWifiNanIfaceMock).configRequest(eq(transactionId), configReqCaptor.capture());
+ config = configReqCaptor.getValue();
+ }
+
+ collector.checkThat("disableDiscoveryAddressChangeIndication", !notifyIdentityChange,
+ equalTo(config.disableDiscoveryAddressChangeIndication));
+ collector.checkThat("disableStartedClusterIndication", !notifyIdentityChange,
+ equalTo(config.disableStartedClusterIndication));
+ collector.checkThat("disableJoinedClusterIndication", !notifyIdentityChange,
+ equalTo(config.disableJoinedClusterIndication));
+
+ return config;
+ }
+}
diff --git a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareServiceImplTest.java
index b5e12d29c..1ab6898f5 100644
--- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareServiceImplTest.java
@@ -70,6 +70,8 @@ public class WifiAwareServiceImplTest {
@Mock
private WifiAwareStateManager mAwareStateManagerMock;
@Mock
+ private WifiAwareShellCommand mWifiAwareShellCommandMock;
+ @Mock
private IBinder mBinderMock;
@Mock
private IWifiAwareEventCallback mCallbackMock;
@@ -114,7 +116,7 @@ public class WifiAwareServiceImplTest {
mDut = new WifiAwareServiceImplSpy(mContextMock);
mDut.fakeUid = mDefaultUid;
- mDut.start(mHandlerThreadMock, mAwareStateManagerMock);
+ mDut.start(mHandlerThreadMock, mAwareStateManagerMock, mWifiAwareShellCommandMock);
verify(mAwareStateManagerMock).start(eq(mContextMock), any());
}
diff --git a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareStateManagerTest.java b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareStateManagerTest.java
index 2797c0e06..1b1157bd8 100644
--- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareStateManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareStateManagerTest.java
@@ -38,8 +38,10 @@ import android.Manifest;
import android.app.AppOpsManager;
import android.app.test.MockAnswerUtil;
import android.app.test.TestAlarmManager;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.hardware.wifi.V1_0.NanStatusType;
import android.net.ConnectivityManager;
@@ -50,7 +52,10 @@ import android.net.wifi.aware.IWifiAwareEventCallback;
import android.net.wifi.aware.PublishConfig;
import android.net.wifi.aware.SubscribeConfig;
import android.net.wifi.aware.WifiAwareManager;
+import android.os.Handler;
+import android.os.IPowerManager;
import android.os.Message;
+import android.os.PowerManager;
import android.os.UserHandle;
import android.os.test.TestLooper;
import android.test.suitebuilder.annotation.SmallTest;
@@ -86,11 +91,14 @@ public class WifiAwareStateManagerTest {
private TestLooper mMockLooper;
private Random mRandomNg = new Random(15687);
private WifiAwareStateManager mDut;
+ @Mock private WifiAwareNativeManager mMockNativeManager;
@Mock private WifiAwareNativeApi mMockNative;
@Mock private Context mMockContext;
@Mock private AppOpsManager mMockAppOpsManager;
@Mock private WifiAwareRttStateManager mMockAwareRttStateManager;
TestAlarmManager mAlarmManager;
+ private PowerManager mMockPowerManager;
+ private BroadcastReceiver mPowerBcastReceiver;
@Mock private WifiAwareDataPathStateManager mMockAwareDataPathStatemanager;
@Rule
@@ -109,9 +117,18 @@ public class WifiAwareStateManagerTest {
when(mMockContext.getSystemService(Context.ALARM_SERVICE))
.thenReturn(mAlarmManager.getAlarmManager());
+ mMockLooper = new TestLooper();
+
+ IPowerManager powerManagerService = mock(IPowerManager.class);
+ mMockPowerManager = new PowerManager(mMockContext, powerManagerService,
+ new Handler(mMockLooper.getLooper()));
+
when(mMockContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
mock(ConnectivityManager.class));
when(mMockContext.getSystemService(Context.APP_OPS_SERVICE)).thenReturn(mMockAppOpsManager);
+ when(mMockContext.getSystemServiceName(PowerManager.class)).thenReturn(
+ Context.POWER_SERVICE);
+ when(mMockContext.getSystemService(PowerManager.class)).thenReturn(mMockPowerManager);
when(mMockContext.checkPermission(eq(android.Manifest.permission.ACCESS_FINE_LOCATION),
anyInt(), anyInt())).thenReturn(PackageManager.PERMISSION_DENIED);
when(mMockContext.checkPermission(eq(Manifest.permission.ACCESS_COARSE_LOCATION),
@@ -120,16 +137,20 @@ public class WifiAwareStateManagerTest {
any())).thenReturn(AppOpsManager.MODE_ERRORED);
when(mMockAppOpsManager.noteOp(eq(AppOpsManager.OP_COARSE_LOCATION), anyInt(),
any())).thenReturn(AppOpsManager.MODE_ERRORED);
+ when(mMockPowerManager.isDeviceIdleMode()).thenReturn(false);
+ when(mMockPowerManager.isInteractive()).thenReturn(true);
- mMockLooper = new TestLooper();
-
+ ArgumentCaptor<BroadcastReceiver> bcastRxCaptor = ArgumentCaptor.forClass(
+ BroadcastReceiver.class);
mDut = new WifiAwareStateManager();
mDut.setNative(mMockNative);
mDut.start(mMockContext, mMockLooper.getLooper());
+ verify(mMockContext).registerReceiver(bcastRxCaptor.capture(), any(IntentFilter.class));
+ mPowerBcastReceiver = bcastRxCaptor.getValue();
installMocksInStateManager(mDut, mMockAwareRttStateManager, mMockAwareDataPathStatemanager);
when(mMockNative.enableAndConfigure(anyShort(), any(), anyBoolean(),
- anyBoolean())).thenReturn(true);
+ anyBoolean(), anyBoolean(), anyBoolean())).thenReturn(true);
when(mMockNative.disable(anyShort())).thenReturn(true);
when(mMockNative.publish(anyShort(), anyInt(), any())).thenReturn(true);
when(mMockNative.subscribe(anyShort(), anyInt(), any()))
@@ -142,6 +163,32 @@ public class WifiAwareStateManagerTest {
}
/**
+ * Test that the set parameter shell command executor works when parameters are valid.
+ */
+ @Test
+ public void testSetParameterShellCommandSuccess() {
+ setSettableParam(WifiAwareStateManager.PARAM_ON_IDLE_DISABLE_AWARE, Integer.toString(1),
+ true);
+ }
+
+ /**
+ * Test that the set parameter shell command executor fails on incorrect name.
+ */
+ @Test
+ public void testSetParameterShellCommandInvalidParameterName() {
+ setSettableParam("XXX", Integer.toString(1), false);
+ }
+
+ /**
+ * Test that the set parameter shell command executor fails on invalid value (not convertible
+ * to an int).
+ */
+ @Test
+ public void testSetParameterShellCommandInvalidValue() {
+ setSettableParam(WifiAwareStateManager.PARAM_ON_IDLE_DISABLE_AWARE, "garbage", false);
+ }
+
+ /**
* Validate that Aware data-path interfaces are brought up and down correctly.
*/
@Test
@@ -242,7 +289,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -274,7 +321,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -298,7 +345,7 @@ public class WifiAwareStateManagerTest {
InOrder inOrder = inOrder(mMockContext, mMockNative, mockCallback);
when(mMockNative.enableAndConfigure(anyShort(), any(), anyBoolean(),
- anyBoolean())).thenReturn(false);
+ anyBoolean(), eq(true), eq(false))).thenReturn(false);
// (1) check initial state
mDut.enableUsage();
@@ -312,7 +359,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
inOrder.verify(mockCallback).onConnectFail(NanStatusType.INTERNAL_FAILURE);
validateInternalClientInfoCleanedUp(clientId);
@@ -356,7 +403,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId1, uid, pid, callingPackage, mockCallback1, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionIdCapture.capture(),
- eq(configRequest), eq(false), eq(true));
+ eq(configRequest), eq(false), eq(true), eq(true), eq(false));
short transactionId = transactionIdCapture.getValue();
mDut.onConfigSuccessResponse(transactionId);
mMockLooper.dispatchAll();
@@ -365,7 +412,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId2, uid, pid, callingPackage, mockCallback2, configRequest, true);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionIdCapture.capture(),
- eq(configRequest), eq(true), eq(false));
+ eq(configRequest), eq(true), eq(false), eq(true), eq(false));
transactionId = transactionIdCapture.getValue();
mDut.onConfigSuccessResponse(transactionId);
mMockLooper.dispatchAll();
@@ -441,7 +488,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -497,7 +544,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(),
- eq(configRequest), eq(false), eq(true));
+ eq(configRequest), eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -561,7 +608,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(),
- eq(configRequest), eq(false), eq(true));
+ eq(configRequest), eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -635,7 +682,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -717,7 +764,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -775,7 +822,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -840,7 +887,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -913,7 +960,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -996,7 +1043,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -1068,7 +1115,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(),
- eq(configRequest), eq(false), eq(true));
+ eq(configRequest), eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -1174,7 +1221,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -1268,7 +1315,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -1351,7 +1398,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -1418,7 +1465,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -1542,7 +1589,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -1627,7 +1674,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -1713,7 +1760,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(),
- eq(configRequest), eq(false), eq(true));
+ eq(configRequest), eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -1809,7 +1856,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(),
- eq(configRequest), eq(false), eq(true));
+ eq(configRequest), eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -1939,7 +1986,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(),
- eq(configRequest), eq(false), eq(true));
+ eq(configRequest), eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -2152,7 +2199,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -2243,7 +2290,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId1, uid, pid, callingPackage, mockCallback1, configRequest1, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(),
- crCapture.capture(), eq(false), eq(true));
+ crCapture.capture(), eq(false), eq(true), eq(true), eq(false));
collector.checkThat("merge: stage 1", crCapture.getValue(), equalTo(configRequest1));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
@@ -2259,7 +2306,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId3, uid, pid, callingPackage, mockCallback3, configRequest3, true);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(),
- crCapture.capture(), eq(true), eq(false));
+ crCapture.capture(), eq(true), eq(false), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback3).onConnectSuccess(clientId3);
@@ -2280,7 +2327,7 @@ public class WifiAwareStateManagerTest {
mMockLooper.dispatchAll();
validateInternalClientInfoCleanedUp(clientId3);
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(),
- crCapture.capture(), eq(false), eq(false));
+ crCapture.capture(), eq(false), eq(false), eq(true), eq(false));
collector.checkThat("configRequest1", configRequest1, equalTo(crCapture.getValue()));
@@ -2335,7 +2382,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -2409,7 +2456,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -2452,7 +2499,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
verifyNoMoreInteractions(mMockNative, mockCallback, mockSessionCallback);
}
@@ -2486,7 +2533,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
short transactionIdConfig = transactionId.getValue();
mDut.onConfigSuccessResponse(transactionIdConfig);
mMockLooper.dispatchAll();
@@ -2542,7 +2589,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(), eq(configRequest),
- eq(false), eq(true));
+ eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -2596,7 +2643,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(),
- eq(configRequest), eq(false), eq(true));
+ eq(configRequest), eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -2648,7 +2695,7 @@ public class WifiAwareStateManagerTest {
mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(),
- eq(configRequest), eq(false), eq(true));
+ eq(configRequest), eq(false), eq(true), eq(true), eq(false));
mDut.onConfigSuccessResponse(transactionId.getValue());
mMockLooper.dispatchAll();
inOrder.verify(mockCallback).onConnectSuccess(clientId);
@@ -2672,6 +2719,116 @@ public class WifiAwareStateManagerTest {
}
}
+ /**
+ * Validate configuration changes on power state changes when Aware is not disabled on doze.
+ */
+ @Test
+ public void testConfigOnPowerStateChanges() throws Exception {
+ final int clientId = 188;
+ final int uid = 1000;
+ final int pid = 2000;
+ final String callingPackage = "com.google.somePackage";
+
+ ConfigRequest configRequest = new ConfigRequest.Builder().build();
+
+ ArgumentCaptor<Short> transactionId = ArgumentCaptor.forClass(Short.class);
+ IWifiAwareEventCallback mockCallback = mock(IWifiAwareEventCallback.class);
+ InOrder inOrder = inOrder(mMockNative, mockCallback);
+
+ mDut.enableUsage();
+ mMockLooper.dispatchAll();
+ inOrder.verify(mMockNative).getCapabilities(transactionId.capture());
+ mDut.onCapabilitiesUpdateResponse(transactionId.getValue(), getCapabilities());
+ mMockLooper.dispatchAll();
+
+ // (1) connect
+ mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
+ mMockLooper.dispatchAll();
+ inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(),
+ eq(configRequest), eq(false), eq(true), eq(true), eq(false));
+ mDut.onConfigSuccessResponse(transactionId.getValue());
+ mMockLooper.dispatchAll();
+ inOrder.verify(mockCallback).onConnectSuccess(clientId);
+
+ // (2) power state change: SCREEN OFF
+ simulatePowerStateChangeInteractive(false);
+ mMockLooper.dispatchAll();
+ inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(),
+ eq(configRequest), eq(false), eq(false), eq(false), eq(false));
+ mDut.onConfigSuccessResponse(transactionId.getValue());
+ mMockLooper.dispatchAll();
+
+ // (3) power state change: DOZE
+ simulatePowerStateChangeDoze(true);
+ mMockLooper.dispatchAll();
+ inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(),
+ eq(configRequest), eq(false), eq(false), eq(false), eq(true));
+ mDut.onConfigSuccessResponse(transactionId.getValue());
+ mMockLooper.dispatchAll();
+
+ // (4) restore power state to default
+ simulatePowerStateChangeInteractive(true); // effectively treated as no-doze
+ mMockLooper.dispatchAll();
+ inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(),
+ eq(configRequest), eq(false), eq(false), eq(true), eq(true));
+ mDut.onConfigSuccessResponse(transactionId.getValue());
+ mMockLooper.dispatchAll();
+
+ verifyNoMoreInteractions(mMockNative, mockCallback);
+ }
+
+ /**
+ * Validate aware enable/disable during doze transitions.
+ */
+ @Test
+ public void testEnableDisableOnDoze() throws Exception {
+ final int clientId = 188;
+ final int uid = 1000;
+ final int pid = 2000;
+ final String callingPackage = "com.google.somePackage";
+
+ setSettableParam(WifiAwareStateManager.PARAM_ON_IDLE_DISABLE_AWARE, Integer.toString(1),
+ true);
+
+ ConfigRequest configRequest = new ConfigRequest.Builder().build();
+
+ ArgumentCaptor<Short> transactionId = ArgumentCaptor.forClass(Short.class);
+ IWifiAwareEventCallback mockCallback = mock(IWifiAwareEventCallback.class);
+ InOrder inOrder = inOrder(mMockContext, mMockNativeManager, mMockNative, mockCallback);
+
+ mDut.enableUsage();
+ mMockLooper.dispatchAll();
+ inOrder.verify(mMockNative).getCapabilities(transactionId.capture());
+ mDut.onCapabilitiesUpdateResponse(transactionId.getValue(), getCapabilities());
+ mMockLooper.dispatchAll();
+
+ // (1) connect
+ mDut.connect(clientId, uid, pid, callingPackage, mockCallback, configRequest, false);
+ mMockLooper.dispatchAll();
+ inOrder.verify(mMockNative).enableAndConfigure(transactionId.capture(),
+ eq(configRequest), eq(false), eq(true), eq(true), eq(false));
+ mDut.onConfigSuccessResponse(transactionId.getValue());
+ mMockLooper.dispatchAll();
+ inOrder.verify(mockCallback).onConnectSuccess(clientId);
+
+ // (3) power state change: DOZE
+ simulatePowerStateChangeDoze(true);
+ mMockLooper.dispatchAll();
+ inOrder.verify(mMockNative).disable((short) 0);
+ validateCorrectAwareStatusChangeBroadcast(inOrder, false);
+
+ // (4) power state change: SCREEN ON (but DOZE still on - fakish but expect no changes)
+ simulatePowerStateChangeInteractive(false);
+ mMockLooper.dispatchAll();
+
+ // (5) power state change: DOZE OFF
+ simulatePowerStateChangeDoze(false);
+ mMockLooper.dispatchAll();
+ validateCorrectAwareStatusChangeBroadcast(inOrder, true);
+
+ verifyNoMoreInteractions(mMockNativeManager, mMockNative, mockCallback);
+ }
+
/*
* Tests of internal state of WifiAwareStateManager: very limited (not usually
* a good idea). However, these test that the internal state is cleaned-up
@@ -2749,6 +2906,16 @@ public class WifiAwareStateManagerTest {
/*
* Utilities
*/
+ private void setSettableParam(String name, String value, boolean expectSuccess) {
+ PrintWriter pwMock = mock(PrintWriter.class);
+ WifiAwareShellCommand parentShellMock = mock(WifiAwareShellCommand.class);
+ when(parentShellMock.getNextArgRequired()).thenReturn("set").thenReturn(name).thenReturn(
+ value);
+ when(parentShellMock.getErrPrintWriter()).thenReturn(pwMock);
+
+ collector.checkThat(mDut.onCommand(parentShellMock), equalTo(expectSuccess ? 0 : -1));
+ }
+
private void dumpDut(String prefix) {
StringWriter sw = new StringWriter();
mDut.dump(null, new PrintWriter(sw), null);
@@ -2823,6 +2990,29 @@ public class WifiAwareStateManagerTest {
}
}
+ /**
+ * Simulate power state change due to doze. Changes the power manager return values and
+ * dispatches a broadcast.
+ */
+ private void simulatePowerStateChangeDoze(boolean isDozeOn) {
+ when(mMockPowerManager.isDeviceIdleMode()).thenReturn(isDozeOn);
+
+ Intent intent = new Intent(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);
+ mPowerBcastReceiver.onReceive(mMockContext, intent);
+ }
+
+ /**
+ * Simulate power state change due to interactive mode change (screen on/off). Changes the power
+ * manager return values and dispatches a broadcast.
+ */
+ private void simulatePowerStateChangeInteractive(boolean isInteractive) {
+ when(mMockPowerManager.isInteractive()).thenReturn(isInteractive);
+
+ Intent intent = new Intent(
+ isInteractive ? Intent.ACTION_SCREEN_ON : Intent.ACTION_SCREEN_OFF);
+ mPowerBcastReceiver.onReceive(mMockContext, intent);
+ }
+
private static Capabilities getCapabilities() {
Capabilities cap = new Capabilities();
cap.maxConcurrentAwareClusters = 1;