如何根据包名屏蔽全面屏手势

在某个应用中可以通过如下修改拦截手势导航:

在EdgeBackGestureHandler中新增对包名的获取方法;

在下面mAllowGesture的判断条件中新增对包名的判断。

diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/EdgeBackGestureHandler.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/EdgeBackGestureHandler.java
old mode 100644
new mode 100755
index 304fe0090e77..a809600728a3
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/EdgeBackGestureHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/EdgeBackGestureHandler.java
@@ -513,7 +513,8 @@ public class EdgeBackGestureHandler extends CurrentUserTracker implements Displa
             mAllowGesture = !mDisabledForQuickstep && mIsBackGestureAllowed
                     && !mGestureBlockingActivityRunning
                     && !QuickStepContract.isBackGestureDisabled(mSysUiFlags)
-                    && isWithinTouchRegion((int) ev.getX(), (int) ev.getY());
+                    && isWithinTouchRegion((int) ev.getX(), (int) ev.getY())
+                    && !"xxxxxxxxx".equals(getPkgName(mContext));
             if (mAllowGesture) {
                 mEdgeBackPlugin.setIsLeftPanel(mIsOnLeftEdge);
                 mEdgeBackPlugin.onMotionEvent(ev);
@@ -658,6 +659,17 @@ public class EdgeBackGestureHandler extends CurrentUserTracker implements Displa
         proto.edgeBackGestureHandler.allowGesture = mAllowGesture;
     }

+    private String getPkgName(Context context) {
+        try {
+            ActivityManager am = context.getSystemService(ActivityManager.class);
+            List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
+            return tasks.get(0).topActivity.getPackageName();
+        } catch (Exception e) {
+            //ignore
+        }
+        return "";
+    }
+
     class SysUiInputEventReceiver extends InputEventReceiver {
         SysUiInputEventReceiver(InputChannel channel, Looper looper) {
             super(channel, looper);
评论0 评论

你可能感兴趣的:(展锐android,android,java,android,studio)