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

Commit 91df8715 authored by Tony Huang's avatar Tony Huang
Browse files

Fix apps crash during testing

FileUtils.contains method not found while testing, fix it by copy
the method into test case.

Bug: 144667472
Test: atest DocumentsUIGoogleTests
Change-Id: I967b22de59ddbfcbe26c326a1341c53610d8d37a
parent e5f1dfc1
Loading
Loading
Loading
Loading
+24 −4
Original line number Diff line number Diff line
@@ -26,16 +26,20 @@ import android.database.MatrixCursor;
import android.database.MatrixCursor.RowBuilder;
import android.graphics.Point;
import android.net.Uri;
import android.os.*;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.FileUtils;
import android.os.Handler;
import android.os.Looper;
import android.os.ParcelFileDescriptor;
import android.provider.DocumentsContract;
import android.provider.DocumentsContract.Document;
import android.provider.DocumentsContract.Root;
import android.provider.DocumentsProvider;
import androidx.annotation.VisibleForTesting;
import android.text.TextUtils;
import android.util.Log;

import android.os.FileUtils;
import androidx.annotation.VisibleForTesting;

import java.io.File;
import java.io.FileNotFoundException;
@@ -183,7 +187,23 @@ public class StubProvider extends DocumentsProvider {
    public boolean isChildDocument(String parentDocId, String docId) {
        final StubDocument parentDocument = mStorage.get(parentDocId);
        final StubDocument childDocument = mStorage.get(docId);
        return FileUtils.contains(parentDocument.file, childDocument.file);

        if (parentDocument.file == null || childDocument.file == null) {
            return false;
        }

        return contains(
                parentDocument.file.getAbsolutePath(), childDocument.file.getAbsolutePath());
    }

    private static boolean contains(String dirPath, String filePath) {
        if (dirPath.equals(filePath)) {
            return true;
        }
        if (!dirPath.endsWith("/")) {
            dirPath += "/";
        }
        return filePath.startsWith(dirPath);
    }

    @Override