当前位置: 首页 > news >正文

Android12 应用更新开机动画

项目selinux是打开的,会涉及到权限问题,所以实在具有系统签名的应用中实现。

将动画资源包放到"/data/local/traces"目录

  • system/core/rootdir/init.rc
 # For security reasons, /data/local/tmp should always be empty.
 # Do not place files or directories in /data/local/tmp
 mkdir /data/local/tmp 0771 shell shell
 mkdir /data/local/traces 0777 shell shell
 mkdir /data/data 0771 system system encryption=None
 mkdir /data/app-private 0771 system system encryption=Require

BootAnimation.cpp中添加路径

  • /frameworks/base/cmds/bootanimation/BootAnimation.cpp
+static const char CUSTOM_BOOTANIMATION_FILE[] = "/data/local/traces/bootanimation.zip";
 static const char OEM_BOOTANIMATION_FILE[] = "/oem/media/bootanimation.zip";
 static const char PRODUCT_BOOTANIMATION_DARK_FILE[] = "/product/media/bootanimation-dark.zip";
 static const char PRODUCT_BOOTANIMATION_FILE[] = "/product/media/bootanimation.zip";
@@ -583,7 +584,7 @@ void BootAnimation::findBootAnimationFile() {
     }
 
     const bool playDarkAnim = android::base::GetIntProperty("ro.boot.theme", 0) == 1;
     // 将添加的路径放在第一位
-    static const std::vector<std::string> bootFiles = {
+    static const std::vector<std::string> bootFiles = {CUSTOM_BOOTANIMATION_FILE,
         APEX_BOOTANIMATION_FILE, playDarkAnim ? PRODUCT_BOOTANIMATION_DARK_FILE : PRODUCT_BOOTANIMATION_FILE,
         OEM_BOOTANIMATION_FILE, SYSTEM_BOOTANIMATION_FILE
     };
     ...
 // 获取可用开机动画路径
 bool BootAnimation::findBootAnimationFileInternal(const std::vector<std::string> &files) {
     for (const std::string& f : files) {
         if (access(f.c_str(), R_OK) == 0) {
             mZipFileName = f.c_str();
             return true;
         }
     }
     return false;
 }
添加权限
  • /device/mediatek/sepolicy/basic/non_plat/bootanim.te
+allow bootanim trace_data_file:dir { search read };
+allow bootanim trace_data_file:file { read open map };
  • /device/mediatek/sepolicy/basic/non_plat/system_app.te
+allow system_app trace_data_file:dir { search read create write add_name remove_name };
+allow system_app trace_data_file:file { read create write open getattr setattr unlink };
复制zip包到指定路径
private static final String DEST_PATH = "/data/local/traces/bootanimation.zip";
public boolean setSystemBootAnimation(String path) {
		File file = new File(path);
		if (file.exists()){
			try {
				File destFile = new File(DEST_PATH);
				Runtime.getRuntime().exec("chmod 777" + DEST_PATH);
				if (destFile.exists()){
					destFile.delete();
				}

				FileInputStream fis = new FileInputStream(path);
				FileOutputStream fos = new FileOutputStream(DEST_PATH);
				byte[] buffer = new byte[1024];
				int byteRead;
				while (-1 != (byteRead = fis.read(buffer))){
					fos.write(buffer, 0, byteRead);
				}

				fis.close();
				fos.flush();
				fos.close();
			} catch (IOException e){
				e.printStackTrace();
				return false;
			}
		}

		File nFile = new File(DEST_PATH);
		if (nFile.exists()){
			try {
				Files.setPosixFilePermissions(nFile.toPath(),
						PosixFilePermissions.fromString("rw-rw-rw-"));
			} catch (IOException e) {
				e.printStackTrace();
				return false;
			}
		}
		return true;
	}

需要系统签名,包在data目录下,恢复出厂设置会被清除。
如果项目的selinux是关闭的,也可以自己创建其他路径

  • system/core/rootdir/init.rc
mkdir /data/local/animation 0777 shell shell

相关文章:

  • React通过命令式的弹窗控制,实现组件封装
  • 选项模式(Options Pattern)
  • QT系列教程(22) QT 实现电子相册(一)--目录树和向导
  • AS_Path过滤器应用灵活配置示例
  • Linux驱动开发-设备树
  • python之使用scapy扫描本机局域网主机,输出IP/MAC表
  • OpenHarmony体系架构深度解析
  • Three.js 进阶(灯光阴影关系和设置、平行光、阴影相机)
  • Vue动态组件完全指南:原理、使用场景与最佳实践
  • 消防设施操作员考试:用故事开启高效备考之旅​
  • 数据分析项目:直播电商用户流失分析
  • 微信小程序面试内容整理-生命周期函数
  • Mamba| Miniforge3 安装和配置
  • 【Python 数据结构 14.邻接表】
  • 【鸿蒙开发】Hi3861学习笔记- GPIO之LED
  • Excel中国式排名,3种方法!
  • b站视频下载工具软件怎么下载
  • const_cast
  • c++ 中的引用
  • Jenkins链接私有仓库Failed to connect to repository,stderr: No ECDSA...的问题
  • 刘小涛任江苏省委副书记
  • 2025年“新时代网络文明公益广告”征集展示活动在沪启动
  • A股三大股指低收:汽车股领涨,大金融走弱,两市成交近1.1万亿元
  • 俄媒:俄乌伊斯坦布尔谈判将于北京时间今天17时30分开始
  • 2000多年前的“新衣”长这样!马王堆文物研究新成果上新
  • 俄外交部:俄乌伊斯坦布尔谈判改在当地时间15日下午举行