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

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

Revert "Start Wifi only after boot completes"

This reverts commit cbde8ce7.

Reason for revert: b/140938772

Change-Id: Ia5b481541895154a0f4da889c62619a4c1c7ecbc
parent cbde8ce7
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -5,9 +5,6 @@ java_library_static {
        "java/**/*.java",
        "java/**/*.aidl",
    ],
    aidl: {
        local_include_dirs: ["java"]
    },
    libs: [
        "services.net",
    ],
+2 −3
Original line number Diff line number Diff line
@@ -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);
}
+0 −23
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;
}
+40 −17
Original line number Diff line number Diff line
@@ -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);

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

            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);
            }
                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.
     *