1

How can one open a file located in a subfolder of the rootfolder, using tasker, in LineageOS 14.1?

My attempts so far have been to:

  1. Create a new task in tasker.
  2. Check if tasker has root permission with variable named "root available": %ROOT. This returns yes. Therefore, I assume Tasker has root permission.
  3. create the action: "open file"
  4. This only allows the accessing the /storage/ of either the internal or external drive.
  5. Therefore, I manually entered the path to the file located in the rootfolder I am trying to access as: /data/misc/wifi/wpa_supplicant.conf and ran the task, but it returns the error: file not found.

    IMG: IMG:

  6. So I tried /data/misc/wifi/wpa_supplicant.conf and ran the task, but it returns the same error.

  7. I tried to open the file with fdroid's app: editor, without opening a file explorer to open the file. But I am unable to pass the file location as an argument to the app editor when I create a task to do it.
  • 1
    I do not not anything about tasker but I do know about shell commands. If that is what tasker is using the problem is you just need to cd into the directory example: cd /data/misc/wifi/ to add another command && or ;should do the trick example : cd /data/misc/wifi/ && your command or cd /data/misc/wifi/; your command depending on how you the commmand to follow through. – Bo Lawson Dec 9 '18 at 22:15
  • 2
    @BoLawson if it's a shell command, one simply has to prefix it with ! to tell Tasker to perfrom it with root powers AFAIR (could be that meanwhile there's a check-box for that). However, I don't know if there's an equivalent for opening a file. – Izzy Dec 9 '18 at 23:04
  • 2
    Good point @Izzy, also to open the file the nano command should do the trick looking like !nano /data/misc/wifi/wpa_supplicant.conf if it comes back with the unknown file/directory error then cd into the directory. On first comment put ! in front of the cd. – Bo Lawson Dec 9 '18 at 23:33
  • 1
    @BoLawson I've missed the editor part. Indeed I'm not sure if a non-root editor app (OP wanted to use a specific one) could work. nano or vi should do fine. – Izzy Dec 10 '18 at 6:22
  • 1
    @BoLawson thank you for the suggestion, at first instant I indeed tried checking if I could execute the command from Termux on android and used cd /data/misc/wifi/ to browse to the directory, verified the file existance using ls. But then got stuck on how to open the file from Termux. wiki.termux.com/wiki/Sharing_Data suggested termux-open wpa_supplicant.conf but I was unable to use or install termux-open from Termux. I did not try nano yet, as I will not be able to access Termux/terminal in ordinary use. I will look into that, thank you! – a.t. Dec 10 '18 at 9:12
3

The inbuilt Open File action doesn't seem to work for non-/storage file paths because it is hardcoded (I presumed from its error logs) to only load a file located under /storage/emulated/0. Even if you mention the absolute location using file://, it would still append /storage/emulated/0 to the file path and throw an error.

Because Open File action simply sends an intent, we can do that manually ourselves. The Send Intent action is pretty good for this, except it also fails with non-/sdcard file paths. Tasker implements FileProvider (a way to securely share files with other apps). The action could work but Tasker's manifest file provisions for not exporting the file provider, which means other apps cannot make use of it. Since Tasker converts even absolute file path (with file://) into a file provider URI, there is no way out for us to load a non-/sdcard file using that action too, except to ask Tasker's developer to fix this, or the user themselves tweaks the manifest file.

The solution, however, is available using command-line. Use the action:

Code → Run Shell:

  • Command:

    am start -a android.intent.action.VIEW -d "file://FILE_PATH" -t "text/plain" -f 0x13000000 -n android/com.android.internal.app.ResolverActivity
    

    file:// is intended as is. In your case, the file path should be file:///data/misc/wifi/wpa_supplicant.conf.

    text/plain can be replaced with text/* too if you don't know your file's mime-type.

    (You can know about am here.) I don't know what that flag (0x13000000) does in particular.

  • tick Use Root

Running the task would now give you the bottom sheet with all the apps which can load a file with mime-type text/plain. However, when testing this, only QuickEdit app was able to load that file successfully, so I recommend using it unless you get this working with an another editor.

  • Nice, I installed tasker to test it out and it works +1 good stuff – Bo Lawson Dec 10 '18 at 9:16
  • Comments are not for extended discussion; this conversation has been moved to chat. – Firelord Dec 10 '18 at 10:12
  • 1
    Thank you very much for the elaborate explanation. I can confirm the described steps with command am start -a android.intent.action.VIEW -d "file://file:///data/misc/wifi/wpa_supplicant.conf" -t "text/plain" -f 0x13000000 -n android/com.android.internal.app.ResolverActivity work in Tasker V5.2.bf1. Indeed the only text editor I could get it to work, currently is QuickEdit as you mentioned. – a.t. Dec 10 '18 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.