use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager10 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_));
}
use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager10 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;
}
use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager10 method nativeSetConfiguration.
// static void NativeSetConfiguration(JNIEnv* env, jclass /*clazz*/, jlong ptr, jint mcc, jint
// mnc,
// jstring locale, jint orientation, jint touchscreen, jint
// density,
// jint keyboard, jint keyboard_hidden, jint navigation,
// jint screen_width, jint screen_height,
// jint smallest_screen_width_dp, jint screen_width_dp,
// jint screen_height_dp, jint screen_layout, jint ui_mode,
// jint color_mode, jint major_version) {
@Implementation(minSdk = P)
protected static void nativeSetConfiguration(long ptr, int mcc, int mnc, @Nullable String locale, int orientation, int touchscreen, int density, int keyboard, int keyboard_hidden, int navigation, int screen_width, int screen_height, int smallest_screen_width_dp, int screen_width_dp, int screen_height_dp, int screen_layout, int ui_mode, int color_mode, int major_version) {
ATRACE_NAME("AssetManager::SetConfiguration");
ResTable_config configuration = new ResTable_config();
// memset(&configuration, 0, sizeof(configuration));
configuration.mcc = (short) (mcc);
configuration.mnc = (short) (mnc);
configuration.orientation = (byte) (orientation);
configuration.touchscreen = (byte) (touchscreen);
configuration.density = (short) (density);
configuration.keyboard = (byte) (keyboard);
configuration.inputFlags = (byte) (keyboard_hidden);
configuration.navigation = (byte) (navigation);
configuration.screenWidth = (short) (screen_width);
configuration.screenHeight = (short) (screen_height);
configuration.smallestScreenWidthDp = (short) (smallest_screen_width_dp);
configuration.screenWidthDp = (short) (screen_width_dp);
configuration.screenHeightDp = (short) (screen_height_dp);
configuration.screenLayout = (byte) (screen_layout);
configuration.uiMode = (byte) (ui_mode);
configuration.colorMode = (byte) (color_mode);
configuration.sdkVersion = (short) (major_version);
if (locale != null) {
String locale_utf8 = locale;
CHECK(locale_utf8 != null);
configuration.setBcp47Locale(locale_utf8);
}
// Constants duplicated from Java class android.content.res.Configuration.
int kScreenLayoutRoundMask = 0x300;
int kScreenLayoutRoundShift = 8;
// In Java, we use a 32bit integer for screenLayout, while we only use an 8bit integer
// in C++. We must extract the round qualifier out of the Java screenLayout and put it
// into screenLayout2.
configuration.screenLayout2 = (byte) ((screen_layout & kScreenLayoutRoundMask) >> kScreenLayoutRoundShift);
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
assetmanager.SetConfiguration(configuration);
}
use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager10 method nativeGetLocales.
// static jobjectArray NativeGetLocales(JNIEnv* env, jclass /*class*/, jlong ptr,
// jboolean exclude_system) {
@Implementation(minSdk = P)
@Nullable
protected static String[] nativeGetLocales(long ptr, boolean exclude_system) {
CppAssetManager2 assetmanager = AssetManagerFromLong(ptr);
Set<String> locales = assetmanager.GetResourceLocales(exclude_system, true);
String[] array = // env.NewObjectArray(locales.size(), g_stringClass, null);
new String[locales.size()];
// if (array == null) {
// return null;
// }
int idx = 0;
for (String locale : locales) {
String java_string = locale;
if (java_string == null) {
return null;
}
// env.SetObjectArrayElement(array, idx++, java_string);
array[idx++] = java_string;
// env.DeleteLocalRef(java_string);
}
return array;
}
use of org.robolectric.res.android.CppAssetManager2 in project robolectric by robolectric.
the class ShadowArscAssetManager10 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);
}
Aggregations