Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 590e2b0f authored by Tony Huang's avatar Tony Huang
Browse files

Fix crash bug while opening zip on recent root

In previous implement, it will still show recents root when open
archive container, and crash when open the zip file again because
its already push docs info to stack and checkArgument will fail.
Refactor the logic isRecents in DocumentStack to fix this behavior.
We also need to add fake DocumentInfo when switch to recent root for
keeping same stack size on root top level. The size on root top is
0 but 1 on other roots, this will cause tool bar issue when open
archive container.

Fix: 127231252
Test: atest DocumentsUIGoogleTests
Change-Id: I49db08b94e28b49b7ef155611cedaae14934a5cf
parent f4de7ac6
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -16,9 +16,10 @@

package com.android.documentsui.base;

import static com.android.documentsui.base.SharedMinimal.DEBUG;
import static androidx.core.util.Preconditions.checkArgument;

import static com.android.documentsui.base.SharedMinimal.DEBUG;

import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Parcel;
@@ -150,6 +151,11 @@ public class DocumentStack implements Durable, Parcelable {
        if (DEBUG) Log.d(TAG, "Root changed to: " + root);
        reset();
        mRoot = root;

        // Add this for keep stack size is 1 on recent root.
        if (root.isRecents()) {
            push(new DocumentInfo());
        }
    }

    /** This will return true even when the initial location is set.
@@ -170,7 +176,7 @@ public class DocumentStack implements Durable, Parcelable {
    }

    public boolean isRecents() {
        return mRoot != null && mRoot.isRecents();
        return mRoot != null && mRoot.isRecents() && size() == 1;
    }

    /**
+9 −0
Original line number Diff line number Diff line
@@ -188,4 +188,13 @@ public class DocumentStackTest {
            return true;
        });
    }

    @Test
    public void testIsRecent() {
        final RootInfo rootRecent = new RootInfo();
        mStack.changeRoot(rootRecent);

        assertEquals(1, mStack.size());
        assertEquals(true, mStack.isRecents());
    }
}