We'll see | Matt Zimmerman

a potpourri of mirth and madness

Posts Tagged ‘Android

Fix broken Android permissions by re-installing apps

with 3 comments

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.

Written by Matt Zimmerman

31 January, 2010 at 12:28

Android emancipation

with 10 comments

This afternoon, I decided to take the plunge and replace the OS on my G1. I had been having problems with the factory software for a while (including extreme slowness and a recurring crash in the calendar sync code) which finally outweighed the risk and inconvenience of flashing it. It looked like I was going to have to wipe it, and if I have to suffer that inconvenience anyway, I might as well go for broke.

“Rooting” the phone to enable the use of an alternative OS was very easy, thanks to the excellent Recovery Flasher application. I installed it by pointing the phone’s browser at the .apk download, though in retrospect it should be even easier to use adb. Recovery Flasher installs an alternative system recovery application, used when you hold down the magic buttons while the phone is starting up. The one which comes with the phone only allowed me to perform a few simple operations, while Recovery Flasher offers more features and doesn’t limit me to OS images blessed by Google.

Next, I downloaded the latest version of the highly recommended Cyanogen build. Thanks to Recovery Flasher, I didn’t even need to rename the file, as it lets me select any .zip file from the SD card to install. This is particularly convenient when experimenting with multiple OS images. On the first try, it failed to verify the .zip, so I copied it again, and it worked. I think the microSD card which was included with the phone is a bit flaky.

I decided to try without wiping my settings, to see if I could preserve them. The Cyanogen installation instructions warned that the first boot would take a long time, but after several minutes, I started to worry. adb logcat gave me some bad news:

I/SystemServer(  631): Starting Content Manager.
I/SystemServer(  631): Starting System Content Providers.
I/SystemServer(  631): Starting Battery Service.
I/SystemServer(  631): Starting Hardware Service.
W/HAL     (  631): load: module=/system/lib/hw/lights.trout.so error=Cannot find library
W/HAL     (  631): load: module=/system/lib/hw/lights.trout.so error=Cannot find library
E/ActivityThread(  631): Failed to find provider info for settings
W/dalvikvm(  631): threadid=31: thread exiting with uncaught exception (group=0x40019a68)
E/AndroidRuntime(  631): Uncaught handler: thread PowerManagerService exiting due to uncaught exception
E/AndroidRuntime(  631): *** EXCEPTION IN SYSTEM PROCESS.  System will crash.
E/AndroidRuntime(  631): java.lang.NullPointerException
E/AndroidRuntime(  631): 	at android.content.ContentQueryMap.(ContentQueryMap.java:65)
E/AndroidRuntime(  631): 	at com.android.server.PowerManagerService.initInThread(PowerManagerService.java:414)
E/AndroidRuntime(  631): 	at com.android.server.PowerManagerService$1.onLooperPrepared(PowerManagerService.java:374)
E/AndroidRuntime(  631): 	at android.os.HandlerThread.run(HandlerThread.java:59)
E/AndroidRuntime(  631): Crash logging skipped, no checkin service
I/Process (  631): Sending signal. PID: 631 SIG: 9

It was stuck in an infinite loop due to this crash. I searched Google for the error and found no help, and after some experimentation (including clearing out the dalvik-cache directory), I resigned myself to wiping my settings. I copied off the /data directory from the phone and rebooted, and the crash disappeared. Since I have a copy, I can restore the settings individually as I need them (and may be able to identify which one triggered the crash).

adb push makes it easy to copy files back onto the device from a backup. It was easy to restore my list of WiFi networks and keys: just restore /data/misc/wifi/wpa_supplicant.conf. It looks like Bluetooth pairings are stored in /data/misc/hcid, and I’ve copied that as well, though I haven’t tested whether it worked.

Restoring applications was also straightforward: adb push some.app.apk /data/app

I didn’t bother trying to figure out how to restore my Google account settings, Twidroid settings or Twitta settings. I just re-entered my account details. Twitta doesn’t seem to be working, though. It gets a timeout trying to contact Twitter and verify my credentials (but I can ping twitter.com fine).

The phone is much snappier now, though whether it’s due to the fresh start or the Cyanogen build, I’m not sure.

Written by Matt Zimmerman

22 August, 2009 at 20:12

Posted in Uncategorized

Tagged with ,