开发者

How to reset android /data/data/com.xxx.xxx permissions linux?

I made some changes and my apps are crashing. Someho开发者_运维知识库w the permissions and usernames of my apps do not line up with the /data/data folder. Each app's username does not line up with the apps' username on the filesystem.I need to reset the filesystem or the username somehow.

I need either the name of the application username/group assignment file, or a method of resetting the permissions for all applications.


I haven't used Android, but I think it is based off of Linux. so it should have a few common standard commands. so type this:

stat -c '%a %n' /data

in a terminal. [You do have a terminal, right?] Anyway, that will tell you the permissions of the /data folder. [If this folder does not have the right permissions, substitute /data for a folder with correct permissions]. A sample output would be this:

755 /data

that means /data has 755 permissions. assuming 755 is your output, type this to recursively change permissions:

chmod -R 755 /data/data/com.xxx.xxx

Or if you want to change everything in /data/data then you can do that instead of /data/data/com.xxx.xxx.

Once the permissions are fixed, next is the ownership. if you know a dir that you know has correct ownership, type this:

ls -ld /root/root/com.correct_ownership_app

Here is the output of that, on my /var folder:

drwxr-xr-x 14 root root 4096 2010-12-16 18:51 /var/

the "root root" means root is the owner [and I think "root" is the group]. First, check the ownership with one of your apps. If it's the same, then the permissions must have been causing the app crashing. if that's the case then you should be done.

Otherwise, to change owner recursively:

chown -R USER /data/data

make sure to change USER to whichever user it should be!


Backup your stuff before doing the below as there's a good chance you'll ruin your phone.

Not a complete answer, but in a nutshell, some applications tend to have their user information stored as space delimited values in /data/system/packages.list while other applications tend to have user information stored as XML format in /data/system/packages.xml. Further to this, ownership as seen in a terminal look a bit different to how they look in these files. For example, on my phone, Whatsapp is Unix user u0_a70 while its XML entry identifies it as userId="10070".

It is thus a little difficult to 'just fix' user permissions as you need 2 different scripts looking at 2 completely different datasets, and Android Linux doesn't exactly ship with XML parsers. The required user ID conversion doesn't help either, because it's not always applicable.

If you're up for the challenge, a starting point using BusyBox bins is as follows:

# Generate a permissions fixer from /data/system/packages.list:
cat /data/system/packages.list | awk '{print "chown u0_a" $2-10000 ":u0_a" $2-10000 " /data/data/"$1" -R"}' > /data/media/fix_perms.sh
chmod +x /data/media/fix_perms.sh

This will generate a list of lines that looks like:

chown u0_a17:u0_a17 /data/data/com.google.android.gsf -R
chown u0_a6:u0_a6 /data/data/com.android.keyguard -R
chown u0_a52:u0_a52 /data/data/com.google.android.calendar -R
chown u0_a48:u0_a48 /data/data/com.android.chrome -R
chown u0_a55:u0_a55 /data/data/jackpal.androidterm -R

which is promising. However, this won't work for users like 'bluetooth', 'radio', and 'system', and lines with those users will instead generate garbage like:

chown -8998:-8998 /data/data/com.android.bluetooth -R

so you'll need to sanity check everything before running the script. A naive way of fixing this could be by piping the above cat..awk into | egrep -v '[0-9][0-9][0-9][0-9]:-[0-9][0-9][0-9][0-9]' but this is a hack solution which won't work in all cases. If this is acceptable to you, then you may combine the above into a single line redirecting into /data/media/fix_perms.sh.

Now, this won't fix anything only defined in /data/system/packages.xml, and any regular script is almost guaranteed to fail across devices, so I won't cover that. If you do want a possible solution, leave a comment and I'll write a mock script for the XML file as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