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

Commit d2872ad0 authored by François Degros's avatar François Degros
Browse files

Make Job.failureCount volatile

This allows Job.hasFailures() to be called from the progress reporting
thread without the need for extra synchronization.

Also removed some synchronized blocks from UnpackJob, which are not
necessary anymore.

Bug: 416381187
Flag: EXEMPT fixing synchronization issues in Job class
Test: atest DocumentsUIGoogleTests:com.android.documentsui.services

Change-Id: I0ae1f1787d8e4f2946a5ded0f902ff9a29546c98
parent dc6e88c4
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -103,7 +103,11 @@ abstract public class Job implements Runnable {

    final UrisSupplier mResourceUris;

    int failureCount = 0;
    /**
     * Number of errors. It is modified by the main thread running setUp(), start() and finish(),
     * and it is read by the progress reporting thread running getJobProgress().
     */
    volatile int failureCount = 0;
    final ArrayList<DocumentInfo> failedDocs = new ArrayList<>();
    final ArrayList<Uri> failedUris = new ArrayList<>();

+3 −7
Original line number Diff line number Diff line
@@ -203,10 +203,8 @@ class UnpackJob(
            if (DEBUG) Log.d(TAG, "Canceled unpacking of ${archiveInfo.derivedUri}")
        } catch (t: Throwable) {
            Log.e(TAG, "Cannot unpack ${redact(archiveInfo.derivedUri)}", t)
            synchronized(this) {
            onFileFailed(archiveInfo)
        }
        }

        return false
    }
@@ -289,11 +287,9 @@ class UnpackJob(
            if (DEBUG) Log.d(TAG, "Canceled unpacking of ${redact(archiveInfo.derivedUri)}")
        } catch (t: Throwable) {
            Log.e(TAG, "Cannot unpack ${redact(archiveInfo.derivedUri)}", t)
            synchronized(this) {
            onFileFailed(archiveInfo)
        }
    }
    }

    private fun extractAllFiles() {
        for (entry in archive!!.entries) {
@@ -325,8 +321,8 @@ class UnpackJob(
            Log.e(TAG, "Cannot extract ${redact(path)} from ${redact(archiveInfo.derivedUri)}", t)
            synchronized(this) {
                tracker.filesRequired--
                onResolveFailed(Uri.withAppendedPath(dirUri, fileName))
            }
            onResolveFailed(Uri.withAppendedPath(dirUri, fileName))
        }

        // Adjust progress expectations after extracting a file.