Fix broken Android permissions by re-installing apps
I run the CyanogenMod derivative of Android on my G1, and somehow managed to get it into a state where it had withdrawn the security permissions from my installed applications. I think this happened when I attempted to upgrade the 1GB microSD to a 4GB one, but the phone failed to boot.
I first noticed the problem when trying to refresh in NewsRob would hang the application, and adb logcat showed:
W/dalvikvm( 540): threadid=3: thread exiting with uncaught exception (group=0x4001e170)
E/NewsRob ( 540): Caught the following exception:
E/NewsRob ( 540): java.lang.SecurityException: Neither user 10039 nor current process has android.permission.WAKE_LOCK.
NewsRob clearly had had this permission before, to prevent the phone from sleeping during a sync. The Manage Applications screen still showed that it did (“System tools: prevent phone from sleeping”). Watching adb logcat while the phone was booting showed what was going on, and that many other applications had the same problem:
W/PackageManager( 138): Not granting permission android.permission.INTERNET to package com.newsrob because it was previously installed without
W/PackageManager( 138): Not granting permission android.permission.WAKE_LOCK to package com.newsrob because it was previously installed without
W/PackageManager( 138): Not granting permission android.permission.ACCESS_NETWORK_STATE to package com.newsrob because it was previously installed without
W/PackageManager( 138): Not granting permission android.permission.VIBRATE to package com.newsrob because it was previously installed without
W/PackageManager( 138): Not granting permission android.permission.WRITE_EXTERNAL_STORAGE to package com.newsrob because it was previously installed without
/data/system/packages.xml, which seems to record which applications are installed and which permissions they have, showed:
<package name="com.newsrob" codePath="/data/app/com.newsrob.apk" system="false" ts="1264200476000" version="353" userId="10039" installer="com.google.android.feedback">
<sigs count="1">
<cert index="25" key="..." />
</sigs>
<perms />
</package>
i.e. the permissions block was empty. It should have looked more like this:
<perms>
<item name="android.permission.VIBRATE" />
<item name="android.permission.WRITE_EXTERNAL_STORAGE" />
<item name="android.permission.ACCESS_NETWORK_STATE" />
<item name="android.permission.WAKE_LOCK" />
<item name="android.permission.INTERNET" />
</perms>
I tried manually hacking it, and also moving and replacing the .apk file on the phone, but packages.xml always returned to this state. Maybe it’s not the master copy of that data.
What finally fixed it for me was to re-install the applications using the package manager, by running:
cd /data/app
for app in *.apk; do pm install -r $app; done
I hadn’t known about the pm command until then, and discovered it by accident when invoking an adb command told me about it. The phone chugged along for quite a while, but eventually re-installed all of the applications, and the problem was fixed.
Web searches showed that I was not the only person to find themselves in this predicament, and did not reveal an obvious solution, so I’m documenting mine here.
http://wiki.cyanogenmod.com/index.php/Fix_permissions
Mark
January 31, 2010 at 16:43
Having seen this script suggested elsewhere, I did try it first (and should have mentioned this). It did not fix this problem.
The fix_permissions script tries to correct the UNIX permissions and ownership (uid, gid, mode) of files and directories. These look like “0”, “1000”, “rwxr-xr-x”, and such.
In my case, the problem was with the Android security permissions granted to applications. These look like “android.permission.INTERNET”, “android.permission.WAKE_LOCK” and are a completely different kettle of fish, despite both being called “permissions”.
Matt Zimmerman
January 31, 2010 at 17:04
I’ve added a link from that page to this article, since it mentions the problem I had but does not explain how to fix it.
Matt Zimmerman
January 31, 2010 at 17:10
[…] I learned that the permissions were “missing” from the “/data/system/packages.xml” […]
Automating Silent Batch Install of Apps & Fix Permissions « mittens blog
May 18, 2010 at 01:41
Very informative and this seemed to fix the error messages on my logcat output. nice go :)
thanks..
kirpi
September 4, 2010 at 09:42
[…] users that have a rooted device and are experiencing similar issues, there’s a nice write-up here that covers how to fix these kind of issues on a rooted […]
Issues with applications after updating to Android 2.2 on Motorola Droid | Daniel Velazco
September 18, 2010 at 20:48
works for me :) thanks!
mrozek
February 26, 2011 at 09:21
Could this be what is causing my mic on my g2 to not work during phone calls?
tom tom
March 19, 2011 at 02:28
This worked for me.
Tried a lot of other stuff, but this one did it. Nice and easy.
Thanks.
Hobbes
July 17, 2012 at 06:17
It works.
But normal user don’t want to do this. Is that a good way to fix it?
Andrew
March 6, 2014 at 23:55