summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author alukin <alukin@google.com> 2023-09-14 13:53:33 +0000
committer alukin <alukin@google.com> 2023-09-14 13:53:33 +0000
commit7eded858188b164e12dff304b61d66637bf7b03b (patch)
tree801e53b2abe03deb5b2781d0ec473b185defc91e
parente4ef060e1b0ff3f0c7b8f9754c6e1f1f5f3415ce (diff)
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
-rw-r--r--services/core/java/com/android/server/SmartStorageMaintIdler.java29
-rw-r--r--services/core/java/com/android/server/StorageManagerService.java2
2 files changed, 20 insertions, 11 deletions
diff --git a/services/core/java/com/android/server/SmartStorageMaintIdler.java b/services/core/java/com/android/server/SmartStorageMaintIdler.java
index 899692611086..44f1e76f7a22 100644
--- a/services/core/java/com/android/server/SmartStorageMaintIdler.java
+++ b/services/core/java/com/android/server/SmartStorageMaintIdler.java
@@ -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) {
- mJobParams = params;
- StorageManagerService ms = StorageManagerService.sSelf;
- if (ms != null) {
- mStarted = true;
- ms.runSmartIdleMaint(mFinishCallback);
+ final StorageManagerService ms = StorageManagerService.sSelf;
+ if (mStarted.compareAndSet(false, true)) {
+ new Thread() {
+ public void run() {
+ mJobParams = params;
+ if (ms != null) {
+ ms.runSmartIdleMaint(mFinishCallback);
+ } else {
+ mStarted.set(false);
+ }
+ }
+ }.start();
+ return ms != null;
}
- return ms != null;
+ return false;
}
@Override
public boolean onStopJob(JobParameters params) {
- mStarted = false;
+ mStarted.set(false);
return false;
}
diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java
index d47573d52767..2606757e008d 100644
--- a/services/core/java/com/android/server/StorageManagerService.java
+++ b/services/core/java/com/android/server/StorageManagerService.java
@@ -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 {