Automating Silent Batch Install of Apps
I have a rooted Nexus One with the Cyanogenmod ROM. I use APPS2SD to place my applications on the SD card, allowing my phone to run fast and have heaps of free memory.
However, lately, I swapped my Micro-SD card with a friend’s in order to check some pictures, and upon booting the phone, it crashed all my third-party applications. Every single one! Replacing my micro-SD into the phone and rebooting did not solve the problem. I received notifications upon notifications informing me of a FORCE-CLOSE.
The error messages spoke of a PERMISSIONS error, and were something like this (each was a different permission error):
android.permission.INTERNET
android.permission.WAKE_LOCK
android.permission.SLEEP
The first thing I tried was to fix_permissions through the phone’s Terminal application. This is achieved by simply:
However, this did not fix the problem. I then tried re-flashing my ROM from the recovery menu (without doing a wipe). That, too, did not work.
Finally, I learned that the permissions were “missing” from the “/data/system/packages.xml” file (which can only be seen through the Root Explorer app)
“The fix_permissions script tries to correct the UNIX permissions and ownership (uid, gid, mode) of files and directories. [...] 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”.” [quote from Matt Zimmerman]
I then followed what he suggested – a method to silently batch install a bunch of apps! Turns out there is a package-manager command that allows you to do exactly this!
Follow these steps, which worked for me perfectly:
- Connect your phone to your computer using the data cable.
- Go to Start –> Run. Type in CMD and press enter.
- In the command-prompt, navigate to the TOOLS folder where your Android SDK is installed (example, C:\android_sdk\tools). If you don’t have it, follow these steps to install the Android SDK.
- Here, type:
adb shell
cd /data/app
for app in *.apk; do pm install -r $app; done
- The applications in the /data/app folder should automatically start batch installing now, one by one. Each app will take about 5 seconds to install.
IMPORTANT:
Those who have the Cyanogenmod ROM and APPS2SD should actually repeat STEP 4 and try these steps (because the APK files can be located elsewhere):
Instead of: cd /data/app
do this: cd /sd-ext/app
and also: cd /sd-ext/app-private
and also: cd /data/app-private
and for good measure, try reinstalling the system apps as well:
You should get a few failures if you try reinstalling the system apps (because they are currently running), but the others will reinstall just fine.
Now just reboot your phone and all the apps should be reinstalled and working just fine!
Read more...