1
Completed

Add support to trigger Samsung Modes & Routines

Samsung's Modes & Routines (M&R) app exposes a few different hidden content providers that can be used by Tasker to run Routines and turn Modes on/off. The advantage of M&R is that it's a system app, so it can control many things that Tasker cannot do alone. For instance, users can toggle Wi-Fi or disconnect a Bluetooth device without needing Shizuku/ADB Wi-Fi. Additionally, there are many other Samsung-specific actions (not going to list them all here). If Tasker could tap into these actions, it would really open up the door for Samsung users to automate things more easily and automate things that weren't possible before.
 
I tested this method out in a simple Android project that displays a menu of all the manual routines, and when the user selects one, it runs that Routine.
 
Documentation
 
AndroidManifest.xml
<uses-permission android:name="com.samsung.android.app.routines.permission.READ_ROUTINE_INFO" />
 
That permission allows you to access a few content providers which allow you to find and/or run the user's modes and routines.
 
 
To GET Routines:
context.contentResolver.query(uri, null, null, null, null)
 
Valid URIs:
  • content://com.samsung.android.app.routines.externalprovider/routine_list?routine_type=normal&condition_type=manual
    • condition_type can also be "auto," but this is not useful for Tasker because "auto" routines cannot be run manually
    • Also accepts query param "only enabled=0" which will return disabled routines as well
  • content://com.samsung.android.app.routines.routineinfoprovider/manual_enabled_routines
Columns are: {"uuid", "name", "icon_resource_id", "icon_color", "is_running", "is_enabled", "is_oneoff"}
 
To GET Modes AND Routines:
context.contentResolver.query(uri, null, null, null, null)
 
Valid URIs:
  • content://com.samsung.android.app.routines.domainmodel.routinetestprovider/routine_uuid_list
    • Also returns automatic routines
Columns are {_uuid, name}
 
To GET Modes:
I couldn't find a content provider with a URI that is externally accessible which returns just the modes. However, you could "get all," "get manual routines" (condition_type=manual), and "get auto routines" (condition_type=auto), then remove the overlapping routines to get just the modes. 
 
I've also found full UUIDs for the modes in logcat. The standard modes seem to be numbered 100, 101, 102, etc. Custom modes have random UUIDs. You could have the user navigate to the modes screen and read from logcat. You cannot do this for the routines, as it doesn't show the full UUID, only the first 6 digits. The content provider is a safer way to get the routines anyway.
 
Finally, this may not even be necessary because you can use a Routine to turn a Mode on/off. It's slightly annoying because you need a Routine for each Mode you want to toggle with Tasker, but not impossible.
 
To RUN/STOP a Mode or Routine:
use context.contentResolver.call(Uri uri, String flag, null, Bundle bundle)
Valid URIs:
  • content://com.samsung.android.app.routines.externalprovider
    • Flag should be one of {"start_manual_routine", "toggle_manual_routine", "end_manual_routine"}
    • Bundle should have one long of key "uuid" and value should be UUID of routine to be started/toggled/stopped
  • content://com.samsung.android.app.routines.domainmodel.routinetestprovider
    • Flag should be one of {"run_routine", "stop_routine"}
    • Bundle should have one long of key "_uuid" and value should be UUID of routine to be started/toggled/stopped
My guess is the "externalprovider" URIs are preferred/intentional, as they are labeled "external". However, "routinetestprovider" (seems like a debugging/test tool of sorts) is the only way to get Modes indirectly from a content provider. Weirdly, "routineinfoprovider" is externally accessible, but "routinemodeprovider" is not.
 
Viewing M&R Source Code
 
I found the source code by pulling the APK:
  1. adb shell pm path com.samsung.android.app.routines
  2. adb pull <path from step 1>

Then I decompiled the APK with JADK. I looked in the manifest for services, receivers, and providers. Most of them require permissions that are locked to signature/system access only, the ones I found that are externally accessible were listed above.

4 replies

Is there any official documentation on this? If not, I'd rather someone make a Java Code action that does this instead of me officially adding it to Tasker, cause it could break at any time.

In that case I would only have to add the permission to the app, right?

Thank you!

A

I wasn't able to find official documentation. Adding the permission would be huge.

Ok, added.

Can you please see if it works and let me know :) Thanks!

https://www.dropbox.com/scl/fi/gyxfw8kimxyb0b1d1yaqu/Tasker.35.apk?rlkey=yacgs4ykb5c3rxb1wgn46a6oa&dl=0

A

Just tested, working perfectly! I'll share a project with others

Cool! :) Let me know!

A

Was the the permission in the latest 6.6.7 beta?

Hhmm, not sure actually  😅Maybe not.

A

I thought it was added too and made a post but someone said the project didn't work with the 6.6.7 beta. When I gave them the Dropbox APK you sent me, it worked for them. They said the permission wasn't listed in Apps > Tasker > Permissions > All Permissions

Yeah, I probably just added it after putting that version up on Google Play...  😅Glad it worked with the permission though!

A

Joao added the required permission for Tasker and gave me an APK to test it out. I was able to make a reusable project. There are 2 tasks which show a List Dialog with all of your Modes or Routines. Selecting one copies the UUID to your clipboard. In any of your tasks, you can then use Perform Task -> Start (or Stop) Samsung Mode/Routine and paste the UUID in Parameter 1. It should start or stop the Mode/Routine you selected!

https://taskernet.com/shares/?user=AS35m8kor%2Fx7fNzIolKvp4xH1ZrW%2BwwJ9s0tiYMLKk%2Bp9qaAhNRqv1LxTWrqJHFZhuxjapw%3D&id=Project%3ARoutines

A

No worries, I think the dropbox link in your reddit post had it. I assume it will make it in the next update? Thanks again for all your hard work and diligence 

Yeah, it'll be in the next update :) Thanks again! People seemed to like this!