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

Commit 2edf4294 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 6800905 from efb4dcbc to sc-d1-release

Change-Id: I167f85de8744a59091abdb3ca8ab48f7a4ecd5db
parents 20d28301 efb4dcbc
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -279,10 +279,11 @@ public class DirectoryLoader extends AsyncTaskLoader<DirectoryResult> {

    @Override
    protected void onStartLoading() {
        if (mResult != null) {
        boolean isCursorStale = checkIfCursorStale(mResult);
        if (mResult != null && !isCursorStale) {
            deliverResult(mResult);
        }
        if (takeContentChanged() || mResult == null) {
        if (takeContentChanged() || mResult == null || isCursorStale) {
            forceLoad();
        }
    }
@@ -311,4 +312,22 @@ public class DirectoryLoader extends AsyncTaskLoader<DirectoryResult> {
        FileUtils.closeQuietly(mResult);
        mResult = null;
    }

    private boolean checkIfCursorStale(DirectoryResult result) {
        if (mResult == null) {
            return true;
        }
        Cursor cursor = result.cursor;
        cursor.moveToPosition(-1);
        for (int pos = 0; pos < cursor.getCount(); ++pos) {
            try {
                if (!cursor.moveToNext()) {
                    return true;
                }
            } catch (Exception e) {
                return true;
            }
        }
        return false;
    }
}
+21 −4
Original line number Diff line number Diff line
@@ -104,8 +104,6 @@ public abstract class MultiRootDocumentsLoader extends AsyncTaskLoader<Directory
     * @param state current state
     * @param executors the executors of authorities
     * @param fileTypeMap the map of mime types and file types.
     * @param lock the selection lock
     * @param contentChangedCallback callback when content changed
     */
    public MultiRootDocumentsLoader(Context context, ProvidersAccess providers, State state,
            Lookup<String, Executor> executors, Lookup<String, String> fileTypeMap) {
@@ -304,10 +302,11 @@ public abstract class MultiRootDocumentsLoader extends AsyncTaskLoader<Directory

    @Override
    protected void onStartLoading() {
        if (mResult != null) {
        boolean isCursorStale = checkIfCursorStale(mResult);
        if (mResult != null && !isCursorStale) {
            deliverResult(mResult);
        }
        if (takeContentChanged() || mResult == null) {
        if (takeContentChanged() || mResult == null || isCursorStale) {
            forceLoad();
        }
    }
@@ -457,4 +456,22 @@ public abstract class MultiRootDocumentsLoader extends AsyncTaskLoader<Directory
            mIsClosed = true;
        }
    }

    private boolean checkIfCursorStale(DirectoryResult result) {
        if (mResult == null) {
            return true;
        }
        Cursor cursor = result.cursor;
        cursor.moveToPosition(-1);
        for (int pos = 0; pos < cursor.getCount(); ++pos) {
            try {
                if (!cursor.moveToNext()) {
                    return true;
                }
            } catch (Exception e) {
                return true;
            }
        }
        return false;
    }
}