diff options
author | David Su <dysu@google.com> | 2019-09-24 21:16:23 +0000 |
---|---|---|
committer | David Su <dysu@google.com> | 2019-09-24 21:16:23 +0000 |
commit | ee58838a291c2d7751924acadc353a2b93e94f48 (patch) | |
tree | da944b37c0258ab37bd710ee16611d9e98bcd568 | |
parent | cbde8ce73fa8bdaa59b428f67760b1e2137e1f1c (diff) |
Revert "Start Wifi only after boot completes"
This reverts commit cbde8ce73fa8bdaa59b428f67760b1e2137e1f1c.
Reason for revert: b/140938772
Change-Id: Ia5b481541895154a0f4da889c62619a4c1c7ecbc
4 files changed, 42 insertions, 46 deletions
diff --git a/services/wifi/Android.bp b/services/wifi/Android.bp index 608fc2c7a55e..3c916a6d00cd 100644 --- a/services/wifi/Android.bp +++ b/services/wifi/Android.bp @@ -5,9 +5,6 @@ java_library_static { "java/**/*.java", "java/**/*.aidl", ], - aidl: { - local_include_dirs: ["java"] - }, libs: [ "services.net", ], diff --git a/services/wifi/java/android/net/wifi/IWifiStackConnector.aidl b/services/wifi/java/android/net/wifi/IWifiStackConnector.aidl index 3af4666b8d9c..eadc7260e81b 100644 --- a/services/wifi/java/android/net/wifi/IWifiStackConnector.aidl +++ b/services/wifi/java/android/net/wifi/IWifiStackConnector.aidl @@ -15,9 +15,8 @@ */ package android.net.wifi; -import android.net.wifi.WifiApiServiceInfo; - /** @hide */ interface IWifiStackConnector { - List<WifiApiServiceInfo> getWifiApiServiceInfos(); + IBinder retrieveApiServiceImpl(String serviceName); + boolean startApiService(String serviceName); } diff --git a/services/wifi/java/android/net/wifi/WifiApiServiceInfo.aidl b/services/wifi/java/android/net/wifi/WifiApiServiceInfo.aidl deleted file mode 100644 index 45e4c69102f0..000000000000 --- a/services/wifi/java/android/net/wifi/WifiApiServiceInfo.aidl +++ /dev/null @@ -1,23 +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 android.net.wifi; - -/** @hide */ -parcelable WifiApiServiceInfo { - String name; - IBinder binder; -} diff --git a/services/wifi/java/android/net/wifi/WifiStackClient.java b/services/wifi/java/android/net/wifi/WifiStackClient.java index dcdfbc54687c..64af7a8845a7 100644 --- a/services/wifi/java/android/net/wifi/WifiStackClient.java +++ b/services/wifi/java/android/net/wifi/WifiStackClient.java @@ -21,13 +21,12 @@ import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_NORMAL; import android.annotation.NonNull; import android.content.Context; import android.net.ConnectivityModuleConnector; +import android.os.HandlerThread; import android.os.IBinder; import android.os.RemoteException; import android.os.ServiceManager; import android.util.Log; -import java.util.List; - /** * Service used to communicate with the wifi stack, which could be running in a separate * module. @@ -57,23 +56,21 @@ public class WifiStackClient { @Override public void onModuleServiceConnected(IBinder service) { Log.i(TAG, "Wifi stack connected"); - registerWifiStackService(service); - - IWifiStackConnector connector = IWifiStackConnector.Stub.asInterface(service); - List<WifiApiServiceInfo> wifiApiServiceInfos; - try { - wifiApiServiceInfos = connector.getWifiApiServiceInfos(); - } catch (RemoteException e) { - throw new RuntimeException("Failed to getWifiApiServiceInfos()", e); - } + // spin up a new thread to not block system_server main thread + HandlerThread thread = new HandlerThread("InitWifiServicesThread"); + thread.start(); + thread.getThreadHandler().post(() -> { + registerWifiStackService(service); + IWifiStackConnector connector = IWifiStackConnector.Stub.asInterface(service); + registerApiServiceAndStart(connector, Context.WIFI_SCANNING_SERVICE); + registerApiServiceAndStart(connector, Context.WIFI_SERVICE); + registerApiServiceAndStart(connector, Context.WIFI_P2P_SERVICE); + registerApiServiceAndStart(connector, Context.WIFI_AWARE_SERVICE); + registerApiServiceAndStart(connector, Context.WIFI_RTT_RANGING_SERVICE); - for (WifiApiServiceInfo wifiApiServiceInfo : wifiApiServiceInfos) { - String serviceName = wifiApiServiceInfo.name; - IBinder binder = wifiApiServiceInfo.binder; - Log.i(TAG, "Registering " + serviceName); - ServiceManager.addService(serviceName, binder); - } + thread.quitSafely(); + }); } } @@ -84,6 +81,32 @@ public class WifiStackClient { Log.i(TAG, "Wifi stack service registered"); } + private void registerApiServiceAndStart( + IWifiStackConnector stackConnector, String serviceName) { + IBinder service = null; + try { + service = stackConnector.retrieveApiServiceImpl(serviceName); + } catch (RemoteException e) { + throw new RuntimeException("Failed to retrieve service impl " + serviceName, e); + } + if (service == null) { + Log.i(TAG, "Service " + serviceName + " not available"); + return; + } + Log.i(TAG, "Registering " + serviceName); + ServiceManager.addService(serviceName, service); + + boolean success = false; + try { + success = stackConnector.startApiService(serviceName); + } catch (RemoteException e) { + throw new RuntimeException("Failed to start service " + serviceName, e); + } + if (!success) { + throw new RuntimeException("Service " + serviceName + " start failed"); + } + } + /** * Start the wifi stack. Should be called only once on device startup. * |