Android13 SplashScreen功能源码分析、移除和客制化
SplashScreen功能从android12开始添加,本文章分析了SplashScreen的启动流程,整体和独立App移除方案以及客制化 获取SplashScreen的window名称 在开发者模式将Animation scale调成10x,adb shell输入命令: dumpsys window windows 获取结果,以下为Splash Screen对应的Window信息 Window #8 Window{9d4659b u0 Splash Screen com.google.android.gm}: mDisplayId=0 rootTaskId=12 mSession=Session{3fbadb0 1074:u0a10116} mClient=android.os.BinderProxy@d8c05aa mOwnerUid=10116 showForAllUsers=true package=com.google.android.gm appop=NONE mAttrs={(0,0)(fillxfill) sim={adjust=pan} ty=APPLICATION_STARTING fmt=TRANSLUCENT wanim=0x7f1603e6 fl=NOT_FOCUSABLE NOT_TOUCHABLE LAYOUT_IN_SCREEN LAYOUT_INSET_DECOR ALT_FOCUSABLE_IM HARDWARE_ACCELERATED DRAWS_SYSTEM_BAR_BACKGROUNDS pfl=SHOW_FOR_ALL_USERS USE_BLAST APPEARANCE_CONTROLLED FIT_INSETS_CONTROLLED apr=LIGHT_STATUS_BARS LIGHT_NAVIGATION_BARS bhv=DEFAULT fitSides=} Requested w=3840 h=2160 mLayoutSeq=1595 mBaseLayer=21000 mSubLayer=0 mToken=ActivityRecord{2e6ad9e u0 com.google.android.gm/.ConversationListActivityGmail} t12} mActivityRecord=ActivityRecord{2e6ad9e u0 com.google.android.gm/.ConversationListActivityGmail} t12} mAppDied=false drawnStateEvaluated=true mightAffectAllDrawn=true mViewVisibility=0x0 mHaveFrame=true mObscured=false mGivenContentInsets=[0,0][0,0] mGivenVisibleInsets=[0,0][0,0] mFullConfiguration={1.0 ?mcc?mnc [en_US] ldltr sw720dp w1280dp h696dp 480dpi lrg long land finger qwerty/v/v dpad/v winConfig={ mBounds=Rect(0, 0 – 3840, 2160) mAppBounds=Rect(0, 0 – 3840, 2160) mMaxBounds=Rect(0, 0 – 3840, 2160) mDisplayRotation=ROTATION_0 mWindowingMode=fullscreen mDisplayWindowingMode=fullscreen mActivityType=standard mAlwaysOnTop=undefined mRotation=ROTATION_0} s.1 fontWeightAdjustment=0} mLastReportedConfiguration={1.0 ?mcc?mnc [en_US] ldltr sw720dp w1280dp h696dp 480dpi lrg long land finger qwerty/v/v dpad/v winConfig={ mBounds=Rect(0, 0 – 3840, 2160) mAppBounds=Rect(0, 0 – 3840, 2160) mMaxBounds=Rect(0, 0 – 3840, 2160) mDisplayRotation=ROTATION_0 mWindowingMode=fullscreen mDisplayWindowingMode=fullscreen mActivityType=standard mAlwaysOnTop=undefined mRotation=ROTATION_0} s.1 fontWeightAdjustment=0} mHasSurface=true isReadyForDisplay()=true mWindowRemovalAllowed=false Frames: parent=[0,0][3840,2160] display=[0,0][3840,2160] frame=[0,0][3840,2160] last=[0,0][3840,2160] insetsChanged=false surface=[0,0][0,0] WindowStateAnimator{28bc62d Splash Screen com.google.android.gm}: mSurface=Surface(name=Splash Screen com.google.android.gm)/@0xfb34762 Surface: shown=true layer=0 alpha=1.0 rect=(0.0,0.0) transform=(1.0, 0.0, 0.0, 1.0) mDrawState=HAS_DRAWN mLastHidden=false mEnterAnimationPending=false mSystemDecorRect=[0,0][0,0] mForceSeamlesslyRotate=false seamlesslyRotate: pending=null isOnScreen=true isVisible=true keepClearAreas: restricted=[], unrestricted=[] 以上获取window名字关键字Splash Screen,在整机代码库framework/base目录下搜索: grep -nr "Splash Screen" 搜索结果:根据搜索结果,定位为framework/base/libs/WindowManager/Shell/src/com/android/wm/shell/startingsurface/StaringSurfaceDrawer.java 311行。 /** * Called when a task need a splash screen starting window. * * @param suggestType The suggestion type to draw the splash screen. */ void addSplashScreenStartingWindow(StartingWindowInfo windowInfo, IBinder appToken, @StartingWindowType int suggestType) { … params.setTitle("Splash Screen " + activityInfo.packageName); // TODO(b/173975965) tracking performance // Prepare the splash screen content view on splash screen worker thread in parallel, so the // content view won't be blocked by binder call like addWindow and relayout. // 1. Trigger splash screen worker thread to create SplashScreenView before/while // Session#addWindow. // 2. Synchronize the SplashscreenView to splash screen thread before Choreographer start … Read more