SystemUI禁止长按Home键弹出历史应用

SystemUI中长按home键,可以最近应用程序调出最近应用程序。

公司需求需要在安全模式下屏蔽长按home键,android模式下不屏蔽。长按home键在PhoneWindowManager.java中处理的。因此查看代码如下:

 

package com.android.internal.policy.impl;
public class  PhoneWindowManager implementsWindowManagerPolicy {
 
static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
private void handleLongPressOnHome() {
       if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
           mHomeConsumed = true;
           performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS,false);
 
           if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI){
                toggleRecentApps();
           } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
                launchAssistAction();
           }
       }
}
 private void toggleRecentApps() {
       mPreloadedRecentApps = false; // preloading no longer needs to becanceled
       sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);
       try {
           IStatusBarService statusbar = getStatusBarService();
           if (statusbar != null) {
                statusbar.toggleRecentApps();//可以在此处修改
           }
       } catch (RemoteException e) {
           Slog.e(TAG, "RemoteException when showing recent apps", e);
           // re-acquire status bar service next time it is needed.
           mStatusBarService = null;
       }
    }
…..
}

在类中通过查看变量LONG_PRESS_HOME_RECENT_SYSTEM_UI,可以搜索得到与之有关的有:toggleRecentApps()、preloadRecentApps()


如上可以在PhoneWindowManager中修改,也可以在systemui中修改,因为可以直接编译,便于调试,所以我是在systemui中处理的,

package com.android.systemui.statusbar;
public abstract class BaseStatusBar extendsSystemUI implements
       CommandQueue.Callbacks {
@Override
   public void toggleRecentApps() {
       int msg = MSG_TOGGLE_RECENTS_PANEL;
       mHandler.removeMessages(msg);
       mHandler.sendEmptyMessage(msg);
    }
 
   @Override
   public void preloadRecentApps() {
       int msg = MSG_PRELOAD_RECENT_APPS;
       mHandler.removeMessages(msg);
       mHandler.sendEmptyMessage(msg);
    }
……………..
}

修改为如下:

@Override
   public void toggleRecentApps() {
             if(android模式){
                       int msg =MSG_TOGGLE_RECENTS_PANEL;
                 mHandler.removeMessages(msg);
                 mHandler.sendEmptyMessage(msg);
             }
    }
 
   @Override
   public void preloadRecentApps() {
             if(android模式){
                       int msg =MSG_PRELOAD_RECENT_APPS;
           mHandler.removeMessages(msg);
           mHandler.sendEmptyMessage(msg);
             }
    }
 


 

你可能感兴趣的:(systemui)