平台
Amlogic s905 + Android 7.1
需求
使用视频作为开机动画, 提供接口用于修改开机视频动画.
解决方案
打开视频开机动画功能:
//设置属性: service.bootvideo=1
服务注册:
|-- device/amlogic/common/products/tv/init.amlogic.rc
service bootvideo /system/bin/bootplayer /system/etc/bootvideo class main user root group system disabled oneshot
视频开机动画实现的程序:
修改方法相对简单, 即是在视频播放前, 读取/data/bootvideo, 若不存在此文件, 则播放默认/system/etc/bootvideo
|-- vendor/amlogic/frameworks/av/LibPlayer/bootplayer/bootplayer.c
int main(int argc, char *argv[]) { play_control_t *pCtrl = NULL; int pid; int pos = 0; int speed = 0; int tmpneedexit = 0; int ret = -1; int fd_di_bypass_all = -1; media_info_t minfo; int osd_is_blank = 0; char tmpcommand[TMP_COMMAND_MAX]; char newframestring[30] = {0}; char newstring0[30] = {0}; int new_frame_count = 0; EMU_STEP tmpstep = EMU_STEP_MENU; osd1_clear = 0; char *di_bypass_all_path = "/sys/module/di/parameters/bypass_all"; pCtrl = (play_control_t*)malloc(sizeof(play_control_t)); memset(pCtrl, 0, sizeof(play_control_t)); memset(&minfo, 0, sizeof(media_info_t)); if (argc < 2) { ALOGD("usage:player file\n"); return -1; } //amsysfs_set_sysfs_str(di_bypass_all_path, "1"); set_video_axis(); player_init(); //streamsource_init(); player_register_update_callback(&pCtrl->callback_fn, &update_player_info, 1000); ALOGD("player callback register....\n"); //尝试读取/data/bootvideo, 若不存在则使用默认传进视频文件地址. char* videoPath = "/data/bootvideo"; FILE* fp = fopen(videoPath, "r"); if(fp){ pCtrl->file_name = strdup(videoPath); }else{ pCtrl->file_name = strdup(argv[1]); } ALOGD("player pCtrl->file_name=%s", pCtrl->file_name); //... }
解决SELinux问题, 打开bootplayer的文件读取权限.
|-- system/sepolicy/domain.te
neverallow { domain -system_server -system_app -init -shell -bootanim -bootanimcp -bootvideo -installd # for relabelfrom and unlink, check for this in explicit neverallow } system_data_file:file no_w_file_perms;
|-- device/amlogic/common/sepolicy/bootvideo.te
# 增加代码 allow bootvideo system_data_file:file{read getattr open write};
结语
使用时, 只需要通过服务或应用, 把视频文件放置到/data/bootvideo中即可. 若为普通APP权限, 则系统可适当增加一个文件拷贝服务, 将指定文件拷贝到/data下, 并赋与相关权限即可.