Do not attempt to special case uncompressed font assets.

The logic to attempt to directly mmap uncompressed font assets
has resulted in breakages for some applications and utilities.
This CL disables this speculative optimzation until we can determine
the problem with this approach and if such an optimization is required.

Bug: 149780695
Test: CtsTextTestCases and androidx.appcompat.widget.AppCompatTextViewTest
Change-Id: I3b10a801a5600aefe8573fab1b28cd79c848c892
This commit is contained in:
Derek Sollenberger
2020-02-21 15:21:41 -05:00
parent 710895ed78
commit dd03a8ef81

View File

@@ -19,7 +19,6 @@ package android.graphics.fonts;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.os.LocaleList;
@@ -220,25 +219,6 @@ public final class Font {
Preconditions.checkNotNull(am, "assetManager can not be null");
Preconditions.checkNotNull(path, "path can not be null");
if (!isAsset) {
// Attempt to open as FD, which should work unless the asset is compressed
AssetFileDescriptor assetFD;
try {
if (cookie > 0) {
assetFD = am.openNonAssetFd(cookie, path);
} else {
assetFD = am.openNonAssetFd(path);
}
try (FileInputStream fis = assetFD.createInputStream()) {
final FileChannel fc = fis.getChannel();
return fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
}
} catch (IOException e) {
// failed to open as FD so now we will attempt to open as an input stream
}
}
try (InputStream assetStream = isAsset ? am.open(path, AssetManager.ACCESS_BUFFER)
: am.openNonAsset(cookie, path, AssetManager.ACCESS_BUFFER)) {