summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRebecca Silberstein <silberst@google.com>2016-09-09 15:59:55 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2016-09-09 15:59:55 +0000
commit90e57d9537773f86e76cde86b2bee875521a03aa (patch)
tree622d2edc1d40f2f10b469becb96d95a37670dac0
parent0ce3ad57f3ce7fcfab17930e8cd48e6da57006fb (diff)
parentdc93140010ce36189b29fd58bc8f25d7636101f5 (diff)
Merge "WifiInjector: Move WifiScanner to WifiInjector"
-rw-r--r--service/java/com/android/server/wifi/FrameworkFacade.java11
-rw-r--r--service/java/com/android/server/wifi/WifiInjector.java18
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java4
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java10
4 files changed, 21 insertions, 22 deletions
diff --git a/service/java/com/android/server/wifi/FrameworkFacade.java b/service/java/com/android/server/wifi/FrameworkFacade.java
index 68556d46a..1c3c5e7ba 100644
--- a/service/java/com/android/server/wifi/FrameworkFacade.java
+++ b/service/java/com/android/server/wifi/FrameworkFacade.java
@@ -20,19 +20,13 @@ import android.app.AppGlobals;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
-import android.content.pm.PackageManager;
import android.net.TrafficStats;
import android.net.ip.IpManager;
-import android.net.wifi.IWifiScanner;
-import android.net.wifi.WifiScanner;
import android.os.Handler;
import android.os.IBinder;
-import android.os.Looper;
import android.os.RemoteException;
import android.os.ServiceManager;
-import android.os.UserManager;
import android.provider.Settings;
-import android.security.KeyStore;
import android.telephony.CarrierConfigManager;
/**
@@ -65,11 +59,6 @@ public class FrameworkFacade {
return ServiceManager.getService(serviceName);
}
- public WifiScanner makeWifiScanner(Context context, Looper looper) {
- return new WifiScanner(context, IWifiScanner.Stub.asInterface(
- getService(Context.WIFI_SCANNING_SERVICE)), looper);
- }
-
public PendingIntent getBroadcast(Context context, int requestCode, Intent intent, int flags) {
return PendingIntent.getBroadcast(context, requestCode, intent, flags);
}
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java
index a60594476..d6e8902b5 100644
--- a/service/java/com/android/server/wifi/WifiInjector.java
+++ b/service/java/com/android/server/wifi/WifiInjector.java
@@ -19,7 +19,9 @@ package com.android.server.wifi;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.wifi.IApInterface;
+import android.net.wifi.IWifiScanner;
import android.net.wifi.IWificond;
+import android.net.wifi.WifiScanner;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.INetworkManagementService;
@@ -81,6 +83,7 @@ public class WifiInjector {
private final IpConfigStore mIpConfigStore;
private final WifiConfigStoreLegacy mWifiConfigStoreLegacy;
private final WifiConfigManager mWifiConfigManager;
+ private WifiScanner mWifiScanner;
private final boolean mUseRealLogger;
@@ -304,4 +307,19 @@ public class WifiInjector {
return new BaseWifiDiagnostics();
}
}
+
+ /**
+ * Obtain an instance of WifiScanner.
+ * If it was not already created, then obtain an instance. Note, this must be done lazily since
+ * WifiScannerService is separate and created later.
+ */
+ public synchronized WifiScanner getWifiScanner() {
+ if (mWifiScanner == null) {
+ mWifiScanner = new WifiScanner(mContext,
+ IWifiScanner.Stub.asInterface(ServiceManager.getService(
+ Context.WIFI_SCANNING_SERVICE)),
+ mWifiStateMachineHandlerThread.getLooper());
+ }
+ return mWifiScanner;
+ }
}
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index 6bb25a944..14ab936b5 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -108,8 +108,6 @@ import com.android.internal.util.Protocol;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
import com.android.server.connectivity.KeepalivePacketData;
-import com.android.server.wifi.hotspot2.IconEvent;
-import com.android.server.wifi.hotspot2.NetworkDetail;
import com.android.server.wifi.hotspot2.Utils;
import com.android.server.wifi.p2p.WifiP2pServiceImpl;
import com.android.server.wifi.util.TelephonyUtil;
@@ -4222,7 +4220,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
// We can't do this in the constructor because WifiStateMachine is created before the
// wifi scanning service is initialized
if (mWifiScanner == null) {
- mWifiScanner = mFacade.makeWifiScanner(mContext, getHandler().getLooper());
+ mWifiScanner = mWifiInjector.getWifiScanner();
synchronized (mWifiReqCountLock) {
mWifiConnectivityManager = new WifiConnectivityManager(mContext,
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index d8b12a00a..3ed98fac7 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -17,7 +17,6 @@
package com.android.server.wifi;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
@@ -61,7 +60,6 @@ import android.os.UserManager;
import android.os.test.TestLooper;
import android.provider.Settings;
import android.security.KeyStore;
-import android.telephony.TelephonyManager;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.Log;
@@ -71,7 +69,6 @@ import com.android.internal.util.AsyncChannel;
import com.android.internal.util.IState;
import com.android.internal.util.StateMachine;
import com.android.server.wifi.hotspot2.NetworkDetail;
-import com.android.server.wifi.hotspot2.Utils;
import com.android.server.wifi.p2p.WifiP2pServiceImpl;
import org.junit.After;
@@ -88,12 +85,10 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.concurrent.CountDownLatch;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
-import java.util.Map;
import java.util.Set;
+import java.util.concurrent.CountDownLatch;
/**
* Unit tests for {@link com.android.server.wifi.WifiStateMachine}.
@@ -158,8 +153,6 @@ public class WifiStateMachineTest {
private FrameworkFacade getFrameworkFacade() throws Exception {
FrameworkFacade facade = mock(FrameworkFacade.class);
- when(facade.makeWifiScanner(any(Context.class), any(Looper.class)))
- .thenReturn(mWifiScanner);
when(facade.getService(Context.NETWORKMANAGEMENT_SERVICE)).thenReturn(
mockWithInterfaces(IBinder.class, INetworkManagementService.class));
@@ -346,6 +339,7 @@ public class WifiStateMachineTest {
when(mWifiInjector.makeWificond()).thenReturn(mWificond);
when(mWifiInjector.getWifiConfigManager()).thenReturn(mWifiConfigManager);
when(mWifiInjector.getWifiSupplicantControl()).thenReturn(mWifiSupplicantControl);
+ when(mWifiInjector.getWifiScanner()).thenReturn(mWifiScanner);
when(mWifiNative.getInterfaceName()).thenReturn("mockWlan");
when(mWifiSupplicantControl.getFrameworkNetworkId(anyInt())).thenReturn(0);