Make sure not to access elements beyond their bounds

This error occurs when dock grid is greater than workspace grid

Error :
java.lang.ArrayIndexOutOfBoundsException: length=4; index=4
	at com.android.launcher3.CellLayout$ViewCluster.isViewTouchingEdge(CellLayout.java:2053)
	at com.android.launcher3.CellLayout.pushViewsToTempLocation(CellLayout.java:1894)
	at com.android.launcher3.CellLayout.attemptPushInDirection(CellLayout.java:2173)
	at com.android.launcher3.CellLayout.rearrangementExists(CellLayout.java:2372)
	at com.android.launcher3.celllayout.ReorderAlgorithm.findReorderSolution(ReorderAlgorithm.java:76)
	at com.android.launcher3.celllayout.ReorderAlgorithm.calculateReorder(ReorderAlgorithm.java:185)
	at com.android.launcher3.CellLayout.calculateReorder(CellLayout.java:2435)
	at com.android.launcher3.CellLayout.performReorder(CellLayout.java:2453)
	at com.android.launcher3.Workspace.manageReorderOnDragOver(Workspace.java:2589)
	at com.android.launcher3.Workspace.onDragOver(Workspace.java:2570)
	at com.android.launcher3.dragndrop.DragController.checkTouchMove(DragController.java:489)
	at com.android.launcher3.dragndrop.DragController.handleMoveEvent(DragController.java:453)
	at com.android.launcher3.dragndrop.LauncherDragController.startDrag(LauncherDragController.java:154)
	at com.android.launcher3.dragndrop.DragController.startDrag(DragController.java:156)
	at com.android.launcher3.Workspace.beginDragShared(Workspace.java:1830)
	at com.android.launcher3.Workspace.beginDragShared(Workspace.java:1732)
	at com.android.launcher3.Workspace.startDrag(Workspace.java:1721)
	at com.android.launcher3.touch.ItemLongClickListener.beginDrag(ItemLongClickListener.java:85)
	at com.android.launcher3.touch.ItemLongClickListener.onWorkspaceItemLongClick(ItemLongClickListener.java:65)
	at com.android.launcher3.touch.ItemLongClickListener.$r8$lambda$nz9MSaglTImbNX-jBQmvpOY7s8M
This commit is contained in:
MrSluffy
2023-10-21 09:53:51 +08:00
parent 781861fb10
commit de644de4fd
+8 -4
View File
@@ -2026,31 +2026,35 @@ public class CellLayout extends ViewGroup {
dirtyEdges &= ~whichEdge;
}
int leftEdgeLength = leftEdge.length;
int rightEdgeLength = rightEdge.length;
int topEdgeLength = topEdge.length;
int bottomEdgeLength = bottomEdge.length;
switch (whichEdge) {
case LEFT:
for (int i = cs.cellY; i < cs.cellY + cs.spanY; i++) {
if (leftEdge[i] == cs.cellX + cs.spanX) {
if (i >= 0 && i < leftEdgeLength && leftEdge[i] == cs.cellX + cs.spanX) {
return true;
}
}
break;
case RIGHT:
for (int i = cs.cellY; i < cs.cellY + cs.spanY; i++) {
if (rightEdge[i] == cs.cellX) {
if (i >= 0 && i < rightEdgeLength && rightEdge[i] == cs.cellX) {
return true;
}
}
break;
case TOP:
for (int i = cs.cellX; i < cs.cellX + cs.spanX; i++) {
if (topEdge[i] == cs.cellY + cs.spanY) {
if (i >= 0 && i < topEdgeLength && topEdge[i] == cs.cellY + cs.spanY) {
return true;
}
}
break;
case BOTTOM:
for (int i = cs.cellX; i < cs.cellX + cs.spanX; i++) {
if (bottomEdge[i] == cs.cellY) {
if (i >= 0 && i < bottomEdgeLength && bottomEdge[i] == cs.cellY) {
return true;
}
}