introduce
In the previous article, I introduced how to disable the status bar dropdown in Android 11, but I missed a point. The status bar can still be dropdown in the lock screen.
scenario
Power off the battery screen, in the lock screen interface, slide at the top, the status bar can be pulled down.
The solution
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java
class NotificationPanelViewController.java{
@Override
protected TouchHandler createTouchHandler(a) {
return new TouchHandler() {
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (mBlockTouches || mQsFullyExpanded && mQs.disallowPanelTouches()) {
return false;
}
/ / code 1
if (isStatusBarDragDownProhibited()) {
return false;
}
initDownStates(event);
// Do not let touches go to shade or QS if the bouncer is visible,
// but still let user swipe down to expand the panel, dismissing the bouncer.
if (mStatusBar.isBouncerShowing()) {
return true;
}
if (mBar.panelEnabled() && mHeadsUpTouchHelper.onInterceptTouchEvent(event)) {
mMetricsLogger.count(COUNTER_PANEL_OPEN, 1);
mMetricsLogger.count(COUNTER_PANEL_OPEN_PEEK, 1);
return true;
}
if(! shouldQuickSettingsIntercept(mDownX, mDownY,0)
&& mPulseExpansionHandler.onInterceptTouchEvent(event)) {
return true;
}
if(! isFullyCollapsed() && onQsIntercept(event)) {return true;
}
return super.onInterceptTouchEvent(event);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
boolean dragDownProhibited = isStatusBarDragDownProhibited();
/ / code 2
if(dragDownProhibited && mBarState ! = StatusBarState.KEYGUARD) {return false;
}
if(mBlockTouches || (mQsFullyExpanded && mQs ! =null
&& mQs.disallowPanelTouches())) {
return false;
}
// Do not allow panel expansion if bouncer is scrimmed, otherwise user would be able
// to pull down QS or expand the shade.
if (mStatusBar.isBouncerShowingScrimmed()) {
return false;
}
// Make sure the next touch won't the blocked after the current ends.
if (event.getAction() == MotionEvent.ACTION_UP
|| event.getAction() == MotionEvent.ACTION_CANCEL) {
mBlockingExpansionForCurrentTouch = false;
}
// When touch focus transfer happens, ACTION_DOWN->ACTION_UP may happen immediately
// without any ACTION_MOVE event.
// In such case, simply expand the panel instead of being stuck at the bottom bar.
if (mLastEventSynthesizedDown && event.getAction() == MotionEvent.ACTION_UP) {
expand(true /* animate */);
}
initDownStates(event);
if(! mIsExpanding && ! shouldQuickSettingsIntercept(mDownX, mDownY,0)
&& mPulseExpansionHandler.onTouchEvent(event)) {
// We're expanding all the other ones shouldn't get this anymore
return true;
}
if(mListenForHeadsUp && ! mHeadsUpTouchHelper.isTrackingHeadsUp() && mHeadsUpTouchHelper.onInterceptTouchEvent(event)) { mMetricsLogger.count(COUNTER_PANEL_OPEN_PEEK,1);
}
boolean handled = false;
if((! mIsExpanding || mHintAnimationRunning) && ! mQsExpanded && mBarState ! = StatusBarState.SHADE && ! mDozing) { handled |= mAffordanceHelper.onTouchEvent(event); }if (mOnlyAffordanceInThisMotion) {
return true;
}
handled |= mHeadsUpTouchHelper.onTouchEvent(event);
/ / code 3
if(! mHeadsUpTouchHelper.isTrackingHeadsUp() && handleQsTouch(event)) {return true;
}
if (event.getActionMasked() == MotionEvent.ACTION_DOWN && isFullyCollapsed()) {
mMetricsLogger.count(COUNTER_PANEL_OPEN, 1);
updateVerticalPanelPosition(event.getX());
handled = true;
}
handled |= super.onTouch(v, event);
return !mDozing || mPulsing || handled;
}
};
}
/ / code 4
public void setQsExpansionEnabled(boolean qsExpansionEnabled) {
if(isStatusBarDragDownProhibited()){
qsExpansionEnabled = false;
}
mQsExpansionEnabled = qsExpansionEnabled;
if (mQs == null) return;
mQs.setHeaderClickable(qsExpansionEnabled);
}
private boolean isStatusBarDragDownProhibited(a) {
return SystemProperties.getBoolean("persist.sys.statusbar.prohibit".false); }}Copy the code
Unlike the previous article, which analyzed the problem of sliding down in the middle of the screen and the status bar being able to drop down, this time the problem occurred when the screen was locked and sliding down at the top of the screen was not disabled. If the screen is not locked, the onTouch returns false and the status bar does not drop down. If you return false, no other gestures will be processed. If you lock a screen, you will not be able to swipe up and show the desktop, so I added a condition for the screen to be unlocked. But in this way, the status bar is not successfully blocked. SetQsExpansionEnabled: setQsExpansionEnabled = false if screen lock is disabled; The mQs header will then be set to non-clickable, and mQsExpansionEnabled = false, which declares the status bar not to be expanded.