Search in sources :

Example 16 with HiddenApi

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

the class ShadowArscAssetManager method retrieveAttributes.

@HiddenApi
@Implementation(minSdk = LOLLIPOP)
protected final boolean retrieveAttributes(long xmlParserToken, int[] attrs, int[] outValues, int[] outIndices) {
    if (xmlParserToken == 0) {
        throw new NullPointerException("xmlParserToken");
    // return JNI_FALSE;
    }
    if (attrs == null) {
        throw new NullPointerException("attrs");
    // return JNI_FALSE;
    }
    if (outValues == null) {
        throw new NullPointerException("out values");
    // return JNI_FALSE;
    }
    CppAssetManager am = assetManagerForJavaObject();
    // if (am == null) {
    // return JNI_FALSE;
    // }
    ResTable res = am.getResources();
    // ResXMLParser xmlParser = (ResXMLParser*)xmlParserToken;
    ResXMLParser xmlParser = Registries.NATIVE_RES_XML_PARSERS.getNativeObject(xmlParserToken);
    // const int NI = env.GetArrayLength(attrs);
    // const int NV = env.GetArrayLength(outValues);
    final int NI = attrs.length;
    final int NV = outValues.length;
    if (NV < (NI * STYLE_NUM_ENTRIES)) {
        throw new IndexOutOfBoundsException("out values too small");
    // return JNI_FALSE;
    }
    // int[] src = (int[])env.GetPrimitiveArrayCritical(attrs, 0);
    // if (src == null) {
    // return JNI_FALSE;
    // }
    int[] src = attrs;
    // int[] baseDest = (int[])env.GetPrimitiveArrayCritical(outValues, 0);
    int[] baseDest = outValues;
    if (baseDest == null) {
        // return JNI_FALSE;
        return false;
    }
    int[] indices = null;
    if (outIndices != null) {
        if (outIndices.length > NI) {
            // indices = (int[])env.GetPrimitiveArrayCritical(outIndices, 0);
            indices = outIndices;
        }
    }
    boolean result = AttributeResolution.RetrieveAttributes(res, xmlParser, src, NI, baseDest, indices);
    if (indices != null) {
    // indices[0] = indicesIdx;
    // env.ReleasePrimitiveArrayCritical(outIndices, indices, 0);
    }
    return result;
}
Also used : CppAssetManager(org.robolectric.res.android.CppAssetManager) ResTable(org.robolectric.res.android.ResTable) ResXMLParser(org.robolectric.res.android.ResXMLParser) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 17 with HiddenApi

use of org.robolectric.annotation.HiddenApi 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));
}
Also used : Ref(org.robolectric.res.android.Ref) CppAssetManager(org.robolectric.res.android.CppAssetManager) FileNotFoundException(java.io.FileNotFoundException) ResXMLTree(org.robolectric.res.android.ResXMLTree) Asset(org.robolectric.res.android.Asset) DynamicRefTable(org.robolectric.res.android.DynamicRefTable) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 18 with HiddenApi

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

Example 19 with HiddenApi

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

the class ShadowArscAssetManager method openNonAssetFdNative.

@HiddenApi
@Implementation
protected ParcelFileDescriptor openNonAssetFdNative(int cookie, String fileName, long[] outOffsets) throws IOException {
    CppAssetManager am = assetManagerForJavaObject();
    ALOGV("openNonAssetFd in %s (Java object %s)", am, this);
    if (fileName == null) {
        return null;
    }
    Asset a = isTruthy(cookie) ? am.openNonAsset(cookie, fileName, Asset.AccessMode.ACCESS_RANDOM) : am.openNonAsset(fileName, Asset.AccessMode.ACCESS_RANDOM, null);
    if (a == null) {
        throw new FileNotFoundException(fileName);
    }
    return returnParcelFileDescriptor(a, outOffsets);
}
Also used : CppAssetManager(org.robolectric.res.android.CppAssetManager) FileNotFoundException(java.io.FileNotFoundException) Asset(org.robolectric.res.android.Asset) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 20 with HiddenApi

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

the class ShadowArscAssetManager method copyTheme.

@HiddenApi
@Implementation(minSdk = LOLLIPOP, maxSdk = O_MR1)
public static void copyTheme(long destPtr, long sourcePtr) {
    ResTableTheme dest = Registries.NATIVE_THEME_REGISTRY.getNativeObject(destPtr);
    ResTableTheme src = Registries.NATIVE_THEME_REGISTRY.getNativeObject(sourcePtr);
    dest.setTo(src);
}
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