BluetoothGatt: onClientRegistered() - status=133 // статус onConnectionStateChange: 257

После обновления Cordova и платформ Android и iOS приложение больше не подключается, и я не могу понять, почему? Logcat в студии Android продолжает повторять одну и ту же ошибку в отношении BluetoothGatt. Я нуб, поэтому я не совсем уверен, как отлаживать отсюда, кроме как гуглить и задавать вопросы.

Я пытался удалить, обновить Gradle, изменить плагины для Wi-Fi, но я считаю, что это ошибка Bluetooth. Но мои убеждения, вероятно, ошибочны.

Цикл в студии Logcat в Android.

D/BluetoothAdapter: STATE_ON
    scan not started yet
I/@@@@@@: @@@ connect
I/@@@@@@: @@@ creating gatt handler
    @@@ getRemoteDevice
    @@@ connectGatt
D/BluetoothAdapter: STATE_ON
D/BluetoothGatt: connect() - device: B8:27:EB:C6:4F:19, auto: false
D/BluetoothAdapter: isSecureModeEnabled
D/BluetoothGatt: registerApp()
    registerApp() - UUID=ae27921d-3fa8-45f4-bf37-b1d9abf04149
D/BluetoothGatt: onClientRegistered() - status=133 clientIf=0
I/@@@@@@: @@@ onConnectionStateChange status: 257 newState: 0
    @@@ connect error - status: 257
D/BluetoothAdapter: stopLeScan()
D/BluetoothAdapter: STATE_ON
D/BluetoothAdapter: scan not started yet
I/@@@@@@: @@@ connect
I/@@@@@@: @@@ creating gatt handler
    @@@ getRemoteDevice
    @@@ connectGatt
D/BluetoothAdapter: STATE_ON
D/BluetoothGatt: connect() - device: B8:27:EB:C6:4F:19, auto: false
D/BluetoothAdapter: isSecureModeEnabled
D/BluetoothGatt: registerApp()
    registerApp() - UUID=33e7344c-33e8-4366-8bd9-9336b80f4ce7
D/BluetoothGatt: onClientRegistered() - status=133 clientIf=0
I/@@@@@@: @@@ onConnectionStateChange status: 257 newState: 0
    @@@ connect error - status: 257
D/BluetoothAdapter: stopLeScan()
D/BluetoothAdapter: STATE_ON
D/BluetoothAdapter: scan not started yet

Это функция, которая выдает ошибки.

    // Also maintains the per-device operation queue.
    private class GattHandler extends BluetoothGattCallback
    {
        // Local copy of the key to BLE.mGatt. Fed by BLE.mNextGattHandle.
        final int mHandle;

        // The queue of operations.
        LinkedList<Runnable> mOperations = new LinkedList<Runnable>();

        // connect() and rssi() are handled separately from other operations.
        CallbackContext mConnectContext;
        CallbackContext mRssiContext;
        CallbackContext mCurrentOpContext;

        // Flag used when writing notification config descriptor.
        // In this case we don't want to send back the result to JavaScript.
        boolean mDontReportWriteDescriptor = false;

        // The Android API connection.
        BluetoothGatt mGatt;

        // Maps of integer to Gatt subobject.
        HashMap<Integer, BluetoothGattService> mServices;
        HashMap<Integer, BluetoothGattCharacteristic> mCharacteristics;
        HashMap<Integer, BluetoothGattDescriptor> mDescriptors;

        // Monotonically incrementing key to the subobject maps.
        int mNextHandle = 1;

        // Notification callbacks. The BluetoothGattCharacteristic object, as found
        // in the mCharacteristics map, is the key.
        HashMap<BluetoothGattCharacteristic, CallbackContext> mNotifications =
            new HashMap<BluetoothGattCharacteristic, CallbackContext>();

        GattHandler(int h, CallbackContext cc)
        {
            mHandle = h;
            mConnectContext = cc;
        }

        // Run the next operation, if any.
        // TODO: Make another method processNext that sets mCurrentOpContext to
        // null and calls process. That would clean up repeated code a bit.
        // Also consider writing method that adds a runnable to the mOperations
        // queue and calls process, this would also reduce some repeated code.
        void process()
        {
            if (mCurrentOpContext != null) return;
            Runnable runnable = mOperations.poll();
            if (runnable == null) return;
            runAction(runnable);
        }

        @Override
        public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState)
        {
            Log.i("@@@@@@", "@@@ onConnectionStateChange status: " + status + " newState: " + newState);

            if (status == BluetoothGatt.GATT_SUCCESS)
            {
                try
                {
                    JSONObject result = new JSONObject();
                    result.put("deviceHandle", mHandle);
                    result.put("state", newState);
                    Log.i("@@@@@@", "@@@ connect success");
                    keepCallback(mConnectContext, result);
                }
                catch(JSONException e)
                {
                    Log.i("@@@@@@", "@@@ connect error: " + e);
                    e.printStackTrace();
                    mConnectContext.error("Connect error: " + e);
                    //assert(false);
                }
            }
            else
            {
                // Could this be where we get 133? Yes it is.
                Log.i("@@@@@@", "@@@ connect error - status: " + status);
                mConnectContext.error(status);
            }
        }

Мне просто нужны хлебные крошки или указания о том, как решить эту проблему или как правильно отлаживать через студию Android. Спасибо


person Curtis M    schedule 26.06.2019    source источник


Ответы (1)


Эта ошибка возникала из-за того, что я неправильно подключался к Wi-Fi, а код, который у меня был до обновления Cordova, и платформы iOS и Android работали нормально. Мне нужно было изменить android:usesCleartextTraffic=true в AndroidManifest в соответствии с документами Cordova при обновлении уровня API. На что здесь есть хороший ответ. а>

и документы: https://developer.android.com/training/articles/security-config

Я надеюсь, что это поможет кому-то, кто обновляет свой проект.

person Curtis M    schedule 28.06.2019
comment
У меня такая же проблема (т.е. вдруг кода, который нормально работал на телефоне, больше нет, и возвращается ошибка 257). Однако это не реализация Cordova. Просто родная Java. Я постараюсь изучить ваши выводы, хотя не уверен, почему Wi-Fi может создавать проблемы для Bluetooth. - person Maurizio Macagno; 20.08.2019
comment
@MaurizioMacagno, да, я бы поискал обновление на вашей платформе, которое может иметь новые меры безопасности, или плагин, который мог быть обновлен и требует изменения кода. - person Curtis M; 20.08.2019