Android Q自定义开关机动画

Android Q自定义开关机动画

====== Step 1: Enable MtkBootanimation ======

/vendor/mediatek/proprietary/operator/frameworks/bootanimation/
Rename Android_disable.mk to Android.mk 

/vendor/mediatek/proprietary/operator/frameworks/bootanimation/MtkBootanimation/
Rename Android_disable.mk to Android.mk 

/frameworks/base/cmds/bootanimation/
Rename Android.bp to Android.bp-

====== Step 2: Configure MtkBootanimation lib and exe ======

/vendor/mediatek/proprietary/operator/frameworks/bootanimation/MtkBootanimation/Android.mk

#####add by songhui for Bootanimation start 
include $(BUILD_EXECUTABLE)
####
#ifeq (OP01,$(word 1,$(subst _, ,$(OPTR_SPEC_SEG_DEF))))
#    ifeq ($(strip $(MTK_BSP_PACKAGE)), yes)
#        include $(BUILD_EXECUTABLE)
#    endif
#else ifeq (OP02,$(word 1,$(subst _, ,$(OPTR_SPEC_SEG_DEF))))
#    ifeq ($(strip $(MTK_BSP_PACKAGE)), yes)
#        include $(BUILD_EXECUTABLE)
#    endif
#else ifeq (OP09,$(word 1,$(subst _, ,$(OPTR_SPEC_SEG_DEF))))
#    ifeq ($(strip $(MTK_BSP_PACKAGE)), yes)
#        include $(BUILD_EXECUTABLE)
#    endif
#    endif
####
#####add by songhui for Bootanimation end

# libbootanimation
# ===========================================================


+LOCAL_SHARED_LIBRARIES += libterservice
+LOCAL_C_INCLUDES += $(MTK_PATH_SOURCE)/hardware/terservice/include/


##### add by songhui for Bootanimation start
include $(BUILD_SHARED_LIBRARY)
#####
#ifeq (OP01,$(word 1,$(subst _, ,$(OPTR_SPEC_SEG_DEF))))
#    ifeq ($(strip $(MTK_BSP_PACKAGE)), yes)
#include $(BUILD_SHARED_LIBRARY)
#    endif
#else ifeq (OP02,$(word 1,$(subst _, ,$(OPTR_SPEC_SEG_DEF))))
#    ifeq ($(strip $(MTK_BSP_PACKAGE)), yes)
#        include $(BUILD_SHARED_LIBRARY)
#endif
#else ifeq (OP09,$(word 1,$(subst _, ,$(OPTR_SPEC_SEG_DEF))))
#    ifeq ($(strip $(MTK_BSP_PACKAGE)), yes)
#        include $(BUILD_SHARED_LIBRARY)
#    endif
#endif
#####add by songhui for Bootanimation end

====== Step 3: Add resources ======

生成自定义bootanimation.zip和shutanimation.zip,并修改Makefile将resource文件放至目录system\media\,参考写法:

$(LOCAL_PATH)/bootanimation.zip:system/media/bootanimation.zip
$(LOCAL_PATH)/shutanimation.zip:system/media/shutanimation.zip

具体改法请参考FAQ03051(包括开关机铃声文件生成),动画文件格式要求请参考FAQ10590。

====== Step 4: Enable Shutdown Animation 以及关机/重启时间控制======

