Search in sources :

Example 46 with CppAssetManager2

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

the class ShadowArscAssetManager9 method nativeOpenAssetFd.

// static jobject NativeOpenAssetFd(JNIEnv* env, jclass /*clazz*/, jlong ptr, jstring asset_path,
// jlongArray out_offsets) {
@Implementation(minSdk = P)
protected static ParcelFileDescriptor nativeOpenAssetFd(long ptr, @NonNull String asset_path, long[] out_offsets) throws IOException {
    String asset_path_utf8 = asset_path;
    if (asset_path_utf8 == null) {
        // This will throw NPE.
        return null;
    }
    ATRACE_NAME(String.format("AssetManager::OpenAssetFd(%s)", asset_path_utf8));
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    Asset asset = assetmanager.Open(asset_path_utf8, Asset.AccessMode.ACCESS_RANDOM);
    if (!isTruthy(asset)) {
        throw new FileNotFoundException(asset_path_utf8);
    }
    return ReturnParcelFileDescriptor(asset, out_offsets);
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) FileNotFoundException(java.io.FileNotFoundException) Asset(org.robolectric.res.android.Asset) Implementation(org.robolectric.annotation.Implementation)

Example 47 with CppAssetManager2

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

the class ShadowArscAssetManager9 method nativeGetResourceIdentifier.

// static jint NativeGetResourceIdentifier(JNIEnv* env, jclass /*clazz*/, jlong ptr, jstring name,
// jstring def_type, jstring def_package) {
@Implementation(minSdk = P)
@AnyRes
protected static int nativeGetResourceIdentifier(long ptr, @NonNull String name, @Nullable String def_type, @Nullable String def_package) {
    String name_utf8 = name;
    if (name_utf8 == null) {
        // This will throw NPE.
        return 0;
    }
    String type = null;
    if (def_type != null) {
        String type_utf8 = def_type;
        CHECK(type_utf8 != null);
        type = type_utf8;
    }
    String package_ = null;
    if (def_package != null) {
        String package_utf8 = def_package;
        CHECK(package_utf8 != null);
        package_ = package_utf8;
    }
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    return (int) (assetmanager.GetResourceId(name_utf8, type, package_));
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) AnyRes(android.annotation.AnyRes) Implementation(org.robolectric.annotation.Implementation)

Example 48 with CppAssetManager2

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

the class ShadowArscAssetManager9 method nativeOpenNonAssetFd.

// static jobject NativeOpenNonAssetFd(JNIEnv* env, jclass /*clazz*/, jlong ptr, jint jcookie,
// jstring asset_path, jlongArray out_offsets) {
@Implementation(minSdk = P)
@Nullable
protected static ParcelFileDescriptor nativeOpenNonAssetFd(long ptr, int jcookie, @NonNull String asset_path, @NonNull long[] out_offsets) throws IOException {
    ApkAssetsCookie cookie = JavaCookieToApkAssetsCookie(jcookie);
    String asset_path_utf8 = asset_path;
    if (asset_path_utf8 == null) {
        // This will throw NPE.
        return null;
    }
    ATRACE_NAME(String.format("AssetManager::OpenNonAssetFd(%s)", asset_path_utf8));
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    Asset asset;
    if (cookie.intValue() != kInvalidCookie) {
        asset = assetmanager.OpenNonAsset(asset_path_utf8, cookie, Asset.AccessMode.ACCESS_RANDOM);
    } else {
        asset = assetmanager.OpenNonAsset(asset_path_utf8, Asset.AccessMode.ACCESS_RANDOM);
    }
    if (!isTruthy(asset)) {
        throw new FileNotFoundException(asset_path_utf8);
    }
    return ReturnParcelFileDescriptor(asset, out_offsets);
}
Also used : ApkAssetsCookie(org.robolectric.res.android.ApkAssetsCookie) CppAssetManager2(org.robolectric.res.android.CppAssetManager2) FileNotFoundException(java.io.FileNotFoundException) Asset(org.robolectric.res.android.Asset) Implementation(org.robolectric.annotation.Implementation) Nullable(android.annotation.Nullable)

