use of org.robolectric.res.android.CppAssetManager 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.CppAssetManager in project robolectric by robolectric.
the class ShadowArscAssetManager method getResourceTypeName.
@Implementation
protected String getResourceTypeName(int resid) {
CppAssetManager cppAssetManager = assetManagerForJavaObject();
ResourceName name = new ResourceName();
if (!cppAssetManager.getResources().getResourceName(resid, true, name)) {
return null;
}
return name.type;
}
use of org.robolectric.res.android.CppAssetManager in project robolectric by robolectric.
the class ShadowArscAssetManager method getArrayStringInfo.
@HiddenApi
@Implementation
protected final int[] getArrayStringInfo(int arrayResId) {
CppAssetManager am = assetManagerForJavaObject();
ResTable res = am.getResources();
final Ref<bag_entry[]> startOfBag = new Ref<>(null);
final int N = res.lockBag(arrayResId, startOfBag);
if (N < 0) {
return null;
}
int[] array = new int[N * 2];
final Ref<Res_value> value = new Ref<>(null);
bag_entry[] bag = startOfBag.get();
for (int i = 0, j = 0; i < N; i++) {
int stringIndex = -1;
int stringBlock = 0;
value.set(bag[i].map.value);
// Take care of resolving the found resource to its final value.
stringBlock = res.resolveReference(value, bag[i].stringBlock, null);
if (value.get().dataType == DataType.STRING.code()) {
stringIndex = value.get().data;
}
if (kThrowOnBadId) {
if (stringBlock == BAD_INDEX) {
throw new IllegalStateException("Bad resource!");
}
}
// todo: It might be faster to allocate a C array to contain
// the blocknums and indices, put them in there and then
// do just one SetIntArrayRegion()
// env->SetIntArrayRegion(array, j, 1, &stringBlock);
array[j] = stringBlock;
// env->SetIntArrayRegion(array, j + 1, 1, &stringIndex);
array[j + 1] = stringIndex;
j += 2;
}
res.unlockBag(startOfBag);
return array;
}
use of org.robolectric.res.android.CppAssetManager 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.CppAssetManager in project robolectric by robolectric.
the class ShadowArscAssetManager method addAssetPathNative.
@HiddenApi
@Implementation(minSdk = VERSION_CODES.N)
protected int addAssetPathNative(String path, boolean appAsLib) {
if (Strings.isNullOrEmpty(path)) {
return 0;
}
CppAssetManager am = assetManagerForJavaObject();
if (am == null) {
return 0;
}
final Ref<Integer> cookie = new Ref<>(null);
boolean res = am.addAssetPath(new String8(path), cookie, appAsLib);
return (res) ? cookie.get() : 0;
}
Aggregations