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

Commit d44fc022 authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN Committed by android-build-merger
Browse files

Merge "Crash the system server if network stack is lost" am: 825181be am: 5bccd693

am: cec6a71e

Change-Id: I034a62ec44ba1da32fd47c842a2bdf86f6ccf542
parents 79eedde0 cec6a71e
Loading
Loading
Loading
Loading
+30 −7
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.net.dhcp.IDhcpServerCallbacks;
import android.net.ip.IIpClientCallbacks;
import android.net.util.SharedLog;
import android.os.Binder;
import android.os.Build;
import android.os.IBinder;
import android.os.Process;
import android.os.RemoteException;
@@ -148,14 +149,18 @@ public class NetworkStackClient {
    private class NetworkStackConnection implements ServiceConnection {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            log("Network stack service connected");
            logi("Network stack service connected");
            registerNetworkStackService(service);
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            // TODO: crash/reboot the system ?
            logWtf("Lost network stack connector", null);
            // The system has lost its network stack (probably due to a crash in the
            // network stack process): better crash rather than stay in a bad state where all
            // networking is broken.
            // onServiceDisconnected is not being called on device shutdown, so this method being
            // called always indicates a bad state for the system server.
            maybeCrashWithTerribleFailure("Lost network stack");
        }
    };

@@ -211,8 +216,7 @@ public class NetworkStackClient {
        }

        if (intent == null) {
            logWtf("Could not resolve the network stack", null);
            // TODO: crash/reboot system server ?
            maybeCrashWithTerribleFailure("Could not resolve the network stack");
            return;
        }

@@ -220,9 +224,9 @@ public class NetworkStackClient {
        // NetworkStackConnection.onServiceConnected().
        if (!context.bindServiceAsUser(intent, new NetworkStackConnection(),
                Context.BIND_AUTO_CREATE | Context.BIND_IMPORTANT, UserHandle.SYSTEM)) {
            logWtf("Could not bind to network stack with " + intent, null);
            maybeCrashWithTerribleFailure(
                    "Could not bind to network stack in-process, or in app with " + intent);
            return;
            // TODO: crash/reboot system server if no network stack after a timeout ?
        }

        log("Network stack service start requested");
@@ -270,6 +274,16 @@ public class NetworkStackClient {
        }
    }

    private void maybeCrashWithTerribleFailure(@NonNull String message) {
        logWtf(message, null);
        if (Build.IS_DEBUGGABLE) {
            throw new IllegalStateException(message);
        }
    }

    /**
     * Log a message in the local log.
     */
    private void log(@NonNull String message) {
        synchronized (mLog) {
            mLog.log(message);
@@ -289,6 +303,15 @@ public class NetworkStackClient {
        }
    }

    /**
     * Log a message in the local and system logs.
     */
    private void logi(@NonNull String message) {
        synchronized (mLog) {
            mLog.i(message);
        }
    }

    /**
     * For non-system server clients, get the connector registered by the system server.
     */