Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cbde8ce7 authored by David Su's avatar David Su
Browse files

Start Wifi only after boot completes

Listen to boot complete in WifiStackService and
perform expensive initialization tasks afterwards.

WifiStackClient no longer drives the initialization
order of services. Instead it receives a list of
services and only registers them with ServiceManager.

Bug: 141003116
Test: atest FrameworksWifiTests
Test: device boots
Test: atest google/perf/boottime/boottime-test -v
Change-Id: If1f2a409f6dc72469b95d4fb491e408ae81b3a74
parent 8e3fc9da
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -5,6 +5,9 @@ java_library_static {
        "java/**/*.java",
        "java/**/*.aidl",
    ],
    aidl: {
        local_include_dirs: ["java"]
    },
    libs: [
        "services.net",
    ],
+3 −2
Original line number Diff line number Diff line
@@ -15,8 +15,9 @@
 */
package android.net.wifi;

import android.net.wifi.WifiApiServiceInfo;

/** @hide */
interface IWifiStackConnector {
     IBinder retrieveApiServiceImpl(String serviceName);
     boolean startApiService(String serviceName);
     List<WifiApiServiceInfo> getWifiApiServiceInfos();
}
+23 −0
Original line number Diff line number Diff line
/*
 * 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;
}
+17 −40
Original line number Diff line number Diff line
@@ -21,12 +21,13 @@ 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.
@@ -56,21 +57,23 @@ public class WifiStackClient {
        @Override
        public void onModuleServiceConnected(IBinder service) {
            Log.i(TAG, "Wifi stack connected");

            // 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);

                thread.quitSafely();
            });
            List<WifiApiServiceInfo> wifiApiServiceInfos;
            try {
                wifiApiServiceInfos = connector.getWifiApiServiceInfos();
            } catch (RemoteException e) {
                throw new RuntimeException("Failed to getWifiApiServiceInfos()", e);
            }

            for (WifiApiServiceInfo wifiApiServiceInfo : wifiApiServiceInfos) {
                String serviceName = wifiApiServiceInfo.name;
                IBinder binder = wifiApiServiceInfo.binder;
                Log.i(TAG, "Registering " + serviceName);
                ServiceManager.addService(serviceName, binder);
            }
        }
    }

@@ -81,32 +84,6 @@ 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.
     *