Search in sources :

Example 11 with HiddenApi

use of org.robolectric.annotation.HiddenApi in project robolectric by robolectric.

the class ShadowLegacyAssetManager method getThemeValue.

@HiddenApi
@Implementation(minSdk = LOLLIPOP)
public boolean getThemeValue(long themePtr, int ident, TypedValue outValue, boolean resolveRefs) {
    ResName resName = getResourceTable().getResName(ident);
    ThemeStyleSet themeStyleSet = getNativeTheme(themePtr).themeStyleSet;
    AttributeResource attrValue = themeStyleSet.getAttrValue(resName);
    while (attrValue != null && attrValue.isStyleReference()) {
        ResName attrResName = attrValue.getStyleReference();
        if (attrValue.resName.equals(attrResName)) {
            Logger.info("huh... circular reference for %s?", attrResName.getFullyQualifiedName());
            return false;
        }
        attrValue = themeStyleSet.getAttrValue(attrResName);
    }
    if (attrValue != null) {
        convertAndFill(attrValue, outValue, config, resolveRefs);
        return true;
    }
    return false;
}
Also used : AttributeResource(org.robolectric.res.AttributeResource) ThemeStyleSet(org.robolectric.res.ThemeStyleSet) ResName(org.robolectric.res.ResName) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 12 with HiddenApi

use of org.robolectric.annotation.HiddenApi in project robolectric by robolectric.

the class ShadowLegacyAssetManager method getResourceValue.

@HiddenApi
@Implementation
public boolean getResourceValue(int ident, int density, TypedValue outValue, boolean resolveRefs) {
    TypedResource value = getAndResolve(ident, config, resolveRefs);
    if (value == null)
        return false;
    getConverter(value).fillTypedValue(value.getData(), outValue);
    return true;
}
Also used : TypedResource(org.robolectric.res.TypedResource) FileTypedResource(org.robolectric.res.FileTypedResource) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 13 with HiddenApi

use of org.robolectric.annotation.HiddenApi in project robolectric by robolectric.

the class ShadowArscAssetManager method loadResourceValue.

@HiddenApi
@Implementation
protected int loadResourceValue(int ident, short density, TypedValue outValue, boolean resolve) {
    if (outValue == null) {
        throw new NullPointerException("outValue");
    // return 0;
    }
    CppAssetManager am = assetManagerForJavaObject();
    if (am == null) {
        return 0;
    }
    final ResTable res = am.getResources();
    final Ref<Res_value> value = new Ref<>(null);
    final Ref<ResTable_config> config = new Ref<>(null);
    final Ref<Integer> typeSpecFlags = new Ref<>(null);
    int block = res.getResource(ident, value, false, density, typeSpecFlags, config);
    if (kThrowOnBadId) {
        if (block == BAD_INDEX) {
            throw new IllegalStateException("Bad resource!");
        // return 0;
        }
    }
    final Ref<Integer> ref = new Ref<>(ident);
    if (resolve) {
        block = res.resolveReference(value, block, ref, typeSpecFlags, config);
        if (kThrowOnBadId) {
            if (block == BAD_INDEX) {
                throw new IllegalStateException("Bad resource!");
            // return 0;
            }
        }
    }
    if (block >= 0) {
        // return copyValue(env, outValue, &res, value, ref, block, typeSpecFlags, &config);
        return copyValue(outValue, res, value.get(), ref.get(), block, typeSpecFlags.get(), config.get());
    }
    return block;
}
Also used : Ref(org.robolectric.res.android.Ref) Res_value(org.robolectric.res.android.ResourceTypes.Res_value) CppAssetManager(org.robolectric.res.android.CppAssetManager) ResTable_config(org.robolectric.res.android.ResTable_config) ResTable(org.robolectric.res.android.ResTable) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 14 with HiddenApi

use of org.robolectric.annotation.HiddenApi 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;
}
Also used : Res_value(org.robolectric.res.android.ResourceTypes.Res_value) CppAssetManager(org.robolectric.res.android.CppAssetManager) ResTable_config(org.robolectric.res.android.ResTable_config) ResTable(org.robolectric.res.android.ResTable) Ref(org.robolectric.res.android.Ref) ResTable.bag_entry(org.robolectric.res.android.ResTable.bag_entry) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 15 with HiddenApi

use of org.robolectric.annotation.HiddenApi in project robolectric by robolectric.

the class ShadowArscAssetManager method resolveAttrs.

@Implementation
@HiddenApi
protected static boolean resolveAttrs(long themeToken, int defStyleAttr, int defStyleRes, int[] inValues, int[] attrs, int[] outValues, int[] outIndices) {
    if (themeToken == 0) {
        throw new NullPointerException("theme token");
    }
    if (attrs == null) {
        throw new NullPointerException("attrs");
    }
    if (outValues == null) {
        throw new NullPointerException("out values");
    }
    final int NI = attrs.length;
    final int NV = outValues.length;
    if (NV < (NI * STYLE_NUM_ENTRIES)) {
        throw new IndexOutOfBoundsException("out values too small");
    }
    int[] src = attrs;
    // if (src == null) {
    // return JNI_FALSE;
    // }
    int[] srcValues = inValues;
    final int NSV = srcValues == null ? 0 : inValues.length;
    int[] baseDest = outValues;
    int destOffset = 0;
    if (baseDest == null) {
        return false;
    }
    int[] indices = null;
    if (outIndices != null) {
        if (outIndices.length > NI) {
            indices = outIndices;
        }
    }
    ResTableTheme theme = Registries.NATIVE_THEME_REGISTRY.getNativeObject(themeToken);
    boolean result = AttributeResolution.ResolveAttrs(theme, defStyleAttr, defStyleRes, srcValues, NSV, src, NI, baseDest, indices);
    if (indices != null) {
    // env.ReleasePrimitiveArrayCritical(outIndices, indices, 0);
    }
    return result;
}
Also used : ResTableTheme(org.robolectric.res.android.ResTableTheme) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Aggregations

HiddenApi (org.robolectric.annotation.HiddenApi)61 Implementation (org.robolectric.annotation.Implementation)61 CppAssetManager (org.robolectric.res.android.CppAssetManager)18 Ref (org.robolectric.res.android.Ref)9 ResTable (org.robolectric.res.android.ResTable)9 FileTypedResource (org.robolectric.res.FileTypedResource)8 Asset (org.robolectric.res.android.Asset)8 TypedResource (org.robolectric.res.TypedResource)6 Res_value (org.robolectric.res.android.ResourceTypes.Res_value)6 FileNotFoundException (java.io.FileNotFoundException)5 ArrayList (java.util.ArrayList)5 ResTableTheme (org.robolectric.res.android.ResTableTheme)5 SuppressLint (android.annotation.SuppressLint)4 ResName (org.robolectric.res.ResName)4 ResTable.bag_entry (org.robolectric.res.android.ResTable.bag_entry)4 ResTable_config (org.robolectric.res.android.ResTable_config)4 IOException (java.io.IOException)3 AttributedOpEntry (android.app.AppOpsManager.AttributedOpEntry)2 OpEntry (android.app.AppOpsManager.OpEntry)2 PackageOps (android.app.AppOpsManager.PackageOps)2