0

An app, due to an unfixed glitch, keeps overwriting an important file

How to lock that file so that it cannot be overwritten ?

Have root. Don't have xposed

2 Answers2

1

You can remove write permission on your file. You would need toybox (inbuilt in Android since v5.0) or busybox. Assuming you have toybox already, use these commands in a terminal emulator:

su
cd /data/media/0/DIR              # replace DIR with wherever your file is. E.g. if the file is in /sdcard/Download, then DIR should be Download, so that the whole command looks like /data/media/0/Download
toybox chown 444 FILE_NAME        # this would set read-only permission for every user in the system for that file. Change 444 to 666 to revert changes.
chattr +i FILE_NAME               # alternative to above command. This prevents writing as well as deletion of the file. Change +i to -i to revert changes.

If you're wondering why the commands are performed on file under /data/media/0, read the answer here from Irfan Latif.

Firelord
  • 25,084
  • 20
  • 124
  • 286
  • 1
    Thanks. Your answer works fine. I used Busybox (playstore). In my Android 4.1 I didn't have to navigate to /data/media/0 before my dir –  Jun 03 '19 at 21:00
0

Solution 1: Move the file to another folder. Thus, the app won't have access to it and can no longer change it.

Solution 2: If the file can't be moved (maybe because you don't want to move it, or that the app needs to access it from that folder), change its permissions to read-only. Any good file manager should be able to do it. click on the file, select properties then remove the write permissions.

Solution 3: Use a terminal and make the file immutable as stated in the comment using the command:

su chattr +i /path/to/your/file

Bear in mind that the second and third solutions will work only if the filesystem accepts the change of permissions or flags.

Reddy Lutonadio
  • 7,164
  • 2
  • 17
  • 49
  • Unfortunately, setting a few R-W flags with a file explorer was not enough (ES File Explorer in my case). The app (which uses the file, and needs it where it is, simply replaces it). –  Jun 03 '19 at 21:03
  • I didn't test your commands (They require Linux, everyone!). Having it, it probably works. –  Jun 03 '19 at 21:05