From 8af83ccd50107c752ef379b32ba5c62e13f00cb3 Mon Sep 17 00:00:00 2001 From: Zhi Dou Date: Fri, 2 Aug 2024 23:10:35 +0000 Subject: [PATCH] change fileinputstream to filechannel The restrict mode doesn't allow to have disk read from main thread. Some apps enabled this check. The code in the dependencies of the fileinputstream. This chagne switch to filechannel. Test: presubmit Bug: 356614910 Change-Id: Icf2175fe75ed1bfad4a048ead680b08e57d6c2ca --- .../android/aconfig/storage/StorageInternalReader.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/aconfig/aconfig_storage_read_api/srcs/android/aconfig/storage/StorageInternalReader.java b/tools/aconfig/aconfig_storage_read_api/srcs/android/aconfig/storage/StorageInternalReader.java index 07558eee30..f73f35e80f 100644 --- a/tools/aconfig/aconfig_storage_read_api/srcs/android/aconfig/storage/StorageInternalReader.java +++ b/tools/aconfig/aconfig_storage_read_api/srcs/android/aconfig/storage/StorageInternalReader.java @@ -19,9 +19,10 @@ package android.aconfig.storage; import android.compat.annotation.UnsupportedAppUsage; import java.io.Closeable; -import java.io.FileInputStream; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; /** @hide */ public class StorageInternalReader { @@ -69,16 +70,15 @@ public class StorageInternalReader { // Map a storage file given file path private static MappedByteBuffer mapStorageFile(String file) { - FileInputStream stream = null; + FileChannel channel = null; try { - stream = new FileInputStream(file); - FileChannel channel = stream.getChannel(); + channel = FileChannel.open(Paths.get(file), StandardOpenOption.READ); return channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()); } catch (Exception e) { throw new AconfigStorageException( String.format("Fail to mmap storage file %s", file), e); } finally { - quietlyDispose(stream); + quietlyDispose(channel); } }