Example 49 with CppAssetManager2

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

the class ShadowArscAssetManager9 method nativeGetResourcePackageName.

// static jstring NativeGetResourcePackageName(JNIEnv* env, jclass /*clazz*/, jlong ptr, jint
// resid) {
@Implementation(minSdk = P)
@Nullable
protected static String nativeGetResourcePackageName(long ptr, @AnyRes int resid) {
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    final ResourceName name = new ResourceName();
    if (!assetmanager.GetResourceName(resid, name)) {
        return null;
    }
    if (name.package_ != null) {
        return name.package_;
    }
    return null;
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) ResourceName(org.robolectric.res.android.CppAssetManager2.ResourceName) Implementation(org.robolectric.annotation.Implementation) Nullable(android.annotation.Nullable)

Example 50 with CppAssetManager2

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

the class ShadowArscAssetManager9 method nativeApplyStyle_measured.

private static void nativeApplyStyle_measured(long ptr, long theme_ptr, @AttrRes int def_style_attr, @StyleRes int def_style_resid, long xml_parser_ptr, @NonNull int[] java_attrs, long out_values_ptr, long out_indices_ptr) {
    CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
    Theme theme = Registries.NATIVE_THEME9_REGISTRY.getNativeObject(theme_ptr);
    CHECK(theme.GetAssetManager() == assetmanager);
    // (void) assetmanager;
    ResXMLParser xml_parser = xml_parser_ptr == 0 ? null : NATIVE_RES_XML_PARSERS.getNativeObject(xml_parser_ptr);
    // int[] out_values = reinterpret_cast<int*>(out_values_ptr);
    // int[] out_indices = reinterpret_cast<int*>(out_indices_ptr);
    ShadowVMRuntime shadowVMRuntime = Shadow.extract(VMRuntime.getRuntime());
    int[] out_values = (int[]) shadowVMRuntime.getObjectForAddress(out_values_ptr);
    int[] out_indices = (int[]) shadowVMRuntime.getObjectForAddress(out_indices_ptr);
    int attrs_len = java_attrs.length;
    int[] attrs = // reinterpret_cast<int*>(env.GetPrimitiveArrayCritical(java_attrs, null));
    java_attrs;
    // if (attrs == null) {
    // return;
    // }
    ApplyStyle(theme, xml_parser, (int) (def_style_attr), (int) (def_style_resid), attrs, attrs_len, out_values, out_indices);
// env.ReleasePrimitiveArrayCritical(java_attrs, attrs, JNI_ABORT);
}
Also used : CppAssetManager2(org.robolectric.res.android.CppAssetManager2) Theme(org.robolectric.res.android.CppAssetManager2.Theme) ResXMLParser(org.robolectric.res.android.ResXMLParser)

Aggregations

CppAssetManager2 (org.robolectric.res.android.CppAssetManager2)66 Implementation (org.robolectric.annotation.Implementation)62 Nullable (android.annotation.Nullable)24 ApkAssetsCookie (org.robolectric.res.android.ApkAssetsCookie)20 ResolvedBag (org.robolectric.res.android.CppAssetManager2.ResolvedBag)18 ResTable_config (org.robolectric.res.android.ResTable_config)18 Res_value (org.robolectric.res.android.ResourceTypes.Res_value)18 Ref (org.robolectric.res.android.Ref)16 FileNotFoundException (java.io.FileNotFoundException)12 Asset (org.robolectric.res.android.Asset)11 Theme (org.robolectric.res.android.CppAssetManager2.Theme)11 ResourceName (org.robolectric.res.android.CppAssetManager2.ResourceName)8 CppApkAssets (org.robolectric.res.android.CppApkAssets)4 Entry (org.robolectric.res.android.CppAssetManager2.ResolvedBag.Entry)4 ResXMLParser (org.robolectric.res.android.ResXMLParser)4 AnyRes (android.annotation.AnyRes)2 AttrRes (android.annotation.AttrRes)2 NonNull (android.annotation.NonNull)2 ApkAssets (android.content.res.ApkAssets)2 Configuration (android.content.res.Configuration)2