Android DisplayPolicy增加一些动作,打开后台接口

Android DisplayPolicy增加一些动作,打开后台接口

  • 前言
  • 一、了解android全局滑动事件的拦截
  • 二、修改
    • 1.DisplayPolicy.java修改


前言

一些后台接口 界面之类的不方便打开,但是测试需要用到,这里就添加一个10秒内上拉6下,打开一个后台接口界面的


一、了解android全局滑动事件的拦截

参考该文章Android10添加 全局左右滑动返回

二、修改

1.DisplayPolicy.java修改

onSwipeFromBottom中发送MSG_OPEN_FACTORY_COUNT 判断次数,同时重置MSG_OPEN_FACTORY_COUNT_REMOVE 的 10S时间,10S内FACTORY_COUNT次数大于6才会打开界面

diff --git a/alps/frameworks/base/services/core/java/com/android/server/wm/DisplayPolicy.java b/alps/frameworks/base/services/core/java/com/android/server/wm/DisplayPolicy.java
index be79d02a47..bd14e9a781 100644
--- a/alps/frameworks/base/services/core/java/com/android/server/wm/DisplayPolicy.java
+++ b/alps/frameworks/base/services/core/java/com/android/server/wm/DisplayPolicy.java
@@ -119,6 +119,7 @@ import android.app.LoadedApk;
 import android.app.ResourcesManager;
 import android.app.StatusBarManager;
 import android.content.Context;
+import android.content.ComponentName;
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.content.res.Resources;
@@ -392,9 +393,15 @@ public class DisplayPolicy {
     private static final int MSG_DISPOSE_INPUT_CONSUMER = 3;
     private static final int MSG_ENABLE_POINTER_LOCATION = 4;
     private static final int MSG_DISABLE_POINTER_LOCATION = 5;
+       
+    private static final int MSG_OPEN_FACTORY_COUNT = 99;
+    private static final int MSG_OPEN_FACTORY_COUNT_REMOVE = 100;
+    private static final int MSG_OPEN_FACTORY = 101;
 
     private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
     private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
+       
+       private int FACTORY_COUNT=0;
 
     private class PolicyHandler extends Handler {
 
@@ -423,10 +430,35 @@ public class DisplayPolicy {
                     break;
                 case MSG_DISABLE_POINTER_LOCATION:
                     disablePointerLocation();
+                    break;
+                               case MSG_OPEN_FACTORY_COUNT:
+                    FACTORY_COUNT++;
+                                       removeMessages(MSG_OPEN_FACTORY_COUNT_REMOVE);
+                                       if(FACTORY_COUNT>5){
+                                               sendEmptyMessage(MSG_OPEN_FACTORY_COUNT_REMOVE);
+                                               sendEmptyMessage(MSG_OPEN_FACTORY);
+                                       }else{
+                                               sendEmptyMessageDelayed(MSG_OPEN_FACTORY_COUNT_REMOVE,10000);
+                                       }
+                    break;
+                               case MSG_OPEN_FACTORY_COUNT_REMOVE:
+                    FACTORY_COUNT=0;
+                    break;                     
+                               case MSG_OPEN_FACTORY:
+                    openFactoryApp();
                     break;
             }
         }
     }
+       
+       private void openFactoryApp(){
+               Intent intent = new Intent();  
+               intent.setComponent(new ComponentName("xxxxx","xxxxxx"));
+               intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+               mContext.startActivityAsUser(intent,UserHandle.CURRENT);
+       }
 
     DisplayPolicy(WindowManagerService service, DisplayContent displayContent) {
         mService = service;
@@ -477,6 +509,7 @@ public class DisplayPolicy {
                         @Override
                    public void onSwipeFromBottom() {
						Slog.i("clifetest","DisplayPolicy onSwipeFromBottom");
                        if (mNavigationBar != null && mNavigationBarPosition == NAV_BAR_BOTTOM) {
                            requestTransientBars(mNavigationBar);
                        }
+						mHandler.sendEmptyMessage(MSG_OPEN_FACTORY_COUNT);
                    }
 

你可能感兴趣的:(android)