summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2022-11-30 05:00:06 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2022-11-30 05:00:06 +0000
commit41ef2ad50e24a113bebecbc30c180b9f15abbf52 (patch)
treee85d83019dd5215c81bf576d0d3b46bebc0d0cdf
parentba6ee84b316b907bb7370bbaa4c7e8db1e8a3a0b (diff)
parent7cf700f0a4358a9a13f8a6ee70d62bdbf3d28c57 (diff)
Merge "Move private HDM PRIORITY_ constants to WorkSourceHelper" into tm-mainline-prod
-rw-r--r--service/java/com/android/server/wifi/HalDeviceManager.java92
-rw-r--r--service/java/com/android/server/wifi/InterfaceConflictManager.java13
-rw-r--r--service/java/com/android/server/wifi/WifiInjector.java2
-rw-r--r--service/java/com/android/server/wifi/util/WorkSourceHelper.java146
-rw-r--r--service/tests/wifitests/src/com/android/server/wifi/HalDeviceManagerTest.java303
-rw-r--r--service/tests/wifitests/src/com/android/server/wifi/InterfaceConflictManagerTest.java13
-rw-r--r--service/tests/wifitests/src/com/android/server/wifi/util/WorkSourceHelperTest.java114
7 files changed, 315 insertions, 368 deletions
diff --git a/service/java/com/android/server/wifi/HalDeviceManager.java b/service/java/com/android/server/wifi/HalDeviceManager.java
index a59c63b685..b0fb6883fd 100644
--- a/service/java/com/android/server/wifi/HalDeviceManager.java
+++ b/service/java/com/android/server/wifi/HalDeviceManager.java
@@ -72,8 +72,6 @@ import org.json.JSONException;
import java.io.FileDescriptor;
import java.io.PrintWriter;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -2469,58 +2467,20 @@ public class HalDeviceManager {
return false;
}
- private static final int PRIORITY_INTERNAL = 0;
- private static final int PRIORITY_BG = 1;
- private static final int PRIORITY_FG_SERVICE = 2;
- private static final int PRIORITY_FG_APP = 3;
- private static final int PRIORITY_SYSTEM = 4;
- private static final int PRIORITY_PRIVILEGED = 5;
- // Keep these in sync with any additions/deletions to above buckets.
- private static final int PRIORITY_MIN = PRIORITY_INTERNAL;
- private static final int PRIORITY_MAX = PRIORITY_PRIVILEGED;
- @IntDef(prefix = { "PRIORITY_" }, value = {
- PRIORITY_INTERNAL,
- PRIORITY_BG,
- PRIORITY_FG_SERVICE,
- PRIORITY_FG_APP,
- PRIORITY_SYSTEM,
- PRIORITY_PRIVILEGED,
- })
- @Retention(RetentionPolicy.SOURCE)
- public @interface RequestorWsPriority {}
-
- /**
- * Returns integer priority level for the provided |ws| based on rules mentioned in
- * {@link #selectInterfacesToDelete(int, int, WorkSource, int, WifiIfaceInfo[])}.
- */
- private static @RequestorWsPriority int getRequestorWsPriority(WorkSourceHelper ws) {
- if (ws.hasAnyPrivilegedAppRequest()) return PRIORITY_PRIVILEGED;
- if (ws.hasAnySystemAppRequest()) return PRIORITY_SYSTEM;
- if (ws.hasAnyForegroundAppRequest(/* allowOverlayBypass */ true)) return PRIORITY_FG_APP;
- if (ws.hasAnyForegroundServiceRequest()) return PRIORITY_FG_SERVICE;
- if (ws.hasAnyInternalRequest()) return PRIORITY_INTERNAL;
- return PRIORITY_BG;
- }
-
/**
* Returns true if the requested iface can delete an existing iface only after user approval.
*/
public boolean needsUserApprovalToDelete(
- int requestedCreateType, WorkSource newWorksource,
- int existingCreateType, WorkSource existingWorksource) {
- return needsUserApprovalToDelete(
- requestedCreateType,
- getRequestorWsPriority(mWifiInjector.makeWsHelper(newWorksource)),
- existingCreateType,
- getRequestorWsPriority(mWifiInjector.makeWsHelper(existingWorksource)));
- }
-
- private boolean needsUserApprovalToDelete(
- int requestedCreateType, int newRequestorWsPriority,
- int existingCreateType, int existingRequestorWsPriority) {
+ int requestedCreateType, @NonNull WorkSourceHelper newRequestorWsHelper,
+ int existingCreateType, @NonNull WorkSourceHelper existingRequestorWsHelper) {
+ @WorkSourceHelper.RequestorWsPriority int newRequestorWsPriority =
+ newRequestorWsHelper.getRequestorWsPriority();
+ @WorkSourceHelper.RequestorWsPriority int existingRequestorWsPriority =
+ existingRequestorWsHelper.getRequestorWsPriority();
+
if (!mWifiUserApprovalRequiredForD2dInterfacePriority
- || newRequestorWsPriority <= PRIORITY_BG
- || existingRequestorWsPriority == PRIORITY_INTERNAL) {
+ || newRequestorWsPriority <= WorkSourceHelper.PRIORITY_BG
+ || existingRequestorWsPriority == WorkSourceHelper.PRIORITY_INTERNAL) {
return false;
}
@@ -2568,19 +2528,23 @@ public class HalDeviceManager {
*/
private boolean allowedToDelete(
@HdmIfaceTypeForCreation int requestedCreateType,
- @RequestorWsPriority int newRequestorWsPriority,
+ @NonNull WorkSourceHelper newRequestorWs,
@HdmIfaceTypeForCreation int existingCreateType,
- @RequestorWsPriority int existingRequestorWsPriority) {
+ @NonNull WorkSourceHelper existingRequestorWs) {
if (!SdkLevel.isAtLeastS()) {
return allowedToDeleteForR(requestedCreateType, existingCreateType);
}
// Defer deletion decision to the InterfaceConflictManager dialog.
- if (needsUserApprovalToDelete(requestedCreateType, newRequestorWsPriority,
- existingCreateType, existingRequestorWsPriority)) {
+ if (needsUserApprovalToDelete(requestedCreateType, newRequestorWs,
+ existingCreateType, existingRequestorWs)) {
return true;
}
+ @HdmIfaceTypeForCreation int newRequestorWsPriority =
+ newRequestorWs.getRequestorWsPriority();
+ @HdmIfaceTypeForCreation int existingRequestorWsPriority =
+ existingRequestorWs.getRequestorWsPriority();
// If the new request is higher priority than existing priority, then the new requestor
// wins. This is because at all other priority levels (except privileged), existing caller
// wins if both the requests are at the same priority level.
@@ -2596,7 +2560,7 @@ public class HalDeviceManager {
// If both the requests are privileged, the new requestor wins. The exception is for
// backwards compatibility with P2P Settings, prefer SoftAP over P2P for when the user
// enables SoftAP with P2P Settings open.
- if (newRequestorWsPriority == PRIORITY_PRIVILEGED) {
+ if (newRequestorWsPriority == WorkSourceHelper.PRIORITY_PRIVILEGED) {
if (requestedCreateType == HDM_CREATE_IFACE_P2P
&& (existingCreateType == HDM_CREATE_IFACE_AP
|| existingCreateType == HDM_CREATE_IFACE_AP_BRIDGE)) {
@@ -2622,9 +2586,9 @@ public class HalDeviceManager {
*/
private boolean allowedToDeleteForNoStaApConcurrencyLohs(
@HdmIfaceTypeForCreation int requestedCreateType,
- @RequestorWsPriority int newRequestorWsPriority,
+ @WorkSourceHelper.RequestorWsPriority int newRequestorWsPriority,
@HdmIfaceTypeForCreation int existingCreateType,
- @RequestorWsPriority int existingRequestorWsPriority) {
+ @WorkSourceHelper.RequestorWsPriority int existingRequestorWsPriority) {
return !canDeviceSupportCreateTypeCombo(
new SparseArray<Integer>() {{
put(IfaceConcurrencyType.STA, 1);
@@ -2632,10 +2596,10 @@ public class HalDeviceManager {
}})
&& (requestedCreateType == HDM_CREATE_IFACE_AP
|| requestedCreateType == HDM_CREATE_IFACE_AP_BRIDGE)
- && newRequestorWsPriority != PRIORITY_INTERNAL
- && newRequestorWsPriority != PRIORITY_PRIVILEGED
+ && newRequestorWsPriority != WorkSourceHelper.PRIORITY_INTERNAL
+ && newRequestorWsPriority != WorkSourceHelper.PRIORITY_PRIVILEGED
&& existingCreateType == HDM_CREATE_IFACE_STA
- && existingRequestorWsPriority == PRIORITY_PRIVILEGED;
+ && existingRequestorWsPriority == WorkSourceHelper.PRIORITY_PRIVILEGED;
}
/**
@@ -2737,10 +2701,10 @@ public class HalDeviceManager {
lookupError = true;
break;
}
- int newRequestorWsPriority = getRequestorWsPriority(newRequestorWsHelper);
- int existingRequestorWsPriority = getRequestorWsPriority(cacheEntry.requestorWsHelper);
- boolean isAllowedToDelete = allowedToDelete(requestedCreateType, newRequestorWsPriority,
- existingCreateType, existingRequestorWsPriority);
+ int newRequestorWsPriority = newRequestorWsHelper.getRequestorWsPriority();
+ int existingRequestorWsPriority = cacheEntry.requestorWsHelper.getRequestorWsPriority();
+ boolean isAllowedToDelete = allowedToDelete(requestedCreateType, newRequestorWsHelper,
+ existingCreateType, cacheEntry.requestorWsHelper);
if (VDBG) {
Log.d(TAG, "info=" + info + ": allowedToDelete=" + isAllowedToDelete
+ " (requestedCreateType=" + requestedCreateType
@@ -2762,7 +2726,7 @@ public class HalDeviceManager {
int numIfacesToDelete = 0;
ifacesToDelete = new ArrayList<>(requestedQuantity);
// Iterate from lowest priority to highest priority ifaces.
- for (int i = PRIORITY_MIN; i <= PRIORITY_MAX; i++) {
+ for (int i = WorkSourceHelper.PRIORITY_MIN; i <= WorkSourceHelper.PRIORITY_MAX; i++) {
List<WifiIfaceInfo> ifacesToDeleteListWithinPriority =
ifacesToDeleteMap.getOrDefault(i, new ArrayList<>());
int numIfacesToDeleteWithinPriority =
diff --git a/service/java/com/android/server/wifi/InterfaceConflictManager.java b/service/java/com/android/server/wifi/InterfaceConflictManager.java
index c7ba72f450..8faba11d32 100644
--- a/service/java/com/android/server/wifi/InterfaceConflictManager.java
+++ b/service/java/com/android/server/wifi/InterfaceConflictManager.java
@@ -39,6 +39,8 @@ import android.util.LocalLog;
import android.util.Log;
import android.util.Pair;
+import androidx.annotation.NonNull;
+
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
import com.android.server.wifi.util.WaitingState;
@@ -61,6 +63,7 @@ public class InterfaceConflictManager {
private static final String TAG = "InterfaceConflictManager";
private boolean mVerboseLoggingEnabled = false;
+ private final WifiInjector mWifiInjector;
private final WifiContext mContext;
private final FrameworkFacade mFrameworkFacade;
private final HalDeviceManager mHdm;
@@ -86,9 +89,10 @@ public class InterfaceConflictManager {
private static final String MESSAGE_BUNDLE_KEY_PENDING_USER = "pending_user_decision";
- public InterfaceConflictManager(WifiContext wifiContext, FrameworkFacade frameworkFacade,
- HalDeviceManager hdm, WifiThreadRunner threadRunner,
+ public InterfaceConflictManager(@NonNull WifiInjector wifiInjector, WifiContext wifiContext,
+ FrameworkFacade frameworkFacade, HalDeviceManager hdm, WifiThreadRunner threadRunner,
WifiDialogManager wifiDialogManager, LocalLog localLog) {
+ mWifiInjector = wifiInjector;
mContext = wifiContext;
mFrameworkFacade = frameworkFacade;
mHdm = hdm;
@@ -285,8 +289,9 @@ public class InterfaceConflictManager {
boolean shouldShowDialogToDelete = false;
for (Pair<Integer, WorkSource> ifaceToDelete : impact) {
- if (mHdm.needsUserApprovalToDelete(createIfaceType, requestorWs,
- ifaceToDelete.first, ifaceToDelete.second)) {
+ if (mHdm.needsUserApprovalToDelete(
+ createIfaceType, mWifiInjector.makeWsHelper(requestorWs),
+ ifaceToDelete.first, mWifiInjector.makeWsHelper(ifaceToDelete.second))) {
shouldShowDialogToDelete = true;
break;
}
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java
index f84e6206fa..bf8f2ef061 100644
--- a/service/java/com/android/server/wifi/WifiInjector.java
+++ b/service/java/com/android/server/wifi/WifiInjector.java
@@ -308,7 +308,7 @@ public class WifiInjector {
mFrameworkFacade, mContext);
// Modules interacting with Native.
mHalDeviceManager = new HalDeviceManager(mContext, mClock, this, wifiHandler);
- mInterfaceConflictManager = new InterfaceConflictManager(mContext, mFrameworkFacade,
+ mInterfaceConflictManager = new InterfaceConflictManager(this, mContext, mFrameworkFacade,
mHalDeviceManager, mWifiThreadRunner, mWifiDialogManager, new LocalLog(
mContext.getSystemService(ActivityManager.class).isLowRamDevice() ? 128 : 256));
mWifiVendorHal = new WifiVendorHal(mContext, mHalDeviceManager, wifiHandler, mWifiGlobals,
diff --git a/service/java/com/android/server/wifi/util/WorkSourceHelper.java b/service/java/com/android/server/wifi/util/WorkSourceHelper.java
index cbd65a8f5f..3651ddc6f7 100644
--- a/service/java/com/android/server/wifi/util/WorkSourceHelper.java
+++ b/service/java/com/android/server/wifi/util/WorkSourceHelper.java
@@ -19,6 +19,7 @@ package com.android.server.wifi.util;
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND_SERVICE;
+import android.annotation.IntDef;
import android.annotation.NonNull;
import android.app.ActivityManager;
import android.content.pm.ApplicationInfo;
@@ -32,6 +33,8 @@ import android.util.Log;
import com.android.wifi.resources.R;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
/**
@@ -49,6 +52,67 @@ public class WorkSourceHelper {
private final PackageManager mPackageManager;
private final Resources mResources;
+ // Internal opportunistic request.
+ public static final int PRIORITY_INTERNAL = 0;
+
+ // Request from a background app.
+ public static final int PRIORITY_BG = 1;
+
+ // Request from a foreground service.
+ public static final int PRIORITY_FG_SERVICE = 2;
+
+ // Request from a foreground app.
+ public static final int PRIORITY_FG_APP = 3;
+
+ // Request from a system app.
+ public static final int PRIORITY_SYSTEM = 4;
+
+ // Request from an app with NETWORK_SETTINGS, NETWORK_SETUP_WIZARD or NETWORK_STACK permission.
+ public static final int PRIORITY_PRIVILEGED = 5;
+
+ // Keep these in sync with any additions/deletions to above buckets.
+ public static final int PRIORITY_MIN = PRIORITY_INTERNAL;
+ public static final int PRIORITY_MAX = PRIORITY_PRIVILEGED;
+ @IntDef(prefix = { "PRIORITY_" }, value = {
+ PRIORITY_INTERNAL,
+ PRIORITY_BG,
+ PRIORITY_FG_SERVICE,
+ PRIORITY_FG_APP,
+ PRIORITY_SYSTEM,
+ PRIORITY_PRIVILEGED,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface RequestorWsPriority {}
+
+ /**
+ * Returns integer priority level for the provided |ws|.
+ */
+ public @RequestorWsPriority int getRequestorWsPriority() {
+ @RequestorWsPriority int totalPriority = PRIORITY_INTERNAL;
+ for (int i = 0; i < mWorkSource.size(); i++) {
+ String packageName = mWorkSource.getPackageName(i);
+ int uid = mWorkSource.getUid(i);
+ final @RequestorWsPriority int priority;
+ if (uid == Process.WIFI_UID) {
+ priority = PRIORITY_INTERNAL;
+ } else if (isPrivileged(uid)) {
+ priority = PRIORITY_PRIVILEGED;
+ } else if (isSystem(packageName, uid)) {
+ priority = PRIORITY_SYSTEM;
+ } else if (isForegroundApp(packageName)) {
+ priority = PRIORITY_FG_APP;
+ } else if (isForegroundService(packageName)) {
+ priority = PRIORITY_FG_SERVICE;
+ } else {
+ priority = PRIORITY_BG;
+ }
+ if (priority > totalPriority) {
+ totalPriority = priority;
+ }
+ }
+ return totalPriority;
+ }
+
public WorkSourceHelper(
@NonNull WorkSource workSource,
@NonNull WifiPermissionsUtil wifiPermissionsUtil,
@@ -71,6 +135,9 @@ public class WorkSourceHelper {
return mWorkSource.toString();
}
+ /**
+ * Check if the request comes from an app with privileged permissions.
+ */
private boolean isPrivileged(int uid) {
return mWifiPermissionsUtil.checkNetworkSettingsPermission(uid)
|| mWifiPermissionsUtil.checkNetworkSetupWizardPermission(uid)
@@ -79,19 +146,8 @@ public class WorkSourceHelper {
}
/**
- * Returns whether any of the one or more worksource objects contains a privileged app
- * request.
- *
- * Privileged = Request from an app with NETWORK_SETTINGS, NETWORK_SETUP_WIZARD or
- * NETWORK_STACK permissions.
+ * Check if the request comes from a system app.
*/
- public boolean hasAnyPrivilegedAppRequest() {
- for (int i = 0; i < mWorkSource.size(); i++) {
- if (isPrivileged(mWorkSource.getUid(i))) return true;
- }
- return false;
- }
-
private boolean isSystem(String packageName, int uid) {
// when checking ActiveModeWarden#INTERNAL_REQUESTOR_WS
if (packageName == null) {
@@ -112,28 +168,14 @@ public class WorkSourceHelper {
}
/**
- * Returns whether any of the one or more worksource objects contains a system app
- * request.
- */
- public boolean hasAnySystemAppRequest() {
- for (int i = 0; i < mWorkSource.size(); i++) {
- if (isSystem(mWorkSource.getPackageName(i), mWorkSource.getUid(i))) return true;
- }
- return false;
- }
-
- /**
- * Check if the request comes from foreground app.
+ * Check if the request comes from a foreground app.
*/
- private boolean isForegroundApp(@NonNull String requestorPackageName,
- boolean allowOverlayBypass) {
- if (allowOverlayBypass) {
- String[] exceptionList = mResources.getStringArray(
- R.array.config_wifiInterfacePriorityTreatAsForegroundList);
- if (exceptionList != null && Arrays.stream(exceptionList).anyMatch(
- s -> TextUtils.equals(requestorPackageName, s))) {
- return true;
- }
+ private boolean isForegroundApp(@NonNull String requestorPackageName) {
+ String[] exceptionList = mResources.getStringArray(
+ R.array.config_wifiInterfacePriorityTreatAsForegroundList);
+ if (exceptionList != null && Arrays.stream(exceptionList).anyMatch(
+ s -> TextUtils.equals(requestorPackageName, s))) {
+ return true;
}
try {
return mActivityManager.getPackageImportance(requestorPackageName)
@@ -145,21 +187,7 @@ public class WorkSourceHelper {
}
/**
- * Returns whether any of the one or more worksource objects contains a foreground app
- * request.
- *
- * @param allowOverlayBypass Use the `config_wifiInterfacePriorityTreatAsForegroundList` overlay
- * to consider the specified packages are foreground.
- */
- public boolean hasAnyForegroundAppRequest(boolean allowOverlayBypass) {
- for (int i = 0; i < mWorkSource.size(); i++) {
- if (isForegroundApp(mWorkSource.getPackageName(i), allowOverlayBypass)) return true;
- }
- return false;
- }
-
- /**
- * Check if the request comes from foreground service.
+ * Check if the request comes from a foreground service.
*/
private boolean isForegroundService(@NonNull String requestorPackageName) {
try {
@@ -171,26 +199,4 @@ public class WorkSourceHelper {
return false;
}
}
-
- /**
- * Returns whether any of the one or more worksource objects contains a foreground service
- * request.
- */
- public boolean hasAnyForegroundServiceRequest() {
- for (int i = 0; i < mWorkSource.size(); i++) {
- if (isForegroundService(mWorkSource.getPackageName(i))) return true;
- }
- return false;
- }
-
- /**
- * Returns whether any of the one or more worksource objects contains an internal
- * (i.e uid = Process.WIFI_UID) request.
- */
- public boolean hasAnyInternalRequest() {
- for (int i = 0; i < mWorkSource.size(); i++) {
- if (mWorkSource.getUid(i) == Process.WIFI_UID) return true;
- }
- return false;
- }
}
diff --git a/service/tests/wifitests/src/com/android/server/wifi/HalDeviceManagerTest.java b/service/tests/wifitests/src/com/android/server/wifi/HalDeviceManagerTest.java
index 04e4f5384f..d9f62e53f0 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/HalDeviceManagerTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/HalDeviceManagerTest.java
@@ -36,7 +36,6 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
-import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
@@ -237,9 +236,12 @@ public class HalDeviceManagerTest extends WifiBaseTest {
when(mWifiInjector.makeWsHelper(TEST_WORKSOURCE_0)).thenReturn(mWorkSourceHelper0);
when(mWifiInjector.makeWsHelper(TEST_WORKSOURCE_1)).thenReturn(mWorkSourceHelper1);
when(mWifiInjector.makeWsHelper(TEST_WORKSOURCE_2)).thenReturn(mWorkSourceHelper2);
- when(mWorkSourceHelper0.hasAnyPrivilegedAppRequest()).thenReturn(true);
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(true);
- when(mWorkSourceHelper2.hasAnyPrivilegedAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper0.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_PRIVILEGED);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_PRIVILEGED);
+ when(mWorkSourceHelper2.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_PRIVILEGED);
when(mWorkSourceHelper0.getWorkSource()).thenReturn(TEST_WORKSOURCE_0);
when(mWorkSourceHelper1.getWorkSource()).thenReturn(TEST_WORKSOURCE_1);
when(mWorkSourceHelper2.getWorkSource()).thenReturn(TEST_WORKSOURCE_2);
@@ -845,8 +847,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
collector.checkThat("P2P was not created", p2pIface, IsNull.notNullValue());
// get NAN interface from a system app: should fail
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
List<Pair<Integer, WorkSource>> nanDetails = mDut.reportImpactToCreateIface(
HDM_CREATE_IFACE_NAN, false, TEST_WORKSOURCE_1);
assertNull("Should not create this NAN", nanDetails);
@@ -856,13 +858,13 @@ public class HalDeviceManagerTest extends WifiBaseTest {
collector.checkThat("not allocated interface", nanIface, IsNull.nullValue());
// Now replace the requestorWs (fg app now) for the P2P iface.
- when(mWorkSourceHelper2.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper2.hasAnyForegroundAppRequest(true)).thenReturn(true);
+ when(mWorkSourceHelper2.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_FG_APP);
assertTrue(mDut.replaceRequestorWs(p2pIface, TEST_WORKSOURCE_2));
// get AP interface again from a system app: should succeed now
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
nanIface = (IWifiNanIface) validateInterfaceSequence(chipMock,
true, // chipModeValid
TestChipV1.STA_CHIP_MODE_ID, // chipModeId (only used if chipModeValid is true)
@@ -921,8 +923,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
collector.checkThat("P2P was not created", p2pIface, IsNull.notNullValue());
// Check if we can create a new P2P interface from foreground app: should fail.
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(true)).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_FG_APP);
List<Pair<Integer, WorkSource>> p2pDetails = mDut.reportImpactToCreateIface(
HDM_CREATE_IFACE_P2P, true, TEST_WORKSOURCE_1);
assertNull("Should not create this P2P", p2pDetails);
@@ -962,7 +964,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
collector.checkThat("P2P was not created", p2pIface, IsNull.notNullValue());
// Check if we can create a new NAN interface from background app: should fail.
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(true)).thenReturn(false);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_BG);
nanDetails = mDut.reportImpactToCreateIface(HDM_CREATE_IFACE_NAN, true, TEST_WORKSOURCE_1);
assertNull("Should not create this NAN", nanDetails);
}
@@ -978,105 +981,96 @@ public class HalDeviceManagerTest extends WifiBaseTest {
*/
@Test
public void testShouldShowDialogToDelete() throws Exception {
- WorkSource newWorkSource = mock(WorkSource.class);
- WorkSource oldWorkSource = mock(WorkSource.class);
WorkSourceHelper newWsHelper = mock(WorkSourceHelper.class);
WorkSourceHelper oldWsHelper = mock(WorkSourceHelper.class);
- when(mWifiInjector.makeWsHelper(newWorkSource)).thenReturn(newWsHelper);
- when(mWifiInjector.makeWsHelper(oldWorkSource)).thenReturn(oldWsHelper);
when(mResources.getBoolean(R.bool.config_wifiUserApprovalRequiredForD2dInterfacePriority))
.thenReturn(false);
mDut = new HalDeviceManagerSpy();
// No dialog if dialogs aren't enabled
- when(newWsHelper.hasAnyForegroundAppRequest(anyBoolean())).thenReturn(true);
- when(oldWsHelper.hasAnyForegroundAppRequest(anyBoolean())).thenReturn(true);
+ when(newWsHelper.getRequestorWsPriority()).thenReturn(WorkSourceHelper.PRIORITY_FG_APP);
+ when(oldWsHelper.getRequestorWsPriority()).thenReturn(WorkSourceHelper.PRIORITY_FG_APP);
assertFalse(mDut.needsUserApprovalToDelete(
- HDM_CREATE_IFACE_P2P, newWorkSource,
- HDM_CREATE_IFACE_AP, oldWorkSource));
+ HDM_CREATE_IFACE_P2P, newWsHelper,
+ HDM_CREATE_IFACE_AP, oldWsHelper));
when(mResources.getBoolean(R.bool.config_wifiUserApprovalRequiredForD2dInterfacePriority))
.thenReturn(true);
mDut = new HalDeviceManagerSpy();
// Should show dialog for appropriate types.
- when(newWsHelper.hasAnyForegroundAppRequest(anyBoolean())).thenReturn(true);
- when(oldWsHelper.hasAnyForegroundAppRequest(anyBoolean())).thenReturn(true);
// Requesting AP
assertFalse(mDut.needsUserApprovalToDelete(
- HDM_CREATE_IFACE_AP, newWorkSource,
- HDM_CREATE_IFACE_AP, oldWorkSource));
+ HDM_CREATE_IFACE_AP, newWsHelper,
+ HDM_CREATE_IFACE_AP, oldWsHelper));
assertFalse(mDut.needsUserApprovalToDelete(
- HDM_CREATE_IFACE_AP, newWorkSource,
- HDM_CREATE_IFACE_AP_BRIDGE, oldWorkSource));
+ HDM_CREATE_IFACE_AP, newWsHelper,
+ HDM_CREATE_IFACE_AP_BRIDGE, oldWsHelper));
assertTrue(mDut.needsUserApprovalToDelete(
- HDM_CREATE_IFACE_AP, newWorkSource,
- HDM_CREATE_IFACE_NAN, oldWorkSource));
+ HDM_CREATE_IFACE_AP, newWsHelper,
+ HDM_CREATE_IFACE_NAN, oldWsHelper));
assertTrue(mDut.needsUserApprovalToDelete(
- HDM_CREATE_IFACE_AP, newWorkSource,
- HDM_CREATE_IFACE_P2P, oldWorkSource));
+ HDM_CREATE_IFACE_AP, newWsHelper,
+ HDM_CREATE_IFACE_P2P, oldWsHelper));
// Requesting AP_BRIDGE
assertFalse(mDut.needsUserApprovalToDelete(
- HDM_CREATE_IFACE_AP_BRIDGE, newWorkSource,
- HDM_CREATE_IFACE_AP, oldWorkSource));
+ HDM_CREATE_IFACE_AP_BRIDGE, newWsHelper,
+ HDM_CREATE_IFACE_AP, oldWsHelper));
assertFalse(mDut.needsUserApprovalToDelete(
- HDM_CREATE_IFACE_AP_BRIDGE, newWorkSource,
- HDM_CREATE_IFACE_AP_BRIDGE, oldWorkSource));
+ HDM_CREATE_IFACE_AP_BRIDGE, newWsHelper,
+ HDM_CREATE_IFACE_AP_BRIDGE, oldWsHelper));
assertTrue(mDut.needsUserApprovalToDelete(
- HDM_CREATE_IFACE_AP_BRIDGE, newWorkSource,
- HDM_CREATE_IFACE_NAN, oldWorkSource));
+ HDM_CREATE_IFACE_AP_BRIDGE, newWsHelper,
+ HDM_CREATE_IFACE_NAN, oldWsHelper));
assertTrue(mDut.needsUserApprovalToDelete(
- HDM_CREATE_IFACE_AP_BRIDGE, newWorkSource,
- HDM_CREATE_IFACE_P2P, oldWorkSource));
+ HDM_CREATE_IFACE_AP_BRIDGE, newWsHelper,
+ HDM_CREATE_IFACE_P2P, oldWsHelper));
// Requesting P2P
assertTrue(mDut.needsUserApprovalToDelete(
- HDM_CREATE_IFACE_P2P, newWorkSource,
- HDM_CREATE_IFACE_AP, oldWorkSource));
+ HDM_CREATE_IFACE_P2P, newWsHelper,
+ HDM_CREATE_IFACE_AP, oldWsHelper));
assertTrue(mDut.needsUserApprovalToDelete(
- HDM_CREATE_IFACE_P2P, newWorkSource,
- HDM_CREATE_IFACE_AP_BRIDGE, oldWorkSource));
+ HDM_CREATE_IFACE_P2P, newWsHelper,
+ HDM_CREATE_IFACE_AP_BRIDGE, oldWsHelper));
assertTrue(mDut.needsUserApprovalToDelete(
- HDM_CREATE_IFACE_P2P, newWorkSource,
- HDM_CREATE_IFACE_NAN, oldWorkSource));
+ HDM_CREATE_IFACE_P2P, newWsHelper,
+ HDM_CREATE_IFACE_NAN, oldWsHelper));
assertFalse(mDut.needsUserApprovalToDelete(
- HDM_CREATE_IFACE_P2P, newWorkSource,
- HDM_CREATE_IFACE_P2P, oldWorkSource));
+ HDM_CREATE_IFACE_P2P, newWsHelper,
+ HDM_CREATE_IFACE_P2P, oldWsHelper));
// Requesting NAN
assertTrue(mDut.needsUserApprovalToDelete(
- HDM_CREATE_IFACE_NAN, newWorkSource,
- HDM_CREATE_IFACE_AP, oldWorkSource));
+ HDM_CREATE_IFACE_NAN, newWsHelper,
+ HDM_CREATE_IFACE_AP, oldWsHelper));
assertTrue(mDut.needsUserApprovalToDelete(
- HDM_CREATE_IFACE_NAN, newWorkSource,
- HDM_CREATE_IFACE_AP_BRIDGE, oldWorkSource));
+ HDM_CREATE_IFACE_NAN, newWsHelper,
+ HDM_CREATE_IFACE_AP_BRIDGE, oldWsHelper));
assertFalse(mDut.needsUserApprovalToDelete(
- HDM_CREATE_IFACE_NAN, newWorkSource,
- HDM_CREATE_IFACE_NAN, oldWorkSource));
+ HDM_CREATE_IFACE_NAN, newWsHelper,
+ HDM_CREATE_IFACE_NAN, oldWsHelper));
assertTrue(mDut.needsUserApprovalToDelete(
- HDM_CREATE_IFACE_NAN, newWorkSource,
- HDM_CREATE_IFACE_P2P, oldWorkSource));
+ HDM_CREATE_IFACE_NAN, newWsHelper,
+ HDM_CREATE_IFACE_P2P, oldWsHelper));
// Foreground should show dialog over Privileged
- when(newWsHelper.hasAnyForegroundAppRequest(anyBoolean())).thenReturn(true);
- when(oldWsHelper.hasAnyPrivilegedAppRequest()).thenReturn(true);
+ when(newWsHelper.getRequestorWsPriority()).thenReturn(WorkSourceHelper.PRIORITY_FG_APP);
+ when(oldWsHelper.getRequestorWsPriority()).thenReturn(WorkSourceHelper.PRIORITY_PRIVILEGED);
assertTrue(mDut.needsUserApprovalToDelete(
- HDM_CREATE_IFACE_NAN, newWorkSource,
- HDM_CREATE_IFACE_P2P, oldWorkSource));
+ HDM_CREATE_IFACE_NAN, newWsHelper,
+ HDM_CREATE_IFACE_P2P, oldWsHelper));
// Foreground should delete Internal without showing dialog
- when(oldWsHelper.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(oldWsHelper.hasAnyForegroundAppRequest(anyBoolean())).thenReturn(false);
- when(oldWsHelper.hasAnyInternalRequest()).thenReturn(true);
+ when(oldWsHelper.getRequestorWsPriority()).thenReturn(WorkSourceHelper.PRIORITY_INTERNAL);
assertFalse(mDut.needsUserApprovalToDelete(
- HDM_CREATE_IFACE_NAN, newWorkSource,
- HDM_CREATE_IFACE_P2P, oldWorkSource));
+ HDM_CREATE_IFACE_NAN, newWsHelper,
+ HDM_CREATE_IFACE_P2P, oldWsHelper));
}
-
//////////////////////////////////////////////////////////////////////////////////////
// Chip Specific Tests - but should work on all chips!
// (i.e. add copies for each test chip)
@@ -1512,8 +1506,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
mInOrder.verify(chipMock.chip).configureChip(TestChipV1.STA_CHIP_MODE_ID);
// Now Create AP Iface.
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(anyBoolean())).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_FG_APP);
IWifiApIface apIface = mock(IWifiApIface.class);
doAnswer(new GetNameAnswer("wlan0")).when(apIface).getName(
any(IWifiIface.getNameCallback.class));
@@ -1712,8 +1706,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
collector.checkThat("STA created", staIface1, IsNull.notNullValue());
// get STA interface again (from a system app)
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
List<Pair<Integer, WorkSource>> staDetails = mDut.reportImpactToCreateIface(
HDM_CREATE_IFACE_STA, false, TEST_WORKSOURCE_1);
assertNotNull("Should not have a problem if STA already exists", staDetails);
@@ -1938,8 +1932,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
executeAndValidateStartupSequence();
// get STA interface from system app.
- when(mWorkSourceHelper0.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper0.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper0.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
IWifiIface staIface = validateInterfaceSequence(chipMock,
false, // chipModeValid
-1000, // chipModeId (only used if chipModeValid is true)
@@ -1953,27 +1947,27 @@ public class HalDeviceManagerTest extends WifiBaseTest {
collector.checkThat("STA created", staIface, IsNull.notNullValue());
// FG app not allowed to create AP interface.
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(true)).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_FG_APP);
assertFalse(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_AP, TEST_WORKSOURCE_1));
// New system app not allowed to create AP interface.
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(true)).thenReturn(false);
- when(mWorkSourceHelper1.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
assertFalse(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_AP, TEST_WORKSOURCE_1));
// Privileged app allowed to create AP interface.
- when(mWorkSourceHelper1.hasAnySystemAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_PRIVILEGED);
assertTrue(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_AP, TEST_WORKSOURCE_1));
// FG app allowed to create NAN interface (since there is no need to delete any interfaces).
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(true)).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_FG_APP);
assertTrue(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_NAN, TEST_WORKSOURCE_1));
// BG app allowed to create P2P interface (since there is no need to delete any interfaces).
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(true)).thenReturn(false);
+ when(mWorkSourceHelper1.getRequestorWsPriority()).thenReturn(WorkSourceHelper.PRIORITY_BG);
assertTrue(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_P2P, TEST_WORKSOURCE_1));
}
@@ -2006,12 +2000,12 @@ public class HalDeviceManagerTest extends WifiBaseTest {
assertTrue(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_AP, TEST_WORKSOURCE_1));
// Allow to create NAN interface (since there is no need to delete any interfaces).
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(true)).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_FG_APP);
assertTrue(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_NAN, TEST_WORKSOURCE_1));
// Allow to create P2P interface (since there is no need to delete any interfaces).
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(true)).thenReturn(false);
+ when(mWorkSourceHelper1.getRequestorWsPriority()).thenReturn(WorkSourceHelper.PRIORITY_BG);
assertTrue(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_P2P, TEST_WORKSOURCE_1));
}
@@ -2061,8 +2055,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
// create STA (system app)
when(mClock.getUptimeSinceBootMillis()).thenReturn(15L);
- when(mWorkSourceHelper0.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper0.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper0.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
IWifiIface staIface = validateInterfaceSequence(chipMock,
false, // chipModeValid
-1000, // chipModeId (only used if chipModeValid is true)
@@ -2076,8 +2070,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
collector.checkThat("STA interface wasn't created", staIface, IsNull.notNullValue());
// create P2P (system app)
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
IWifiIface p2pIface = validateInterfaceSequence(chipMock,
true, // chipModeValid
TestChipV2.CHIP_MODE_ID, // chipModeId
@@ -2386,8 +2380,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
executeAndValidateStartupSequence();
// get STA interface from system app.
- when(mWorkSourceHelper0.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper0.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper0.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
IWifiIface staIface = validateInterfaceSequence(chipMock,
false, // chipModeValid
-1000, // chipModeId (only used if chipModeValid is true)
@@ -2401,8 +2395,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
collector.checkThat("STA created", staIface, IsNull.notNullValue());
// get AP interface from system app.
- when(mWorkSourceHelper0.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper0.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper0.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
IWifiIface apIface = validateInterfaceSequence(chipMock,
true, // chipModeValid
TestChipV2.CHIP_MODE_ID, // chipModeId
@@ -2416,27 +2410,27 @@ public class HalDeviceManagerTest extends WifiBaseTest {
collector.checkThat("AP created", apIface, IsNull.notNullValue());
// FG app not allowed to create STA interface.
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(true)).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_FG_APP);
assertFalse(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_STA, TEST_WORKSOURCE_1));
// New system app not allowed to create STA interface.
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(true)).thenReturn(false);
- when(mWorkSourceHelper1.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
assertFalse(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_STA, TEST_WORKSOURCE_1));
// Privileged app allowed to create STA interface.
- when(mWorkSourceHelper1.hasAnySystemAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_PRIVILEGED);
assertTrue(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_STA, TEST_WORKSOURCE_1));
// FG app allowed to create NAN interface (since there is no need to delete any interfaces).
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(true)).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_FG_APP);
assertTrue(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_NAN, TEST_WORKSOURCE_1));
// BG app allowed to create P2P interface (since there is no need to delete any interfaces).
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(true)).thenReturn(false);
+ when(mWorkSourceHelper0.getRequestorWsPriority()).thenReturn(WorkSourceHelper.PRIORITY_BG);
assertTrue(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_P2P, TEST_WORKSOURCE_1));
}
@@ -2486,8 +2480,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
// create STA (system app)
when(mClock.getUptimeSinceBootMillis()).thenReturn(15L);
- when(mWorkSourceHelper0.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper0.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper0.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
IWifiIface staIface = validateInterfaceSequence(chipMock,
false, // chipModeValid
-1000, // chipModeId (only used if chipModeValid is true)
@@ -2501,8 +2495,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
collector.checkThat("STA interface wasn't created", staIface, IsNull.notNullValue());
// create P2P (system app)
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
IWifiIface p2pIface = validateInterfaceSequence(chipMock,
true, // chipModeValid
TestChipV3.CHIP_MODE_ID, // chipModeId
@@ -2628,8 +2622,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
verify(staDestroyedListener2).onDestroyed(getName(staIface2));
// request STA2 (foreground app): should fail
- when(mWorkSourceHelper1.hasAnySystemAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(true)).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_FG_APP);
staDetails = mDut.reportImpactToCreateIface(HDM_CREATE_IFACE_STA, false, TEST_WORKSOURCE_1);
assertNotNull("should not fail when asking for same STA", staDetails);
assertEquals(0, staDetails.size());
@@ -2723,8 +2717,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
executeAndValidateStartupSequence();
// get STA interface from system app.
- when(mWorkSourceHelper0.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper0.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper0.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
IWifiIface staIface = validateInterfaceSequence(chipMock,
false, // chipModeValid
-1000, // chipModeId (only used if chipModeValid is true)
@@ -2738,8 +2732,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
collector.checkThat("STA created", staIface, IsNull.notNullValue());
// get AP interface from system app.
- when(mWorkSourceHelper0.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper0.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper0.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
IWifiIface apIface = validateInterfaceSequence(chipMock,
true, // chipModeValid
TestChipV3.CHIP_MODE_ID, // chipModeId (only used if chipModeValid is true)
@@ -2753,27 +2747,28 @@ public class HalDeviceManagerTest extends WifiBaseTest {
collector.checkThat("AP created", apIface, IsNull.notNullValue());
// FG app not allowed to create STA interface.
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(true)).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_FG_APP);
assertFalse(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_STA, TEST_WORKSOURCE_1));
// New system app not allowed to create STA interface.
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(true)).thenReturn(false);
- when(mWorkSourceHelper1.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
assertFalse(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_STA, TEST_WORKSOURCE_1));
// Privileged app allowed to create STA interface.
- when(mWorkSourceHelper1.hasAnySystemAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_PRIVILEGED);
assertTrue(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_STA, TEST_WORKSOURCE_1));
// FG app not allowed to create NAN interface.
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(true)).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_FG_APP);
assertFalse(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_NAN, TEST_WORKSOURCE_1));
// Privileged app allowed to create P2P interface.
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_PRIVILEGED);
assertTrue(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_P2P, TEST_WORKSOURCE_1));
}
@@ -2822,8 +2817,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
// create STA (system app)
when(mClock.getUptimeSinceBootMillis()).thenReturn(15L);
- when(mWorkSourceHelper0.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper0.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper0.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
IWifiIface staIface = validateInterfaceSequence(chipMock,
false, // chipModeValid
-1000, // chipModeId (only used if chipModeValid is true)
@@ -2837,8 +2832,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
collector.checkThat("STA interface wasn't created", staIface, IsNull.notNullValue());
// create P2P (system app)
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
IWifiIface p2pIface = validateInterfaceSequence(chipMock,
true, // chipModeValid
TestChipV4.CHIP_MODE_ID, // chipModeId
@@ -2945,8 +2940,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
collector.checkThat("NAN interface wasn't created", nanIface, IsNull.notNullValue());
// request STA2 (foreground app): should fail
- when(mWorkSourceHelper1.hasAnySystemAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(true)).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_FG_APP);
staDetails = mDut.reportImpactToCreateIface(HDM_CREATE_IFACE_STA, false, TEST_WORKSOURCE_1);
assertNotNull("should not fail when asking for same STA", staDetails);
assertEquals(0, staDetails.size());
@@ -3132,8 +3127,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
InterfaceDestroyedListener.class);
// create P2P (internal request)
- when(mWorkSourceHelper0.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper0.hasAnyInternalRequest()).thenReturn(true);
+ when(mWorkSourceHelper0.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_INTERNAL);
// create NAN (privileged app): will destroy P2P
IWifiIface nanIface = validateInterfaceSequence(chipMock,
true, // chipModeValid
@@ -3254,8 +3249,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
executeAndValidateStartupSequence();
// get STA interface from system app.
- when(mWorkSourceHelper0.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper0.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper0.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
IWifiIface staIface = validateInterfaceSequence(chipMock,
false, // chipModeValid
-1000, // chipModeId (only used if chipModeValid is true)
@@ -3269,8 +3264,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
collector.checkThat("STA created", staIface, IsNull.notNullValue());
// get AP interface from system app.
- when(mWorkSourceHelper0.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper0.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper0.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
IWifiIface apIface = validateInterfaceSequence(chipMock,
true, // chipModeValid
TestChipV4.CHIP_MODE_ID, // chipModeId (only used if chipModeValid is true)
@@ -3284,27 +3279,28 @@ public class HalDeviceManagerTest extends WifiBaseTest {
collector.checkThat("AP created", apIface, IsNull.notNullValue());
// FG app not allowed to create STA interface.
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(true)).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_FG_APP);
assertFalse(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_STA, TEST_WORKSOURCE_1));
// New system app not allowed to create STA interface.
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(true)).thenReturn(false);
- when(mWorkSourceHelper1.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
assertFalse(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_STA, TEST_WORKSOURCE_1));
// Privileged app allowed to create STA interface.
- when(mWorkSourceHelper1.hasAnySystemAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_PRIVILEGED);
assertTrue(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_STA, TEST_WORKSOURCE_1));
// FG app not allowed to create NAN interface.
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(true)).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_FG_APP);
assertFalse(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_NAN, TEST_WORKSOURCE_1));
// Privileged app allowed to create P2P interface.
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_PRIVILEGED);
assertTrue(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_P2P, TEST_WORKSOURCE_1));
}
@@ -3376,8 +3372,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
executeAndValidateStartupSequence();
// get STA interface from system app.
- when(mWorkSourceHelper0.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper0.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper0.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
IWifiIface staIface;
if (isWigigSupported) {
staIface = validateInterfaceSequence(chipMock,
@@ -3403,8 +3399,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
}
// get AP interface from system app.
- when(mWorkSourceHelper0.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper0.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper0.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
IWifiIface apIface;
if (isWigigSupported) {
apIface = validateInterfaceSequence(chipMock,
@@ -3429,7 +3425,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
}
if (SdkLevel.isAtLeastS()) {
// Privileged app allowed to create P2P interface.
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_PRIVILEGED);
assertThat(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_P2P,
android.hardware.wifi.V1_5.IWifiChip.ChipCapabilityMask.WIGIG,
TEST_WORKSOURCE_1), is(isWigigSupported));
@@ -3837,9 +3834,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
collector.checkThat("STA created", staIface, IsNull.notNullValue());
// get STA interface from foreground app.
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnySystemAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnyForegroundAppRequest(true)).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_FG_APP);
staIface = validateInterfaceSequence(chipMock,
true, // chipModeValid
TestChipV7.DUAL_STA_CHIP_MODE_ID, // chipModeId (only used if chipModeValid is true)
@@ -3854,13 +3850,14 @@ public class HalDeviceManagerTest extends WifiBaseTest {
// New system app not allowed to create AP interface since it would tear down the privileged
// app STA during the chip mode change.
- when(mWorkSourceHelper2.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper2.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper2.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
assertFalse(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_AP, TEST_WORKSOURCE_2));
// Privileged app allowed to create AP interface since it is able to tear down the
// privileged app STA during the chip mode change.
- when(mWorkSourceHelper2.hasAnyPrivilegedAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper2.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_PRIVILEGED);
assertTrue(mDut.isItPossibleToCreateIface(HDM_CREATE_IFACE_AP, TEST_WORKSOURCE_2));
}
@@ -3898,8 +3895,8 @@ public class HalDeviceManagerTest extends WifiBaseTest {
collector.checkThat("Bridged AP created", apBridgedIface, IsNull.notNullValue());
// get AP interface for a system app.
- when(mWorkSourceHelper1.hasAnyPrivilegedAppRequest()).thenReturn(false);
- when(mWorkSourceHelper1.hasAnySystemAppRequest()).thenReturn(true);
+ when(mWorkSourceHelper1.getRequestorWsPriority())
+ .thenReturn(WorkSourceHelper.PRIORITY_SYSTEM);
IWifiIface apIface = validateInterfaceSequence(chipMock,
true, // chipModeValid
TestChipV8.CHIP_MODE_ID, // chipModeId
diff --git a/service/tests/wifitests/src/com/android/server/wifi/InterfaceConflictManagerTest.java b/service/tests/wifitests/src/com/android/server/wifi/InterfaceConflictManagerTest.java
index a90e8e19db..81cfd3e76a 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/InterfaceConflictManagerTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/InterfaceConflictManagerTest.java
@@ -47,6 +47,7 @@ import com.android.dx.mockito.inline.extended.ExtendedMockito;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
import com.android.server.wifi.util.WaitingState;
+import com.android.server.wifi.util.WorkSourceHelper;
import com.android.wifi.resources.R;
import org.junit.Before;
@@ -67,6 +68,7 @@ public class InterfaceConflictManagerTest {
private TestLooper mTestLooper;
private InterfaceConflictManager mDut;
+ @Mock WifiInjector mWifiInjector;
@Mock WifiContext mWifiContext;
@Mock Resources mResources;
@Mock FrameworkFacade mFrameworkFacade;
@@ -77,11 +79,17 @@ public class InterfaceConflictManagerTest {
@Mock WifiDialogManager mWifiDialogManager;
@Mock WifiDialogManager.DialogHandle mDialogHandle;
@Mock LocalLog mLocalLog;
+ @Mock WorkSourceHelper mWsHelper;
+ @Mock WorkSourceHelper mExistingWsHelper;
private static final int TEST_UID = 1234;
private static final String TEST_PACKAGE_NAME = "some.package.name";
private static final String TEST_APP_NAME = "Some App Name";
private static final WorkSource TEST_WS = new WorkSource(TEST_UID, TEST_PACKAGE_NAME);
+ private static final int EXISTING_UID = 5678;
+ private static final String EXISTING_PACKAGE_NAME = "existing.package.name";
+ private static final WorkSource EXISTING_WS =
+ new WorkSource(EXISTING_UID, EXISTING_PACKAGE_NAME);
ArgumentCaptor<WifiDialogManager.SimpleDialogCallback> mCallbackCaptor =
ArgumentCaptor.forClass(WifiDialogManager.SimpleDialogCallback.class);
@@ -104,10 +112,13 @@ public class InterfaceConflictManagerTest {
when(mFrameworkFacade.getAppName(any(), anyString(), anyInt())).thenReturn(TEST_APP_NAME);
when(mWifiDialogManager.createSimpleDialog(
any(), any(), any(), any(), any(), any(), any())).thenReturn(mDialogHandle);
+
+ when(mWifiInjector.makeWsHelper(eq(TEST_WS))).thenReturn(mWsHelper);
+ when(mWifiInjector.makeWsHelper(eq(EXISTING_WS))).thenReturn(mExistingWsHelper);
}
private void initInterfaceConflictManager() {
- mDut = new InterfaceConflictManager(mWifiContext, mFrameworkFacade, mHdm,
+ mDut = new InterfaceConflictManager(mWifiInjector, mWifiContext, mFrameworkFacade, mHdm,
new WifiThreadRunner(new Handler(mTestLooper.getLooper())), mWifiDialogManager,
mLocalLog);
mDut.handleBootCompleted();
diff --git a/service/tests/wifitests/src/com/android/server/wifi/util/WorkSourceHelperTest.java b/service/tests/wifitests/src/com/android/server/wifi/util/WorkSourceHelperTest.java
index d7d46be3a7..a7210b9fee 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/util/WorkSourceHelperTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/util/WorkSourceHelperTest.java
@@ -16,11 +16,11 @@
package com.android.server.wifi.util;
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
+import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_CACHED;
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND_SERVICE;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.when;
@@ -42,6 +42,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
/** Unit tests for {@link WorkSourceHelper}. */
@@ -58,91 +59,54 @@ public class WorkSourceHelperTest extends WifiBaseTest {
@Mock private PackageManager mPackageManager;
@Mock private Resources mResources;
- private WorkSource mWorkSource;
- private WorkSourceHelper mWorkSourceHelper;
-
- @Before public void setUp() {
+ @Before public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
-
- // Create a test worksource with 2 app's request.
- mWorkSource = new WorkSource();
- mWorkSource.add(new WorkSource(TEST_UID_1, TEST_PACKAGE_1));
- mWorkSource.add(new WorkSource(TEST_UID_2, TEST_PACKAGE_2));
-
- mWorkSourceHelper = new WorkSourceHelper(
- mWorkSource, mWifiPermissionsUtil, mActivityManager, mPackageManager, mResources);
- }
-
- @Test
- public void testHasAnyPrivilegedRequest() {
- assertFalse(mWorkSourceHelper.hasAnyPrivilegedAppRequest());
-
- when(mWifiPermissionsUtil.checkNetworkSettingsPermission(TEST_UID_1)).thenReturn(true);
- assertTrue(mWorkSourceHelper.hasAnyPrivilegedAppRequest());
- }
-
- @Test
- public void testHasAnySystemRequest() throws Exception {
- ApplicationInfo appInfo = new ApplicationInfo();
- when(mPackageManager.getApplicationInfoAsUser(any(), anyInt(), any())).thenReturn(appInfo);
-
- assertFalse(mWorkSourceHelper.hasAnySystemAppRequest());
-
- appInfo.flags = ApplicationInfo.FLAG_SYSTEM;
- assertTrue(mWorkSourceHelper.hasAnySystemAppRequest());
+ when(mActivityManager.getPackageImportance(null)).thenReturn(IMPORTANCE_CACHED);
+ when(mPackageManager.getApplicationInfoAsUser(any(), anyInt(), any())).thenReturn(
+ Mockito.mock(ApplicationInfo.class));
}
@Test
- public void testHasAnyForegroundAppRequest() throws Exception {
- // 2 from bg app.
+ public void testGetRequestorWsPriority() throws Exception {
+ // PRIORITY_INTERNAL
+ WorkSource ws = new WorkSource(Process.WIFI_UID, "com.android.wifi");
+ WorkSourceHelper wsHelper = new WorkSourceHelper(
+ ws, mWifiPermissionsUtil, mActivityManager, mPackageManager, mResources);
+ assertEquals(wsHelper.getRequestorWsPriority(), WorkSourceHelper.PRIORITY_INTERNAL);
+
+ // PRIORITY_BG
+ ws.add(new WorkSource(TEST_UID_1, TEST_PACKAGE_1));
+ ws.add(new WorkSource(TEST_UID_2, TEST_PACKAGE_2));
+ when(mActivityManager.getPackageImportance(TEST_PACKAGE_1)).thenReturn(IMPORTANCE_CACHED);
+ when(mActivityManager.getPackageImportance(TEST_PACKAGE_2)).thenReturn(IMPORTANCE_CACHED);
+ assertEquals(WorkSourceHelper.PRIORITY_BG, wsHelper.getRequestorWsPriority());
+
+ // PRIORITY_FG_SERVICE
when(mActivityManager.getPackageImportance(TEST_PACKAGE_1))
- .thenReturn(IMPORTANCE_BACKGROUND);
- when(mActivityManager.getPackageImportance(TEST_PACKAGE_2))
- .thenReturn(IMPORTANCE_BACKGROUND);
- assertFalse(mWorkSourceHelper.hasAnyForegroundAppRequest(true));
-
- // override background status
- when(mResources.getStringArray(
- R.array.config_wifiInterfacePriorityTreatAsForegroundList)).thenReturn(
- new String[]{TEST_PACKAGE_2});
- assertTrue(mWorkSourceHelper.hasAnyForegroundAppRequest(true));
- assertFalse(mWorkSourceHelper.hasAnyForegroundAppRequest(false));
+ .thenReturn(IMPORTANCE_FOREGROUND_SERVICE);
+ assertEquals(WorkSourceHelper.PRIORITY_FG_SERVICE, wsHelper.getRequestorWsPriority());
- // 1 request from fg app, 1 from bg app.
+ // PRIORITY_FG_APP
when(mActivityManager.getPackageImportance(TEST_PACKAGE_1))
.thenReturn(IMPORTANCE_FOREGROUND);
- assertTrue(mWorkSourceHelper.hasAnyForegroundAppRequest(true));
- }
+ assertEquals(WorkSourceHelper.PRIORITY_FG_APP, wsHelper.getRequestorWsPriority());
- @Test
- public void testHasAnyForegroundServiceRequest() throws Exception {
- // 2 from bg app.
+ // PRIORITY_FG_APP with "treat as foreground" package
when(mActivityManager.getPackageImportance(TEST_PACKAGE_1))
.thenReturn(IMPORTANCE_BACKGROUND);
- when(mActivityManager.getPackageImportance(TEST_PACKAGE_2))
- .thenReturn(IMPORTANCE_BACKGROUND);
- assertFalse(mWorkSourceHelper.hasAnyForegroundServiceRequest());
-
- // 1 request from fg service, 1 from bg app.
- when(mActivityManager.getPackageImportance(TEST_PACKAGE_1))
- .thenReturn(IMPORTANCE_FOREGROUND_SERVICE);
- when(mActivityManager.getPackageImportance(TEST_PACKAGE_2))
- .thenReturn(IMPORTANCE_BACKGROUND);
- assertTrue(mWorkSourceHelper.hasAnyForegroundServiceRequest());
- }
-
+ when(mResources.getStringArray(
+ R.array.config_wifiInterfacePriorityTreatAsForegroundList)).thenReturn(
+ new String[]{TEST_PACKAGE_2});
+ assertEquals(WorkSourceHelper.PRIORITY_FG_APP, wsHelper.getRequestorWsPriority());
- @Test
- public void testHasAnyInternalRequest() throws Exception {
- // 2 from bg app.
- when(mActivityManager.getPackageImportance(TEST_PACKAGE_1))
- .thenReturn(IMPORTANCE_BACKGROUND);
- when(mActivityManager.getPackageImportance(TEST_PACKAGE_2))
- .thenReturn(IMPORTANCE_BACKGROUND);
- assertFalse(mWorkSourceHelper.hasAnyInternalRequest());
+ // PRIORITY_SYSTEM
+ ApplicationInfo appInfo = new ApplicationInfo();
+ appInfo.flags = ApplicationInfo.FLAG_SYSTEM;
+ when(mPackageManager.getApplicationInfoAsUser(any(), anyInt(), any())).thenReturn(appInfo);
+ assertEquals(WorkSourceHelper.PRIORITY_SYSTEM, wsHelper.getRequestorWsPriority());
- // add a new internal request.
- mWorkSource.add(new WorkSource(Process.WIFI_UID, "com.android.wifi"));
- assertTrue(mWorkSourceHelper.hasAnyInternalRequest());
+ // PRIORITY_PRIVILEGED
+ when(mWifiPermissionsUtil.checkNetworkSettingsPermission(TEST_UID_1)).thenReturn(true);
+ assertEquals(WorkSourceHelper.PRIORITY_PRIVILEGED, wsHelper.getRequestorWsPriority());
}
}