Perhaps one way to achieve this is to check if the device has been facory reset, then use a script to insert specific settings once. For this I need to launch a script early in the boot sequence.
This could be achieved by dismantling the boot.img, altering the init.rc, then re-building, which requires significant work and risks bricking the device. So I looked for a way to run a script without significant re-flashing. here goes:
xlog changes the system log level, and is called just a few times at boot-up. Xlog is run early, and as root, with the parameter boot.
This script renames xlog as xlogboot, introduces a script in place of xlog, which runs another script, startup.sh when xlog is called with parameter boot. All the original parameters are passed to the renamed xlog binary, so the system functionality should not be changed.
I pushed the script to the device, then run it as root. I can now edit /system/bin/startup.sh to run whatever initialisation commands I wish. I have so far tested on a ZTE v965 .
#!/system/bin/sh #This script creates a hook into the bootup system of Android #This hook operates when /system/bin/xlog is called with #the first parameter 'boot' #Use this script entirely at your own risk. I highly recommend #you ensure YOU have a backup of YOUR device before going further #Public Domain Nick Hill 2014 if [ -e /system/bin/xlogboot ] || [ -e /system/bin/startup.sh ]; then echo "This script may have already been run, exiting.." exit 1 fi if [ ! -e /system/bin/xlog ] then echo "This script is not running in an expected environment. Exiting.." exit 2 fi if [ $USER != "root" ] then echo "This script must be run as root. try running su. Exiting.." exit 3 fi touch /system/bin/atestfile if [ ! -e /system/bin/atestfile ] then echo "It appears system folder is not mounted read-write. Remounting..." mount -o remount,rw /system else rm /system/bin/atestfile fi echo -e '#!/system/bin/sh\n' > /system/bin/startup.sh chown root:root /system/bin/startup.sh chmod 755 /system/bin/startup.sh mv /system/bin/xlog /system/bin/xlogboot echo -e '#!/system/bin/sh\n/system/bin/xlogboot $*\nif [ "$1" == "boot" ] \nthen\n/system/bin/startup.sh\nfi\n' >/system/bin/xlog chown root:shell /system/bin/xlog chmod 755 /system/bin/xlog