Android 10 如何在通知栏下拉状态栏会暂停第三方应用播放视频

前言

在第三方视频类APP在进行播放时,若是下拉通知栏则会让播放暂停,对于第三方应用我们是没有代码,只能在源码中去拦截该分发焦点的地方。
原因:通知栏和系统弹窗弹出时会暂时获取窗口焦点,而并不会pause前台的activity(取消则会让前台activity重新获取焦点)

代码路径

frameworks/basecore/java/android/view/ViewRootImpl.java

修改记录

在ViewRootImpl.java文件中handleWindowFocusChanged()方法来分发窗口焦点

diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 3cd2b1e8500..218213ee251 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -118,7 +118,6 @@ import com.android.internal.util.Preconditions;
 import com.android.internal.view.BaseSurfaceHolder;
 import com.android.internal.view.RootViewSurfaceTaker;
 import com.android.internal.view.SurfaceCallbackHelper;

 import java.io.FileDescriptor;
 import java.io.IOException;
 import java.io.OutputStream;
@@ -130,7 +129,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Queue;
 import java.util.concurrent.CountDownLatch;

 /**
  * The top of a view hierarchy, implementing the needed protocol between View
  * and the WindowManager.  This is for the most part an internal implementation
@@ -2906,7 +2905,9 @@ public class ViewRootImpl extends AbsViewRootImpl implements ViewParent,
             }
             if (mView != null) {
                 mAttachInfo.mKeyDispatchState.reset();
-                mView.dispatchWindowFocusChanged(hasWindowFocus);
+                if ("根据包名类名来过滤是否分发焦点") {
+                    mView.dispatchWindowFocusChanged(hasWindowFocus);
+                }
                 mAttachInfo.mTreeObserver.dispatchOnWindowFocusChange(hasWindowFocus);
                 if (mAttachInfo.mTooltipHost != null) {
                     mAttachInfo.mTooltipHost.hideTooltip();

你可能感兴趣的:(Andoid10,系统定制化开发系列,android,java,开发语言)