• MTK平台 Android4.0.3 定制关机动画


    实现效果是这样的,长按电源键弹出关机对话框,选择关机项将呈现关机动画和音乐直到正常关机完毕,下面说说具体思路及实现代码

    找到长按电源键控制代码 /frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

    1. <span style="font-size:12px;">private final Runnable mPowerLongPress = new Runnable() {  
    2.         public void run() {  
    3.             // The context isn't read  
    4.             if (mLongPressOnPowerBehavior < 0) {  
    5.                 mLongPressOnPowerBehavior = mContext.getResources().getInteger(  
    6.                         com.android.internal.R.integer.config_longPressOnPowerBehavior);  
    7.             }  
    8.             switch (mLongPressOnPowerBehavior) {  
    9.             case LONG_PRESS_POWER_NOTHING:  
    10.                 break;  
    11.             case LONG_PRESS_POWER_GLOBAL_ACTIONS:  
    12.                 mPowerKeyHandled = true;  
    13.                 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);  
    14.                 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);  
    15.                 showGlobalActionsDialog();  
    16.                 break;  
    17.             case LONG_PRESS_POWER_SHUT_OFF:  
    18.                 mPowerKeyHandled = true;  
    19.                 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);  
    20.                 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);  
    21.                 mWindowManagerFuncs.shutdown();  
    22.                 break;  
    23.             }  
    24.         }  
    25.     };  
    26. </span>  
    方法 showGlobalActionsDialog() 就是控制关机选项对话框的弹出,点击关机项控制代码在

    /frameworks/base/policy/src/com/android/internal/policy/impl/GlobalActions.java

    1. <span style="font-size:12px;">new SinglePressAction(  
    2.                     com.android.internal.R.drawable.ic_lock_power_off,  
    3.                     R.string.global_action_power_off) {  
    4.   
    5.                 public void onPress() {  
    6.                     // shutdown by making sure radio and power are handled accordingly.  
    7.                     mWindowManagerFuncs.shutdown();  
    8.                 }  
    9.   
    10.                 public boolean onLongPress() {  
    11.                     mWindowManagerFuncs.rebootSafeMode();  
    12.                     return true;  
    13.                 }  
    14.   
    15.                 public boolean showDuringKeyguard() {  
    16.                     return true;  
    17.                 }  
    18.   
    19.                 public boolean showBeforeProvisioning() {  
    20.                     return true;  
    21.                 }  
    22.             });  
    23. </span>  
    正常关机会调用此方法 mWindowManagerFuncs.shutdown(); 将弹出 “正在关机” 的弹出框, 现在我们需要在调用此方法时屏弊掉此对话框,同时播放动画和音乐,该如何做昵? 下面一步一步跟踪shutdown() 方法代码,不难发现你最终会找到这个类 /frameworks/base/services/java/com/android/server/pm/ShutdownThread.java 看看这部分代码

    1. <span style="font-size:12px;">synchronized (mEnableAnimatingSync) {  
    2.   
    3.             if(!mEnableAnimating) {  
    4.                 sInstance.mPowerManager.setBacklightBrightness(PowerManager.BRIGHTNESS_DIM);  
    5.             } else {  
    6.                 if (mShutOffAnimation) {  
    7.                     Log.e(TAG, "mIBootAnim.isCustBootAnim() is true");  
    8.                     bootanimCust();  
    9.                 } else {  
    10.                     pd = new ProgressDialog(context);  
    11.                     pd.setTitle(context.getText(com.android.internal.R.string.power_off));  
    12.                     pd.setMessage(context.getText(com.android.internal.R.string.shutdown_progress));  
    13.                     pd.setIndeterminate(true);  
    14.                     pd.setCancelable(false);  
    15.                     pd.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);  
    16.                     /* To fix video+UI+blur flick issue */  
    17.                     pd.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);  
    18.                     pd.show();  
    19.                 }  
    20.                 sInstance.mHandler.postDelayed(mDelayDim, screenTurnOffTime);   
    21.             }  
    22.         }</span>  
    很明显 mShutOffAnimation 布尔变量是控制是否显示关机动画和默认“正在关机”弹出框的枢纽所在,当它为true时会播放事先放在/system/media/下的shutanimation.和shutaudio资源,而为false时,将会弹出默认“正在关机”对话框,所以此时,要想播放动画我们只需要保证mShutOffAnimation = true就成了,那么这就好改了,可以直接在 此方法的前面默认加上 

    1. <span style="font-size:12px;">mShutOffAnimation = true;</span>  
    就成了,然后可以编译试试效果, 执行./makeMtk mm frameworks/base/services/java/  将会生成out/target/product/xxx/system/framework/services.jar , 最后通过adb push 到手机shell下 /system/framework目录,重启手机,再关机,如果不出意外的话相信此刻已经出现迹了!! 
  • 相关阅读:
    简单了解Linux文件目录
    解决GitLab的Forbidden和Nginx启动失败
    浅谈apidoc的使用
    Linux安装apidoc
    DevExpress的GridControl的实时加载数据解决方案(取代分页)
    Devexpress使用经验1
    ajax下载文件
    var str = "1,21,".TrimEnd(',');
    MSSQ调优所需用的语句
    js中替换返回json中的空格为&nbsp;
  • 原文地址:https://www.cnblogs.com/liang123/p/6325386.html
Copyright © 2020-2023  润新知