api-impl/android/content/res/AssetManager.java: fix error condition for openAsset

This commit is contained in:
Mis012
2023-06-06 16:26:46 +02:00
parent eac3e42ede
commit 970011a5cb

View File

@@ -311,20 +311,20 @@ public final class AssetManager {
* @see #open(String) * @see #open(String)
* @see #list * @see #list
*/ */
public final InputStream open(String fileName, int accessMode) public final InputStream open(String fileName, int accessMode) throws IOException {
throws IOException { int asset;
synchronized (this) { synchronized (this) {
if (!mOpen) { if (!mOpen) {
throw new RuntimeException("Assetmanager has been closed"); throw new RuntimeException("Assetmanager has been closed");
} }
int asset = openAsset(fileName, accessMode); asset = openAsset(fileName, accessMode);
if (asset != 0) { if (asset >= 0) {
AssetInputStream res = new AssetInputStream(asset); AssetInputStream res = new AssetInputStream(asset);
incRefsLocked(res.hashCode()); incRefsLocked(res.hashCode());
return res; return res;
} }
} }
throw new FileNotFoundException("Asset file: " + fileName); throw new FileNotFoundException("Asset file: " + fileName + ", errno: " + asset);
} }
public final AssetFileDescriptor openFd(String fileName) public final AssetFileDescriptor openFd(String fileName)
@@ -405,20 +405,20 @@ public final class AssetManager {
* @param fileName Name of the asset to retrieve. * @param fileName Name of the asset to retrieve.
* @param accessMode Desired access mode for retrieving the data. * @param accessMode Desired access mode for retrieving the data.
*/ */
public final InputStream openNonAsset(int cookie, String fileName, int accessMode) public final InputStream openNonAsset(int cookie, String fileName, int accessMode) throws IOException {
throws IOException { int asset;
synchronized (this) { synchronized (this) {
if (!mOpen) { if (!mOpen) {
throw new RuntimeException("Assetmanager has been closed"); throw new RuntimeException("Assetmanager has been closed");
} }
int asset = openNonAssetNative(cookie, fileName, accessMode); asset = openNonAssetNative(cookie, fileName, accessMode);
if (asset != 0) { if (asset >= 0) {
AssetInputStream res = new AssetInputStream(asset); AssetInputStream res = new AssetInputStream(asset);
incRefsLocked(res.hashCode()); incRefsLocked(res.hashCode());
return res; return res;
} }
} }
throw new FileNotFoundException("Asset absolute file: " + fileName); throw new FileNotFoundException("Asset absolute file: " + fileName + ", errno: " + asset);
} }
public final AssetFileDescriptor openNonAssetFd(String fileName) public final AssetFileDescriptor openNonAssetFd(String fileName)
@@ -493,20 +493,20 @@ public final class AssetManager {
* @param cookie Identifier of the package to be opened. * @param cookie Identifier of the package to be opened.
* @param fileName Name of the asset to retrieve. * @param fileName Name of the asset to retrieve.
*/ */
/*package*/ final XmlBlock openXmlBlockAsset(int cookie, String fileName) /*package*/ final XmlBlock openXmlBlockAsset(int cookie, String fileName) throws IOException {
throws IOException { int xmlBlock;
synchronized (this) { synchronized (this) {
if (!mOpen) { if (!mOpen) {
throw new RuntimeException("Assetmanager has been closed"); throw new RuntimeException("Assetmanager has been closed");
} }
int xmlBlock = openXmlAssetNative(cookie, fileName); xmlBlock = openXmlAssetNative(cookie, fileName);
if (xmlBlock != 0) { if (xmlBlock >= 0) {
XmlBlock res = new XmlBlock(this, xmlBlock); XmlBlock res = new XmlBlock(this, xmlBlock);
incRefsLocked(res.hashCode()); incRefsLocked(res.hashCode());
return res; return res;
} }
} }
throw new FileNotFoundException("Asset XML file: " + fileName); throw new FileNotFoundException("Asset XML file: " + fileName + ", errno : " + xmlBlock);
} }
/*package*/ void xmlBlockGone(int id) { /*package*/ void xmlBlockGone(int id) {