use of org.robolectric.res.android.CppAssetManager 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));
}
use of org.robolectric.res.android.CppAssetManager 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;
}
use of org.robolectric.res.android.CppAssetManager 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);
}
use of org.robolectric.res.android.CppAssetManager in project robolectric by robolectric.
the class ShadowArscAssetManager method getResourcePackageName.
@Implementation
protected String getResourcePackageName(int resid) {
CppAssetManager cppAssetManager = assetManagerForJavaObject();
ResourceName name = new ResourceName();
if (!cppAssetManager.getResources().getResourceName(resid, true, name)) {
return null;
}
return name.packageName.trim();
}
use of org.robolectric.res.android.CppAssetManager in project robolectric by robolectric.
the class ShadowArscAssetManager method getResourceEntryName.
@Implementation
protected String getResourceEntryName(int resid) {
CppAssetManager cppAssetManager = assetManagerForJavaObject();
ResourceName name = new ResourceName();
if (!cppAssetManager.getResources().getResourceName(resid, true, name)) {
return null;
}
return name.name;
}
Aggregations