Search in sources :

Example 1 with Entry

use of org.robolectric.res.android.CppAssetManager2.ResolvedBag.Entry in project robolectric by robolectric.

the class ShadowArscAssetManager9 method nativeGetResourceIntArray.

// static jintArray NativeGetResourceIntArray(JNIEnv* env, jclass /*clazz*/, jlong ptr, jint
// resid) {
@Implementation(minSdk = P)
@Nullable
protected static int[] nativeGetResourceIntArray(long ptr, @ArrayRes int resid) {
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    ResolvedBag bag = assetmanager.GetBag(resid);
    if (bag == null) {
        return null;
    }
    int[] array = new int[bag.entry_count];
    // if (array == null) {
    // return null;
    // }
    // reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(array, null));
    int[] buffer = array;
    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<>(null);
        final Ref<Integer> flags = new Ref<>(0);
        final Ref<Integer> ref = new Ref<>(0);
        ApkAssetsCookie cookie = assetmanager.ResolveReference(entry.cookie, value, selected_config, flags, ref);
        if (cookie.intValue() == kInvalidCookie) {
            // env.ReleasePrimitiveArrayCritical(array, buffer, JNI_ABORT);
            return null;
        }
        if (value.get().dataType >= Res_value.TYPE_FIRST_INT && value.get().dataType <= Res_value.TYPE_LAST_INT) {
            buffer[i] = (int) (value.get().data);
        }
    }
    // env.ReleasePrimitiveArrayCritical(array, buffer, 0);
    return array;
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) ResolvedBag(org.robolectric.res.android.CppAssetManager2.ResolvedBag) Res_value(org.robolectric.res.android.ResourceTypes.Res_value) ResTable_config(org.robolectric.res.android.ResTable_config) Ref(org.robolectric.res.android.Ref) ApkAssetsCookie(org.robolectric.res.android.ApkAssetsCookie) Implementation(org.robolectric.annotation.Implementation) Nullable(android.annotation.Nullable)

Example 2 with Entry

use of org.robolectric.res.android.CppAssetManager2.ResolvedBag.Entry in project robolectric by robolectric.

the class ShadowArscAssetManager9 method nativeGetResourceBagValue.

// static jint NativeGetResourceBagValue(JNIEnv* env, jclass /*clazz*/, jlong ptr, jint resid,
// jint bag_entry_id, jobject typed_value) {
@Implementation(minSdk = P)
protected static int nativeGetResourceBagValue(long ptr, @AnyRes int resid, int bag_entry_id, @NonNull TypedValue typed_value) {
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    ResolvedBag bag = assetmanager.GetBag(resid);
    if (bag == null) {
        return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE);
    }
    final Ref<Integer> type_spec_flags = new Ref<>(bag.type_spec_flags);
    ApkAssetsCookie cookie = K_INVALID_COOKIE;
    Res_value bag_value = null;
    for (ResolvedBag.Entry entry : bag.entries) {
        if (entry.key == (int) (bag_entry_id)) {
            cookie = entry.cookie;
            bag_value = entry.value;
        // Keep searching (the old implementation did that).
        }
    }
    if (cookie.intValue() == kInvalidCookie) {
        return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE);
    }
    final Ref<Res_value> value = new Ref<>(bag_value);
    final Ref<Integer> ref = new Ref<>(resid);
    final Ref<ResTable_config> selected_config = new Ref<>(null);
    cookie = assetmanager.ResolveReference(cookie, value, selected_config, type_spec_flags, ref);
    if (cookie.intValue() == kInvalidCookie) {
        return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE);
    }
    return CopyValue(cookie, value.get(), ref.get(), type_spec_flags.get(), null, typed_value);
}
Also used : Ref(org.robolectric.res.android.Ref) CppAssetManager2(org.robolectric.res.android.CppAssetManager2) ApkAssetsCookie(org.robolectric.res.android.ApkAssetsCookie) ResolvedBag(org.robolectric.res.android.CppAssetManager2.ResolvedBag) Res_value(org.robolectric.res.android.ResourceTypes.Res_value) ResTable_config(org.robolectric.res.android.ResTable_config) Implementation(org.robolectric.annotation.Implementation)

