UBports Robot Logo UBports Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    How to send MMS over DUBS to ofono?

    Scheduled Pinned Locked Moved App Development
    17 Posts 3 Posters 1.4k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
      Reply
      • Reply as topic
      Log in to reply
      This topic has been deleted. Only users with topic management privileges can see it.
      • K Offline
        kjhg84j9
        last edited by

        Hey guys,

        I'm just looking for an example on how to send MMS messages via DBUS to ofono. I've found one example online but I'm unable to get it working. There are lots of test details in the ofono git but they dont really help me in figuring out how to send MMS messages, just eveything else.. Is anyone able to provide an example in python or another language or help me get this one working?

        I was able to receive MMS by monitoring the dbus with GVariant and just working backwards from the data it sends. I could do the same thing for sending.... Monitor everything, slowly work down the name, interface, etc, and try and duplicate what the messaging app is sending but there has to be a better way, right?

        I'm doing all my testing on a nexus 5.

        Cheers!

        1 Reply Last reply Reply Quote 0
        • lduboeufL Online
          lduboeuf
          last edited by lduboeuf

          Have you looked at github repos such as https://github.com/ubports/telepathy-ofono/tree/xenial/tests

          i'm interested if you find something, good luck 😉
          Have you tried AppDev Telegram channel ?

          For an overview ( old resource but guess it is close to what it is now ) : https://wiki.ubuntu.com/Touch/Specs/MMSInfrastructure

          1 Reply Last reply Reply Quote 1
          • K Offline
            kjhg84j9
            last edited by

            I have not seen that github repo before. I'll need to have a better look at it but it looks like it has an function to send MMS messages. Thanks!

            I have seen that other link. however, I read it when I was just getting started with my project and forgot all about it. Looking at my code now I'm listening on org.ofono.mms.Service for MMSes. I remember seeing telepathy interfaces but I ignored them. I'll have to take another look and see, I might have done this the hard way.

            I'm thinking the python script above is trying to send a message on the wrong interface now. I'm also reading about smil files and trying to understand what they do. I just ignored them when I was receiving the MMS because I didn't need the data.

            I plan to have everything up on gitlab when I'm done and it will be heavily documented mostly because I'm learning and I have no idea what I'm doing. Commenting code helps me learn and remember what I'm doing.

            Cheers!

            1 Reply Last reply Reply Quote 1
            • K Offline
              kjhg84j9
              last edited by

              Receiving MMSes are only consistent on the interface I'm using so I guess I have the right one.

              sending seems to follow the spec. Later this weekend I'll write something to toss the same data at the interface and see what happens.

              method call time=1580999265.470354 sender=:1.152 -> destination=com.canonical.TelephonyServiceHandler serial=903 path=/com/canonical/TelephonyServiceHandler; interface=com.canonical.TelephonyServiceHandler; member=SendMessage
                 string "ofono/ofono/account0"
                 string "This is an outbound mms message."
                 array [
                 ]
                 array [
                    dict entry(
                       string "chatType"
                       variant             int32 2
                    )
                    dict entry(
                       string "participantIds"
                       variant             array [
                             string "613xxxyyyy"
                             string "613xxxzzzz"
                          ]
                    )
                    dict entry(
                       string "threadId"
                       variant             string "mms:a389e2a7ac4ef7055304eab4f57c27f9"
                    )
                 ]
              
              
              
              
              method call time=1581001468.154282 sender=:1.152 -> destination=com.canonical.TelephonyServiceHandler serial=980 path=/com/canonical/TelephonyServiceHandler; interface=com.canonical.TelephonyServiceHandler; member=SendMessage                                               
                 string "ofono/ofono/account0"                                    
                 string "Small out mms"                                                                                                               
                 array [                                                          
                 ]                                                                
                 array [                                                                                                                              
                    dict entry(                                                                                                                                                                                                                                                               
                       string "chatType"                                                                                                              
                       variant             int32 2                                
                    )                                                                                                                                                                                                                                                                         
                    dict entry(                                                                                                                       
                       string "participantIds"                                                                                                        
                       variant             array [                                                                                                                                                                                                                                            
                             string "613xxxyyyy"                                                                                                      
                             string "613xxxzzzz"                                  
                          ]                                                       
                    )                                                             
                    dict entry(                                                   
                       string "threadId"                                          
                       variant             string "mms:a389e2a7ac4ef7055304eab4f57c27f9"                                                              
                    )                                                                                                                                                                                                                                                                         
                 ]
              
              
              1 Reply Last reply Reply Quote 1
              • lduboeufL Online
                lduboeuf
                last edited by

                If one day you can do something about mms being lost when cellular data is off that would be awesome 🙂 https://github.com/ubports/telepathy-ofono/issues/9
                Good luck for your research

                K 1 Reply Last reply Reply Quote 0
                • K Offline
                  kjhg84j9 @lduboeuf
                  last edited by

                  @lduboeuf I will definitely take a look after my app is done.

                  I haven't looked into it yet but there's also a bug with the messages app. if you receive a group MMS and you don't already have the room created it will fail silently. There's info in the logs but basically the Messages app cant find the room and fails, it doesn't try to create it. everything else seems fine it just doesn't build the room. if you do this yourself you'll receive future messages to that group chat but you need to know who to add without any sort of notification.

                  I'm just getting into coding and the open source community so everything is all very new to me. I'm not sure of the process to look for bugs and open one if none exist but I'll get there 🙂

                  Thank you again!

                  1 Reply Last reply Reply Quote 0
                  • lduboeufL Online
                    lduboeuf
                    last edited by

                    https://github.com/ubports/ubuntu-touch is the entry point for bugs.
                    Some of them are directly set in related repository, but for a better audience (more a end user bug report) it is better to look at that repo first.

                    1 Reply Last reply Reply Quote 0
                    • K Offline
                      kjhg84j9
                      last edited by kjhg84j9

                      Alright, so, I got it.

                      I'm going put some notes here to help others should they need it. telepathy-ofono is a middle man for the ubuntu message app. I'm not using that here, my goal is to build something for the PinePhone no matter what OS they choose. With that, I'm talking directly to ofono.

                      Here is the dbus call you need to replicate. This is a group MMS message sent with text.

                      method call time=1580999265.497178 sender=:1.19 -> destination=org.ofono.mms serial=407 path=/org/ofono/mms/302220546062670; interface=org.ofono.mms.Service; member=SendMessage
                         array [
                            string "613xxxyyyy"
                            string "613xxxzzzz"
                         ]
                         array [
                            struct {
                               string "text_0.txt"
                               string "text/plain"
                               string "/home/phablet/.local/share/telepathy-ofono/attachments/attachmentLh3156"
                            }
                            struct {
                               string "smil.xml"
                               string "application/smil"
                               string "/home/phablet/.local/share/telepathy-ofono/attachments/attachmentnS3156"
                            }
                         ]
                      

                      the path (/home/phablet/.local/share/telepathy-ofono/attachments/) does not matter. The directory above is from telepathy-ofono so you can put it anywhere.

                      The plaintext file (attachmentLh3156) is just that, the text of the message you want to send.

                      MMS message testing
                      

                      The smil.xml (attachmentnS3156) will change depending on the amount of attachments (not recipents). If you're just sending text, like above your smil file will look like

                      <smil>   <head>     <layout>         <region id="Text" width="100%" height="100%" fit="scroll" />     </layout>   </head>   <body>       <par dur="3s">       <text src="text_0.txt" region="Text" />     </par>   </body> </smil>
                      

                      As an example, if you want to send a picture in this group chat you'd have to change the smil file to:

                      <smil>   <head>     <layout>         <region id="Image" width="100%" height="100%" fit="meet" />     </layout>   </head>   <body>       <par dur="5000ms">       <img src="pic.jpg" region="Image" />     </par>   </body> </smil>
                      

                      and of course you'd need to attach a picture. Pictures are limited in their size for me, I can only send pictures under 300KB. This is just the jpg file you're sending you dont have to do anything fancy.

                      The code I used is VERY lazily modified from the python script I posted in my question. There are errors and some of the code isn't use. my only goal was to test it, not make it look pretty 🙂 I'm going to spend my weekend translating this to C and cleaning it up.

                       phablet@ubuntu-phablet:~$ cat ./sendmms.py
                      #!/home/phablet/.cache/libertine-container/learning/rootfs/usr/bin/python
                      import sys
                      import dbus
                      import csv
                      if (len(sys.argv) < 4):
                              print "Usage: %s"\
                                      " <recipient>,..."\
                                      " <smil-file-path>"\
                                      " <<content-id>,<content-type>,<file-path>>,..."\
                                      % (sys.argv[0])
                              print "Sample(Related): %s"\
                                      " \"+33611111111,+33622222222\""\
                                      " \"smil.txt\""\
                                      " \"cid-1,text/plain,text.txt\""\
                                      " \"cid-2,image/jpeg,image.jpg\""\
                                      % (sys.argv[0])
                              print "Sample(Mixed): %s"\
                                      " \"+33611111111,+33622222222\""\
                                      " \"\""\
                                      " \"cid-1,text/plain,text.txt\""\
                                      " \"cid-2,image/jpeg,image.jpg\""\
                                      % (sys.argv[0])
                              sys.exit(1)
                      bus = dbus.SessionBus()
                      manager = dbus.Interface(bus.get_object('org.ofono.mms', '/org/ofono/mms'),
                                                              'org.ofono.mms.Manager')
                      
                      print bus
                      print manager
                      
                      #services = manager.GetServices()
                      services = "org.ofono.mms.Service"
                      #path = services[0][0]
                      path = "/org/ofono/mms/302220546062670"
                      service = dbus.Interface(bus.get_object('org.ofono.mms', path),
                                                                      'org.ofono.mms.Service')
                      recipients = dbus.Array([],signature=dbus.Signature('s'))
                      reader = csv.reader([sys.argv[1]])
                      for r in reader:
                              print "Recipient list: %s" % r
                              for i in r:
                                      recipients.append(dbus.String(i))
                      if sys.argv[2] == "":
                              print "Send MMS as Mixed"
                              smil = ""
                      else:
                              print "Send MMS as Related"
                              print "Smil path: %s" % (sys.argv[2])
                              file = open(sys.argv[2],"r")
                              smil = dbus.String(file.read())
                      attachments = dbus.Array([],signature=dbus.Signature('(sss)'))
                      for a in sys.argv[3:]:
                              print "Attachment: (%s)" % a
                              reader = csv.reader([a])
                              for r in reader:
                                      attachments.append(dbus.Struct((dbus.String(r[0]),
                                                                      dbus.String(r[1]),
                                                                      dbus.String(r[2])
                                                                      ), signature=None))
                      
                      print "hello"
                      path = service.SendMessage(recipients, attachments)
                      print "hello2"
                      print path
                      phablet@ubuntu-phablet:~$ 
                      

                      and finally the command I used to send it:

                      phablet@ubuntu-phablet:~$ ./sendmms.py "613xxxyyyy,613xxxzzz" "" "smil.xml,application/smil,/pic.smil" "pic.jpg,image/jpeg,/pic.jpg" 
                      <dbus._dbus.SessionBus (session) at 0xb66ba090>
                      <Interface <ProxyObject wrapping <dbus._dbus.SessionBus (session) at 0xb66ba090> :1.4 /org/ofono/mms at 0xb66b4410> implementing 'org.ofono.mms.Manager' at 0xb66bc6b0>
                      Recipient list: ['613xxxyyyy', '613xxxzzz']
                      Send MMS as Mixed
                      Attachment: (smil.xml,application/smil,/pic.smil)
                      Attachment: (pic.jpg,image/jpeg,/pic.jpg)
                      hello
                      ERROR:dbus.proxies:Introspect error on :1.4:/org/ofono/mms/302220546062670: dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
                      hello2
                      /org/ofono/mms/302220546062670/3c49e41edd7b06b4d51eaf3b28d1fd3b
                      phablet@ubuntu-phablet:~$ 
                      

                      EDIT:

                      here is the smil for a picture and some text in an MMS. the filenames inside the smil dont matter.

                      <smil>   <head>     <layout>         <region id="Image" width="100%" height="100%" fit="meet" /><region id="Text" width="100%" height="100%" fit="scroll" />     </layout>   </head>   <body>       <par dur="5000ms">       <img src="5129919622724107199.jpg" region="Image" />     </par><par dur="3s">       <text src="text_0.txt" region="Text" />     </par>   </body> </smil>
                      

                      Edit2: very rough C code from someone whos just learning.... Back to building my app! thanks everyone!

                      #include <stdio.h>
                      #include <stdlib.h>
                      #include <gio/gio.h>
                      #include <string.h>
                      
                      static gchar *object_name       = "org.ofono.mms";
                      static gchar *object_path       = "/org/ofono/mms/302220546062670";
                      static gchar *object_interface  = "org.ofono.mms.Service";
                      
                      
                      int main(  ) {
                      
                      
                        GOptionContext *opt_context;
                        opt_context = g_option_context_new ("Web-Messages-send_mms");
                      
                        GError *error;
                        GDBusProxy *proxy;
                      
                        proxy = NULL;
                        error = NULL;
                      
                      
                        proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
                                                               G_DBUS_PROXY_FLAGS_NONE,
                                                               NULL, /* GDBusInterfaceInfo */
                                                               object_name,
                                                               object_path,
                                                               object_interface,
                                                               NULL, /* GCancellable */
                                                               &error);
                      
                      
                      
                      
                        GVariant *variant;
                        GVariantBuilder *builder;
                        builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
                        g_variant_builder_add(builder, "s", "613xxxyyyy");
                        g_variant_builder_add(builder, "s", "613xxxzzzz");
                        variant = g_variant_new("as", builder);
                        g_variant_builder_unref(builder);
                      
                      
                      
                        GVariant *value1;
                        GVariant *value2;
                      
                        value1 = g_variant_new ("(sss)", "smil.xml", "application/smil", "/text.smil");
                        value2 = g_variant_new ("(sss)", "text_0.txt", "text/plain", "/text_0.txt");
                      
                      
                        GVariant *variant2;
                        GVariantBuilder *builder2;
                        builder2 = g_variant_builder_new(G_VARIANT_TYPE("a*"));
                        g_variant_builder_add(builder2, "*", value1);
                        g_variant_builder_add(builder2, "*", value2);
                        variant2 = g_variant_new("a*", builder2);
                        g_variant_builder_unref(builder2);
                      
                        GVariant *package;
                      
                        package = g_variant_new ("(**)", variant, variant2);
                      
                      
                        gchar *parameters_str;
                        parameters_str = g_variant_print (package, TRUE);
                        g_print ("parameters_str: \"%s\" \n", parameters_str);
                        g_free (parameters_str);
                      
                      
                      
                      
                      if (proxy == NULL) {
                          g_printerr ("Error creating proxy: %s\n", error->message);
                          g_error_free (error);
                        }
                        else {
                          g_dbus_proxy_call_sync (proxy,
                                                  "SendMessage",
                                                  package,
                                                  G_DBUS_CALL_FLAGS_NONE,
                                                  -1,
                                                  NULL,
                                                  &error);
                        }
                      
                      
                      
                      
                      
                      
                          if (proxy != NULL)
                            g_object_unref (proxy);
                          g_option_context_free (opt_context);
                      
                      
                      
                      
                      
                      
                      
                      
                      
                      
                      
                      
                          return 0;
                      }
                      
                      

                      Edit again:

                      For people here from google, I decided to go with Python. My script to bridge to matrix is here. There is a send SMS and a send MMS function that should be helpful.

                      1 Reply Last reply Reply Quote 4
                      • lduboeufL Online
                        lduboeuf
                        last edited by lduboeuf

                        wow impressive, thanks for sharing
                        That 's right, there is lots of issues regarding MMS and UT, but seems that most developers don't use them a lot, still need some volonteers :).

                        1 Reply Last reply Reply Quote 1
                        • G Offline
                          Giiba
                          last edited by

                          It may be you have discovered what is wrong with mms on UT. There are various issues reported all hard to replicate, but in general group mms messages never appear.

                          That a room is not created upon reciet might just be the answer...

                          K 1 Reply Last reply Reply Quote 1
                          • K Offline
                            kjhg84j9 @Giiba
                            last edited by kjhg84j9

                            @Giiba I must be going mad but I'm sure there was something in the dbus log under phablets home dir. Tail the dbus log and you can watch every MMS arrive and if its a new group it says something like no room found. I found this building my app so I just made a room with the same numbers and I started getting mmses.

                            I'm not at home so I can't support any of this.

                            as a side note, my app receives every MMS I toss at it so I dont think there are any big problems with ofono.

                            Edit: on mobile

                            1 Reply Last reply Reply Quote 0
                            • G Offline
                              Giiba
                              last edited by Giiba

                              Do group mms messages come through in your app (ie. multiple recipients)?

                              1 Reply Last reply Reply Quote 0
                              • G Offline
                                Giiba
                                last edited by Giiba

                                You are correct sir. I did a test group mms, and sure enough nothing came through to the app but in the dbus log I see the error for each reply (I know the replies were valid as I added my wife to the test and her android phone recieved all of them).

                                Error creating channel for incoming message  "org.freedesktop.Telepathy.Error.InvalidHandle" "MMS Group not found in cache."
                                

                                How does your app handle this?

                                EDIT:
                                And I see an accompanying error in the messaging app:

                                file:///usr/share/messaging-app//MultiRecipientInput.qml:289:21: QML Binding: Property 'index' does not exist on TextField.
                                
                                lduboeufL K 2 Replies Last reply Reply Quote 0
                                • lduboeufL Online
                                  lduboeuf @Giiba
                                  last edited by

                                  @Giiba I think there is an old PR for that https://github.com/ubports/telepathy-ofono/pull/6

                                  G 1 Reply Last reply Reply Quote 0
                                  • G Offline
                                    Giiba @lduboeuf
                                    last edited by

                                    @lduboeuf I think @kjhg84j9 success points to the problem being the messaging app, not ofono. Not that I understand much of this system.

                                    1 Reply Last reply Reply Quote 0
                                    • K Offline
                                      kjhg84j9 @Giiba
                                      last edited by

                                      @Giiba said in How to send MMS over DUBS to ofono?:

                                      How does your app handle this?

                                      I'm completely separate from the ubuntu messages app and all my stuff is cli only right now. messages I send dont even show up in the messages app.

                                      You can run dbus-monitor on the phone and watch everything sent over the dbus. my app watches this for messages from org.ofono.mms and then unpacks them.

                                      I have a long road ahead of me before I understand enough to help out with any of this.Also, I want to get the first version of my app up and out of the way before I start doing other things.

                                      G 1 Reply Last reply Reply Quote 1
                                      • G Offline
                                        Giiba @kjhg84j9
                                        last edited by

                                        @kjhg84j9
                                        Don't worry, I am not expecting a quick fix. But this is the first time in a year that I have found log entries regarding mms messaging.

                                        I am now able to see all of the messages I don't get in the error log. That's progress.

                                        1 Reply Last reply Reply Quote 1
                                        • First post
                                          Last post