1.监听apk启动和退出有很多方法,比如topActivity,或者在ActivityThread.java中监听等;但是这些都会存在一些问题,或在部分情况监听不到,或者错误(如自由窗口的apk无法监听退出)
2. WindowManagerService.java 中有REPORT_FOCUS_CHANGE,可以监听focus的变化,并且lastFocus和newFocus可以看到怎样的apk切换,也可以监听到apk不同类名界面的切换
--- a/sprd/frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/sprd/frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -315,7 +315,7 @@ import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
-
+import android.util.Log;
/** {@hide} */
public class WindowManagerService extends AbsWindowManagerService
implements Watchdog.Monitor, WindowManagerPolicy.WindowManagerFuncs {
@@ -4830,7 +4830,7 @@ public class WindowManagerService extends AbsWindowManagerService
final DisplayContent displayContent = (DisplayContent)