[Miscellaneous Android Development] heart_crafter:
Copy Data Scripts

This procedure will let a cook save his custom app settings, and let it restore after a fresh flash.

I'll use com.android.launcher (adw launcher) from CyanogenMod as an example.

Here is what we’ll have to do.

First step, you have to do all the customization on your launcher. Change all the settings as you like.

Then zip(tar) the app data folder and save it on sdcard as com.android.launcher.tar.gz ,

here’s the command to make the tar file “busybox tar -vzcf /sdcard/com.android.launcher.tar.gz -C /data/data/ com.android.launcher”

Then Copy the tar file on the system image under /system/usr/customize/apps_data/com.android.launcher.tar.gz

Copy following in a file named getown and save it in /system/bin

#!/system/bin/sh
#
# Gets Folder/File owner in app_### format

AppName=$1
mkdir -p /system/usr/customize
rm -f /system/usr/customize/owner.tmp
strStats=$( busybox stat -t "$AppName" )
intCount=0
strOwner=0
for i in $strStats ;do
intCount=$(($intCount+1))
if [ "$intCount" = "5" ]; then
strOwner=$i
fi
done
owner=${strOwner#1} && owner=${owner#0} && owner=${owner#0} && owner=app_${owner#0}
echo $owner > /system/usr/customize/owner.tmp

Put the following code in the init.d script folder

#!/system/bin/sh
#
# Waits until boot is completed and adds the customizations.

timeBootCompleted=$(getprop ro.runtime.firstboot)
until [ "$timeBootCompleted" != "" ]; do
timeBootCompleted=$(getprop ro.runtime.firstboot)
sleep 3
log -p I -t boot "========== Waiting for runtime... ==========="
done

if [ ! -e "/system/usr/customize/logs/first_boot_completed" ];then
#Start adding ADW Launcher Prefs================================================
#Add ADW Launcher Prefs
AppName='com.android.launcher'

#Waits until app is completely loaded
until [ -d /data/data/$AppName/lib ]; do
log -p I -t boot "Waiting for /data/data/$AppName"
done
sleep 5

#Gets current ownership of the installed app so we can put the same ownership on the files will extract from the zip file.
sh /system/bin/getown "/data/data/$AppName"
owner=$(cat /system/usr/customize/owner.tmp)
log -p I -t boot "Owner of $AppName is $owner"
log -p I -t boot "========= Restoring $ AppName..."

#Extracts the files.
busybox tar -vzxf /system/usr/customize/apps_data/$AppName.tar.gz -C /data/data

#Apply the ownership to the extracted files.
chown $owner.$owner /data/data/$AppName/*
chown $owner.$owner /data/data/$AppName/shared_prefs/*
chown $owner.$owner /data/data/$AppName/databases/*
chown $owner.$owner /data/data/$AppName/files/*
chown system.system /data/data/$AppName/lib

#Restart App, or you can reboot if you are importing multiple apps data.
pm disable $AppName
pm enable $AppName
#end adding ADW Launcher Prefs================================================

log -p I -t boot "===== Saving a file for next boot to check if the scripts ran before or not ======"
chmod 777 /system/usr/customize
busybox mkdir -p /system/usr/customize/logs
chmod 777 /system/usr/customize/logs
echo > /system/usr/customize/logs/first_boot_completed
fi

This process worked for eclair minus the getown part and #!/system/bin/sh. I had to make getown for cyan.

In eclair i used the following instead of getown

owner=$( busybox stat -c %u /data/data/$AppName )
owner=${strOwner#1} && owner=${owner#0} && owner=${owner#0} && owner=app_${owner#0}
and #!/system/bin/busybox sh instead of #!/system/bin/sh

Steve, I started this for you so you can put the adw setting with your next release :D

and other people can maybe learn or enhance my codes :D

maybe i should have run this script first before putting it out :D

edit:

just tested the code line by line... looks good, i tried putting it in init.d... it never started up the script... :S

oh maybe because i didnt save the script in unix(LF) format :P