BootAnimation.cpp
/*
* Copyright (C) 2007 The Android Open Source Project; // namespace android
bootanimation_main.cpp
/*
* Copyright (C) 2007 The Android Open Source 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.
*/
#define LOG_TAG "BootAnimation"
#include
#include
#include
#include
#include
#include
#if defined(HAVE_PTHREADS)
# include
# include
#endif
#include "BootAnimation.h"
#include "unistd.h"
bool gUseBootVideo = false;
bool gUseBootAdv = false;
using namespace android;
// ---------------------------------------------------------------------------
int main(int argc, char** argv)
{
#if defined(HAVE_PTHREADS)
setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_DISPLAY);
#endif
char value[PROPERTY_VALUE_MAX];
/*
通过属性设置关闭开机动画
*/
property_get("debug.sf.nobootanimation", value, "0");
int noBootAnimation = atoi(value);
ALOGI_IF(noBootAnimation, "boot animation disabled");
if (!noBootAnimation) {
/*
开启线程池
*/
sp
ProcessState::self()->startThreadPool();
/*
实例化开机动画对象
*/
// create the boot animation object
sp
//add video boot
memset(value,0,sizeof(value));
property_get("persist.service.bootvideo", value, "2");
if(atoi(value)!=2)
gUseBootVideo = (atoi(value) == 1 ? true : false);
else{
memset(value,0,sizeof(value));
ALOGE("chenwh0 service.bootvideo=%d",atoi(value));
property_get("service.bootvideo", value, "0");
ALOGE("chenwh1 service.bootvideo=%d",atoi(value));
gUseBootVideo = (atoi(value) == 1 ? true : false);
}
if(gUseBootVideo){
//
// boot->setBootVolume();
property_set("service.bootvideo", "2");
}else {
//add adv boot
memset(value,0,sizeof(value));
property_get("persist.service.bootadv", value, "2");
if (atoi(value) != 2)
gUseBootAdv = (atoi(value) == 1 ? true : false);
else {
memset(value, 0, sizeof(value));
property_get("service.bootadv", value, "0");
gUseBootAdv = (atoi(value) == 1 ? true : false);
}
if(gUseBootAdv){
// boot->setBootVolume();
property_set("service.bootadv", "2");
}
}
//judge whether is shutdown bootanimation
if(argc>1){
if(strcmp(argv[1],"-shutdown")==0){
boot->isShutdown(true);
}
}
/*
将开机动画对象抛入线程池
ThreadPool继承binder类
startThreadPool()和joinThreadPool()的用法可以参考android的binder机制。
*/
IPCThreadState::self()->joinThreadPool();
}
return 0;
}
BootAnimation.h
/*
* Copyright (C) 2007 The Android Open Source 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.
*/
#ifndef ANDROID_BOOTANIMATION_H
#define ANDROID_BOOTANIMATION_H
#include
#include
#include
#include
#include
#include
#include
#include "AnimInfo.h"
class SkBitmap;
namespace android {
class Surface;
class SurfaceComposerClient;
class SurfaceControl;
// ---------------------------------------------------------------------------
/*
BootAnimation类继承了Thread类和IBinder::DeathRecipient类,几个override函数的作用如下:
onFirstRef()属于其父类RefBase,该函数在强引用sp新增引用计数時调用,就是当 有sp包装的类初始化的时候调用。
binderDied(),当对象死掉时或者其他情况导致该Binder发生结束了,就会回调binderDied()方法;
readyToRun()定义Thread执行前的初始化工作;
threadLoop()是每个线程类都要实现的,在这里定义thread的执行内容,这个函数如果返回true,则函数会不停地执行threadloop中的内容,如果这个函数返回false,则threadloop中的内容仅仅执行一次线程就会退出;
*/
class BootAnimation : public Thread, public IBinder::DeathRecipient
{
public:
BootAnimation();
virtual ~BootAnimation();
sp
//add for shutdown animation
bool mShutdown;
void isShutdown(bool shutdown);
void setBootVolume();
private:
virtual bool threadLoop();
virtual status_t readyToRun();
virtual void onFirstRef();
virtual void binderDied(const wp
struct Texture {
GLint w;
GLint h;
GLuint name;
};
struct Animation {
struct Frame {
String8 name;
FileMap* map;
char* pbuf;
size_t psize;
mutable GLuint tid;
bool operator < (const Frame& rhs) const {
return name < rhs.name;
}
};
struct Part {
int count;
int pause;
String8 path;
SortedVector frames;
bool playUntilComplete;
};
int fps;
int width;
int height;
Vector
};
status_t initTexture(Texture* texture, AssetManager& asset, const char* name);
status_t initTexture(void* buffer, size_t len);
bool android();
bool movie();
void checkExit();
status_t CheckBootAnimation();
void initAnimInfo();
bool videoEnd();
bool launcherDisplayedNow();
void checkOnePartExit();
sp
AssetManager mAssets;
Texture mAndroid[2];
int mWidth;
int mHeight;
EGLDisplay mDisplay;
EGLDisplay mContext;
EGLDisplay mSurface;
sp
sp
bool mAndroidAnimation;
ZipFileRO mZip;
AnimInfo mAnimInfo;
int mRotation;
};
// ---------------------------------------------------------------------------
}; // namespace android
#endif // ANDROID_BOOTANIMATION_H