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

Commit ec9a352d authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN
Browse files

Allow Bluetooth to bind to NetworkStack

Test: flashed, verified bluetooth tethering gets IP address
Bug: b/112869080
Change-Id: Idfbfdf54754fea46eb0099b9b9a3bdc29dd241e0
parent 79d05c93
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.net.dhcp.IDhcpServer.STATUS_INVALID_ARGUMENT;
import static android.net.dhcp.IDhcpServer.STATUS_SUCCESS;
import static android.net.dhcp.IDhcpServer.STATUS_UNKNOWN_ERROR;

import static com.android.server.util.PermissionUtil.checkDumpPermission;
import static com.android.server.util.PermissionUtil.checkNetworkStackCallingPermission;

import android.annotation.NonNull;
@@ -139,7 +140,7 @@ public class NetworkStackService extends Service {
        @Override
        protected void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter fout,
                @Nullable String[] args) {
            checkNetworkStackCallingPermission();
            checkDumpPermission();
            final IndentingPrintWriter pw = new IndentingPrintWriter(fout, "  ");
            pw.println("NetworkStack logs:");
            mLog.dump(fd, pw, args);
+15 −2
Original line number Diff line number Diff line
@@ -31,8 +31,21 @@ public final class PermissionUtil {
     */
    public static void checkNetworkStackCallingPermission() {
        // TODO: check that the calling PID is the system server.
        if (getCallingUid() != Process.SYSTEM_UID && getCallingUid() != Process.ROOT_UID) {
            throw new SecurityException("Invalid caller: " + getCallingUid());
        final int caller = getCallingUid();
        if (caller != Process.SYSTEM_UID && caller != Process.BLUETOOTH_UID) {
            throw new SecurityException("Invalid caller: " + caller);
        }
    }

    /**
     * Check that the caller is allowed to dump the network stack, e.g. dumpsys.
     * @throws SecurityException The caller is not allowed to dump the network stack.
     */
    public static void checkDumpPermission() {
        final int caller = getCallingUid();
        if (caller != Process.SYSTEM_UID && caller != Process.ROOT_UID
                && caller != Process.SHELL_UID) {
            throw new SecurityException("No dump permissions for caller: " + caller);
        }
    }