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

Commit ff7db40b authored by Jaikumar Ganesh's avatar Jaikumar Ganesh
Browse files

Make setting the adapter properties asynchronous.

1. These involve disk operations and multiple processes.
2. onPropertyChange already informs us asychronously.
3. Settings app is the only user, will have to revisit the function
   if we make them public.

Change-Id: If019a83c05a0c9e625f27faf99063d33f369f0d8
parent f0a896b3
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -309,6 +309,8 @@ class BluetoothEventLoop {
            // Note: bluez only sends this property change when it restarts.
            if (propValues[1].equals("true"))
                onRestartRequired();
        } else if (name.equals("DiscoverableTimeout")) {
            mBluetoothService.setProperty(name, propValues[1]);
        }
    }

+5 −12
Original line number Diff line number Diff line
@@ -744,11 +744,10 @@ static jboolean setAdapterPropertyNative(JNIEnv *env, jobject object, jstring ke
    LOGV(__FUNCTION__);
    native_data_t *nat = get_native_data(env, object);
    if (nat) {
        DBusMessage *reply, *msg;
        DBusMessage *msg;
        DBusMessageIter iter;
        DBusError err;
        dbus_bool_t reply = JNI_FALSE;
        const char *c_key = env->GetStringUTFChars(key, NULL);
        dbus_error_init(&err);

        msg = dbus_message_new_method_call(BLUEZ_DBUS_BASE_IFC,
                                           get_adapter_path(env, object),
@@ -764,19 +763,13 @@ static jboolean setAdapterPropertyNative(JNIEnv *env, jobject object, jstring ke
        dbus_message_iter_init_append(msg, &iter);
        append_variant(&iter, type, value);

        reply = dbus_connection_send_with_reply_and_block(nat->conn, msg, -1, &err);
        // Asynchronous call - the callbacks come via propertyChange
        reply = dbus_connection_send_with_reply(nat->conn, msg, NULL, -1);
        dbus_message_unref(msg);

        env->ReleaseStringUTFChars(key, c_key);
        return reply ? JNI_TRUE : JNI_FALSE;

        if (!reply) {
            if (dbus_error_is_set(&err)) {
                LOG_AND_FREE_DBUS_ERROR(&err);
            } else
                LOGE("DBus reply is NULL in function %s", __FUNCTION__);
            return JNI_FALSE;
        }
        return JNI_TRUE;
    }
#endif
    return JNI_FALSE;