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

Commit 7eded858 authored by alukin's avatar alukin
Browse files

Move SmartStorageMaintIdler execution to a separate thread

Sometimes SmartStorageMaintIdler execution takes too much time
because of some Vold global locks contention,
so moving the execution to a separate thread to prevent any ANR.
Bug: 286902553
Test: presubmit

Change-Id: Ie79cc12ac31da51ff7225f076c582bb039f1f42f
parent e4ef060e
Loading
Loading
Loading
Loading
+19 −10
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.content.Context;
import android.util.Slog;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

public class SmartStorageMaintIdler extends JobService {
    private static final String TAG = "SmartStorageMaintIdler";
@@ -34,15 +35,15 @@ public class SmartStorageMaintIdler extends JobService {

    private static final int SMART_MAINT_JOB_ID = 2808;

    private boolean mStarted;
    private final AtomicBoolean mStarted = new AtomicBoolean(false);
    private JobParameters mJobParams;
    private final Runnable mFinishCallback = new Runnable() {
        @Override
        public void run() {
            Slog.i(TAG, "Got smart storage maintenance service completion callback");
            if (mStarted) {
            if (mStarted.get()) {
                jobFinished(mJobParams, false);
                mStarted = false;
                mStarted.set(false);
            }
            // ... and try again in a next period
            scheduleSmartIdlePass(SmartStorageMaintIdler.this,
@@ -52,18 +53,26 @@ public class SmartStorageMaintIdler extends JobService {

    @Override
    public boolean onStartJob(JobParameters params) {
        final StorageManagerService ms = StorageManagerService.sSelf;
        if (mStarted.compareAndSet(false, true)) {
            new Thread() {
                public void run() {
                    mJobParams = params;
        StorageManagerService ms = StorageManagerService.sSelf;
                    if (ms != null) {
            mStarted = true;
                        ms.runSmartIdleMaint(mFinishCallback);
                    } else {
                        mStarted.set(false);
                    }
                }
            }.start();
            return ms != null;
        }
        return false;
    }

    @Override
    public boolean onStopJob(JobParameters params) {
        mStarted = false;
        mStarted.set(false);
        return false;
    }

+1 −1
Original line number Diff line number Diff line
@@ -2771,7 +2771,7 @@ class StorageManagerService extends IStorageManager.Stub
        return true;
    }

    void runSmartIdleMaint(Runnable callback) {
    synchronized void runSmartIdleMaint(Runnable callback) {
        enforcePermission(android.Manifest.permission.MOUNT_FORMAT_FILESYSTEMS);

        try {