[BetterBatteryStats] chamonix:
Very interesting stuff. I have found (in the log after reboot) where things go wrong.

11-22 17:16:22.644 I/PackageManager( 751): /system/priv-app/com.asksven.betterbatterystats_signed.apk changed; collecting certs
11-22 17:16:22.664 I/PackageManager( 751): Package com.asksven.betterbatterystats codePath changed from /mnt/asec/com.asksven.betterbatterystats-1/pkg.apk to /system/priv-app/com.asksven.betterbatterystats_signed.apk; Retaining data and using new
11-22 17:16:22.664 W/PackageManager( 751): Code path for pkg : com.asksven.betterbatterystats changing from /mnt/asec/com.asksven.betterbatterystats-1/pkg.apk to /system/priv-app/com.asksven.betterbatterystats_signed.apk
11-22 17:16:22.664 W/PackageManager( 751): Resource path for pkg : com.asksven.betterbatterystats changing from /mnt/asec/com.asksven.betterbatterystats-1/res.zip to /system/priv-app/com.asksven.betterbatterystats_signed.apk

11-22 17:16:22.784 I/PackageManager( 751): Package com.android.chrome at /system/app/Chrome.apk ignored: updated version 1650059 better than this 1599105
11-22 17:16:23.044 I/PackageManager( 751): Package com.google.earth at /system/app/GoogleEarth.apk ignored: updated version 13294050 better than this 13282140
11-22 17:16:23.084 I/PackageManager( 751): Package com.hp.android.printservice at /system/app/HPPrintPlugin.apk ignored: updated version 40 better than this 39
11-22 17:16:23.134 I/PackageManager( 751): Package com.google.android.talk at /system/app/Hangouts.apk ignored: updated version 20128130 better than this 20012130
11-22 17:16:23.284 I/PackageManager( 751): Package com.google.android.apps.maps at /system/app/Maps.apk ignored: updated version 704001124 better than this 703001223
11-22 17:16:23.334 I/PackageManager( 751): Package com.google.android.music at /system/app/Music2.apk ignored: updated version 1301 better than this 1224
11-22 17:16:23.474 I/PackageManager( 751): Package com.quickoffice.android at /system/app/QuickOffice.apk ignored: updated version 131106 better than this 131009
11-22 17:16:23.574 I/PackageManager( 751): Package com.google.android.youtube at /system/app/YouTube.apk ignored: updated version 5227 better than this 5111
11-22 17:16:23.604 W/PackageParser( 751): Unknown element under <application>: uses-permission at /system/app/shutdownlistener.apk Binary XML file line #11
11-22 17:16:23.614 I/PackageManager( 751): Package eu.chainfire.supersu at /system/app/Superuser.apk ignored: updated version 175 better than this 1

11-22 17:16:23.614 I/PackageManager( 751): Expecting better updatd system app for com.asksven.betterbatterystats; removing system app
11-22 17:16:27.114 I/PackageManager( 751): Running dexopt on: com.asksven.betterbatterystats
11-22 17:16:27.374 I/PackageManager( 751): Deleting stale container for com.asksven.betterbatterystats-1
11-22 17:16:27.674 W/PackageManager( 751): Container com.asksven.betterbatterystats-1 is stale

In the first part you can see that BBS is moved from the asec path to priv-app. In the second part you can see what I was expecting to happen: a newer version than the one present in the system directory is detected so the apk from system is ignored.

Now this can have multiple reasons:

1. the is because of the manifest parsing error the happened before the reboot:

11-22 17:13:54.563 W/zipro ( 753): Unable to open zip '/system/priv-app/com.asksven.betterbatterystats_signed.apk': Permission denied
11-22 17:13:54.563 D/asset ( 753): failed to open Zip archive '/system/priv-app/com.asksven.betterbatterystats_signed.apk'
11-22 17:13:54.563 W/PackageParser( 753): Unable to read AndroidManifest.xml of /system/priv-app/com.asksven.betterbatterystats_signed.apk11-22 17:13:54.563 W/PackageParser( 753): java.io.FileNotFoundException: AndroidManifest.xml

2. There is - besides the version number from the manifest - something else that makes PackageManager believe that the APK present in priv-app is more recent than the one from asec

3. The way I handle the installation of the system app is for other reasons incompatible with encrypted apps from gplay

Now I have found a way to install my own app from gplay (you will laugh but that isn't that easy) and can do some testing. And even better the sources of PackageManager are open source so I will do some reading (this is going to be a long night.

Edit:

I recommend some good reading: ;)

https://android.googlesource.com/pl.../android/server/pm/PackageManagerService.java

and

https://android.googlesource.com/pl...re/java/android/content/pm/PackageParser.java

Now from what I uderstand the fact that the newly installed app gets removed is because PackageManager detect that a newer package has been installed from OTA (obviously the stuff I do is not something that was considered in design). When a newer package is installed from OTA the /data.... package is removed and the settings/app-data moved.

I believe that happens because as soon as the apk is copied to /system/priv-app the listener on that directory (PackageManagerService) starts processing it and fails because the perms and ownership are not right (I change those after moving the APK).

I will now try to change that by first settings perms and ownership and then moving the APK.

Edit 2:

did the steps by hand:

1. cp apk to /system

2. chmod 644 and chown root:root

3: cp -p to /system/priv-app

These step resulted in the installed app to stay and to not lose the preferences / data.

I have now added that modified sequence to RC7 and will push in a few.