Platform: RK3288
OS: Android 7.1.2
Kernel: v4.4.143
需求:
Android系统项目定制开机动画,自定义的开机动画需保存在/system/media/bootanimation.zip,终端在横竖屏状态加载不同的bootanimation.zip,以实现在横竖屏的LOGO都能正常显示不拉伸。
解决:
1、制作横屏和竖屏的bootanimation.zip
方法1:
路径:/device/rockchip/rk3288/bootanimation
在源码里添加放置两个bootanimation.zip,举例命名为bootanimation_h.zip和bootanimation_v.zip分别代表横屏的LOGO和竖屏的LOGO;
路径:/device/rockchip/rk3288/rk3288.mk
编译时会将/device/rockchip/rk3288/bootanimation/的两个压缩包拷贝到system/media/目录下
PRODUCT_COPY_FILES += device/rockchip/rk3288/bootanimation/bootanimation_v.zip:system/media/bootanimation_v.zip
PRODUCT_COPY_FILES += device/rockchip/rk3288/bootanimation/bootanimation_h.zip:system/media/bootanimation_h.zip
方法2:
路径:out/target/product/rk3288/system/media
直接在此路径放置压缩包,打包时会自动存到系统/system/media/目录下
2、通过判断横竖屏执行不同的bootanimation
diff --git a/cmds/bootanimation/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp
index 24c8fa4..86bb671 100755
--- a/cmds/bootanimation/BootAnimation.cpp
+++ b/cmds/bootanimation/BootAnimation.cpp
@@ -64,13 +64,17 @@
namespace android {
+#define CONFIG_DATA_FILES_PLAYING
static const char OEM_BOOTANIMATION_FILE[] = "/oem/media/bootanimation.zip";
-static const char SYSTEM_BOOTANIMATION_FILE[] = "/system/media/bootanimation.zip";
+static const char SYSTEM_BOOTANIMATION_ROTATION_HENG_FILE[] = "/system/media/bootanimation_h.zip";
+static const char SYSTEM_BOOTANIMATION_ROTATION_SHU_FILE[] = "/system/media/bootanimation_v.zip";
static const char SYSTEM_SHUTDOWNANIMATION_FILE[] = "/system/media/shutdownanimation.zip";
static const char SYSTEM_ENCRYPTED_BOOTANIMATION_FILE[] = "/system/media/bootanimation-encrypted.zip";
//support boot video
static const char DATA_BOOTVIDEO_FILE[] = "/data/local/bootanimation.ts";
-static const char SYSTEM_BOOTVIDEO_FILE[] = "/system/media/bootanimation.ts";
+//static const char SYSTEM_BOOTVIDEO_FILE[] = "/system/media/bootanimation.ts";
+
+static const char SYSTEM_BOOTVIDEO_FILE[] = "/system/media/bootanimation.mp4";
static const char SYSTEM_DATA_DIR_PATH[] = "/data/system";
static const char SYSTEM_TIME_DIR_NAME[] = "time";
static const char SYSTEM_TIME_DIR_PATH[] = "/data/system/time";
@@ -97,6 +101,8 @@ static const int ANIM_ENTRY_NAME_MAX = 256;
static constexpr size_t TEXT_POS_LEN_MAX = 16;
static const char BOOT_COMPLETED_PROP_NAME[] = "sys.boot_completed";
static const char BOOTREASON_PROP_NAME[] = "ro.boot.bootreason";
+static int mBootLogoMode = 0;
+String8 systemBootanimationFile;
// bootreasons list in "system/core/bootstat/bootstat.cpp".
static const std::vector PLAY_SOUND_BOOTREASON_BLACKLIST {
"kernel_panic",
@@ -116,6 +122,11 @@ BootAnimation::BootAnimation(bool shutdown) : Thread(false), mClockEnabled(true)
mReverseAxis = false;
mVideoFile = NULL;
mVideoAnimation = false;
+ char property[PROPERTY_VALUE_MAX];
+ if (property_get("ro.sf.hwrotation", property, "0") > 0) {
+ mBootLogoMode = atoi(property);
+ }
if(mShutdown){
sp dtoken(SurfaceComposerClient::getBuiltInDisplay(
ISurfaceComposer::eDisplayIdMain)); // primary_display_token
@@ -343,11 +354,23 @@ status_t BootAnimation::readyToRun() {
mFlingerSurfaceControl = control;
mFlingerSurface = s;
+ mDataZipAnimtaion = false;
+
// If the device has encryption turned on or is in process
// of being encrypted we show the encrypted boot animation.
char decrypt[PROPERTY_VALUE_MAX];
property_get("vold.decrypt", decrypt, "");
bool encryptedAnimation = atoi(decrypt) != 0 || !strcmp("trigger_restart_min_framework", decrypt);
+ if (mBootLogoMode == 0||mBootLogoMode == 180) {
+ ALOGE("SYSTEM_BOOTANIMATION_ROTATION_HENG_FILE");
+ systemBootanimationFile = SYSTEM_BOOTANIMATION_ROTATION_HENG_FILE;
+ }else if(mBootLogoMode == 90||mBootLogoMode == 270){
+ ALOGE("GCC SYSTEM_BOOTANIMATION_ROTATION_SHU_FILE");
+ systemBootanimationFile = SYSTEM_BOOTANIMATION_ROTATION_SHU_FILE;
+ }else {
+ ALOGE("SYSTEM_BOOTANIMATION_ROTATION_HENG_FILE");
+ systemBootanimationFile = SYSTEM_BOOTANIMATION_ROTATION_HENG_FILE;
+ }
if (!mShutdown) {
if (encryptedAnimation && (access(SYSTEM_ENCRYPTED_BOOTANIMATION_FILE, R_OK) == 0)) {
mZipFileName = SYSTEM_ENCRYPTED_BOOTANIMATION_FILE;
@@ -355,8 +378,8 @@ status_t BootAnimation::readyToRun() {
else if (access(OEM_BOOTANIMATION_FILE, R_OK) == 0) {
mZipFileName = OEM_BOOTANIMATION_FILE;
}
- else if (access(SYSTEM_BOOTANIMATION_FILE, R_OK) == 0) {
- mZipFileName = SYSTEM_BOOTANIMATION_FILE;
+ else if (access(systemBootanimationFile, R_OK) == 0) {
+ mZipFileName = systemBootanimationFile;
}
//add for boot video
@@ -747,7 +770,7 @@ bool BootAnimation::parseAnimationDesc(Animation& animation)
part.count = 1;
part.pause = 0;
part.audioData = NULL;
- part.animation = loadAnimation(String8(SYSTEM_BOOTANIMATION_FILE));
+ part.animation = loadAnimation(String8(systemBootanimationFile));
if (part.animation != NULL)
animation.parts.add(part);
}
diff --git a/cmds/bootanimation/BootAnimation.h b/cmds/bootanimation/BootAnimation.h
index cc043bb..4f263bb 100755
--- a/cmds/bootanimation/BootAnimation.h
+++ b/cmds/bootanimation/BootAnimation.h
@@ -160,6 +160,7 @@ private:
bool mSystemBoot;
String8 mZipFileName;
bool mVideoAnimation;
+ bool mDataZipAnimtaion;
char* mVideoFile;
nsecs_t mStartbootanimaTime;
int mBootVideoTime;
原理:
---后面补充---