最近在搞android13的项目,之前搞过android11的Systemui禁止下拉,想着应该可以直接移植过去。直到开始着手修改发现11到13的变化还是挺大的,很多类都找不到了。于是又重新研究了下,好了废话不多说。
1.解锁状态下禁止Syatemui下拉
代码路径:\SystemUI\src\com\android\systemui\statusbar\CommandQueue.java
public boolean panelsEnabled() {
//KingYan 注释掉现有的返回 默认返回false
return false;
/** KingYan 注释掉以下代码
final int disabled1 = getDisabled1(DEFAULT_DISPLAY);
final int disabled2 = getDisabled2(DEFAULT_DISPLAY);
return (disabled1 & StatusBarManager.DISABLE_EXPAND) == 0
&& (disabled2 & StatusBarManager.DISABLE2_NOTIFICATION_SHADE) == 0
&& !ONLY_CORE_APPS;*/
}
2.禁止解锁状态下在Launcher空白区域下拉
代码路径:SystemUI/src/com/android/systemui/recents/OverviewProxyService.java
@Override
public void onStatusBarMotionEvent(MotionEvent event) {
// KingYan 注释掉以下代码
/* verifyCallerAndClearCallingIdentity("onStatusBarMotionEvent", () -> {
mCentralSurfacesOptionalLazy.get().ifPresent(centralSurfaces -> {
if (event.getActionMasked() == ACTION_DOWN) {
centralSurfaces.getPanelController().startExpandLatencyTracking();
}
mHandler.post(() -> {
int action = event.getActionMasked();
if (action == ACTION_DOWN) {
mInputFocusTransferStarted = true;
mInputFocusTransferStartY = event.getY();
mInputFocusTransferStartMillis = event.getEventTime();
centralSurfaces.onInputFocusTransfer(
mInputFocusTransferStarted, false *//* cancel *//*,
0 *//* velocity *//*);
}
if (action == ACTION_UP || action == ACTION_CANCEL) {
mInputFocusTransferStarted = false;
float velocity = (event.getY() - mInputFocusTransferStartY)
/ (event.getEventTime() - mInputFocusTransferStartMillis);
centralSurfaces.onInputFocusTransfer(mInputFocusTransferStarted,
action == ACTION_CANCEL,
velocity);
}
event.recycle();
});
});
});*/
}
3.禁止锁屏页面从中间位置(时间位置)下拉
代码路径:SystemUI/src/com/android/systemui/statusbar/LockscreenShadeTransitionController.kt
private const val SPRING_BACK_ANIMATION_LENGTH_MS = 375L
private const val RUBBERBAND_FACTOR_STATIC = 0.15f
private const val RUBBERBAND_FACTOR_EXPANDABLE = 0.5f
/**
* A class that controls the lockscreen to shade transition
*/
@SysUISingleton
class LockscreenShadeTransitionController @Inject constructor(
private val statusBarStateController: SysuiStatusBarStateController,
private val logger: LSShadeTransitionLogger,
private val keyguardBypassController: KeyguardBypassController,
private val lockScreenUserManager: NotificationLockscreenUserManager,
private val falsingCollector: FalsingCollector,
private val ambientState: AmbientState,
private val mediaHierarchyManager: MediaHierarchyManager,
private val scrimTransitionController: LockscreenShadeScrimTransitionController,
private val keyguardTransitionControllerFactory:
LockscreenShadeKeyguardTransitionController.Factory,
private val depthController: NotificationShadeDepthController,
private val context: Context,
private val splitShadeOverScrollerFactory: SplitShadeLockScreenOverScroller.Factory,
private val singleShadeOverScrollerFactory: SingleShadeLockScreenOverScroller.Factory,
wakefulnessLifecycle: WakefulnessLifecycle,
configurationController: ConfigurationController,
falsingManager: FalsingManager,
dumpManager: DumpManager
) : Dumpable {
//......省略部分代码
/**
* The touch helper responsible for the drag down animation.
*/
//KingYan 如下代码新增传入参数 statusBarStateController
val touchHelper = DragDownHelper(statusBarStateController,falsingManager, falsingCollector, this, context)
private val splitShadeOverScroller: SplitShadeLockScreenOverScroller by lazy {
splitShadeOverScrollerFactory.create(qS, nsslController)
}
private val phoneShadeOverScroller: SingleShadeLockScreenOverScroller by lazy {
singleShadeOverScrollerFactory.create(nsslController)
}
//......省略部分代码
}
/**
* A utility class to enable the downward swipe on the lockscreen to go to the full shade and expand
* the notification where the drag started.
*/
//KingYan 新增 private val statusBarStateController: SysuiStatusBarStateController, Disable lock screen page drop-down status bar
class DragDownHelper(
private val statusBarStateController: SysuiStatusBarStateController,
private val falsingManager: FalsingManager,
private val falsingCollector: FalsingCollector,
private val dragDownCallback: LockscreenShadeTransitionController,
context: Context
) : Gefingerpoken {
private var dragDownAmountOnStart = 0.0f
lateinit var expandCallback: ExpandHelper.Callback
lateinit var host: View
private var minDragDistance = 0
private var initialTouchX = 0f
private var initialTouchY = 0f
private var touchSlop = 0f
private var slopMultiplier = 0f
private val temp2 = IntArray(2)
private var draggedFarEnough = false
private var startingChild: ExpandableView? = null
private var lastHeight = 0f
var isDraggingDown = false
private set
private val isFalseTouch: Boolean
get() {
return if (!dragDownCallback.isFalsingCheckNeeded) {
false
} else {
falsingManager.isFalseTouch(Classifier.NOTIFICATION_DRAG_DOWN) || !draggedFarEnough
}
}
val isDragDownEnabled: Boolean
get() = dragDownCallback.isDragDownEnabledForView(null)
init {
updateResources(context)
}
fun updateResources(context: Context) {
minDragDistance = context.resources.getDimensionPixelSize(
R.dimen.keyguard_drag_down_min_distance)
val configuration = ViewConfiguration.get(context)
touchSlop = configuration.scaledTouchSlop.toFloat()
slopMultiplier = configuration.scaledAmbiguousGestureMultiplier
}
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
val x = event.x
val y = event.y
when (event.actionMasked) {
MotionEvent.ACTION_DOWN -> {
draggedFarEnough = false
isDraggingDown = false
startingChild = null
initialTouchY = y
initialTouchX = x
}
MotionEvent.ACTION_MOVE -> {
val h = y - initialTouchY
// Adjust the touch slop if another gesture may be being performed.
val touchSlop = if (event.classification
== MotionEvent.CLASSIFICATION_AMBIGUOUS_GESTURE)
touchSlop * slopMultiplier
else
touchSlop
if (h > touchSlop && h > Math.abs(x - initialTouchX)) {
//KingYan 新增如下判断 Disable lock screen page drop-down status bar
if (statusBarStateController.state == StatusBarState.KEYGUARD){
return true
}
falsingCollector.onNotificationStartDraggingDown()
isDraggingDown = true
captureStartingChild(initialTouchX, initialTouchY)
initialTouchY = y
initialTouchX = x
dragDownCallback.onDragDownStarted(startingChild)
dragDownAmountOnStart = dragDownCallback.dragDownAmount
return startingChild != null || dragDownCallback.isDragDownAnywhereEnabled
}
}
}
return false
}
override fun onTouchEvent(event: MotionEvent): Boolean {
if (!isDraggingDown) {
return false
}
val x = event.x
val y = event.y
when (event.actionMasked) {
MotionEvent.ACTION_MOVE -> {
lastHeight = y - initialTouchY
captureStartingChild(initialTouchX, initialTouchY)
dragDownCallback.dragDownAmount = lastHeight + dragDownAmountOnStart
if (startingChild != null) {
handleExpansion(lastHeight, startingChild!!)
}
if (lastHeight > minDragDistance) {
if (!draggedFarEnough) {
draggedFarEnough = true
dragDownCallback.onCrossedThreshold(true)
}
} else {
if (draggedFarEnough) {
draggedFarEnough = false
dragDownCallback.onCrossedThreshold(false)
}
}
return true
}
MotionEvent.ACTION_UP -> if (!falsingManager.isUnlockingDisabled && !isFalseTouch &&
dragDownCallback.canDragDown()) {
dragDownCallback.onDraggedDown(startingChild, (y - initialTouchY).toInt())
if (startingChild != null) {
expandCallback.setUserLockedChild(startingChild, false)
startingChild = null
}
isDraggingDown = false
} else {
stopDragging()
return false
}
MotionEvent.ACTION_CANCEL -> {
stopDragging()
return false
}
}
return false
}
private fun captureStartingChild(x: Float, y: Float) {
if (startingChild == null) {
startingChild = findView(x, y)
if (startingChild != null) {
if (dragDownCallback.isDragDownEnabledForView(startingChild)) {
expandCallback.setUserLockedChild(startingChild, true)
} else {
startingChild = null
}
}
}
}
private fun handleExpansion(heightDelta: Float, child: ExpandableView) {
var hDelta = heightDelta
if (hDelta < 0) {
hDelta = 0f
}
val expandable = child.isContentExpandable
val rubberbandFactor = if (expandable) {
RUBBERBAND_FACTOR_EXPANDABLE
} else {
RUBBERBAND_FACTOR_STATIC
}
var rubberband = hDelta * rubberbandFactor
if (expandable && rubberband + child.collapsedHeight > child.maxContentHeight) {
var overshoot = rubberband + child.collapsedHeight - child.maxContentHeight
overshoot *= 1 - RUBBERBAND_FACTOR_STATIC
rubberband -= overshoot
}
child.actualHeight = (child.collapsedHeight + rubberband).toInt()
}
private fun cancelChildExpansion(child: ExpandableView) {
if (child.actualHeight == child.collapsedHeight) {
expandCallback.setUserLockedChild(child, false)
return
}
val anim = ObjectAnimator.ofInt(child, "actualHeight",
child.actualHeight, child.collapsedHeight)
anim.interpolator = Interpolators.FAST_OUT_SLOW_IN
anim.duration = SPRING_BACK_ANIMATION_LENGTH_MS
anim.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
expandCallback.setUserLockedChild(child, false)
}
})
anim.start()
}
private fun stopDragging() {
falsingCollector.onNotificationStopDraggingDown()
if (startingChild != null) {
cancelChildExpansion(startingChild!!)
startingChild = null
}
isDraggingDown = false
dragDownCallback.onDragDownReset()
}
private fun findView(x: Float, y: Float): ExpandableView? {
host.getLocationOnScreen(temp2)
return expandCallback.getChildAtRawPosition(x + temp2[0], y + temp2[1])
}
}
4.禁止锁屏页面状态栏下拉
代码路径:SystemUI\src\com\android\systemui\statusbar\phone\NotificationPanelViewController.java
void setQsExpansion(float height) {
//KingYan 新增如下判断 Disable lock screen page drop-down status bar
if(mStatusBarStateController.getState() != StatusBarState.SHADE){
return;
}
height = Math.min(Math.max(height, mQsMinExpansionHeight), mQsMaxExpansionHeight);
mQsFullyExpanded = height == mQsMaxExpansionHeight && mQsMaxExpansionHeight != 0;
boolean qsAnimatingAway = !mQsAnimatorExpand && mAnimatingQS;
if (height > mQsMinExpansionHeight && !mQsExpanded && !mStackScrollerOverscrolling
&& !mDozing && !qsAnimatingAway) {
setQsExpanded(true);
} else if (height <= mQsMinExpansionHeight && mQsExpanded) {
setQsExpanded(false);
}
mQsExpansionHeight = height;
updateQsExpansion();
requestScrollerTopPaddingUpdate(false /* animate */);
mKeyguardStatusBarViewController.updateViewState();
if (mBarState == StatusBarState.SHADE_LOCKED || mBarState == KEYGUARD) {
updateKeyguardBottomAreaAlpha();
positionClockAndNotifications();
}
if (mAccessibilityManager.isEnabled()) {
mView.setAccessibilityPaneTitle(determineAccessibilityPaneTitle());
}
if (!mFalsingManager.isUnlockingDisabled() && mQsFullyExpanded
&& mFalsingCollector.shouldEnforceBouncer()) {
mCentralSurfaces.executeRunnableDismissingKeyguard(null, null /* cancelAction */,
false /* dismissShade */, true /* afterKeyguardGone */, false /* deferred */);
}
if (DEBUG_DRAWABLE) {
mView.invalidate();
}
}