user media
group audio
disabled
oneshot
//关机铃声服务 /system/media/shutdownsound是关机铃声
service shutdownsound /system/bin/mplayer /system/media/shutdownsound
user media
group audio
disabled
oneshot
//定义了一个bootanim的服务,对应执行/system/bin/bootanimation
//disabled 表示init进程创建只是创建它,但不立刻执行
//oneshot 表示该服务只执行一次
service bootanim /system/bin/bootanimation
user graphics
group graphics
disabled
oneshot
当android系统boot时,开始加载动画和开机铃声,其代码位于
//源文件SurfaceFlinger.cpp
status_t SurfaceFlinger::readyToRun() {
// start boot animation service
property\_set("ctl.start", "bootanim");//注
{
char value\[PROPERTY\_VALUE\_MAX\];
property\_get("persist.sys.profile.silent", value, "0");
if (atoi(value)== 0){
LOGI("start:persist.sys.profile.silent is soundable");
// start startupsound service
property\_set("ctl.start","startupsound");//注
} else {
LOGI("start:persist.sys.profile.silent is silent");
}
}
return NO\_ERROR;
}
当Android完成boot后,关闭动画和开机铃声,代码位于
//源文件SurfaceFlinger.cpp
void SurfaceFlinger::bootFinished() {
const nsecs_t now = systemTime();
const nsecs_t duration = now - mBootTime;
LOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) );
mBootFinished = true;
//stop bootanim service
property_set("ctl.stop", "bootanim");
char value[PROPERTY_VALUE_MAX];
property_get("persist.sys.profile.silent", value, "0");
if (atoi(value)== 0){
LOGI("stop:persist.sys.profile.silent is soundable");
//stop startupsound service
property\_set("ctl.stop","startupsound");
} else {
LOGI("stop:persist.sys.profile.silent is silent");
}
}
如何理解ctr.start和ctr.stop系统属性?
每一项服务必须在/init.rc中定义.Android系统启动时,init守护进程将解析init.rc和启动属性服务,属性“
ctl.start ”和“ ctl.stop ”是用来启动和停止服务的。一旦收到设置“ ctrl.start
”属性的请求,属性服务将使用该属性值作为服务名找到该服务,启动该服务。这项服务的启动结果将会放入“ init.svc.<服务名>“属性中
。客户端应用程序可以轮询那个属性值,以确定结果。想更深入了解Android property系统可以参考博文《(翻译)Android属性系统》。
property\_set("ctl.start",ServiceName);就是启动ServiceName服务(在init.rc中定义);
property\_set("ctl.stop",ServiceName)相对的是关闭ServiceName服务。
A启动动画服务
由于开机动画和关机动画除了播放的动画文件不同,其他的完全一致,这里重复利用/system/bin/bootanimation代码,
仿照开机动画服务,我们新定义关机动画
service shutdownanim /system/bin/bootanimation -shutdown
user graphics
group graphics
disabled
oneshot
唯一要注意的是关机动画使用的/system/bin/bootanimation带了-shutdown参数,这个参数用来区分加载的动画文件为开机还是关机动画。当bootanimation服务启动时,进入/frameworks/base/cmds/bootanimation/bootanimation\_main.cpp主函数main
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);
LOGI\_IF(noBootAnimation, "boot animation disabled");
if (!noBootAnimation) {
sp<ProcessState> proc(ProcessState::self());
ProcessState::self()\->startThreadPool();
// create the animation object
sp<BootAnimation> boot = new BootAnimation();
//根据是否有参数,来设置动画对象的isShutdown属性
if (argc > 0) {
if (strcmp(argv\[0\], "-shutdown")==0) {
boot\->isShutdown(true);
最后
下面是辛苦给大家整理的学习路线,有需要的可以点击这里免费获取