Example 3 with Entry

use of org.robolectric.res.android.CppAssetManager2.ResolvedBag.Entry in project robolectric by robolectric.

the class ShadowArscAssetManager9 method nativeGetResourceStringArrayInfo.

// static jintArray NativeGetResourceStringArrayInfo(JNIEnv* env, jclass /*clazz*/, jlong ptr,
// jint resid) {
@Implementation(minSdk = P)
@Nullable
protected static int[] nativeGetResourceStringArrayInfo(long ptr, @ArrayRes int resid) {
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    ResolvedBag bag = assetmanager.GetBag(resid);
    if (bag == null) {
        return null;
    }
    int[] array = new int[bag.entry_count * 2];
    // if (array == null) {
    // return null;
    // }
    // reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(array, null));
    int[] buffer = array;
    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<>(null);
        final Ref<Integer> flags = new Ref<>(0);
        final Ref<Integer> ref = new Ref<>(0);
        ApkAssetsCookie cookie = assetmanager.ResolveReference(entry.cookie, value, selected_config, flags, ref);
        if (cookie.intValue() == kInvalidCookie) {
            // env.ReleasePrimitiveArrayCritical(array, buffer, JNI_ABORT);
            return null;
        }
        int string_index = -1;
        if (value.get().dataType == Res_value.TYPE_STRING) {
            string_index = (int) (value.get().data);
        }
        buffer[i * 2] = ApkAssetsCookieToJavaCookie(cookie);
        buffer[(i * 2) + 1] = string_index;
    }
    // env.ReleasePrimitiveArrayCritical(array, buffer, 0);
    return array;
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) ResolvedBag(org.robolectric.res.android.CppAssetManager2.ResolvedBag) Res_value(org.robolectric.res.android.ResourceTypes.Res_value) ResTable_config(org.robolectric.res.android.ResTable_config) Ref(org.robolectric.res.android.Ref) ApkAssetsCookie(org.robolectric.res.android.ApkAssetsCookie) Implementation(org.robolectric.annotation.Implementation) Nullable(android.annotation.Nullable)

Example 4 with Entry

use of org.robolectric.res.android.CppAssetManager2.ResolvedBag.Entry in project robolectric by robolectric.

the class ShadowArscAssetManager9 method nativeGetResourceStringArray.

// static jobjectArray NativeGetResourceStringArray(JNIEnv* env, jclass /*clazz*/, jlong ptr,
// jint resid) {
@Implementation(minSdk = P)
@Nullable
protected static String[] nativeGetResourceStringArray(long ptr, @ArrayRes int resid) {
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    ResolvedBag bag = assetmanager.GetBag(resid);
    if (bag == null) {
        return null;
    }
    String[] array = new String[bag.entry_count];
    if (array == null) {
        return null;
    }
    for (int i = 0; i < bag.entry_count; i++) {
        ResolvedBag.Entry entry = bag.entries[i];
        // Resolve any references to their final value.
        final Ref<Res_value> value = new Ref<>(entry.value);
        final Ref<ResTable_config> selected_config = new Ref<>(null);
        final Ref<Integer> flags = new Ref<>(0);
        final Ref<Integer> ref = new Ref<>(0);
        ApkAssetsCookie cookie = assetmanager.ResolveReference(entry.cookie, value, selected_config, flags, ref);
        if (cookie.intValue() == kInvalidCookie) {
            return null;
        }
        if (value.get().dataType == Res_value.TYPE_STRING) {
            CppApkAssets apk_assets = assetmanager.GetApkAssets().get(cookie.intValue());
            ResStringPool pool = apk_assets.GetLoadedArsc().GetStringPool();
            String java_string = null;
            int str_len;
            String str_utf8 = pool.stringAt(value.get().data);
            if (str_utf8 != null) {
                java_string = str_utf8;
            } else {
                String str_utf16 = pool.stringAt(value.get().data);
                java_string = str_utf16;
            }
            // // Check for errors creating the strings (if malformed or no memory).
            // if (env.ExceptionCheck()) {
            // return null;
            // }
            // env.SetObjectArrayElement(array, i, java_string);
            array[i] = java_string;
        // If we have a large amount of string in our array, we might overflow the
        // local reference table of the VM.
        // env.DeleteLocalRef(java_string);
        }
    }
    return array;
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) ResolvedBag(org.robolectric.res.android.CppAssetManager2.ResolvedBag) Res_value(org.robolectric.res.android.ResourceTypes.Res_value) ResTable_config(org.robolectric.res.android.ResTable_config) Ref(org.robolectric.res.android.Ref) ApkAssetsCookie(org.robolectric.res.android.ApkAssetsCookie) ResStringPool(org.robolectric.res.android.ResStringPool) CppApkAssets(org.robolectric.res.android.CppApkAssets) Implementation(org.robolectric.annotation.Implementation) Nullable(android.annotation.Nullable)

