From: Jimmy Huang Date: Thu, 18 Sep 2014 20:50:37 +0000 (-0700) Subject: Query available modems and connect to first modem found X-Git-Tag: accepted/tizen/ivi/20140926.101841~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e9af7594df4a0f2dc36d14191923a2fad20a5393;p=profile%2Fivi%2Fphoned.git Query available modems and connect to first modem found Query Ofono for a list of available modems when phoned starts and set the default modem to the first one. This will allow phoned to handle incoming calls. Change-Id: I450d101dad17d0e8a71c0a09993ad906888a5c82 Signed-off-by: Jimmy Huang --- diff --git a/packaging/phoned.changes b/packaging/phoned.changes index 7944db3..83c3e72 100644 --- a/packaging/phoned.changes +++ b/packaging/phoned.changes @@ -1,3 +1,6 @@ +* Thu Sep 18 2014 Jimmy Huang accepted/tizen/ivi/20140915.195444-1-g32e0ce7 +- Query available modems and connect to first modem found + * Mon Sep 15 2014 Jimmy Huang accepted/tizen/ivi/20140908.201319-5-g84a14e0 - Fix FTBFS for x86_64 - Fixed a bug where it doesn't handle multiple addresses diff --git a/src/ofono.cpp b/src/ofono.cpp index db7ccb6..7b89a5c 100644 --- a/src/ofono.cpp +++ b/src/ofono.cpp @@ -61,10 +61,16 @@ OFono::~OFono() { gboolean OFono::checkForModemPowered(gpointer user_data) { OFono *ctx = static_cast(user_data); - if(!ctx || !ctx->mModemPath) + if(!ctx) return G_SOURCE_CONTINUE; // continuous timeout + if(!ctx->mModemPath) { + LoggerD("No modem available, get all available modems"); + ctx->getModems(); + } + if(!ctx->isModemPowered(ctx->mModemPath)) { + LoggerD("modem is not powered"); ctx->setModemPowered(ctx->mModemPath, true); } @@ -372,6 +378,64 @@ void OFono::removeModem(const char *modemPath) { } } +void OFono::getModems() +{ + LoggerD("entered"); + + GError *err = NULL; + GVariant *reply = NULL; + reply = g_dbus_connection_call_sync( g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL), + OFONO_SERVICE, + "/", + OFONO_MANAGER_IFACE, + "GetModems", + NULL, + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &err); + + if(err || !reply) { + if(err) { + LoggerE("error calling GetModems method"); + g_error_free(err); + } + else if(!reply) + LoggerE("reply is NULL"); + + return; + } + + GVariantIter *modems; + GVariantIter *props; + const char *path; + g_variant_get(reply, "(a(oa{sv}))", &modems); + while(g_variant_iter_next(modems, "(oa{sv})", &path, &props)) { + // check if the modem is from selected remote device + std::string pathString(path); + size_t idx = pathString.find( "_" ) + 1; // index of address of remote device + std::string modemRemoteBtAddress = pathString.substr (idx, pathString.length()-idx); + + // remove additional underscores + modemRemoteBtAddress.erase(std::remove_if(modemRemoteBtAddress.begin(),modemRemoteBtAddress.end(),isnxdigit),modemRemoteBtAddress.end()); + + // check if it is a valid bluetooth MAC address + if(makeMACFromRawMAC(modemRemoteBtAddress)) + { + LoggerD("Modem found: " << modemRemoteBtAddress); + modemAdded(modemRemoteBtAddress); + } + + g_variant_iter_free(props); + } + + g_variant_iter_free(modems); + g_variant_unref(reply); + + return; +} + void OFono::getCalls() { LoggerD("entered"); diff --git a/src/ofono.h b/src/ofono.h index 19cd166..264f4c8 100644 --- a/src/ofono.h +++ b/src/ofono.h @@ -139,7 +139,8 @@ class OFono { const gchar *signal_name, GVariant *parameters, gpointer user_data); - //DBUS: array{object,dict} GetCalls() + //DBUS: array{object,dict} + void getModems(); //Get an array of call object paths and properties of available modems void getCalls(); //Get an array of call object paths and properties that represents the currently present calls. void addCall(const char *path, GVariantIter *props); void removeCall(OFono::Call **call); diff --git a/src/phone.cpp b/src/phone.cpp index 3e3cdfc..b3d5aed 100644 --- a/src/phone.cpp +++ b/src/phone.cpp @@ -287,7 +287,12 @@ void Phone::deviceRemoved(const char *device) { void Phone::modemAdded(std::string &modem) { LoggerD("modem added: " << modem); - if(!mWantedRemoteDevice.compare(modem)) { + if (mWantedRemoteDevice.empty()) { + LoggerD("No modem selected yet, default to: " << modem); + mWantedRemoteDevice = modem; + storeSelectedRemoteDeviceMAC(modem); + startServices(); + } else if(!mWantedRemoteDevice.compare(modem)) { selectModem(mWantedRemoteDevice); } }