summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorDavid Su <dysu@google.com>2019-09-24 14:03:27 -0700
committerDavid Su <dysu@google.com>2019-09-24 14:03:27 -0700
commit144a530c6303f0dfb06a092bef3125a13d3c96f7 (patch)
tree82d4f077409c4b4c8d21689f76e26e2e572faa8d /service
parentb6b18ba110233448ee62a3483282c8f63cb45a84 (diff)
Revert "Start Wifi only after boot completes"
This reverts commit 9f9825205dbf9e86f3d78396f582b3006145fc94. Reason: b/140938772 Bug: 140938772 Test: none Change-Id: I3fb1110355cdc0e5219af61950196a8aa3c81a15
Diffstat (limited to 'service')
-rw-r--r--service/AndroidManifest.xml8
-rw-r--r--service/AndroidManifest_InProcess.xml6
-rw-r--r--service/java/com/android/server/wifi/BootCompleteReceiver.java98
-rw-r--r--service/java/com/android/server/wifi/WifiStackService.java68
4 files changed, 30 insertions, 150 deletions
diff --git a/service/AndroidManifest.xml b/service/AndroidManifest.xml
index 878b7d51b..ee05237ed 100644
--- a/service/AndroidManifest.xml
+++ b/service/AndroidManifest.xml
@@ -69,8 +69,7 @@
<!-- TODO(b/135691051): Need to move to network stack process.
"android:process="com.google.android.networkstack"
This is not possible currently because hidden API access is denied when run on network
- stack process.
- <receiver> also needs to run on the networkstack process. -->
+ stack process -->
<application
android:persistent="true"
android:directBootAware="true"
@@ -82,10 +81,5 @@
<action android:name="android.net.wifi.IWifiStackConnector"/>
</intent-filter>
</service>
- <receiver android:name="com.android.server.wifi.BootCompleteReceiver">
- <intent-filter>
- <action android:name="android.intent.action.BOOT_COMPLETED" />
- </intent-filter>
- </receiver>
</application>
</manifest>
diff --git a/service/AndroidManifest_InProcess.xml b/service/AndroidManifest_InProcess.xml
index c480a464a..866f129fb 100644
--- a/service/AndroidManifest_InProcess.xml
+++ b/service/AndroidManifest_InProcess.xml
@@ -37,11 +37,5 @@
<action android:name="android.net.wifi.IWifiStackConnector.InProcess"/>
</intent-filter>
</service>
- <receiver android:name="com.android.server.wifi.BootCompleteReceiver"
- android:process="system">
- <intent-filter>
- <action android:name="android.intent.action.BOOT_COMPLETED" />
- </intent-filter>
- </receiver>
</application>
</manifest>
diff --git a/service/java/com/android/server/wifi/BootCompleteReceiver.java b/service/java/com/android/server/wifi/BootCompleteReceiver.java
deleted file mode 100644
index 86f263a2d..000000000
--- a/service/java/com/android/server/wifi/BootCompleteReceiver.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (C) 2019 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.Context;
-import android.content.Intent;
-import android.util.Log;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.annotation.concurrent.GuardedBy;
-
-/**
- * Receives boot complete broadcast (registered in AndroidManifest.xml).
- *
- * Ensures that if WifiStack is initialized after boot complete, we can check whether boot was
- * already completed, since if we start listening for the boot complete broadcast now it will be too
- * late and we will never get the broadcast.
- *
- * This BroadcastReceiver can be registered multiple times in different places, and it will ensure
- * that all registered callbacks are triggered exactly once.
- */
-public class BootCompleteReceiver extends BroadcastReceiver {
- private static final String TAG = "WifiBootCompleteReceiver";
-
- private static final Object sLock = new Object();
- @GuardedBy("sLock")
- private static boolean sIsBootCompleted = false;
- @GuardedBy("sLock")
- private static final List<Runnable> sCallbacks = new ArrayList<>(1);
-
- public BootCompleteReceiver() {
- Log.d(TAG, "Constructed BootCompleteReceiver");
- }
-
- /**
- * Registers a callback that will be triggered when boot is completed. Note that if boot has
- * already been completed when the callback is registered, the callback will be triggered
- * immediately.
- *
- * No guarantees are made about which thread the callback is triggered on. Please do not
- * perform expensive operations in the callback, instead post to other threads.
- */
- public static void registerCallback(Runnable callback) {
- boolean runImmediately = false;
-
- synchronized (sLock) {
- if (sIsBootCompleted) {
- runImmediately = true;
- } else {
- sCallbacks.add(callback);
- }
- }
-
- // run callback outside of synchronized block
- if (runImmediately) {
- Log.d(TAG, "Triggering callback immediately since boot is already complete.");
- callback.run();
- } else {
- Log.d(TAG, "Enqueuing callback since boot is not yet complete.");
- }
- }
-
- @Override
- public void onReceive(Context context, Intent intent) {
- Log.d(TAG, "Received boot complete broadcast");
-
- List<Runnable> callbacks = new ArrayList<>(1);
-
- synchronized (sLock) {
- sIsBootCompleted = true;
- callbacks.addAll(sCallbacks);
- sCallbacks.clear();
- }
-
- // run callbacks outside of synchronized block
- for (Runnable r : callbacks) {
- Log.d(TAG, "Triggered callback");
- r.run();
- }
- }
-}
diff --git a/service/java/com/android/server/wifi/WifiStackService.java b/service/java/com/android/server/wifi/WifiStackService.java
index 8887005b0..dbf3882eb 100644
--- a/service/java/com/android/server/wifi/WifiStackService.java
+++ b/service/java/com/android/server/wifi/WifiStackService.java
@@ -31,11 +31,8 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.net.wifi.IWifiStackConnector;
-import android.net.wifi.WifiApiServiceInfo;
import android.os.Binder;
-import android.os.Handler;
import android.os.IBinder;
-import android.os.Looper;
import android.os.UserHandle;
import android.os.storage.StorageManager;
import android.util.Log;
@@ -50,7 +47,6 @@ import com.android.server.wifi.scanner.WifiScanningService;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
-import java.util.stream.Collectors;
/**
* Android service used to start the wifi stack when bound to via an intent.
@@ -71,21 +67,41 @@ public class WifiStackService extends Service {
}
@Override
- public List<WifiApiServiceInfo> getWifiApiServiceInfos() {
+ public IBinder retrieveApiServiceImpl(@NonNull String serviceName) {
// Ensure this is being invoked from system_server only.
mContext.enforceCallingOrSelfPermission(
android.Manifest.permission.NETWORK_STACK, "WifiStackService");
long ident = Binder.clearCallingIdentity();
try {
synchronized (mApiServices) {
- return mApiServices.entrySet().stream()
- .map(entry -> {
- WifiApiServiceInfo service = new WifiApiServiceInfo();
- service.name = entry.getKey();
- service.binder = entry.getValue().retrieveImpl();
- return service;
- })
- .collect(Collectors.toList());
+ WifiServiceBase serviceBase = mApiServices.get(serviceName);
+ if (serviceBase == null) return null;
+ return serviceBase.retrieveImpl();
+ }
+ } finally {
+ Binder.restoreCallingIdentity(ident);
+ }
+ }
+
+ @Override
+ public boolean startApiService(@NonNull String serviceName) {
+ // Ensure this is being invoked from system_server only.
+ mContext.enforceCallingOrSelfPermission(
+ android.Manifest.permission.NETWORK_STACK, "WifiStackService");
+ long ident = Binder.clearCallingIdentity();
+ try {
+ synchronized (mApiServices) {
+ WifiServiceBase serviceBase = mApiServices.get(serviceName);
+ if (serviceBase == null) return false;
+ serviceBase.onStart();
+ // The current active user might have switched before the wifi services
+ // started up. So, send a onSwitchUser callback just after onStart callback is
+ // invoked.
+ int currentUser = ActivityManager.getCurrentUser();
+ if (currentUser != UserHandle.USER_SYSTEM) {
+ serviceBase.onSwitchUser(currentUser);
+ }
+ return true;
}
} finally {
Binder.restoreCallingIdentity(ident);
@@ -175,16 +191,6 @@ public class WifiStackService extends Service {
return false;
}
- // BootCompleteReceiver is registered in AndroidManifest.xml and here. The receiver
- // registered here is triggered earlier, while the receiver registered in the manifest
- // is more reliable since it is registered earlier, so we are guaranteed to get the
- // broadcast (if we register too late the broadcast may have already triggered and we
- // would have missed it). Register in both places and BootCompleteReceiver will ensure that
- // callbacks are called exactly once.
- Log.d(TAG, "Registering BootCompleteReceiver to listen for ACTION_BOOT_COMPLETED");
- context.registerReceiver(new BootCompleteReceiver(),
- new IntentFilter(Intent.ACTION_BOOT_COMPLETED));
-
synchronized (mApiServices) {
// Top level wifi feature flag.
if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
@@ -213,22 +219,6 @@ public class WifiStackService extends Service {
}
}
- Handler handler = new Handler(Looper.myLooper());
- // register callback to start Wifi services after boot completes
- BootCompleteReceiver.registerCallback(() -> handler.post(() -> {
- int currentUser = ActivityManager.getCurrentUser();
- synchronized (mApiServices) {
- for (WifiServiceBase service : mApiServices.values()) {
- service.onStart();
- // The current active user might have switched before the wifi services started
- // up. So, send a onSwitchUser callback just after onStart callback is invoked.
- if (currentUser != UserHandle.USER_SYSTEM) {
- service.onSwitchUser(currentUser);
- }
- }
- }
- }));
-
// Register broadcast receiver for system events.
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_USER_SWITCHED);