summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Chen <stewchen@google.com>2016-11-16 17:40:36 -0800
committerStephen Chen <stewchen@google.com>2016-12-05 10:46:25 -0800
commitf09b6de086d5a00417613886aa43402285d2a8ab (patch)
treeafb848195f3f0144a9694dd1c824cb8c3632eb61
parentf229afcd54fc31eaf0f66cfb9e548cfc49d689e1 (diff)
Create an empty implementation of WifiWakeupController.
Bug: 32918599 Test: runtest --path frameworks/opt/net/wifi/tests/wifitests/src/com/android/server/wifi/WifiWakeupControllerTest.java Change-Id: Ib3926ff77be29e5e8364791dc68d8c22a2c6fa1d
-rw-r--r--service/java/com/android/server/wifi/WifiInjector.java7
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java3
-rw-r--r--service/java/com/android/server/wifi/WifiWakeupController.java93
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiWakeupControllerTest.java86
4 files changed, 189 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java
index fffac5d8a..48e0b98e8 100644
--- a/service/java/com/android/server/wifi/WifiInjector.java
+++ b/service/java/com/android/server/wifi/WifiInjector.java
@@ -71,6 +71,7 @@ public class WifiInjector {
private final WifiSettingsStore mSettingsStore;
private final WifiCertManager mCertManager;
private final WifiNotificationController mNotificationController;
+ private final WifiWakeupController mWifiWakeupController;
private final WifiLockManager mLockManager;
private final WifiController mWifiController;
private final Clock mClock = new Clock();
@@ -160,6 +161,8 @@ public class WifiInjector {
mNotificationController = new WifiNotificationController(mContext,
mWifiServiceHandlerThread.getLooper(), mWifiStateMachine,
mFrameworkFacade, null, this);
+ mWifiWakeupController = new WifiWakeupController(mContext,
+ mWifiServiceHandlerThread.getLooper(), mFrameworkFacade);
mLockManager = new WifiLockManager(mContext, BatteryStatsService.getService());
mWifiController = new WifiController(mContext, mWifiStateMachine, mSettingsStore,
mLockManager, mWifiServiceHandlerThread.getLooper(), mFrameworkFacade);
@@ -236,6 +239,10 @@ public class WifiInjector {
return mNotificationController;
}
+ public WifiWakeupController getWifiWakeupController() {
+ return mWifiWakeupController;
+ }
+
public WifiLockManager getWifiLockManager() {
return mLockManager;
}
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index ac3d8bf79..ef5c31d6d 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -138,6 +138,7 @@ public class WifiServiceImpl extends IWifiManager.Stub {
/* Tracks the open wi-fi network notification */
private WifiNotificationController mNotificationController;
+ private WifiWakeupController mWifiWakeupController;
/* Polls traffic stats and notifies clients */
private WifiTrafficPoller mTrafficPoller;
/* Tracks the persisted states for wi-fi & airplane mode */
@@ -330,6 +331,7 @@ public class WifiServiceImpl extends IWifiManager.Stub {
mCertManager = mWifiInjector.getWifiCertManager();
mNotificationController = mWifiInjector.getWifiNotificationController();
+ mWifiWakeupController = mWifiInjector.getWifiWakeupController();
mWifiLockManager = mWifiInjector.getWifiLockManager();
mWifiMulticastLockManager = mWifiInjector.getWifiMulticastLockManager();
@@ -1481,6 +1483,7 @@ public class WifiServiceImpl extends IWifiManager.Stub {
mWifiController.dump(fd, pw, args);
mSettingsStore.dump(fd, pw, args);
mNotificationController.dump(fd, pw, args);
+ mWifiWakeupController.dump(fd, pw, args);
mTrafficPoller.dump(fd, pw, args);
pw.println();
pw.println("Locks held:");
diff --git a/service/java/com/android/server/wifi/WifiWakeupController.java b/service/java/com/android/server/wifi/WifiWakeupController.java
new file mode 100644
index 000000000..1349c6d7d
--- /dev/null
+++ b/service/java/com/android/server/wifi/WifiWakeupController.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.server.wifi;
+
+import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.database.ContentObserver;
+import android.net.wifi.WifiManager;
+import android.os.Handler;
+import android.os.Looper;
+import android.provider.Settings;
+
+import com.android.internal.annotations.VisibleForTesting;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+
+/**
+ * Handles enabling Wi-Fi for the Wi-Fi Wakeup feature.
+ * @hide
+ */
+final class WifiWakeupController {
+
+ private Context mContext;
+ private final FrameworkFacade mFrameworkFacade;
+ private final Handler mHandler;
+ @VisibleForTesting
+ final ContentObserver mContentObserver;
+ @VisibleForTesting
+ boolean mWifiWakeupEnabled;
+
+ WifiWakeupController(Context context, Looper looper, FrameworkFacade frameworkFacade) {
+ mContext = context;
+ mFrameworkFacade = frameworkFacade;
+
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
+ filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
+
+ mHandler = new Handler(looper);
+
+ mContext.registerReceiver(mBroadcastReceiver, filter, null, mHandler);
+ mContentObserver = new ContentObserver(mHandler) {
+ @Override
+ public void onChange(boolean selfChange) {
+ mWifiWakeupEnabled = getWifiWakeupEnabledSetting();
+ }
+ };
+ ContentResolver cr = mContext.getContentResolver();
+ cr.registerContentObserver(Settings.Global.getUriFor(
+ Settings.Global.WIFI_WAKEUP_ENABLED), true, mContentObserver);
+ mWifiWakeupEnabled = getWifiWakeupEnabledSetting();
+ }
+
+ private boolean getWifiWakeupEnabledSetting() {
+ return mFrameworkFacade.getIntegerSetting(mContext,
+ Settings.Global.WIFI_WAKEUP_ENABLED, 0) == 1;
+ }
+
+ private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
+ handleWifiStateChanged(intent);
+ } else if (intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
+ handleScanResultsAvailable(intent);
+ }
+ }
+ };
+
+ private void handleWifiStateChanged(Intent intent) {};
+ private void handleScanResultsAvailable(Intent intent) {};
+
+ void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+ pw.println("mWifiWakeupEnabled " + mWifiWakeupEnabled);
+ }
+}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiWakeupControllerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiWakeupControllerTest.java
new file mode 100644
index 000000000..c714d8225
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/WifiWakeupControllerTest.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wifi;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import android.app.NotificationManager;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.net.wifi.WifiScanner;
+import android.os.test.TestLooper;
+import android.provider.Settings;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/**
+ * Unit tests for {@link com.android.server.wifi.WifiWakeupController}.
+ */
+public class WifiWakeupControllerTest {
+ public static final String TAG = "WifiScanningServiceTest";
+
+ @Mock private Context mContext;
+ @Mock private WifiStateMachine mWifiStateMachine;
+ @Mock private FrameworkFacade mFrameworkFacade;
+ @Mock private NotificationManager mNotificationManager;
+ @Mock private WifiScanner mWifiScanner;
+ @Mock private ContentResolver mContentResolver;
+ private WifiWakeupController mWifiWakeupController;
+
+
+ /** Initialize objects before each test run. */
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ when(mContext.getContentResolver()).thenReturn(mContentResolver);
+ when(mFrameworkFacade.getIntegerSetting(mContext,
+ Settings.Global.WIFI_WAKEUP_ENABLED, 0)).thenReturn(1);
+ TestLooper testLooper = new TestLooper();
+ mWifiWakeupController = new WifiWakeupController(
+ mContext, testLooper.getLooper(), mFrameworkFacade);
+ }
+
+ /** Test WifiWakeupEnabledSettingObserver enables feature correctly. */
+ @Test
+ public void testEnableWifiWakeup() {
+ assertTrue(mWifiWakeupController.mWifiWakeupEnabled);
+
+ when(mFrameworkFacade.getIntegerSetting(mContext,
+ Settings.Global.WIFI_WAKEUP_ENABLED, 0)).thenReturn(0);
+ mWifiWakeupController.mContentObserver.onChange(true);
+ assertFalse(mWifiWakeupController.mWifiWakeupEnabled);
+ }
+
+ /** Test dump() does not crash. */
+ @Test
+ public void testDump() {
+ StringWriter stringWriter = new StringWriter();
+ mWifiWakeupController.dump(
+ new FileDescriptor(), new PrintWriter(stringWriter), new String[0]);
+ }
+
+}