android4.4 添加关机音乐关机动画

来源:互联网 发布:java实现第三方登录 编辑:程序博客网 时间:2024/06/04 08:38

4.4的开关机动画的服务为bootanimation (全志allwinner平台下)

init.rc里面有下面一行,开机时候会调用此服务 service bootanim /system/bin/bootanimation。surfaceflinger里面用过ctrl_start 调用服务,详细可以搜索代码。

虽然bootanim名称为开机动画,但代码里面其实包含了关机动画和关机音乐相关的内容。

51         property_get("sys.shutdown_animation", cmd, "boot");                                       
52         const char* url = "/system/media/boot.wav";                                                
53         if (!strcmp(cmd, "shutdown")) {           
54             url = "/system/media/shutdown.wav";   
55         }                                         

sys.shutdown_animation 属性值为shutdown时,播放shuudown.wav


关机音乐在哪里启动bootanimation 并设置属性文件sys.shutdown_animation 为shutdown呢?

./frameworks/base/services/java/com/android/server/power/ShutdownThread.java中的beginShutdownSequence(Context context) 函数中

373         // throw up an indeterminate system dialog to indicate radio is
374         // shutting down.
375         final ProgressDialog pd = new ProgressDialog(context);
376         pd.setTitle(context.getText(com.android.internal.R.string.power_off));
377         pd.setMessage(context.getText(com.android.internal.R.string.shutdown_progress));
378         pd.setIndeterminate(true);
379         pd.setCancelable(false);
380         pd.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
381
382         int shutdownduration = SystemProperties.getInt("persist.sys.shutdownduration", 0);
383         if (shutdownduration <= 0) pd.show();

persist.sys.shutdownduration需要设置成>0,设置成1.

如下代码会设置sys.shutdown_animation为shutdown,并开启bootanim服务。

446     public void run() {
447         BroadcastReceiver br = new BroadcastReceiver() {
448             @Override public void onReceive(Context context, Intent intent) {
449                 // We don't allow apps to cancel this, so ignore the result.
450                 actionDone();
451             }
452         };
453         int shutdownduration = SystemProperties.getInt("persist.sys.shutdownduration", 0);
454         if(!mBootFastEnable){
455             int value = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.ACCELER    OMETER_ROTATION, 0, UserHandle.USER_CURRENT);
456             int rotation = Surface.ROTATION_0;
457             long startTime = 0;
458             if (shutdownduration > 0) {
459                 IWindowManager mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("w    indow"));
460                 if (mWindowManager != null) {
461                     try{
462                         rotation = mWindowManager.getRotation();
463                         mWindowManager.freezeRotation(Surface.ROTATION_0);
464                         mWindowManager.updateRotation(true, true);
465                     } catch (RemoteException e) {
466                         e.printStackTrace();
467                     }
468                 }
469                 if (rotation != Surface.ROTATION_0) {

470                     SystemClock.sleep(600);
471                 } else {
472                     SystemClock.sleep(200);
473                 }
474                 startTime = SystemClock.uptimeMillis();
475                 SystemProperties.set("sys.shutdown_animation", "shutdown"); //设置sys.shutdown_animation值为shutdown,在bootanim服务中会用到次书属性判断是开机还是关机
476                 SystemProperties.set("service.bootanim.exit", "0");
477                 SystemProperties.set("ctl.start", "bootanim");
478             }

。。。。。。。。。。。。。。。。。

577             if (shutdownduration > 0) {
578                 long sleepTime = SystemClock.uptimeMillis() - startTime; //保证anim运行时间shutdownduration,sleep 确保anim运行完。
579                 sleepTime = shutdownduration - sleepTime;
580                 if (sleepTime > 0)
581                     SystemClock.sleep(sleepTime);
582                 if (value == 0) {
583                     Settings.System.putInt(mContext.getContentResolver(), Settings.System.USER_ROTATION, rot    ation);
584                 }
585                 Settings.System.putIntForUser(mContext.getContentResolver(), Settings.System.ACCELEROMETER_R    OTATION, value, UserHandle.USER_CURRENT);
586             }
587                 rebootOrShutdown(mReboot, mRebootReason);

总结:

设置persist.sys.shutdownduration属性的值即可调用关机动画和音乐,属性值对应ms,为anim运行的时间。比如播放音乐的时间,播放动画的时间。


0 0