Android 4.0+ Bluetooth-Verbindungsfehler zu einem eingebetteten Gerät: "Berechtigung verweigert"

Ich habe folgendes Setup:

Ein Android-Gerät verwendet einen Client-Socket, um eine Verbindung mit einem eingebetteten Remote-Gerät herzustellen. Die Android-Anwendung verwendet den folgenden Codeausschnitt, um eine Verbindung mit dem eingebetteten Gerät herzustellen.

Auf dem eingebetteten Gerät wird der MindTree BT-Stapel verwendet, bei dem der serielle Server-Socket gemäß einigen Eigenschaften des Geräts vorbereitet wird, mit denen die Android-Anwendung vertraut ist. Die auf dem eingebetteten Gerät definierte Verbindung ist nicht gesichert.

Die Kombination beider Anwendungen funktioniert bei:

2 LG-Handys verschiedene Modelle (Versionscode <10verwendet die "normale Methode")2 HTC's verschiedene Modelle (Versionscode <10verwendet die "Workaround-Methode")Pantech Tablet (Versionscode <13verwendet die "Workaround-Methode")

Heute habe ich die Anwendung auf Samsung S3, Motorola MB886 und einem Nexus 7 ausprobiert ... Alle führten zu einer "Verweigerung der Erlaubnis" beim Anrufen vonsocket.connect ()... (Ich habe die richtigen Berechtigungen im Manifest, sonst würde es auf den anderen Geräten nicht funktionieren.)

Alle neuen Geräte, auf denen ich getestet habe, sind mit Versionscode> 4.0 ausgestattet. Ich frage mich daher:

Kennt jemand irgendwelche Änderungen in der API? Vielleicht erzwingt Android 4.0+ Sicherheit?

Es scheint, dass der Fehler im Verbindungsstatus auftritt, da ich in den eingebetteten Programmprotokollen sehen kann ...

Irgendwelche Einsichten?

Der Code:

public final synchronized int connectToDevice(int connectingMethod)
        throws BluetoohConnectionException {
    if (socket != null)
        throw new BadImplementationException("Error socket is not null!!");
    connecting = true;
    logInfo("+---+ Connecting to device...");

    try {
        lastException = null;
        lastPacket = null;
        if (connectingMethod == BluetoothModule.BT_StandardConnection
                || connectingMethod == BluetoothModule.BT_ConnectionTBD)
            try {

                socket = fetchBT_Socket_Normal();
                connectToSocket(socket);
                listenForIncomingSPP_Packets();
                onConnetionEstablished();
                return BluetoothModule.BT_StandardConnection;
            } catch (BluetoohConnectionException e) {
                socket = null;
                if (connectingMethod == BluetoothModule.BT_StandardConnection) {
                    throw e;
                }
                logWarning("Error creating socket!", e);
            }
        if (connectingMethod == BluetoothModule.BT_ReflectiveConnection
                || connectingMethod == BluetoothModule.BT_ConnectionTBD)
            try {
                socket = fetchBT_Socket_Reflection(1);
                connectToSocket(socket);
                listenForIncomingSPP_Packets();
                onConnetionEstablished();
                return BluetoothModule.BT_ReflectiveConnection;
            } catch (BluetoohConnectionException e) {
                socket = null;
                if (connectingMethod == BluetoothModule.BT_ReflectiveConnection) {
                    throw e;
                }
                logWarning("Error creating socket!", e);
            }
        throw new BluetoohConnectionException("Error creating RFcomm socket for BT Device:" + this
                + "\n BAD connectingMethod==" + connectingMethod);
    } finally {
        connecting = false;
    }
}

protected void onConnetionEstablished() {
    logInfo("+---+ Connection established");
}

private synchronized void listenForIncomingSPP_Packets() {
    if (socketListeningThread != null)
        throw new BadImplementationException("Already lisening on Socket for BT Device" + this);
    logInfo("+---+ Listening for incoming packets");
    socketListeningThread = new Thread(socketListener, "Packet Listener - " + bluetoothDevice.getName());
    socketListeningThread.start();
}

private BluetoothSocket fetchBT_Socket_Normal()
        throws BluetoohConnectionException {
    try {
        logInfo("+---+ Fetching BT RFcomm Socket standard for UUID: " + uuid + "...");
        return bluetoothDevice.createRfcommSocketToServiceRecord(UUID.fromString(uuid));
    } catch (Exception e) {
        throw new BluetoohConnectionException("Error Fetching BT RFcomm Socket!", e);
    }
}

private BluetoothSocket fetchBT_Socket_Reflection(int connectionIndex)
        throws BluetoohConnectionException {
    Method m;
    try {
        logInfo("+---+ Fetching BT RFcomm Socket workaround index " + connectionIndex + "...");
        m = bluetoothDevice.getClass().getMethod("createRfcommSocket", new Class[]{int.class});
        return (BluetoothSocket) m.invoke(bluetoothDevice, connectionIndex);
    } catch (Exception e) {
        throw new BluetoohConnectionException("Error Fetching BT RFcomm Socket!", e);
    }
}

private void connectToSocket(BluetoothSocket socket)
        throws BluetoohConnectionException {
    try {
        logInfo("+---+ Connecting to socket...");
        socket.connect();
        logInfo("+---+ Connected to socket");
    } catch (IOException e) {
        try {
            socket.close();
        } catch (IOException e1) {
            logError("Error while closing socket", e1);
        } finally {
            socket = null;
        }
        throw new BluetoohConnectionException("Error connecting to socket with Device" + this, e);
    }
}

Antworten auf die Frage(1)

Ihre Antwort auf die Frage