making a "quasi-case-sensitive" SMS trigger for my flow

Post your questions and help other users.

Moderator: Martin

Post Reply
walker
Posts: 4
Joined: 19 Dec 2013 19:21

making a "quasi-case-sensitive" SMS trigger for my flow

Post by walker » 19 Dec 2013 20:07

Hello Martin and Automagic community :)

What I need is a flow that would be triggered by word in SMS, but I want the match to be case-sensitive (cause non case-sensitive passwords are a bad idea)

It seems to me that, assuming Android regex can check a case-sensitive match, it should be possible to check whether SMS text contains a case-sensitive pattern via Conditions facility.

So let's say the password is
AndreW_xX99

The SMS text is:
Hey, AndreW_xX99, check this out!

The trigger is obviously SMS Received

So, I need a condition to check whether sms_text contains the exact, case-specific pattern
AndreW_xX99

So that if SMS contains (for some reason) AndreW_xx99 or AndreW_Xx99, the flow would not proceed, and will only execute if AndreW_xX99 is encountered.

Problem:
I suck at regex :(

Would any resident magician help me out ?

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: making a "quasi-case-sensitive" SMS trigger for my flow

Post by Martin » 19 Dec 2013 20:52

Hi,

The string function contains should also work in this case so you don't need a regex.
A condition Expression with one of the following scripts should work:

Code: Select all

contains(sms_text, "AndreW_xX99")
The function tests if the string in variable sms_text contains the second paramter and returns either true or false.

You could also use one of the following scripts when the password is at the begin or end of the SMS:

Code: Select all

startsWith(sms_text, "AndreW_xX99")
respectively

Code: Select all

endsWith(sms_text, "AndreW_xX99")
alternatively using the regex way:

Code: Select all

matches(sms_text, ".*AndreW_xX99.*")
Regards,
Martin

walker
Posts: 4
Joined: 19 Dec 2013 19:21

Re: making a "quasi-case-sensitive" SMS trigger for my flow

Post by walker » 20 Dec 2013 08:19

Thanks Martin!
It works!

Well... it works most of the time, but that's a separate issue because it is apparently caused by phone being dual-sim

SMS sent to SIM1 triggers the flow 10 times out of 10 attempts, but SMS sent to SIM2 triggers it about 8 times out of 10 attempts. Logs don't elucidate anything with regards to failure, and preventing other apps from getting the SMS doesn't fix the SIM2 issue (the obvious fix is not to send SMS to only use SIM1 for triggering the flow, but hey, I thought I'd report anyway)

The phone is Gionee GN708W (aka fly iq-446 aka xoloQ800).

In case you feel like taking a look at what the hell is happening inside this dual-sim phone's code, some clever Russians have managed to get complete kernel source code ( http://yadi.sk/d/-zrdnTk_4Iy7c ).

P.S.:

I think I will make a secondary flow that triggers by the password being present in notification (in same manner as above), waits for 5 seconds and runs another flow that checks whether the "primary" SMS-based flow has run or is running, and, in case neither of that is true, performs the intended action (resets screen lock).
Having the main SMS-flow leave behind a global variable or, perhaps better yet, a file, should not be hard and would allow to reliably check whether it has run.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: making a "quasi-case-sensitive" SMS trigger for my flow

Post by Martin » 20 Dec 2013 11:55

Dual SIM devices can behave strange in some cases since the base Android APIs are not really prepared for such an extension so each manufacturer tries to add the second SIM in the best possible way without breaking too many functions.

In case of an incoming SMS the OS should notify the apps with a broadcast intent about the new SMS. It would be interesting to know if your device does not send the event at all when Automagic misses the SMS. Could you please turn on Debug log in the preferences of Automagic and check whether the log contains a line like the following when an SMS is missed?
20.12.2013 12:00:00.000 Received intent Intent { act=android.provider.Telephony.SMS_RECEIVED flg=0x8000010 (has extras) } extras: format=3gpp, pdus=[Ljava.lang.Object;@43aee720
Are you using the stock SMS app of the device or a third party SMS app? What Android version are you using?

walker
Posts: 4
Joined: 19 Dec 2013 19:21

Re: making a "quasi-case-sensitive" SMS trigger for my flow

Post by walker » 20 Dec 2013 22:23

Hi Martin!

Seems to be broadcasting intent allright.

I use stock SMS app, but after translating some of the Russian forums with google translate (not the best way to learn new stuff) I've learned that this model often comes with oddball apps and strains of SMSReg (my phone was bought in India, but hey, you never know), so there might be something there messing up the SMS app.

There is a tool for killing known "questionable payload" on Chinese MTK-based phones.

I guess I'll try a new firmware (maybe a few customs as well) and that cleaning tool.

Will test again then.

Post Reply