/vendor/mediatek/proprietary/frameworks/base/services/core/java/com/mediatek/server/MtkShutdownThread.java

    ///added for Shutdown animation @{
    -private static final int MIN_SHUTDOWN_ANIMATION_PLAY_TIME = 5 * 1000;
    +private static int MIN_SHUTDOWN_ANIMATION_PLAY_TIME = 5 * 1000;

    @Override
    protected boolean mIsShowShutdownSysui() {
+        if(SystemProperties.getInt("persist.sys.shutanimation", 0) == 0){
+            return true;
+        } else
        // for Shutdown animation
        if(isCustBootAnim()== ANIMATION_MODE) {
            //Show Animation ,No Sysui.
            return false;
        }
        // Show Shutdown SysUI
        return true;
    }

    // added for Shutdown animation
    private void shutdownAnimationService() {
        if(isCustBootAnim()!= ANIMATION_MODE) {
                return;
        }
        /* M: fix shutdown animation timing issue */
        Log.i(TAG, "set service.shutanim.running to 1");
        SystemProperties.set("service.shutanim.running", "1");

        //*/ hct.sjt, 2019-02-20, modify for reboot animation play time delay start.
+        if (((MtkShutdownThread)sInstance)
+                    .mContext.getResources().getBoolean(
+                    com.mediatek.internal.R.bool.reboot_animation_play_time_delay) || (mReboot == true)) {
+            Log.i(TAG, "hct shutdownAnimationService delayForPlayAnimation");
+            delayForPlayAnimation();
+        } else if ((mReboot == true && mReason != null && mReason.equals("recovery")) ||
                (mReboot == false)) {
            delayForPlayAnimation();
        }
    }

    private boolean showShutdownAnimation(Context context) {
+        if(SystemProperties.getInt("persist.sys.shutanimation", 0) == 0){
+            return false;
+        }
        beginAnimationTime = 0;
        if (isCustBootAnim()== ANIMATION_MODE) {
            configShutdownAnimation(context);
            // Show Shutdown Animation
            bootanimCust(context);
            return true;
        }
        return false;
    }

    private static void bootanimCust(Context context) {
        boolean isRotaionEnabled = false;
        // [MTK] fix shutdown animation timing issue
        SystemProperties.set("service.shutanim.running", "0");
        Log.i(TAG, "set service.shutanim.running to 0");
        try {
            isRotaionEnabled = Settings.System.getInt(context.getContentResolver(),
                    Settings.System.ACCELEROMETER_ROTATION, 1) != 0;
            if (isRotaionEnabled) {
                final IWindowManager wm = IWindowManager.Stub.asInterface(
                        ServiceManager.getService(Context.WINDOW_SERVICE));
                if (wm != null) {
                    wm.freezeRotation(Surface.ROTATION_0);
                }
                Settings.System.putInt(context.getContentResolver(),
                        Settings.System.ACCELEROMETER_ROTATION, 0);
                Settings.System.putInt(context.getContentResolver(),
                        MtkSettingsExt.System.ACCELEROMETER_ROTATION_RESTORE, 1);
            }
        } catch (NullPointerException ex) {
            Log.e(TAG, "check Rotation: context object is null when get Rotation");
        } catch (RemoteException e) {
            e.printStackTrace();
        }

+        // hct add for shutdown animation play time start at 2018-05-22
+        if (context.getResources().getInteger(
+                com.mediatek.internal.R.integer.shutdown_animation_play_time) != 0) {
+            MIN_SHUTDOWN_ANIMATION_PLAY_TIME = context.getResources().getInteger(
+                    com.mediatek.internal.R.integer.shutdown_animation_play_time);
+            Log.i(TAG, "hct  mtkShutdownThread bootanimCust MIN_SHUTDOWN_ANIMATION_PLAY_TIME = " + MIN_SHUTDOWN_ANIMATION_PLAY_TIME);
+        }
+        // hct add for shutdown animation play time end at 2018-05-22

        beginAnimationTime = SystemClock.elapsedRealtime() + MIN_SHUTDOWN_ANIMATION_PLAY_TIME;
        //Disable key dispatch
        try {
            final IWindowManager wm = IWindowManager.Stub.asInterface(
                    ServiceManager.getService(Context.WINDOW_SERVICE));
            if (wm != null) {
                wm.setEventDispatching(false);
            }
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        //Disable key dispatch
        startBootAnimation();
    }



    private static int getScreenTurnOffTime(Context context) {
        int screenTurnOffTime = 0;
        try {
            screenTurnOffTime = getScreenTurnOffTime();
+            // hct add for shutdown animation play time start at 2018-05-22
+            if (context.getResources().getInteger(
+                    com.mediatek.internal.R.integer.shutdown_animation_play_time) != 0) {
+                screenTurnOffTime = context.getResources().getInteger(
+                        com.mediatek.internal.R.integer.shutdown_animation_play_time);
+                Log.i(TAG, "hct screen turn off time shutdown_animation_play_time =" + context.getResources().getInteger(
+                        com.mediatek.internal.R.integer.shutdown_animation_play_time));
+            }
+            // hct add for shutdown animation play time end at 2018-05-22
            Log.i(TAG, "screen turn off time screenTurnOffTime =" + screenTurnOffTime);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return screenTurnOffTime;
    }

    public static int isCustBootAnim() {
+        int mode = DEFAULT_MODE;
+        if(mShutOffAnimation == -1) {
+            mode = ANIMATION_MODE; //Enable Shutdown Animation
+            mShutOffAnimation = mode;
+            Log.i(TAG,"mShutOffAnimation: " + mode);
+            return mode;
+        } else {
            return mShutOffAnimation;
        }
    }
}

vendor/mediatek/proprietary/frameworks / base/res/res/values/config.xml

    <integer name="shutdown_animation_play_time">6000</integer>
    <bool name="reboot_animation_play_time_delay">true</bool>

vendor/mediatek/proprietary/frameworks / base/res/res/values/symbols.xml

  <java-symbol type="integer" name="shutdown_animation_play_time" />
  <java-symbol type="bool" name="reboot_animation_play_time_delay" />

====== Step5: Init AudioPath ======

vendor/mediatek/proprietary/operator/frameworks/bootanimation/MtkBootanimation/BootAnimation.cpp

#define PATH_COUNT 3
// add by songhui
#include <binder/IServiceManager.h>
#include "ITerService.h"
#define REGIONAL_BOOTANIM_GET_MNC   "persist.vendor.bootanim.mnc"
// add by songhui

    mAssets.addDefaultAssets();
	// add by songhui
//    sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(
//            ISurfaceComposer::eDisplayIdMain));
  +  sp<IBinder> dtoken(SurfaceComposerClient::getInternalDisplayToken()); 
	// add by songhui
    DisplayInfo dinfo;

   sp<MediaPlayer> mediaplayer;
	// add by songhui
 +   const char* resourcePath = initAudioPath();

void BootAnimation::initBootanimationZip() {
    ZipFileRO* zipFile = NULL;
    String8     ZipFileName;
	// add by songhui
+    char BootanimFileName[PROPERTY_VALUE_MAX];
#ifdef MSSI_MTK_CARRIEREXPRESS_PACK
    char OPTR[PROPERTY_VALUE_MAX];

====== Step6: Add mtkbootanimation Packages ======

Add mtkbootanimation packages to device.mk, and make clean before rebuild all load.

Add below codes in alps\device\mediatek$(platform_name)\device.mk

ifeq ($(strip $(HCT_BOOTANIM)), yes)
    PRODUCT_SYSTEM_DEFAULT_PROPERTIES += \
    persist.sys.bootanimation=1 
endif

ifeq ($(strip $(HCT_SHUTANIM)), yes)
    PRODUCT_SYSTEM_DEFAULT_PROPERTIES += \
    persist.sys.shutanimation=1 
endif
 
 PRODUCT_PACKAGES += mtkbootanimation \
                        libmtkbootanimation

====== Step7: 解决首次开机无铃声======
frameworks/av/services/audioflinger/Threads.cpp

                // if stream volume was successfully sent to the HAL, mLeftVolFloat == v here and we
                // remove stream volume contribution from software volume.
                if (v != 0.0f && mLeftVolFloat == v) {
                   vlf = min(1.0f, vlf / v);
                   vrf = min(1.0f, vrf / v);
                   vaf = min(1.0f, vaf / v);
               }
            }
			//add by songhui begin
			char mvalue[PROPERTY_VALUE_MAX] = { 1 };
			property_get("service.bootanim.exit", mvalue, "");
			if (strcmp(mvalue,"0") == 0){
				ALOGE("bootanim volume setting");
				vlf = 0.25f;
				vrf = 0.25f;
			}
			//add by songhui end            
            // XXX: these things DON'T need to be done each time
            mAudioMixer->setBufferProvider(trackId, track);
            mAudioMixer->enable(trackId);	

device/mediatek/sepolicy/basic/non_plat/audioserver.te

# add boot audio
allow audioserver bootanim:binder call;
发布了13 篇原创文章 · 获赞 4 · 访问量 4529

猜你喜欢

转载自blog.csdn.net/a785722173/article/details/103557038