13 #include "android_jni_utils.h"
16 #include <freerdp/channels/channels.h>
17 #include <freerdp/log.h>
19 #include "android_jni_callback.h"
21 #define TAG CLIENT_TAG("android.utils")
33 if ((*g_JavaVm)->GetEnv(g_JavaVm, (
void**)&env, JNI_VERSION_1_4) != JNI_OK)
35 WLog_FATAL(TAG,
"Failed to obtain JNIEnv");
41 jobject create_string_builder(JNIEnv* env,
char* initialStr)
48 cls = (*env)->FindClass(env,
"java/lang/StringBuilder");
55 methodId = (*env)->GetMethodID(env, cls,
"<init>",
"(Ljava/lang/String;)V");
60 jstring jstr = (*env)->NewStringUTF(env, initialStr);
63 obj = (*env)->NewObject(env, cls, methodId, jstr);
68 methodId = (*env)->GetMethodID(env, cls,
"<init>",
"()V");
73 obj = (*env)->NewObject(env, cls, methodId);
79 char* get_string_from_string_builder(JNIEnv* env, jobject strBuilder)
84 const char* native_str;
88 cls = (*env)->FindClass(env,
"java/lang/StringBuilder");
93 methodId = (*env)->GetMethodID(env, cls,
"toString",
"()Ljava/lang/String;");
98 strObj = (*env)->CallObjectMethod(env, strBuilder, methodId);
101 native_str = (*env)->GetStringUTFChars(env, strObj, NULL);
104 result = _strdup(native_str);
105 (*env)->ReleaseStringUTFChars(env, strObj, native_str);
110 jstring jniNewStringUTF(JNIEnv* env,
const char* in,
int len)
113 jchar* unicode = NULL;
114 jint result_size = 0;
115 unsigned char* utf8 = (
unsigned char*)in;
124 unicode = (jchar*)malloc(
sizeof(jchar) * (len + 1));
130 for (jint i = 0; i < len; i++)
132 unsigned char one = utf8[i];
143 unicode[result_size++] = one;
161 unsigned char two = utf8[i + 1];
162 unsigned char three = utf8[i + 2];
163 if ((two & 0xc0) == 0x80 && (three & 0xc0) == 0x80)
166 unicode[result_size++] =
167 ((one & 0x0f) << 12) | ((two & 0x3f) << 6) | (three & 0x3f);
176 unsigned char two = utf8[i + 1];
177 if ((two & 0xc0) == 0x80)
180 unicode[result_size++] = ((one & 0x1f) << 6) | (two & 0x3f);
187 out = (*env)->NewString(env, unicode, result_size);