大体思路是,将第三方应用保存在system/media/app目录下,在用户第一次启动手机或者恢复出厂设置的时候将这些apk文件拷贝到/data/app目录下面,PackageManagerService在系统启动的时候会自动扫描data/app目录下面的文件,然后自动安装。
具体步骤如下:
第一步,新加一个文件preinstall.txt来判断用户是在烧写手机和恢复出厂设置后第一次启动手机,还是用户正常重启手机。如果该文件在data/app目录存在,则是用户正常重启手机,否则就是用户恢复出厂设置或者第一次刷机后开机,这时就需要自动安装预装程序。注意此文件内容一定不能为空,否则shell脚本-s会认为该文件不存在
第二步,在system/core/rootdir/etc目录下新建shell脚本文件,如init.qcom.preinstall.sh,内容如下:
#!/system/bin/sh
# Copyright (c) 2009-2012, Code Aurora Forum. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of Code Aurora nor
# the names of its contributors may be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
#