由于客户的几个app中使用的.so文件是同名的,所以不能单独把.so提取出来,内置这些.so到系统库中.。 只能这样来实现,系统在第一次刷机完后,用install 的方式来安装这些应用.
整体思路如下:
1.把这些要install的应用放置在freescale\imx7\device\fsl\shiyuan_7d_eink\preinstall这个路径。包括安装apk脚本和Android.mk文件,和启动这些apk的脚本文件。
其中安装apk脚本如下:
#!/system/bin/busybox sh
BUSYBOX="/system/bin/busybox"
if [ ! -e /data/system.notfirstrun ]; then
echo "do preinstall job"
/system/bin/sh /system/bin/pm preinstall /system/preinstall
$BUSYBOX touch /data/system.notfirstrun
echo "preinstall ok"
fi
Android.mk:
# Copyright (C) 2008 The Android Open Source Project
# Copyright (C) 2012 Broadcom Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
LOCAL_PATH := $(call my-dir)
#########################
include $(CLEAR_VARS)
LOCAL_MODULE := SYAirdisk-ink.apk
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_MODULE_PATH := $(TARGET_OUT)/preinstall
LOCAL_MODULE_CLASS := APPS
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)
#########################
include $(CLEAR_VARS)
LOCAL_MODULE := SYCCASworker_ink.apk
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_MODULE_PATH := $(TARGET_OUT)/preinstall
LOCAL_MODULE_CLASS := APPS
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)
#########################
include $(CLEAR_VARS)
LOCAL_MODULE := SYLocalserver_ink.apk
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_MODULE_PATH := $(TARGET_OUT)/preinstall
LOCAL_MODULE_CLASS := APPS
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)
#########################
include $(CLEAR_VARS)
just_copy_to :=system/bin/preinstall.sh
just_copy_from:=$(LOCAL_PATH)/preinstall.sh
$(shell mkdir -p $(just_copy_to))
$(shell cp $(just_copy_from) $(just_copy_to))
启动apk的脚本如下:
#!/system/bin/busybox sh
echo "start two important service process"
am startservice org.golang.app.ccasworker/.GoNativeService
sleep 1
am startservice org.golang.app.localserver/.GoNativeAidlService
sleep 1
am startservice org.golang.app.airdisk/.GoNativeService
echo "end of the starting operation"
2.在apk文件,安装apk脚本,Android.mk文件,和启动apk脚本文件放置在对应路径后;把对应的apk拷贝到/system/preinstall路径下,实现如下:
#For WhiteListApp and preinstall apks;add by Jack 2019/04/09
PRODUCT_COPY_FILES += \
device/fsl/shiyuan_7d_eink/WhiteListApp.properties:system/etc/WhiteListApp.properties \
device/fsl/shiyuan_7d_eink/preinstall/SYCCASworker_ink.apk:system/preinstall/SYCCASworker_ink.apk \
device/fsl/shiyuan_7d_eink/preinstall/SYLocalserver_ink.apk:system/preinstall/SYLocalserver_ink.apk \
device/fsl/shiyuan_7d_eink/preinstall/SYAirdisk-ink.apk:system/preinstall/SYAirdisk-ink.apk
把preinstall.sh,和startTargetProc.sh两个脚本拷贝到Android系统路径/system/bin下
PRODUCT_COPY_FILES += \
device/fsl/shiyuan_7d_eink/preinstall/preinstall.sh:system/bin/preinstall.sh \
device/fsl/shiyuan_7d_eink/preinstall/startTargetProc.sh:system/bin/startTargetProc.sh
那么至此,Android源码编译后的结果是,脚本已经拷贝到/system/bin下面 ,apk.拷贝到/system/preinstall路径下;
3.刷完机后,Android系统启动的时候,会启动init.rc脚本文件,在这个脚本文件中调用安装apk的脚本,和调用启动apk的脚本。
a.init.rc 中调用安装应用脚本
service preinstall /system/bin/busybox sh /system/bin/preinstall.sh
user root
group root
disabled
oneshot
b.init.rc中嵌入调用启动apk的脚本
#start the two services
#触发器,当系统属性dev.bootcomplete=1即启动完成时触发
on property:dev.bootcomplete=1
start startservice
service startservice /system/bin/startTargetProc.sh
class late_start
user root
group root
disabled
oneshot
4,至此,第一次刷完机,预安装的应用会安装在/data/app路径下。
再次启动系统,就会执行启动应用脚本,把应用默认启动起来.
总结:
此次预安装的可卸载的apk中的总的思路,是要把目标apk,从源码移动到/system/preinstall路径下,不能移动到/system/app,也不能 移动到/system/priv-app下。所以需要copy,而不能通过Android.mk编译进系统。