summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRebecca Silberstein <silberst@google.com>2017-06-09 14:55:32 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-06-09 14:55:32 +0000
commitfd97a990e1c1467a5f1e9634885f5a34c1e66e5c (patch)
tree3eef5a26dbd589255c5c18c5ba5c261c130beb19 /tests
parentb4f2651a4c0958f7604561070773fbd67e70145e (diff)
parent8ec0ba59c20b8266d735912fb71575834c991acc (diff)
Merge "WifiServiceImpl: check app status for startLOHS" into oc-dev
am: 8ec0ba59c2 Change-Id: Id2a629c5363fb024abc4406a91ae60d0ae343d8b
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java40
1 files changed, 38 insertions, 2 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index 45ffa8c04..d5bfb2045 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -74,6 +74,7 @@ import android.os.Message;
import android.os.Messenger;
import android.os.PowerManager;
import android.os.Process;
+import android.os.RemoteException;
import android.os.UserManager;
import android.os.WorkSource;
import android.os.test.TestLooper;
@@ -761,6 +762,9 @@ public class WifiServiceImplTest {
// allow test to proceed without a permission check failure
when(mSettingsStore.getLocationModeSetting(mContext))
.thenReturn(LOCATION_MODE_HIGH_ACCURACY);
+ try {
+ when(mFrameworkFacade.isAppForeground(anyInt())).thenReturn(true);
+ } catch (RemoteException e) { }
when(mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING))
.thenReturn(false);
int result = mWifiServiceImpl.startLocalOnlyHotspot(mAppMessenger, mAppBinder,
@@ -813,12 +817,43 @@ public class WifiServiceImplTest {
}
/**
+ * Only start LocalOnlyHotspot if the caller is the foreground app at the time of the request.
+ */
+ @Test
+ public void testStartLocalOnlyHotspotFailsIfRequestorNotForegroundApp() throws Exception {
+ when(mSettingsStore.getLocationModeSetting(mContext))
+ .thenReturn(LOCATION_MODE_HIGH_ACCURACY);
+
+ when(mFrameworkFacade.isAppForeground(anyInt())).thenReturn(false);
+ int result = mWifiServiceImpl.startLocalOnlyHotspot(mAppMessenger, mAppBinder,
+ TEST_PACKAGE_NAME);
+ assertEquals(LocalOnlyHotspotCallback.ERROR_INCOMPATIBLE_MODE, result);
+ }
+
+ /**
+ * Do not register the LocalOnlyHotspot request if the caller app cannot be verified as the
+ * foreground app at the time of the request (ie, throws an exception in the check).
+ */
+ @Test
+ public void testStartLocalOnlyHotspotFailsIfForegroundAppCheckThrowsRemoteException()
+ throws Exception {
+ when(mSettingsStore.getLocationModeSetting(mContext))
+ .thenReturn(LOCATION_MODE_HIGH_ACCURACY);
+
+ when(mFrameworkFacade.isAppForeground(anyInt())).thenThrow(new RemoteException());
+ int result = mWifiServiceImpl.startLocalOnlyHotspot(mAppMessenger, mAppBinder,
+ TEST_PACKAGE_NAME);
+ assertEquals(LocalOnlyHotspotCallback.ERROR_INCOMPATIBLE_MODE, result);
+ }
+
+ /**
* Only start LocalOnlyHotspot if we are not tethering.
*/
@Test
- public void testHotspotDoesNotStartWhenAlreadyTethering() {
+ public void testHotspotDoesNotStartWhenAlreadyTethering() throws Exception {
when(mSettingsStore.getLocationModeSetting(mContext))
.thenReturn(LOCATION_MODE_HIGH_ACCURACY);
+ when(mFrameworkFacade.isAppForeground(anyInt())).thenReturn(true);
mWifiServiceImpl.updateInterfaceIpState(WIFI_IFACE_NAME, IFACE_IP_MODE_TETHERED);
mLooper.dispatchAll();
int returnCode = mWifiServiceImpl.startLocalOnlyHotspot(
@@ -830,9 +865,10 @@ public class WifiServiceImplTest {
* Only start LocalOnlyHotspot if admin setting does not disallow tethering.
*/
@Test
- public void testHotspotDoesNotStartWhenTetheringDisallowed() {
+ public void testHotspotDoesNotStartWhenTetheringDisallowed() throws Exception {
when(mSettingsStore.getLocationModeSetting(mContext))
.thenReturn(LOCATION_MODE_HIGH_ACCURACY);
+ when(mFrameworkFacade.isAppForeground(anyInt())).thenReturn(true);
when(mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING))
.thenReturn(true);
int returnCode = mWifiServiceImpl.startLocalOnlyHotspot(