use of org.robolectric.res.android.Asset in project robolectric by robolectric.
the class ShadowFontBuilder method nGetNativeAsset.
// transliterated from frameworks/base/core/jni/android/graphics/fonts/Font.cpp
@Implementation(maxSdk = Q)
protected static long nGetNativeAsset(AssetManager assetMgr, String path, boolean isAsset, int cookie) {
// NPE_CHECK_RETURN_ZERO(env, assetMgr);
Preconditions.checkNotNull(assetMgr);
// NPE_CHECK_RETURN_ZERO(env, path);
Preconditions.checkNotNull(path);
// Guarded<AssetManager2>* mgr = AssetManagerForJavaObject(env, assetMgr);
CppAssetManager2 mgr = ShadowArscAssetManager10.AssetManagerForJavaObject(assetMgr);
// if (mgr == nullptr) {
if (mgr == null) {
return 0;
}
// ScopedUtfChars str(env, path);
// if (str.c_str() == nullptr) {
// return 0;
// }
// std::unique_ptr<Asset> asset;
Asset asset;
{
// ScopedLock<AssetManager2> locked_mgr(*mgr);
if (isAsset) {
// asset = locked_mgr->Open(str.c_str(), Asset::ACCESS_BUFFER);
asset = mgr.Open(path, AccessMode.ACCESS_BUFFER);
} else if (cookie > 0) {
// Valid java cookies are 1-based, but AssetManager cookies are 0-based.
// asset = locked_mgr->OpenNonAsset(str.c_str(), static_cast<ApkAssetsCookie>(cookie - 1), Asset::ACCESS_BUFFER);
asset = mgr.OpenNonAsset(path, ApkAssetsCookie.forInt(cookie - 1), AccessMode.ACCESS_BUFFER);
} else {
// asset = locked_mgr->OpenNonAsset(str.c_str(), Asset::ACCESS_BUFFER);
asset = mgr.OpenNonAsset(path, AccessMode.ACCESS_BUFFER);
}
}
// return reinterpret_cast<jlong>(asset.release());
return Registries.NATIVE_ASSET_REGISTRY.register(asset);
}
use of org.robolectric.res.android.Asset in project robolectric by robolectric.
the class ShadowArscAssetManager method openAssetFd.
@HiddenApi
@Implementation
protected ParcelFileDescriptor openAssetFd(String fileName, long[] outOffsets) throws IOException {
CppAssetManager am = assetManagerForJavaObject();
ALOGV("openAssetFd in %s", am);
String fileName8 = fileName;
if (fileName8 == null) {
return null;
}
Asset a = am.open(fileName8, Asset.AccessMode.ACCESS_RANDOM);
if (a == null) {
throw new FileNotFoundException(fileName8);
}
return returnParcelFileDescriptor(a, outOffsets);
}
use of org.robolectric.res.android.Asset in project robolectric by robolectric.
the class ShadowArscAssetManager method openAsset.
@HiddenApi
@Implementation
protected final Number openAsset(String fileName, int mode) throws FileNotFoundException {
CppAssetManager am = assetManagerForJavaObject();
ALOGV("openAsset in %s", am);
String fileName8 = fileName;
if (fileName8 == null) {
throw new IllegalArgumentException("Empty file name");
}
if (mode != AccessMode.ACCESS_UNKNOWN.mode() && mode != AccessMode.ACCESS_RANDOM.mode() && mode != AccessMode.ACCESS_STREAMING.mode() && mode != AccessMode.ACCESS_BUFFER.mode()) {
throw new IllegalArgumentException("Bad access mode");
}
Asset a = am.open(fileName8, AccessMode.fromInt(mode));
if (a == null) {
throw new FileNotFoundException(fileName8);
}
return RuntimeEnvironment.castNativePtr(Registries.NATIVE_ASSET_REGISTRY.register(a));
}
use of org.robolectric.res.android.Asset in project robolectric by robolectric.
the class ShadowArscAssetManager method readAsset.
@HiddenApi
@Implementation(minSdk = LOLLIPOP)
protected final int readAsset(long asset, byte[] bArray, int off, int len) throws IOException {
Asset a = getAsset(asset);
if (a == null || bArray == null) {
throw new NullPointerException("asset");
}
if (len == 0) {
return 0;
}
int bLen = bArray.length;
if (off < 0 || off >= bLen || len < 0 || len > bLen || (off + len) > bLen) {
throw new IndexOutOfBoundsException();
}
byte[] b = bArray;
int res = a.read(b, off, len);
if (res > 0)
return res;
if (res < 0) {
throw new IOException();
}
return -1;
}
use of org.robolectric.res.android.Asset in project robolectric by robolectric.
the class ShadowArscAssetManager method readAssetChar.
@HiddenApi
@Implementation(minSdk = LOLLIPOP)
protected final int readAssetChar(long asset) {
Asset a = getAsset(asset);
byte[] b = new byte[1];
int res = a.read(b, 1);
return res == 1 ? b[0] & 0xff : -1;
}
Aggregations