summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/WifiInjector.java3
-rw-r--r--service/java/com/android/server/wifi/WifiLockManager.java69
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java36
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiLockManagerTest.java61
4 files changed, 69 insertions, 100 deletions
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java
index fbcc45568..988bdf086 100644
--- a/service/java/com/android/server/wifi/WifiInjector.java
+++ b/service/java/com/android/server/wifi/WifiInjector.java
@@ -319,7 +319,8 @@ public class WifiInjector {
mWifiConfigStore, mWifiNetworkSuggestionsManager, mWifiMetrics.getWakeupMetrics(),
this, mFrameworkFacade, mClock);
mLockManager = new WifiLockManager(mContext, BatteryStatsService.getService(),
- mClientModeImpl, mFrameworkFacade, clientModeImplLooper, mClock, mWifiMetrics);
+ mClientModeImpl, mFrameworkFacade, new Handler(clientModeImplLooper), mWifiNative,
+ mClock, mWifiMetrics);
mWifiController = new WifiController(mContext, mClientModeImpl, clientModeImplLooper,
mSettingsStore, mWifiServiceHandlerThread.getLooper(), mFrameworkFacade,
mActiveModeWarden);
diff --git a/service/java/com/android/server/wifi/WifiLockManager.java b/service/java/com/android/server/wifi/WifiLockManager.java
index 3d4ceb1e7..ab0871554 100644
--- a/service/java/com/android/server/wifi/WifiLockManager.java
+++ b/service/java/com/android/server/wifi/WifiLockManager.java
@@ -20,9 +20,8 @@ import android.app.ActivityManager;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.os.Binder;
+import android.os.Handler;
import android.os.IBinder;
-import android.os.Looper;
-import android.os.Message;
import android.os.RemoteException;
import android.os.WorkSource;
import android.os.WorkSource.WorkChain;
@@ -31,9 +30,6 @@ import android.util.SparseArray;
import android.util.StatsLog;
import com.android.internal.app.IBatteryStats;
-import com.android.internal.util.AsyncChannel;
-import com.android.server.wifi.util.WifiAsyncChannel;
-import com.android.server.wifi.util.WifiHandler;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -62,9 +58,9 @@ public class WifiLockManager {
private final FrameworkFacade mFrameworkFacade;
private final ClientModeImpl mClientModeImpl;
private final ActivityManager mActivityManager;
- private final ClientModeImplInterfaceHandler mCmiIfaceHandler;
+ private final Handler mHandler;
private final WifiMetrics mWifiMetrics;
- private WifiAsyncChannel mClientModeImplChannel;
+ private final WifiNative mWifiNative;
private final List<WifiLock> mWifiLocks = new ArrayList<>();
// map UIDs to their corresponding records (for low-latency locks)
@@ -85,15 +81,16 @@ public class WifiLockManager {
private long mCurrentSessionStartTimeMs;
WifiLockManager(Context context, IBatteryStats batteryStats,
- ClientModeImpl clientModeImpl, FrameworkFacade frameworkFacade, Looper looper,
- Clock clock, WifiMetrics wifiMetrics) {
+ ClientModeImpl clientModeImpl, FrameworkFacade frameworkFacade, Handler handler,
+ WifiNative wifiNative, Clock clock, WifiMetrics wifiMetrics) {
mContext = context;
mBatteryStats = batteryStats;
mClientModeImpl = clientModeImpl;
mFrameworkFacade = frameworkFacade;
mActivityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
- mCmiIfaceHandler = new ClientModeImplInterfaceHandler(looper);
mCurrentOpMode = WifiManager.WIFI_MODE_NO_LOCKS_HELD;
+ mWifiNative = wifiNative;
+ mHandler = handler;
mClock = clock;
mWifiMetrics = wifiMetrics;
@@ -147,7 +144,7 @@ public class WifiLockManager {
mActivityManager.addOnUidImportanceListener(new ActivityManager.OnUidImportanceListener() {
@Override
public void onUidImportance(final int uid, final int importance) {
- mCmiIfaceHandler.post(() -> {
+ mHandler.post(() -> {
UidRec uidRec = mLowLatencyUidWatchList.get(uid);
if (uidRec == null) {
// Not a uid in the watch list
@@ -647,10 +644,13 @@ public class WifiLockManager {
}
private int getLowLatencyModeSupport() {
- if (mLatencyModeSupport == LOW_LATENCY_SUPPORT_UNDEFINED
- && mClientModeImplChannel != null) {
- long supportedFeatures =
- mClientModeImpl.syncGetSupportedFeatures(mClientModeImplChannel);
+ if (mLatencyModeSupport == LOW_LATENCY_SUPPORT_UNDEFINED) {
+ String ifaceName = mWifiNative.getClientInterfaceName();
+ if (ifaceName == null) {
+ return LOW_LATENCY_SUPPORT_UNDEFINED;
+ }
+
+ long supportedFeatures = mWifiNative.getSupportedFeatureSet(ifaceName);
if (supportedFeatures != 0) {
if ((supportedFeatures & WifiManager.WIFI_FEATURE_LOW_LATENCY) != 0) {
mLatencyModeSupport = LOW_LATENCY_SUPPORTED;
@@ -793,45 +793,6 @@ public class WifiLockManager {
}
}
- /**
- * Handles interaction with ClientModeImpl
- */
- private class ClientModeImplInterfaceHandler extends WifiHandler {
- private WifiAsyncChannel mCmiChannel;
-
- ClientModeImplInterfaceHandler(Looper looper) {
- super(TAG, looper);
- mCmiChannel = mFrameworkFacade.makeWifiAsyncChannel(TAG);
- mCmiChannel.connect(mContext, this, mClientModeImpl.getHandler());
- }
-
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED: {
- if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
- mClientModeImplChannel = mCmiChannel;
- } else {
- Slog.e(TAG, "ClientModeImpl connection failure, error=" + msg.arg1);
- mClientModeImplChannel = null;
- }
- break;
- }
- case AsyncChannel.CMD_CHANNEL_DISCONNECTED: {
- Slog.e(TAG, "ClientModeImpl channel lost, msg.arg1 =" + msg.arg1);
- mClientModeImplChannel = null;
- //Re-establish connection
- mCmiChannel.connect(mContext, this, mClientModeImpl.getHandler());
- break;
- }
- default: {
- Slog.d(TAG, "ClientModeImplInterfaceHandler.handleMessage ignoring msg=" + msg);
- break;
- }
- }
- }
- }
-
private class WifiLock implements IBinder.DeathRecipient {
String mTag;
int mUid;
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index 5f0ac3b95..611474604 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -2808,25 +2808,47 @@ public class WifiServiceImpl extends BaseWifiService {
mLog.info("acquireWifiLock uid=% lockMode=%")
.c(Binder.getCallingUid())
.c(lockMode).flush();
- if (mWifiLockManager.acquireWifiLock(lockMode, tag, binder, ws)) {
- return true;
+
+ Mutable<Boolean> lockSuccess = new Mutable<>();
+ boolean runWithScissorsSuccess = mWifiInjector.getClientModeImplHandler().runWithScissors(
+ () -> {
+ lockSuccess.value = mWifiLockManager.acquireWifiLock(lockMode, tag, binder, ws);
+ }, RUN_WITH_SCISSORS_TIMEOUT_MILLIS);
+ if (!runWithScissorsSuccess) {
+ Log.e(TAG, "Failed to post runnable to acquireWifiLock");
+ return false;
}
- return false;
+
+ return lockSuccess.value;
}
@Override
public void updateWifiLockWorkSource(IBinder binder, WorkSource ws) {
mLog.info("updateWifiLockWorkSource uid=%").c(Binder.getCallingUid()).flush();
- mWifiLockManager.updateWifiLockWorkSource(binder, ws);
+
+ boolean runWithScissorsSuccess = mWifiInjector.getClientModeImplHandler().runWithScissors(
+ () -> {
+ mWifiLockManager.updateWifiLockWorkSource(binder, ws);
+ }, RUN_WITH_SCISSORS_TIMEOUT_MILLIS);
+ if (!runWithScissorsSuccess) {
+ Log.e(TAG, "Failed to post runnable to updateWifiLockWorkSource");
+ }
}
@Override
public boolean releaseWifiLock(IBinder binder) {
mLog.info("releaseWifiLock uid=%").c(Binder.getCallingUid()).flush();
- if (mWifiLockManager.releaseWifiLock(binder)) {
- return true;
+
+ Mutable<Boolean> lockSuccess = new Mutable<>();
+ boolean runWithScissorsSuccess = mWifiInjector.getClientModeImplHandler().runWithScissors(
+ () -> {
+ lockSuccess.value = mWifiLockManager.releaseWifiLock(binder);
+ }, RUN_WITH_SCISSORS_TIMEOUT_MILLIS);
+ if (!runWithScissorsSuccess) {
+ Log.e(TAG, "Failed to post runnable to releaseWifiLock");
+ return false;
}
- return false;
+ return lockSuccess.value;
}
@Override
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiLockManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiLockManagerTest.java
index a51a7a841..7cedfe36d 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiLockManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiLockManagerTest.java
@@ -26,16 +26,12 @@ import android.net.wifi.WifiManager;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
-import android.os.Message;
import android.os.WorkSource;
import android.os.test.TestLooper;
import androidx.test.filters.SmallTest;
import com.android.internal.app.IBatteryStats;
-import com.android.internal.util.AsyncChannel;
-import com.android.server.wifi.util.WifiAsyncChannel;
-import com.android.server.wifi.util.WifiHandler;
import org.junit.Before;
import org.junit.Test;
@@ -57,6 +53,7 @@ public class WifiLockManagerTest {
private static final int DEFAULT_TEST_UID_4 = 55;
private static final int WIFI_LOCK_MODE_INVALID = -1;
private static final String TEST_WIFI_LOCK_TAG = "TestTag";
+ private static final String INTERFACE_NAME = "IfaceName";
private ActivityManager.OnUidImportanceListener mUidImportanceListener;
@@ -71,10 +68,10 @@ public class WifiLockManagerTest {
@Mock ClientModeImpl mClientModeImpl;
@Mock FrameworkFacade mFrameworkFacade;
@Mock ActivityManager mActivityManager;
- @Mock WifiAsyncChannel mChannel;
- @Mock WifiHandler mCmiHandler;
@Mock WifiMetrics mWifiMetrics;
+ @Mock WifiNative mWifiNative;
TestLooper mLooper;
+ Handler mHandler;
/**
* Method to setup a WifiLockManager for the tests.
@@ -90,13 +87,12 @@ public class WifiLockManagerTest {
MockitoAnnotations.initMocks(this);
mLooper = new TestLooper();
+ mHandler = new Handler(mLooper.getLooper());
when(mContext.getSystemService(Context.ACTIVITY_SERVICE)).thenReturn(mActivityManager);
- when(mFrameworkFacade.makeWifiAsyncChannel(anyString())).thenReturn(mChannel);
- when(mClientModeImpl.getHandler()).thenReturn(mCmiHandler);
+ when(mWifiNative.getClientInterfaceName()).thenReturn(INTERFACE_NAME);
mWifiLockManager = new WifiLockManager(mContext, mBatteryStats,
- mClientModeImpl, mFrameworkFacade, mLooper.getLooper(), mClock, mWifiMetrics);
- connectAsyncChannel();
+ mClientModeImpl, mFrameworkFacade, mHandler, mWifiNative, mClock, mWifiMetrics);
}
private void acquireWifiLockSuccessful(int lockMode, String tag, IBinder binder, WorkSource ws)
@@ -127,17 +123,6 @@ public class WifiLockManagerTest {
assertNotNull(mUidImportanceListener);
}
- private void connectAsyncChannel() {
- ArgumentCaptor<WifiHandler> handlerCaptor = ArgumentCaptor.forClass(WifiHandler.class);
- verify(mChannel).connect(eq(mContext), handlerCaptor.capture(), any(Handler.class));
- WifiHandler handler = handlerCaptor.getValue();
-
- Message msg = new Message();
- msg.what = AsyncChannel.CMD_CHANNEL_HALF_CONNECTED;
- msg.arg1 = AsyncChannel.STATUS_SUCCESSFUL;
- handler.handleMessage(msg);
- }
-
private void releaseWifiLockSuccessful(IBinder binder) throws Exception {
ArgumentCaptor<IBinder.DeathRecipient> deathRecipient =
ArgumentCaptor.forClass(IBinder.DeathRecipient.class);
@@ -736,7 +721,7 @@ public class WifiLockManagerTest {
mWifiLockManager.handleScreenStateChanged(true);
when(mFrameworkFacade.isAppForeground(anyInt())).thenReturn(true);
when(mClientModeImpl.setLowLatencyMode(anyBoolean())).thenReturn(true);
- when(mClientModeImpl.syncGetSupportedFeatures(any()))
+ when(mWifiNative.getSupportedFeatureSet(INTERFACE_NAME))
.thenReturn((long) WifiManager.WIFI_FEATURE_LOW_LATENCY);
acquireWifiLockSuccessful(WifiManager.WIFI_MODE_FULL_LOW_LATENCY, "",
@@ -755,7 +740,7 @@ public class WifiLockManagerTest {
// Set screen on, and app foreground
mWifiLockManager.handleScreenStateChanged(true);
when(mFrameworkFacade.isAppForeground(anyInt())).thenReturn(true);
- when(mClientModeImpl.syncGetSupportedFeatures(any()))
+ when(mWifiNative.getSupportedFeatureSet(INTERFACE_NAME))
.thenReturn((long) WifiManager.WIFI_FEATURE_TX_POWER_LIMIT);
acquireWifiLockSuccessful(WifiManager.WIFI_MODE_FULL_LOW_LATENCY, "",
@@ -774,7 +759,7 @@ public class WifiLockManagerTest {
// Set screen on, and app foreground
mWifiLockManager.handleScreenStateChanged(true);
when(mFrameworkFacade.isAppForeground(anyInt())).thenReturn(true);
- when(mClientModeImpl.syncGetSupportedFeatures(any()))
+ when(mWifiNative.getSupportedFeatureSet(INTERFACE_NAME))
.thenReturn((long) WifiManager.WIFI_FEATURE_LOW_LATENCY);
// Make sure setLowLatencyMode() is successful
@@ -808,7 +793,7 @@ public class WifiLockManagerTest {
// Set screen on, and app is foreground
mWifiLockManager.handleScreenStateChanged(true);
when(mFrameworkFacade.isAppForeground(anyInt())).thenReturn(true);
- when(mClientModeImpl.syncGetSupportedFeatures(any()))
+ when(mWifiNative.getSupportedFeatureSet(INTERFACE_NAME))
.thenReturn((long) WifiManager.WIFI_FEATURE_LOW_LATENCY);
// Fail the call to ClientModeImpl
@@ -837,7 +822,7 @@ public class WifiLockManagerTest {
// Set screen on, and app is foreground
mWifiLockManager.handleScreenStateChanged(true);
when(mFrameworkFacade.isAppForeground(anyInt())).thenReturn(true);
- when(mClientModeImpl.syncGetSupportedFeatures(any()))
+ when(mWifiNative.getSupportedFeatureSet(INTERFACE_NAME))
.thenReturn((long) WifiManager.WIFI_FEATURE_LOW_LATENCY);
// Succeed to setLowLatencyMode()
@@ -863,7 +848,7 @@ public class WifiLockManagerTest {
// Set screen on, app foreground
mWifiLockManager.handleScreenStateChanged(true);
when(mFrameworkFacade.isAppForeground(anyInt())).thenReturn(true);
- when(mClientModeImpl.syncGetSupportedFeatures(any()))
+ when(mWifiNative.getSupportedFeatureSet(INTERFACE_NAME))
.thenReturn((long) WifiManager.WIFI_FEATURE_LOW_LATENCY);
// Make sure setLowLatencyMode() is successful
@@ -897,7 +882,7 @@ public class WifiLockManagerTest {
// Initially, set screen on, app foreground
mWifiLockManager.handleScreenStateChanged(true);
when(mFrameworkFacade.isAppForeground(anyInt())).thenReturn(true);
- when(mClientModeImpl.syncGetSupportedFeatures(any()))
+ when(mWifiNative.getSupportedFeatureSet(INTERFACE_NAME))
.thenReturn((long) WifiManager.WIFI_FEATURE_LOW_LATENCY);
// Make sure setLowLatencyMode() is successful
@@ -936,7 +921,7 @@ public class WifiLockManagerTest {
// Initially, set screen on, and app background
mWifiLockManager.handleScreenStateChanged(true);
when(mFrameworkFacade.isAppForeground(anyInt())).thenReturn(false);
- when(mClientModeImpl.syncGetSupportedFeatures(any()))
+ when(mWifiNative.getSupportedFeatureSet(INTERFACE_NAME))
.thenReturn((long) WifiManager.WIFI_FEATURE_LOW_LATENCY);
// Make sure setLowLatencyMode() is successful
when(mClientModeImpl.setLowLatencyMode(anyBoolean())).thenReturn(true);
@@ -975,7 +960,7 @@ public class WifiLockManagerTest {
// Initially, set screen on, and app background
mWifiLockManager.handleScreenStateChanged(true);
when(mFrameworkFacade.isAppForeground(anyInt())).thenReturn(false);
- when(mClientModeImpl.syncGetSupportedFeatures(any()))
+ when(mWifiNative.getSupportedFeatureSet(INTERFACE_NAME))
.thenReturn((long) WifiManager.WIFI_FEATURE_LOW_LATENCY);
mWifiLockManager.updateWifiClientConnected(true);
@@ -1019,7 +1004,7 @@ public class WifiLockManagerTest {
public void testForceLowLatency() throws Exception {
when(mClientModeImpl.setLowLatencyMode(anyBoolean())).thenReturn(true);
when(mClientModeImpl.setPowerSave(anyBoolean())).thenReturn(true);
- when(mClientModeImpl.syncGetSupportedFeatures(any()))
+ when(mWifiNative.getSupportedFeatureSet(INTERFACE_NAME))
.thenReturn((long) WifiManager.WIFI_FEATURE_LOW_LATENCY);
InOrder inOrder = inOrder(mClientModeImpl);
@@ -1050,7 +1035,7 @@ public class WifiLockManagerTest {
when(mClientModeImpl.setLowLatencyMode(anyBoolean())).thenReturn(true);
when(mClientModeImpl.setPowerSave(anyBoolean())).thenReturn(true);
mWifiLockManager.handleScreenStateChanged(false);
- when(mClientModeImpl.syncGetSupportedFeatures(any()))
+ when(mWifiNative.getSupportedFeatureSet(INTERFACE_NAME))
.thenReturn((long) WifiManager.WIFI_FEATURE_LOW_LATENCY);
mWifiLockManager.updateWifiClientConnected(true);
@@ -1086,7 +1071,7 @@ public class WifiLockManagerTest {
when(mClientModeImpl.setPowerSave(anyBoolean())).thenReturn(true);
mWifiLockManager.handleScreenStateChanged(true);
when(mFrameworkFacade.isAppForeground(anyInt())).thenReturn(true);
- when(mClientModeImpl.syncGetSupportedFeatures(any()))
+ when(mWifiNative.getSupportedFeatureSet(INTERFACE_NAME))
.thenReturn((long) WifiManager.WIFI_FEATURE_LOW_LATENCY);
InOrder inOrder = inOrder(mClientModeImpl);
@@ -1126,7 +1111,7 @@ public class WifiLockManagerTest {
public void testForceLowLatencyTwice() throws Exception {
when(mClientModeImpl.setLowLatencyMode(anyBoolean())).thenReturn(true);
when(mClientModeImpl.setPowerSave(anyBoolean())).thenReturn(true);
- when(mClientModeImpl.syncGetSupportedFeatures(any()))
+ when(mWifiNative.getSupportedFeatureSet(INTERFACE_NAME))
.thenReturn((long) WifiManager.WIFI_FEATURE_LOW_LATENCY);
mWifiLockManager.updateWifiClientConnected(true);
@@ -1152,7 +1137,7 @@ public class WifiLockManagerTest {
public void testForceHiPerfLowLatency() throws Exception {
when(mClientModeImpl.setLowLatencyMode(anyBoolean())).thenReturn(true);
when(mClientModeImpl.setPowerSave(anyBoolean())).thenReturn(true);
- when(mClientModeImpl.syncGetSupportedFeatures(any()))
+ when(mWifiNative.getSupportedFeatureSet(INTERFACE_NAME))
.thenReturn((long) WifiManager.WIFI_FEATURE_LOW_LATENCY);
mWifiLockManager.updateWifiClientConnected(true);
InOrder inOrder = inOrder(mClientModeImpl);
@@ -1180,7 +1165,7 @@ public class WifiLockManagerTest {
public void testForceLowLatencyHiPerf() throws Exception {
when(mClientModeImpl.setLowLatencyMode(anyBoolean())).thenReturn(true);
when(mClientModeImpl.setPowerSave(anyBoolean())).thenReturn(true);
- when(mClientModeImpl.syncGetSupportedFeatures(any()))
+ when(mWifiNative.getSupportedFeatureSet(INTERFACE_NAME))
.thenReturn((long) WifiManager.WIFI_FEATURE_LOW_LATENCY);
mWifiLockManager.updateWifiClientConnected(true);
@@ -1208,7 +1193,7 @@ public class WifiLockManagerTest {
@Test
public void testForceLowLatencyFailure() throws Exception {
when(mClientModeImpl.setLowLatencyMode(anyBoolean())).thenReturn(false);
- when(mClientModeImpl.syncGetSupportedFeatures(any()))
+ when(mWifiNative.getSupportedFeatureSet(INTERFACE_NAME))
.thenReturn((long) WifiManager.WIFI_FEATURE_LOW_LATENCY);
InOrder inOrder = inOrder(mClientModeImpl);
@@ -1330,7 +1315,7 @@ public class WifiLockManagerTest {
// Set condition for activation of low-latency (except connection to AP)
mWifiLockManager.handleScreenStateChanged(true);
when(mFrameworkFacade.isAppForeground(anyInt())).thenReturn(true);
- when(mClientModeImpl.syncGetSupportedFeatures(any()))
+ when(mWifiNative.getSupportedFeatureSet(INTERFACE_NAME))
.thenReturn((long) WifiManager.WIFI_FEATURE_LOW_LATENCY);
InOrder inOrder = inOrder(mWifiMetrics);