[G1 Android Development] Darkstrumn:
Just an long-winded example of multi theme handling...

First, let me say sorry for being so verbose...

Well, sort of...:p

It is only like app2sd in that you store your apps on the sdcard vs on the Android internal memory. You gain the same storage and speed benefits of storing your apps externally.

Android2sd doesn't make use symlinks and doesn't manipulate the filesystem directly; instead it uses profiles. The base profile is a snapshot of the Android at the time of install; in so much as, it is a copy of your /system /data /and cache volumes at the moment of the android2sd install.

From that point, the initial profile called android2sd is then updated with the modifications (new dirs and scripts) that expand the functionality of the Android system.

This new profile is stored in the overlayEnv subdir on the ext2\ext3 second partition of the sdcard.

The init.rc file is updated to load the new startup-sequence.sh boot script that is copied to the Android /data/local/bin subdir. The startup-sequence.sh in-turn loads a2sdLoader.sh among other tasks which loads your overlay setup (which you can modify however you like)

The default android2sd profile overlays the profile versions of /system /data and /cache over the normal mountpoints. This is done before the system begins loading apps and configuring the runtime system. The apps and settings are then loaded from the profile space located on sd, and the android is now on sd. If you disable the init.rc file and reboot, or power down, remove the sdcard and power up, the Android will load just as it was prior to the android2sd install. (you can now put the sdcard back in;))

The un-profile version and the profile version of the Android are completely separate, however I have back-tunnels\\mount points in the android2sd allowing access to the Android under the overlays.

Any changes you make to one is specific to that environment. So you can have profiles of different themes, etc and they will be separate unless you modify the profiles to be overlapping:

Say you installed android2sd and had a rather "vanilla" setup. It installed as profile android2sd.

You now install the HERO theme using the update.zip method. This will modify the Android directly and your android2sd profile will still be "vanilla".

So you like the theme and decide to make it into a profile. you run the buildNewA2SDProfile.sh HERO script (the sdcard must be insterted at this point) to build a new profile called HERO...The script mounts the overlyEnv space, builds the new profile..a snapshot of the once "vanilla" Android now in HERO form.

Now you go and get the AERO theme and do the same thing. You reflash the main rom to cleanup the theme, back to your "vanilla" theme. Flash the update.zip containing the new AERO theme which updates Android directly; overwriting the "vanilla" theme with the AERO theme, then run the profile creation script naming the new profile AERO.

Now you have 3 profiles and 3 themes. Note if in your android2sd profile you loaded 250+ apps, they are likely not currently in your HERO and AERO profiles unless you "installed" them after you created AND loaded the profile. (The profile must be loaded when you copy or install the apps to the apps folder to properly update the package system in that profile, else you are updating your current environment).

See below changing theme on loading the various profiles we've set up here.

An Andvanced Profile Setup:

This profile scheme is fine if you want each profile to have different apps, but once you start installing the same app on multiple profiles it can get messy.

So I would have done this...

After the initial install you have profile 'android2sd'. You may have had a few apps installed on the Android that are now in the profile by default.

The following is done before rebooting\\loading into the new android2sd profile.

Now we create a new -BLANK profile called 'apps'. Only the /data/app and /data/app-private dirs with all the apps you intend have installed in your profiles, are stored in this profile.

So, we make the new apps profile and copy the apps dirs into the apps overlay profile, and delete them from the android2sd profile (just the files not the dirs).

WARNING:

As we make each theme we load, into a profile, we only copy NON-THEME apk's into the 'apps' profile (removing them from the theme profile). Themed apks have different certs due to image or logic changes introduced via the theme. Those changes are specific to that theme and should not be put into the global apps container!

Ok, we update the a2sdLoader.sh script to overlay the apps container dirs over the "base" profile's /data/app and /data/app-private subdirs respectively.

So the "base" profile 'android2sd' is overlayed, and then the 'apps' profile is layered over the base.

The reason we do this is the Android system "loads\\installs" every apk at every reboot. If the apk is already in the package system, it is loaded, else it is installed. /data/data is the apps install location and packages.xml holds our install data. If the 2 are mismatched, you have problems which in the extreme case is a boot loop. So, we are leaving the /data/data and /data/system/packages.xml to each profile intact and only storing our non-theme app apks in a global apps profile.

Now we've gone through and created our HERO and AERO profiles based on the scenario above,

and all profiles will have most of the same global apps "installed", but the package system is likely different thanks to the differing files in the themes that were installed.

As we have the apps dirs shared, any profile that gets a new app (via market or other means), the other profiles when loaded will install\\load the new app as well, and the permissions should be handled appropriately for each profile.

Final Product:

So in our example:

We have Android which started out 'vanilla' and may yet still be. Aka "Safe Normal" mode

We have a profile called 'andoird2sd' based on our vanilla Android

We have a profile called 'HERO' based on the Android when the that theme was installed

We have a profile called 'AERO' based on the Android when that theme was installed

We have a profile called 'apps' which is our global apps container profile

We update a2sdLoader.sh to load one of the three profiles "android2sd, HERRO, or AERO" and then the 'apps' profile is overlayed over the /data/app and /data/app-private dirs of our selected theme

The update for the apps bit need only be done once, and then for the themes, you only need update the variable holding the name of the desired theme.:D

Changing Theme Profiles:

Changing which profile loads, is currently a manual process and the most cumbersome part of this theme-profiling is the dual flash, flash rom to make the theme vanilla, then flash the theme. (I would delete any apps left in the /data/app dir after loading the 'vanilla' theme, as they may be left over from the previous theme. If you know they are not, then you can leave them be.

Anyway, we update the a2sdLoader.sh to affect our theme change. We select which theme profile to load, then reboot. (with init.rc enabled, and the sdcard inserted of course :rolleyes:)

I know that is a lot to absorb, but give it a go and follow along and you will see it isn't really all that bad.:)