Query available modems and connect to first modem found 72/27772/4
authorJimmy Huang <jimmy.huang@intel.com>
Thu, 18 Sep 2014 20:50:37 +0000 (13:50 -0700)
committerJimmy Huang <jimmy.huang@intel.com>
Thu, 18 Sep 2014 22:37:45 +0000 (15:37 -0700)
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 <jimmy.huang@intel.com>
packaging/phoned.changes
src/ofono.cpp
src/ofono.h
src/phone.cpp

index 7944db3..83c3e72 100644 (file)
@@ -1,3 +1,6 @@
+* Thu Sep 18 2014 Jimmy Huang <jimmy.huang@intel.com> accepted/tizen/ivi/20140915.195444-1-g32e0ce7
+- Query available modems and connect to first modem found
+
 * Mon Sep 15 2014 Jimmy Huang <jimmy.huang@intel.com> accepted/tizen/ivi/20140908.201319-5-g84a14e0
 - Fix FTBFS for x86_64
 - Fixed a bug where it doesn't handle multiple addresses
index db7ccb6..7b89a5c 100644 (file)
@@ -61,10 +61,16 @@ OFono::~OFono() {
 
 gboolean OFono::checkForModemPowered(gpointer user_data) {
     OFono *ctx = static_cast<OFono*>(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");
index 19cd166..264f4c8 100644 (file)
@@ -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);
index 3e3cdfc..b3d5aed 100644 (file)
@@ -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);
     }
 }