Android内置音频文件

时间:2022-02-01 19:45:07

1、在vendor/Tecnon_BuildIn下新建preloadfiles文件夹,里面放置要内置的音频文件和copy脚本,copytosystem.mk脚本如下:

LOCAL_PATH:= vendor/Tecnon_BuildIn/preloadfiles

PRODUCT_COPY_FILES += \
$(LOCAL_PATH)/music/Go_On.mp3:system/preloadmusic/Go_On.mp3 \
$(LOCAL_PATH)/music/Red.mp3:system/preloadmusic/Red.mp3 \
$(LOCAL_PATH)/music/Salamalekun.mp3:system/preloadmusic/Salamalekun.mp3

preloadfiles文件夹的Android.mk编译脚本为:

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := preloadfile.sh
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
LOCAL_SRC_FILES := preloadfile.sh
include $(BUILD_PREBUILT)

preloadfiles.sh脚本为:

#!/system/bin/sh
PRELOAD_DEST=/storage/sdcard0
#preload video
PRELOADVIDEO_DEST=${PRELOAD_DEST}/Movies
PRELOADVIDEO_FLAG=${PRELOADVIDEO_DEST}/.videocopied
PRELOADVIDEO_SRC=/system/preloadvideo

if [ ! -d ${PRELOADVIDEO_DEST} ]
then
mkdir -p ${PRELOADVIDEO_DEST}
fi

if [ ! -f ${PRELOADVIDEO_FLAG} ]
then
files=$(ls ${PRELOADVIDEO_SRC}/)
for i in ${files};do
cat ${PRELOADVIDEO_SRC}/${i} > ${PRELOADVIDEO_DEST}/${i}
done
echo "aaaa" > ${PRELOADVIDEO_FLAG}
fi

#preload music
PRELOADMUSIC_DEST=${PRELOAD_DEST}/Music
PRELOADMUSIC_FLAG=${PRELOADMUSIC_DEST}/.musiccopied
PRELOADMUSIC_SRC=/system/preloadmusic

if [ ! -d ${PRELOADMUSIC_DEST} ]
then
mkdir -p ${PRELOADMUSIC_DEST}
fi

if [ ! -f ${PRELOADMUSIC_FLAG} ]
then
files=$(ls ${PRELOADMUSIC_SRC}/)
for i in ${files};do
cat ${PRELOADMUSIC_SRC}/${i} > ${PRELOADMUSIC_DEST}/${i}
done
echo "aaaa" > ${PRELOADMUSIC_FLAG}
fi

#preload picture
PRELOADPIC_DEST=${PRELOAD_DEST}/Pictures
PRELOADPIC_FLAG=${PRELOADPIC_DEST}/.piccopied
PRELOADPIC_SRC=/system/preloadpic

if [ ! -d ${PRELOADPIC_DEST} ]
then
mkdir -p ${PRELOADPIC_DEST}
fi

if [ ! -f ${PRELOADPIC_FLAG} ]
then
files=$(ls ${PRELOADPIC_SRC}/)
for i in ${files};do
cat ${PRELOADPIC_SRC}/${i} > ${PRELOADPIC_DEST}/${i}
done
echo "aaaa" > ${PRELOADPIC_FLAG}
fi

preloadfiles.te策略文件路径:device\mediatek\common\sepolicy\basic

# ==============================================
# Policy File of /system/xbin/preloadfile Executable File

# ==============================================
# Type Declaration
# ==============================================
type preloadfile_exec , exec_type, file_type;
type preloadfile ,domain;


# ==============================================
# MTK Policy Rule
# ==============================================
init_daemon_domain(preloadfile)

#binder_use(preloadfile)
#binder_service(preloadfile)

# permission for android N policy
allow preloadfile toolbox_exec:file {rx_file_perms};

# purpose: allow preloadfile to access storage in N version
allow preloadfile media_rw_data_file:dir {create_dir_perms};
allow preloadfile media_rw_data_file:file { create_file_perms };
allow preloadfile mnt_user_file:dir {create_dir_perms};
allow preloadfile mnt_user_file:lnk_file {create_file_perms };
allow preloadfile fuse:dir {create_dir_perms};
allow preloadfile fuse:file {create_file_perms};
allow preloadfile sdcardfs:dir {create_dir_perms};
allow preloadfile sdcardfs:file {create_file_perms};
allow preloadfile shell_exec:file {rx_file_perms};
allow preloadfile storage_file:lnk_file {create_file_perms };
allow preloadfile tmpfs:dir{create_dir_perms};
allow preloadfile tmpfs:file{create_file_perms};
allow preloadfile system_file:dir{read open};
allow preloadfile system_file:file{read open};

在te策略文件同级路径下的file_contexts文件里添加如下一行:

/system/xbin/dingyufile.sh u:object_r:dingyufile_exec:s0

把这个mk文件和sh脚本添加到device.mk文件中:device\mediatek\common\device.mk

$(call inherit-product-if-exists, vendor/Tecnon_BuildIn/preloadfiles/copytosystem.mk)
PRODUCT_PACKAGES += preloadfile.sh

2、在init.project.rc文件中添加:

service preloadfile /system/xbin/preloadfile.sh
class main
oneshot
disabled
seclabel u:r:preloadfile:s0

3、frameworks\base\services\core\java\com\android\server\MountService.java类的MountServiceHandler中H_VOLUME_BROADCAST选项下添加:

android.os.SystemProperties.set("ctl.start", "preloadfile");


加载内置存储的时候运行service preloadfile,就可以把音频复制到内部存储中