一、原理简介
我们直接用最简单的替换zip的方式来更换开机动画,首先我们要查看系统代码使用的zip包的路径,可能与aosp原生的代码不一定一样。
/frameworks/base/cmds/bootanimation/BootAnimation.cpp
bool BootAnimation::threadLoop() {
ATRACE_CALL();
bool result;
initShaders();
// We have no bootanimation file, so we use the stock android logo
// animation.
if (mZipFileName.empty()) {
ALOGD("No animation file");
result = android();
} else {
result = movie();
}
//**省略后续代码**//
}
看到是使用mZipFileName来判断的,我们看看初始化的地方
bool BootAnimation::findBootAnimationFileInternal(const std::vector<std::string> &files) {
ATRACE_CALL();
for (const std::string& f : files) {
if (access(f.c_str(), R_OK) == 0) {
mZipFileName = f.c_str();
return true;
}
}
return false;
}
void BootAnimation::findBootAnimationFile() {
ATRACE_CALL();
const bool playDarkAnim = android::base::GetIntProperty("ro.boot.theme", 0) == 1;
const std::string productBootanimationFile = PRODUCT_BOOTANIMATION_DIR +
android::base::GetProperty("ro.product.bootanim.file", playDarkAnim ?
PRODUCT_BOOTANIMATION_DARK_FILE : PRODUCT_BOOTANIMATION_FILE);
static const std::vector<std::string> bootFiles = {
APEX_BOOTANIMATION_FILE, productBootanimationFile,
OEM_BOOTANIMATION_FILE, SYSTEM_BOOTANIMATION_FILE
};
static const std::vector<std::string> shutdownFiles = {
PRODUCT_SHUTDOWNANIMATION_FILE, OEM_SHUTDOWNANIMATION_FILE, SYSTEM_SHUTDOWNANIMATION_FILE, ""
};
static const std::vector<std::string> userspaceRebootFiles = {
PRODUCT_USERSPACE_REBOOT_ANIMATION_FILE, OEM_USERSPACE_REBOOT_ANIMATION_FILE,
SYSTEM_USERSPACE_REBOOT_ANIMATION_FILE,
};
if (android::base::GetBoolProperty("sys.init.userspace_reboot.in_progress", false)) {
findBootAnimationFileInternal(userspaceRebootFiles);
} else if (mShuttingDown) {
findBootAnimationFileInternal(shutdownFiles);
} else {
//查找开机动画的路径
findBootAnimationFileInternal(bootFiles);
}
}
通过代码我们可以查找到几个路径,最好验证的方式直接adb shell然后查找几个zip是否存在,也可以看Bootanimation的日志。最后我们发现是在/product/media/下面的动画zip文件。到这里如果有现成的zip可以push直接替换验证,要编译的时候起作用我们还需要看看这个zpi的生成规则。
规则mk的路径
/media/arcxea/stat/lineageos/vendor/lineage/bootanimation/Android.mk
#
# Copyright (C) 2016 The CyanogenMod Project
# 2017-2024 The LineageOS Project
#
# 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.
#
TARGET_GENERATED_BOOTANIMATION := $(TARGET_OUT_INTERMEDIATES)/BOOTANIMATION/bootanimation.zip
$(TARGET_GENERATED_BOOTANIMATION): INTERMEDIATES := $(call intermediates-dir-for,BOOTANIMATION,bootanimation)
$(TARGET_GENERATED_BOOTANIMATION): $(SOONG_ZIP)
@echo "Building bootanimation.zip"
@rm -rf $(dir $@)
@mkdir -p $(INTERMEDIATES)
$(hide) tar xfp vendor/lineage/bootanimation/bootanimation.tar -C $(INTERMEDIATES)
$(hide) if [ $(TARGET_SCREEN_HEIGHT) -lt $(TARGET_SCREEN_WIDTH) ]; then \
IMAGEWIDTH=$(TARGET_SCREEN_HEIGHT); \
else \
IMAGEWIDTH=$(TARGET_SCREEN_WIDTH); \
fi; \
IMAGESCALEWIDTH=$$IMAGEWIDTH; \
IMAGESCALEHEIGHT=$$(expr $$IMAGESCALEWIDTH / 3); \
if [ "$(TARGET_BOOTANIMATION_HALF_RES)" = "true" ]; then \
IMAGEWIDTH="$$(expr "$$IMAGEWIDTH" / 2)"; \
fi; \
IMAGEHEIGHT=$$(expr $$IMAGEWIDTH / 3); \
RESOLUTION="$$IMAGEWIDTH"x"$$IMAGEHEIGHT"; \
prebuilts/tools-lineage/${HOST_OS}-x86/bin/mogrify -resize $$RESOLUTION -colors 256 $(INTERMEDIATES)/*/*.png; \
echo "$$IMAGESCALEWIDTH $$IMAGESCALEHEIGHT 60" > $(INTERMEDIATES)/desc.txt; \
cat vendor/lineage/bootanimation/desc.txt >> $(INTERMEDIATES)/desc.txt
$(hide) $(SOONG_ZIP) -L 0 -o $@ -C $(INTERMEDIATES) -D $(INTERMEDIATES)
ifeq ($(TARGET_BOOTANIMATION),)
TARGET_BOOTANIMATION := $(TARGET_GENERATED_BOOTANIMATION)
endif
include $(CLEAR_VARS)
LOCAL_MODULE := bootanimation.zip
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(TARGET_OUT_PRODUCT)/media
include $(BUILD_SYSTEM)/base_rules.mk
$(LOCAL_BUILT_MODULE): $(TARGET_BOOTANIMATION)
@cp $(TARGET_BOOTANIMATION) $@
include $(CLEAR_VARS)
BOOTANIMATION_SYMLINK := $(TARGET_OUT_PRODUCT)/media/bootanimation-dark.zip
$(BOOTANIMATION_SYMLINK): $(LOCAL_INSTALLED_MODULE)
@mkdir -p $(dir $@)
$(hide) ln -sf bootanimation.zip $@
ALL_DEFAULT_INSTALLED_MODULES += $(BOOTANIMATION_SYMLINK)
大概看了一下就明白了,图片放在bootanimation.tar,解压并做了分辨率适配,然后和desc.txt一起打包,看了下desc.txt只支持3个part,我们可以按照开始,循环,结束三个part1,part2,part3来放入图片即可,更换掉原本的bootanimation.tar。
二、编译
替换完成后我们执行编译命令
make bootanimation.zip
这时候我们可以找到生成的动画zip,在这个路径下面ineageos/out/target/product/blueline/obj/BOOTANIMATION/,这时候我们整编就起作用了。简单验证的话push到/product/media/路径开机就行,总体还是比较简单的。