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

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

http://www.kler.cn/a/581807.html

相关文章:

  • element tree树形结构默认展开全部
  • HTTP与HTTPS的深度解析:技术差异、安全机制及应用场景
  • 火语言RPA--PDF页数统计
  • 四种常见的 API 架构风格(带示例)
  • 前后端+数据库的项目实战--学生信息管理系统-易
  • Unity辅助工具_头部与svn
  • 【CXX】6.6 UniquePtr<T> — std::unique_ptr<T>
  • 深入理解 Rust 中的模式匹配语法
  • SpringBoot(1)——创建SpringBoot项目的方式
  • rom定制系列------小米note3 原生安卓15 批量线刷 默认开启usb功能选项 插电自启等
  • Java中数据库索引选择B+树而非红黑树的详细解析
  • DeepSeek引领端侧AI革命,边缘智能重构AI价值金字塔
  • Spring Boot中@Valid 与 @Validated 注解的详解
  • c++-------------------智能指针
  • 途游游戏25届AI算法岗内推
  • 2024华为OD机试真题-日志排序(C++)-E卷-100分
  • AttributeError: module ‘backend_interagg‘ has no attribute ‘FigureCanvas‘
  • Android Compose MutableInteractionSource介绍
  • 工程化与框架系列(28)--前端国际化实现
  • TDengine作为存储有什么缺点