Android如何将第三方预装的AP安装在data/app下面,用户可以选择卸载,但是在用户恢复出厂设置后,会再次自动安装

转自:http://blog.csdn.net/dekunchenivan/article/details/8448693


[plain]  view plain copy
  1. 大体思路是,将第三方应用保存在system/media/app目录下,在用户第一次启动手机或者恢复出厂设置的时候将这些apk文件拷贝到/data/app目录下面,PackageManagerService在系统启动的时候会自动扫描data/app目录下面的文件,然后自动安装。  

具体步骤如下:

[plain]  view plain copy
  1. 第一步,新加一个文件preinstall.txt来判断用户是在烧写手机和恢复出厂设置后第一次启动手机,还是用户正常重启手机。如果该文件在data/app目录存在,则是用户正常重启手机,否则就是用户恢复出厂设置或者第一次刷机后开机,这时就需要自动安装预装程序。注意此文件内容一定不能为空,否则shell脚本-s会认为该文件不存在  

第二步,在system/core/rootdir/etc目录下新建shell脚本文件,如init.qcom.preinstall.sh,内容如下:

[plain]  view plain copy
  1. #!/system/bin/sh  
  2. # Copyright (c) 2009-2012, Code Aurora Forum. All rights reserved.  
  3. #  
  4. # Redistribution and use in source and binary forms, with or without  
  5. # modification, are permitted provided that the following conditions are met:  
  6. #     * Redistributions of source code must retain the above copyright  
  7. #       notice, this list of conditions and the following disclaimer.  
  8. #     * Redistributions in binary form must reproduce the above copyright  
  9. #       notice, this list of conditions and the following disclaimer in the  
  10. #       documentation and/or other materials provided with the distribution.  
  11. #     * Neither the name of Code Aurora nor  
  12. #       the names of its contributors may be used to endorse or promote  
  13. #       products derived from this software without specific prior written  
  14. #       permission.  
  15. #  
  16. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"  
  17. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE  
  18. # IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND  
  19. # NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR  
  20. # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  
  21. # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,  
  22. # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;  
  23. # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  
  24. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR  
  25. # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF  
  26. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
  27. #  
  28. cd /system/media/app  
[plain]  view plain copy
  1. #android shell script: check if preinstall.txt is exist  
  2. if [ -s /data/app/preinstall.txt ]; then  
  3.     echo "don't need to copy preinstall files"  
  4. else  
[plain]  view plain copy
  1. # scan all apk files under system/media/app  
  2. apklist="$(ls)"  
  3. for apkfile in ${apklist}; do  
[plain]  view plain copy
  1. #copy all apk file to data/app  
  2. dd if=${apkfile} of=/data/app/${apkfile}  
[plain]  view plain copy
  1.     # change the permission  
  2.     chmod 666 /data/app/${apkfile}  
  3. done  


第三步,在device/qcom/common/common.mk中新加一行

INIT+= init.qcom.preinstall.sh


第四步,修改system/core/rootdir/Android.mk

新增内容如下

[plain]  view plain copy
  1. include $(CLEAR_VARS)  
  2. LOCAL_MODULE       := init.qcom.preinstall.sh   56  
  3. LOCAL_MODULE_TAGS  := optional eng  57  
  4. LOCAL_MODULE_CLASS := ETC   58  
  5. LOCAL_SRC_FILES    := etc/init.qcom.preinstall.sh   59  
  6. include $(BUILD_PREBUILT)  


第五步,修改system/core/rootdir/init.rc文件,添加如下内容

chmod0555/system/etc/init.qcom.preinstall.sh

service preinstalld /system/bin/sh /system/etc/init.qcom.preinstall.sh

class main

group system


最后修改你的编译文件,将第三方软件打包如system/media/app目录



以上是在高通4.04平台上面实现方案


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值