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



    前言

    一些后台接口 界面之类的不方便打开,但是测试需要用到,这里就添加一个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);
                        }
     
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
  • 相关阅读:
    Android 优化 - 磁盘缓存DiskLruCache
    docker 部署 ES集群
    43 mysql insert select 的实现
    Easyui常用语法 Combobox
    数据结构--选择排序
    学无止境,资深架构师—到底是如何阅读JDK源码的?
    云扩RPA携手中联教育引领财务机器人教学创新
    【极简python】第四章 列表,字典,元组
    数据结构与算法 | 第二章:线性表
    Java中set的实现类
  • 原文地址:https://blog.csdn.net/xuyewen288/article/details/133884193