Android<->Desktop SMS interface needs to account for deleted messages
Open, NormalPublic

Description

This is not just a cosmetic issue. For whatever reason, if you delete messages on the phone, then send or receive new messages, the desktop interface will not update until you have sent or received a number of messages in a conversation equal to the number deleted in that conversation

sredman created this task.Mar 20 2019, 8:30 PM
sredman triaged this task as Normal priority.
cubix added a subscriber: cubix.Sep 13 2020, 7:18 AM

Hi, I'm new and I want to work on this.

aniketkumar removed sredman as the assignee of this task.EditedSep 13 2020, 7:30 AM
aniketkumar added a subscriber: aniketkumar.

Hi, I'm new and I want to work on this.

Go for it!

aniketkumar assigned this task to cubix.Sep 13 2020, 7:34 AM
cubix added a comment.Sep 13 2020, 9:45 AM

Since, I'm new, can you help me out on how to go about this issue. It would be of immense help if you can mentor me a bit.

Mr_Pyro removed a subscriber: Mr_Pyro.Sep 13 2020, 9:52 AM
cubix added a comment.Sep 13 2020, 2:03 PM

Does the deleting here refer to deleting for everyone or just deleting from the phone?

Since, I'm new, can you help me out on how to go about this issue. It would be of immense help if you can mentor me a bit.

sure!

Does the deleting here refer to deleting for everyone or just deleting from the phone?

Deleting from the phone as well as from the SMS App's cache on the desktop.

Does the deleting here refer to deleting for everyone or just deleting from the phone?

Deleting from the phone as well as from the SMS App's cache on the desktop.

Specifically, the bug is that if you delete a message from the phone, it is *not* deleted from the desktop's cache, and then the desktop behaves strangely. I suspect this is because Android re-uses the IDs of the deleted messages.

Since, I'm new, can you help me out on how to go about this issue. It would be of immense help if you can mentor me a bit.

You're welcome to ask anybody for help (I recommend you join us on Telegram), but I'll leave you in Aniket's capable hands for now. He probably knows the SMS stuff better than I do at this point anyway :)

My quick suggestion would be to study how we watch for *new* messages in the Android app, because I believe there is a similar way to watch for deleted messages.

cubix added a comment.Sep 14 2020, 5:15 AM

Okay I will look into that. How do I find it in the codebase? I will also join on telegram shortly.

cubix added a comment.Sep 14 2020, 5:19 AM

Also is this an issue of the desktop app or the android kde connect app?

Also is this an issue of the desktop app or the android kde connect app?

Both the C++ and the Android implementations would need to have code added to handle deleted messages

Okay I will look into that. How do I find it in the codebase? I will also join on telegram shortly.

You will want to start by looking at the SMS plugin both on the C++ side and the Android side. The "onPacketReceived" and "onCreate" methods in both are probably the most interesting places to start tracking through how the plugins work

cubix added a comment.EditedSep 14 2020, 6:42 AM

Ok, I will go through that. Also on another note, I am bit confused about dbus and how/what its being used for. Can you give me some pointers?

cubix added a comment.Sep 14 2020, 7:01 AM

I have set up the desktop source for kde connect. Can you tell me how to set up the android one? Can I do it in my phone or should i do it in an emulator.

I have set up the desktop source for kde connect. Can you tell me how to set up the android one? Can I do it in my phone or should i do it in an emulator.

You can do it both ways! Setting up an emulator will require doing lots of configurations on your machine whereas running in android will be easier to setup. If you want to setup emulator for KDE Connect follow the guide given at this link KDEConnect Android Emulator

cubix added a comment.Sep 15 2020, 4:00 AM
This comment was removed by cubix.
cubix added a comment.EditedSep 15 2020, 5:36 AM

I went throught the smsplugin in the c++ and the java side.

private class MessageContentObserver extends ContentObserver {

        /**
         * Create a ContentObserver to watch the Messages database. onChange is called for
         * every subscribed change
         *
         * @param handler Handler object used to make the callback
         */
        MessageContentObserver(Handler handler) {
            super(handler);
        }

        /**
         * The onChange method is called whenever the subscribed-to database changes
         *
         * In this case, this onChange expects to be called whenever *anything* in the Messages
         * database changes and simply reports those updated messages to anyone who might be listening
         */
        @Override
        public void onChange(boolean selfChange) {
            // If the KDE Connect is set as default Sms app
            // prevent from reading the latest message in the database before the sentReceivers mark it as sent
            if (Utils.isDefaultSmsApp(context)) {
                return;
            }

            sendLatestMessage();
        }

    }

This is the code on the java side which sends the newest message. Should we create a change in this method so that it takes into consideration changes when messages are deleted as well? @aniketkumar

Can someone help me out on this?

aniketkumar added a comment.EditedSep 15 2020, 5:06 PM

With the help of this observer class, you have to figure out a way to get the threadID and uid of the deleted message and then just send this information to the desktop SMS App where the SMS App will look into its cache for the deleted message and will remove it from there and after that just update the UI of the SMS App.

cubix added a comment.Sep 16 2020, 6:29 AM

Okay. Does Android apis have this kind of functionality? Like some function in android.telephony.smsmanager?

Okay. Does Android apis have this kind of functionality? Like some function in android.telephony.smsmanager?

I'm not sure if android API provides us with such functionality :(

cubix added a comment.Sep 16 2020, 1:33 PM

Alright. Are we supposed to refresh it then everytime? Or if the count of messages decreases - a workaround maybe?

Alright. Are we supposed to refresh it then everytime? Or if the count of messages decreases - a workaround maybe?

Have you tried looking in the MessageContentObserver class above? Did that not get called when deleting a message?

We do not have all of the answers. Sometimes you can find an answer of StackOverflow for how to do things with SMS on Android but for the most part we're the only independent group going it. And there is essentially no documentation. A large amount of experimentation is going to be required!

cubix added a comment.Sep 17 2020, 4:43 PM

Okay, I'll debug and check if it gets called!