diff options
author | Matt Ranostay <matt.ranostay@konsulko.com> | 2019-01-09 18:40:26 -0800 |
---|---|---|
committer | Matt Ranostay <matt.ranostay@konsulko.com> | 2019-04-04 16:01:15 -0700 |
commit | 020e5b1720c971380c3250580db5530dbe358627 (patch) | |
tree | 3dba3528fbb15fb579fbb5d75c33d250acb16eba /binding | |
parent | 8d4abe69907961af0dd5f872b157c58241b0e107 (diff) |
binding: telephony: remove bluetooth dependency
By subscribing to org.ofono.Modem PropertyChanged events it can be
detected when a handsfree profile device is connected. In turn the
bluetooth service access is no longer needed.
Bug-AGL: SPEC-2117
Change-Id: Iae92c66962ac88e07d58d75e566ae31e7128c831
Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'binding')
-rw-r--r-- | binding/gdbus/ofono_manager.c | 17 | ||||
-rw-r--r-- | binding/telephony-binding.c | 172 |
2 files changed, 75 insertions, 114 deletions
diff --git a/binding/gdbus/ofono_manager.c b/binding/gdbus/ofono_manager.c index 1086beb..98d8c5b 100644 --- a/binding/gdbus/ofono_manager.c +++ b/binding/gdbus/ofono_manager.c @@ -69,8 +69,19 @@ int ofono_manager_set_default_modem(const char *address) else if (!strcmp(key, "Type")) type = g_variant_get_string(value, NULL); } - /* If the HFP modem matches the BT address, is powered, and online then set as default */ - if (!g_strcmp0(type, "hfp") && !g_strcmp0(address, serial) && powered && online) { + + /* If not a HFP modem then continue */ + if (g_strcmp0(type, "hfp")) + continue; + + /* If address is NULL then use the first modem as default, + * and if not then continue if doesn't match address. + */ + if (address && g_strcmp0(address, serial)) + continue; + + /* If powered, and online then set as default */ + if (powered && online) { default_modem.address = serial; default_modem.path = path; default_modem.name = name; @@ -78,7 +89,7 @@ int ofono_manager_set_default_modem(const char *address) default_modem.powered = powered; default_modem.online = online; default_modem.valid = TRUE; - AFB_NOTICE("New modem: %s (%s)", name, address); + AFB_NOTICE("New modem: %s (%s)", name, serial); break; } } diff --git a/binding/telephony-binding.c b/binding/telephony-binding.c index 50d3638..a013196 100644 --- a/binding/telephony-binding.c +++ b/binding/telephony-binding.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Konsulko Group + * Copyright (C) 2017-2019 Konsulko Group * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ #include "ofono_voicecallmanager.h" #include "ofono_voicecall.h" -#define HFP_UUID "0000111f-0000-1000-8000-00805f9b34fb" +#define OFONO_MODEM_INTERFACE "org.ofono.Modem" static OrgOfonoVoiceCallManager *vcm; static OrgOfonoVoiceCall *incoming_call, *voice_call; @@ -201,74 +201,80 @@ static int ofono_init_default_modem(void) return ret; } -static gboolean is_hfp_dev_and_init(struct json_object *dev) +static void ofono_modem_signal_callback( + GDBusConnection *connection, + const gchar *sender_name, + const gchar *object_path, + const gchar *interface_name, + const gchar *signal_name, + GVariant *parameters, + gpointer user_data) { - struct json_object *props = NULL, *val = NULL; - int i, connected = 0; + GVariant *var = NULL; + const gchar *key = NULL; + gchar *address, *tmp; + gboolean state; - json_object_object_get_ex(dev, "properties", &props); - if (!props) - return FALSE; + /* Only support hands-free profile for now */ + if (strncasecmp(object_path, "/hfp/org/bluez", 14)) + return; - json_object_object_get_ex(props, "connected", &val); - connected = json_object_get_boolean(val); - if (!val || !connected) - return FALSE; + if (g_strcmp0(signal_name, "PropertyChanged")) + return; - json_object_object_get_ex(props, "uuids", &val); - for (i = 0; i < json_object_array_length(val); i++) { - const char *uuid = json_object_get_string(json_object_array_get_idx(val, i)); - struct json_object *val1 = NULL; - int ret; + g_variant_get(parameters, "(sv)", &key, &var); - if (g_strcmp0(HFP_UUID, uuid)) - continue; + if (g_strcmp0(key, "Online")) + return; - json_object_object_get_ex(props, "address", &val1); + state = g_variant_get_boolean(var); - ret = ofono_manager_set_default_modem(json_object_get_string(val1)); - if (ret != 0) - return FALSE; + address = g_strdup(strstr(object_path, "dev_") + 4); + tmp = address; - ofono_init_default_modem(); - return TRUE; + for (; *tmp; tmp++) { + if (*tmp == '_') *tmp = ':'; } - return FALSE; -} - -static void discovery_result_cb(void *closure, struct json_object *result, - const char *error, const char *info, - afb_api_t api) -{ - enum json_type type; - struct json_object *dev, *tmp; - int i; - - if (!json_object_object_get_ex(result, "devices", &tmp)) - return; - type = json_object_get_type(tmp); + if (state) { + ofono_manager_set_default_modem((const char *) address); - if (type != json_type_array) - return; - - for (i = 0; i < json_object_array_length(tmp); i++) { - dev = json_object_array_get_idx(tmp, i); - if (is_hfp_dev_and_init(dev)) - return; + if (ofono_manager_get_default_modem_valid()) { + ofono_init_default_modem(); + } + } else if (!g_strcmp0(ofono_manager_get_default_modem_address(), address)) { + AFB_NOTICE("Removing modem: (%s)", address); + ofono_manager_invalidate_default_modem(); } + + g_free(address); } -static void ofono_hfp_init(afb_api_t api) +static void ofono_event_init(void) { - struct json_object *args; + GError *error = NULL; + GDBusConnection *conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + + g_dbus_connection_signal_subscribe(conn, + NULL, /* sender */ + OFONO_MODEM_INTERFACE, + NULL, /* member */ + NULL, /* object path */ + NULL, /* arg0 */ + G_DBUS_SIGNAL_FLAGS_NONE, + ofono_modem_signal_callback, + NULL, /* user ptr */ + NULL); +} + - args = json_object_new_object(); - json_object_object_add(args, "value", json_object_new_string("device_changes")); - afb_api_call_sync(api, "Bluetooth-Manager", "subscribe", args, NULL, NULL, NULL); +static void ofono_hfp_init(void) +{ + ofono_manager_set_default_modem(NULL); - args = json_object_new_object(); - afb_api_call(api, "Bluetooth-Manager", "managed_objects", args, discovery_result_cb, NULL); + if (ofono_manager_get_default_modem_valid()) { + ofono_init_default_modem(); + } } static int ofono_init(afb_api_t api) @@ -281,19 +287,13 @@ static int ofono_init(afb_api_t api) incoming_call_event = afb_daemon_make_event("incomingCall"); terminated_call_event = afb_daemon_make_event("terminatedCall"); - ret = afb_daemon_require_api("Bluetooth-Manager", 1); - if (ret) { - AFB_ERROR("unable to initialize bluetooth binding"); - return -1; - } - /* Start the main loop thread */ pthread_create(&tid, NULL, main_loop_thread, NULL); ret = ofono_manager_init(); if (ret == 0) { - ofono_manager_invalidate_default_modem(); - ofono_hfp_init(api); + ofono_event_init(); + ofono_hfp_init(); } else { AFB_ERROR("failed to initialize ofono manager"); } @@ -332,58 +332,8 @@ static int init(afb_api_t api) return ofono_init(api); } -static void process_connection_event(afb_api_t api, struct json_object *object) -{ - struct json_object *val = NULL, *props = NULL; - const char *action, *address; - int connected = 0; - - json_object_object_get_ex(object, "action", &val); - if (!val) - return; - action = json_object_get_string(val); - if (g_strcmp0("changed", action)) - return; - - json_object_object_get_ex(object, "properties", &props); - if (!props) - return; - - json_object_object_get_ex(props, "connected", &val); - if (!val) - return; - connected = json_object_get_boolean(val); - - if (connected) { - struct json_object *args = json_object_new_object(); - - afb_api_call(api, "Bluetooth-Manager", "managed_objects", - args, discovery_result_cb, NULL); - return; - } - - json_object_object_get_ex(props, "address", &val); - if (!val) - return; - address = json_object_get_string(val); - - if (!g_strcmp0(address, ofono_manager_get_default_modem_address())) { - ofono_manager_invalidate_default_modem(); - ofono_voicecallmanager_free(vcm); - } -} - -static void onevent(afb_api_t api, const char *event, struct json_object *object) -{ - if (!g_ascii_strcasecmp(event, "Bluetooth-Manager/device_changes")) - process_connection_event(api, object); - else - AFB_ERROR("Unsupported event: %s\n", event); -} - const afb_binding_t afbBindingV3 = { .api = "telephony", .verbs = verbs, .init = init, - .onevent = onevent, }; |