Android: Fix package uid mismatches

A while ago, I set up Apps2SD on my ADP, and while I am not sure what, I must have done something wrong, because afterwards, Android refused to boot properly, claiming that the file system permissions of pretty much all installed packages didn’t match up:

Package x.y.z has mismatched uid: 10089 on disk, 10079 in settings

Here’s the Python script I used to apply the file system permissions that Android expected. It iterates over the packages defined in your devices /data/system/packages.xml. Use at your own risk.

"""Parse Android's /data/system/packages.xml file and spits out
shell code to fix UIDs.

This helps you fix "Package x.y.z has mismatched uid: 10089 on disk, 10079
in settings" errors.
"""

from xml.dom import minidom

xmldoc = minidom.parse('packages.xml')

packages = xmldoc.getElementsByTagName('package')
ignored = []
for package in packages:
    try:
        userId = package.attributes['userId'].value
        is_shared = False
    except KeyError:
        userId = package.attributes['sharedUserId'].value
        is_shared = True

    # do not touch permissions of shared apks (they userid always seems to be 1000)
    if not is_shared:
        print "busybox chown %s:%s %s" % (userId, userId, package.attributes['codePath'].value) 

    for subdir in ('', 'databases', 'shared_prefs'):  # note we don't touch lib/
        print "busybox chown %s %s:%s /data/data/%s/%s" % (
            '-R' if subdir else '', userId, userId, package.attributes['name'].value, subdir)

8 thoughts on “Android: Fix package uid mismatches

  1. I have used cyanogen’s shell code and it works perfect. He acknowledged your work in that link above.

    Like

  2. If you have some spare time 😉 you could maybe add another hack. If something goes wrong with the sdcard (e.g. at reboot) you may experience loosing apps (like me). market says app is installed, but starting says app is gone. So a tool for removing dead apps would be great. So one can re-install them again…
    Thanks

    Like

Leave a comment