android10 禁止下拉状态栏

时间: 2023-07-11 admin IT培训

android10 禁止下拉状态栏

android10 禁止下拉状态栏

需求:android10 禁止下拉状态栏,也就是禁止下拉如下图的快速设置面板(
Quick settings panel,也叫QS面板)

修改后:怎么拉都拉不下来,包括锁屏页面和正常桌面都无法下拉状态栏。

修改点:

frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java

    @ShadeViewRefactor(RefactorComponent.INPUT)private final DragDownCallback mDragDownCallback = new DragDownCallback() {/* Only ever called as a consequence of a lockscreen expansion gesture. */@Overridepublic boolean onDraggedDown(View startingChild, int dragLengthY) {//加上这个if即可在滑动锁屏页面禁止下拉if (mStatusBarState == StatusBarState.KEYGUARD) {return false;}if (mStatusBarState == StatusBarState.KEYGUARD&& hasActiveNotifications()) {mLockscreenGestureLogger.write(MetricsEvent.ACTION_LS_SHADE,(int) (dragLengthY / mDisplayMetrics.density),0 /* velocityDp - N/A */);if (!mAmbientState.isDozing() || startingChild != null) {// We have notifications, go to locked shade.mShadeController.goToLockedShade(startingChild);if (startingChild instanceof ExpandableNotificationRow) {ExpandableNotificationRow row = (ExpandableNotificationRow) startingChild;row.onExpandedByGesture(true /* drag down is always an open */);}}return true;} else if (mDynamicPrivacyController.isInLockedDownShade()) {mStatusbarStateController.setLeaveOpenOnKeyguardHide(true);mStatusBar.dismissKeyguardThenExecute(() -> false /* dismissAction */,null /* cancelRunnable */, false /* afterKeyguardGone */);return true;} else {// abort gesture.return false;}}......

frameworks/base/core/java/android/app/StatusBarManager.java

    @UnsupportedAppUsagepublic void disable(int what) {//加上这行what = what | DISABLE_EXPAND;what = what | DISABLE_EXPAND;try {final int userId = Binder.getCallingUserHandle().getIdentifier();final IStatusBarService svc = getService();if (svc != null) {svc.disableForUser(what, mToken, mContext.getPackageName(), userId);}} catch (RemoteException ex) {throw ex.rethrowFromSystemServer();}}

frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java

    @Overridepublic boolean onTouchEvent(MotionEvent event) {boolean barConsumedEvent = mBar.interceptTouchEvent(event);if (DEBUG_GESTURES) {if (event.getActionMasked() != MotionEvent.ACTION_MOVE) {EventLog.writeEvent(EventLogTags.SYSUI_PANELBAR_TOUCH,event.getActionMasked(), (int) event.getX(), (int) event.getY(),barConsumedEvent ? 1 : 0);}}// return barConsumedEvent || super.onTouchEvent(event);//在这里直接return true;return true;}

参考文章:
Android9.0禁止滑动锁下拉状态栏
Android源码分析

Android10 Frameworks专栏其他文章:
android10 隐藏投影
android10 修改媒体音的默认值
android10 隐藏SystemUI锁屏下的多用户图标
android10 动态添加和隐藏一级菜单