Example 5 with Entry

use of org.robolectric.res.android.CppAssetManager2.ResolvedBag.Entry in project robolectric by robolectric.

the class ShadowArscAssetManager10 method nativeGetResourceBagValue.

// static jint NativeGetResourceBagValue(JNIEnv* env, jclass /*clazz*/, jlong ptr, jint resid,
// jint bag_entry_id, jobject typed_value) {
@Implementation(minSdk = P)
protected static int nativeGetResourceBagValue(long ptr, @AnyRes int resid, int bag_entry_id, @NonNull TypedValue typed_value) {
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    ResolvedBag bag = assetmanager.GetBag(resid);
    if (bag == null) {
        return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE);
    }
    final Ref<Integer> type_spec_flags = new Ref<>(bag.type_spec_flags);
    ApkAssetsCookie cookie = K_INVALID_COOKIE;
    Res_value bag_value = null;
    for (ResolvedBag.Entry entry : bag.entries) {
        if (entry.key == (int) (bag_entry_id)) {
            cookie = entry.cookie;
            bag_value = entry.value;
        // Keep searching (the old implementation did that).
        }
    }
    if (cookie.intValue() == kInvalidCookie) {
        return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE);
    }
    final Ref<Res_value> value = new Ref<>(bag_value);
    final Ref<Integer> ref = new Ref<>(resid);
    final Ref<ResTable_config> selected_config = new Ref<>(null);
    cookie = assetmanager.ResolveReference(cookie, value, selected_config, type_spec_flags, ref);
    if (cookie.intValue() == kInvalidCookie) {
        return ApkAssetsCookieToJavaCookie(K_INVALID_COOKIE);
    }
    return CopyValue(cookie, value.get(), ref.get(), type_spec_flags.get(), null, typed_value);
}
Also used : Ref(org.robolectric.res.android.Ref) CppAssetManager2(org.robolectric.res.android.CppAssetManager2) ApkAssetsCookie(org.robolectric.res.android.ApkAssetsCookie) ResolvedBag(org.robolectric.res.android.CppAssetManager2.ResolvedBag) Res_value(org.robolectric.res.android.ResourceTypes.Res_value) ResTable_config(org.robolectric.res.android.ResTable_config) Implementation(org.robolectric.annotation.Implementation)

Aggregations

Res_value (org.robolectric.res.android.ResourceTypes.Res_value)15 ResolvedBag (org.robolectric.res.android.CppAssetManager2.ResolvedBag)14 Implementation (org.robolectric.annotation.Implementation)10 ApkAssetsCookie (org.robolectric.res.android.ApkAssetsCookie)10 CppAssetManager2 (org.robolectric.res.android.CppAssetManager2)10 Ref (org.robolectric.res.android.Ref)10 ResTable_config (org.robolectric.res.android.ResTable_config)10 Nullable (android.annotation.Nullable)6 Entry (org.robolectric.res.android.CppAssetManager2.ResolvedBag.Entry)5 CppApkAssets (org.robolectric.res.android.CppApkAssets)2 ResStringPool (org.robolectric.res.android.ResStringPool)2 DynamicPackageEntry (org.robolectric.res.android.LoadedArsc.DynamicPackageEntry)1 ResTable_map (org.robolectric.res.android.ResourceTypes.ResTable_map)1 ResTable_map_entry (org.robolectric.res.android.ResourceTypes.ResTable_map_entry)1