use of org.robolectric.res.android.Ref 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;
}
use of org.robolectric.res.android.Ref in project robolectric by robolectric.
the class ShadowArscAssetManager method getArrayIntResource.
@HiddenApi
@Implementation
public int[] getArrayIntResource(int arrayResId) {
CppAssetManager am = assetManagerForJavaObject();
if (am == null) {
return null;
}
final ResTable res = am.getResources();
// final ResTable::bag_entry* startOfBag;
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];
if (array == null) {
res.unlockBag(startOfBag);
return null;
}
final Ref<Res_value> valueRef = new Ref<>(null);
bag_entry[] bag = startOfBag.get();
for (int i = 0; i < N; i++) {
valueRef.set(bag[i].map.value);
// Take care of resolving the found resource to its final value.
int block = res.resolveReference(valueRef, bag[i].stringBlock, null, null, null);
if (kThrowOnBadId) {
if (block == BAD_INDEX) {
// seems like this is missing from android_util_AssetManager.cpp?
res.unlockBag(startOfBag);
throw new IllegalStateException("Bad resource!");
// return array;
}
}
Res_value value = valueRef.get();
if (value.dataType >= DataType.TYPE_FIRST_INT && value.dataType <= DataType.TYPE_LAST_INT) {
int intVal = value.data;
// env->SetIntArrayRegion(array, i, 1, &intVal);
array[i] = intVal;
}
}
res.unlockBag(startOfBag);
return array;
}
use of org.robolectric.res.android.Ref in project robolectric by robolectric.
the class ShadowArscAssetManager method loadThemeAttributeValue.
@HiddenApi
@Implementation(minSdk = LOLLIPOP)
protected static int loadThemeAttributeValue(long themeHandle, int ident, TypedValue outValue, boolean resolve) {
ResTableTheme theme = Preconditions.checkNotNull(Registries.NATIVE_THEME_REGISTRY.getNativeObject(themeHandle));
ResTable res = theme.getResTable();
final Ref<Res_value> value = new Ref<>(null);
// XXX value could be different in different configs!
final Ref<Integer> typeSpecFlags = new Ref<>(0);
int block = theme.GetAttribute(ident, value, typeSpecFlags);
final Ref<Integer> ref = new Ref<>(0);
if (resolve) {
block = res.resolveReference(value, block, ref, typeSpecFlags);
if (kThrowOnBadId) {
if (block == BAD_INDEX) {
throw new IllegalStateException("Bad resource!");
}
}
}
return block >= 0 ? copyValue(outValue, res, value.get(), ref.get(), block, typeSpecFlags.get(), null) : block;
}
use of org.robolectric.res.android.Ref in project robolectric by robolectric.
the class ShadowArscAssetManager method getConfiguration.
@VisibleForTesting
ResTable_config getConfiguration() {
final Ref<ResTable_config> config = new Ref<>(new ResTable_config());
assetManagerForJavaObject().getConfiguration(config);
return config.get();
}
use of org.robolectric.res.android.Ref in project robolectric by robolectric.
the class ShadowArscAssetManager10 method nativeGetResourceArray.
// static jint NativeGetResourceArray(JNIEnv* env, jclass /*clazz*/, jlong ptr, jint resid,
// jintArray out_data) {
@Implementation(minSdk = P)
protected static int nativeGetResourceArray(long ptr, @ArrayRes int resid, @NonNull int[] out_data) {
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
ResolvedBag bag = assetmanager.GetBag(resid);
if (bag == null) {
return -1;
}
int out_data_length = out_data.length;
if ((int) (bag.entry_count) > out_data_length * STYLE_NUM_ENTRIES) {
throw new IllegalArgumentException("Input array is not large enough");
}
int[] buffer = // reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(out_data, null));
out_data;
if (buffer == null) {
return -1;
}
int[] cursor = buffer;
for (int i = 0; i < bag.entry_count; i++) {
ResolvedBag.Entry entry = bag.entries[i];
final Ref<Res_value> value = new Ref<>(entry.value);
final Ref<ResTable_config> selected_config = new Ref<>(new ResTable_config());
selected_config.get().density = 0;
final Ref<Integer> flags = new Ref<>(bag.type_spec_flags);
final Ref<Integer> ref = new Ref<>(0);
ApkAssetsCookie cookie = assetmanager.ResolveReference(entry.cookie, value, selected_config, flags, ref);
if (cookie.intValue() == kInvalidCookie) {
// env.ReleasePrimitiveArrayCritical(out_data, buffer, JNI_ABORT);
return -1;
}
// Deal with the special @null value -- it turns back to TYPE_NULL.
if (value.get().dataType == Res_value.TYPE_REFERENCE && value.get().data == 0) {
value.set(Res_value.NULL_VALUE);
}
int offset = i * STYLE_NUM_ENTRIES;
cursor[offset + STYLE_TYPE] = (int) (value.get().dataType);
cursor[offset + STYLE_DATA] = (int) (value.get().data);
cursor[offset + STYLE_ASSET_COOKIE] = ApkAssetsCookieToJavaCookie(cookie);
cursor[offset + STYLE_RESOURCE_ID] = (int) (ref.get());
cursor[offset + STYLE_CHANGING_CONFIGURATIONS] = (int) (flags.get());
cursor[offset + STYLE_DENSITY] = (int) (selected_config.get().density);
// cursor += STYLE_NUM_ENTRIES;
}
// env.ReleasePrimitiveArrayCritical(out_data, buffer, 0);
return (int) (bag.entry_count);
}
Aggregations