summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Massimo Carli <mcarli@google.com> 2023-06-21 12:50:35 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2023-06-21 12:50:35 +0000
commit4d80a87054187eecc67ca69cdea07c6a8d3df046 (patch)
tree1e3c268c306b86b84e482776b0c187af919b5ba1
parent62f8301744ed1be4354722c35f7a7d69c0f98e80 (diff)
parent8620b356aeef4aee43ff80d58c7f437b36a20f55 (diff)
Merge "Allow DiskRead ThreadPolicy in LetterboxConfigurationPersister" into udc-dev am: 99eba6f039 am: 8620b356ae
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23750905 Change-Id: I0d91d72bdd2bbfecc404fc74c5073c803ee7e410 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--services/core/java/com/android/server/wm/LetterboxConfigurationPersister.java20
1 files changed, 19 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/wm/LetterboxConfigurationPersister.java b/services/core/java/com/android/server/wm/LetterboxConfigurationPersister.java
index 3b10debaa753..756339701590 100644
--- a/services/core/java/com/android/server/wm/LetterboxConfigurationPersister.java
+++ b/services/core/java/com/android/server/wm/LetterboxConfigurationPersister.java
@@ -16,6 +16,8 @@
package com.android.server.wm;
+import static android.os.StrictMode.setThreadPolicy;
+
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
@@ -23,6 +25,8 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.os.Environment;
+import android.os.StrictMode;
+import android.os.StrictMode.ThreadPolicy;
import android.util.AtomicFile;
import android.util.Slog;
@@ -125,7 +129,7 @@ class LetterboxConfigurationPersister {
final File prefFiles = new File(configFolder, LETTERBOX_CONFIGURATION_FILENAME);
mConfigurationFile = new AtomicFile(prefFiles);
mPersisterQueue = persisterQueue;
- readCurrentConfiguration();
+ runWithDiskReadsThreadPolicy(this::readCurrentConfiguration);
}
/**
@@ -275,6 +279,20 @@ class LetterboxConfigurationPersister {
}
}
+ // The LetterboxConfigurationDeviceConfig needs to access the
+ // file with the current reachability position once when the
+ // device boots. Because DisplayThread uses allowIo=false
+ // accessing a file triggers a DiskReadViolation.
+ // Here we use StrictMode to allow the current thread to read
+ // the AtomicFile once in the current thread restoring the
+ // original ThreadPolicy after that.
+ private void runWithDiskReadsThreadPolicy(Runnable runnable) {
+ final ThreadPolicy currentPolicy = StrictMode.getThreadPolicy();
+ setThreadPolicy(new ThreadPolicy.Builder().permitDiskReads().build());
+ runnable.run();
+ setThreadPolicy(currentPolicy);
+ }
+
private static class UpdateValuesCommand implements
PersisterQueue.WriteQueueItem<UpdateValuesCommand> {