use of org.robolectric.res.android.Ref in project robolectric by robolectric.
the class ShadowArscAssetManager method retrieveArray.
@Implementation
@HiddenApi
protected int retrieveArray(int id, int[] outValues) {
if (outValues == null) {
throw new NullPointerException("out values");
}
CppAssetManager am = assetManagerForJavaObject();
if (am == null) {
return 0;
}
ResTable res = am.getResources();
final Ref<ResTable_config> config = new Ref<>(new ResTable_config());
Res_value value;
int block;
int NV = outValues.length;
// int[] baseDest = (int[])env->GetPrimitiveArrayCritical(outValues, 0);
int[] baseDest = outValues;
int[] dest = baseDest;
// if (dest == null) {
// throw new NullPointerException(env, "java/lang/OutOfMemoryError", "");
// return JNI_FALSE;
// }
// Now lock down the resource object and start pulling stuff from it.
res.lock();
final Ref<bag_entry[]> arrayEnt = new Ref<>(null);
final Ref<Integer> arrayTypeSetFlags = new Ref<>(0);
int bagOff = res.getBagLocked(id, arrayEnt, arrayTypeSetFlags);
// final ResTable::bag_entry* endArrayEnt = arrayEnt +
// (bagOff >= 0 ? bagOff : 0);
int destOffset = 0;
final Ref<Integer> typeSetFlags = new Ref<>(0);
while (destOffset < NV && destOffset < bagOff * STYLE_NUM_ENTRIES) /*&& arrayEnt < endArrayEnt*/
{
bag_entry curArrayEnt = arrayEnt.get()[destOffset / STYLE_NUM_ENTRIES];
block = curArrayEnt.stringBlock;
typeSetFlags.set(arrayTypeSetFlags.get());
config.get().density = 0;
value = curArrayEnt.map.value;
final Ref<Integer> resid = new Ref<>(0);
if (value.dataType != DataType.NULL.code()) {
// Take care of resolving the found resource to its final value.
// printf("Resolving attribute reference\n");
final Ref<Res_value> resValueRef = new Ref<>(value);
int newBlock = res.resolveReference(resValueRef, block, resid, typeSetFlags, config);
value = resValueRef.get();
if (kThrowOnBadId) {
if (newBlock == BAD_INDEX) {
throw new IllegalStateException("Bad resource!");
}
}
if (newBlock >= 0)
block = newBlock;
}
// Deal with the special @null value -- it turns back to TYPE_NULL.
if (value.dataType == DataType.REFERENCE.code() && value.data == 0) {
value = Res_value.NULL_VALUE;
}
// printf("Attribute 0x%08x: final type=0x%x, data=0x%08x\n", curIdent, value.dataType, value.data);
// Write the final value back to Java.
dest[destOffset + STYLE_TYPE] = value.dataType;
dest[destOffset + STYLE_DATA] = value.data;
dest[destOffset + STYLE_ASSET_COOKIE] = res.getTableCookie(block);
dest[destOffset + STYLE_RESOURCE_ID] = resid.get();
dest[destOffset + STYLE_CHANGING_CONFIGURATIONS] = typeSetFlags.get();
dest[destOffset + STYLE_DENSITY] = config.get().density;
// dest += STYLE_NUM_ENTRIES;
destOffset += STYLE_NUM_ENTRIES;
// arrayEnt++;
}
destOffset /= STYLE_NUM_ENTRIES;
res.unlock();
return destOffset;
}
use of org.robolectric.res.android.Ref in project robolectric by robolectric.
the class ShadowArscAssetManager method returnParcelFileDescriptor.
static ParcelFileDescriptor returnParcelFileDescriptor(Asset a, long[] outOffsets) throws FileNotFoundException {
final Ref<Long> startOffset = new Ref<Long>(-1L);
final Ref<Long> length = new Ref<Long>(-1L);
;
FileDescriptor fd = a.openFileDescriptor(startOffset, length);
if (fd == null) {
throw new FileNotFoundException("This file can not be opened as a file descriptor; it is probably compressed");
}
long[] offsets = outOffsets;
if (offsets == null) {
// fd.close();
return null;
}
offsets[0] = startOffset.get();
offsets[1] = length.get();
// return new ParcelFileDescriptor(fileDesc);
return ParcelFileDescriptor.open(a.getFile(), ParcelFileDescriptor.MODE_READ_ONLY);
}
use of org.robolectric.res.android.Ref in project robolectric by robolectric.
the class ShadowArscAssetManager method openXmlAssetNative.
// /*package*/@HiddenApi @Implementation public static final @NativeConfig
// int getThemeChangingConfigurations(long theme);
@HiddenApi
@Implementation
protected final Number openXmlAssetNative(int cookie, String fileName) throws FileNotFoundException {
CppAssetManager am = assetManagerForJavaObject();
if (am == null) {
return RuntimeEnvironment.castNativePtr(0);
}
ALOGV("openXmlAsset in %s (Java object %s)\n", am, ShadowArscAssetManager.class);
String fileName8 = fileName;
if (fileName8 == null) {
return RuntimeEnvironment.castNativePtr(0);
}
int assetCookie = cookie;
Asset a;
if (isTruthy(assetCookie)) {
a = am.openNonAsset(assetCookie, fileName8, AccessMode.ACCESS_BUFFER);
} else {
final Ref<Integer> assetCookieRef = new Ref<>(assetCookie);
a = am.openNonAsset(fileName8, AccessMode.ACCESS_BUFFER, assetCookieRef);
assetCookie = assetCookieRef.get();
}
if (a == null) {
throw new FileNotFoundException(fileName8);
}
final DynamicRefTable dynamicRefTable = am.getResources().getDynamicRefTableForCookie(assetCookie);
ResXMLTree block = new ResXMLTree(dynamicRefTable);
int err = block.setTo(a.getBuffer(true), (int) a.getLength(), true);
a.close();
if (err != NO_ERROR) {
throw new FileNotFoundException("Corrupt XML binary file");
}
return RuntimeEnvironment.castNativePtr(Registries.NATIVE_RES_XML_TREES.register(block));
}
use of org.robolectric.res.android.Ref in project robolectric by robolectric.
the class ShadowArscAssetManager method getArraySize.
@HiddenApi
@Implementation
protected int getArraySize(int id) {
CppAssetManager am = assetManagerForJavaObject();
if (am == null) {
return 0;
}
final ResTable res = am.getResources();
res.lock();
final Ref<bag_entry[]> defStyleEnt = new Ref<>(null);
int bagOff = res.getBagLocked(id, defStyleEnt, null);
res.unlock();
return bagOff;
}
use of org.robolectric.res.android.Ref in project robolectric by robolectric.
the class ShadowArscAssetManager method loadResourceBagValueInternal.
private static int loadResourceBagValueInternal(int ident, int bagEntryId, TypedValue outValue, boolean resolve, ResTable res) {
// Now lock down the resource object and start pulling stuff from it.
res.lock();
int block = -1;
final Ref<Res_value> valueRef = new Ref<>(null);
final Ref<bag_entry[]> entryRef = new Ref<>(null);
final Ref<Integer> typeSpecFlags = new Ref<>(0);
int entryCount = res.getBagLocked(ident, entryRef, typeSpecFlags);
bag_entry[] bag_entries = entryRef.get();
for (int i = 0; i < entryCount; i++) {
bag_entry entry = bag_entries[i];
if (bagEntryId == entry.map.name.ident) {
block = entry.stringBlock;
valueRef.set(entry.map.value);
}
}
res.unlock();
if (block < 0) {
return block;
}
final Ref<Integer> ref = new Ref<>(ident);
if (resolve) {
block = res.resolveReference(valueRef, block, ref, typeSpecFlags);
if (kThrowOnBadId) {
if (block == BAD_INDEX) {
throw new IllegalStateException("Bad resource!");
}
}
}
if (block >= 0) {
return copyValue(outValue, res, valueRef.get(), ref.get(), block, typeSpecFlags.get());
}
return block;
}
Aggregations