import com.freerdp.freerdpcore.services.QuickConnectHistoryGateway;
public class GlobalApp extends Application implements LibFreeRDP.EventListener {
- private static Map<Integer, SessionState> sessionMap;
+ private static Map<Long, SessionState> sessionMap;
private static final String TAG = "GlobalApp";
public GlobalApp() {
- sessionMap = Collections.synchronizedMap(new HashMap<Integer, SessionState>());
+ sessionMap = Collections.synchronizedMap(new HashMap<Long, SessionState>());
LibFreeRDP.setEventListener(this);
}
// RDP session handling
static public SessionState createSession(BookmarkBase bookmark, Context context) {
SessionState session = new SessionState(LibFreeRDP.newInstance(context), bookmark);
- sessionMap.put(Integer.valueOf(session.getInstance()), session);
+ sessionMap.put(Long.valueOf(session.getInstance()), session);
return session;
}
static public SessionState createSession(Uri openUri, Context context) {
SessionState session = new SessionState(LibFreeRDP.newInstance(context), openUri);
- sessionMap.put(Integer.valueOf(session.getInstance()), session);
+ sessionMap.put(Long.valueOf(session.getInstance()), session);
return session;
}
- static public SessionState getSession(int instance) {
+ static public SessionState getSession(long instance) {
return sessionMap.get(instance);
}
return new ArrayList<SessionState>(sessionMap.values());
}
- static public void freeSession(int instance) {
+ static public void freeSession(long instance) {
if (GlobalApp.sessionMap.containsKey(instance)) {
GlobalApp.sessionMap.remove(instance);
LibFreeRDP.freeInstance(instance);
}
// helper to send FreeRDP notifications
- private void sendRDPNotification(int type, int param) {
+ private void sendRDPNotification(int type, long param) {
// send broadcast
Intent intent = new Intent(ACTION_EVENT_FREERDP);
intent.putExtra(EVENT_TYPE, type);
}
@Override
- public void OnPreConnect(int instance) {
+ public void OnPreConnect(long instance) {
Log.v(TAG, "OnPreConnect");
}
// //////////////////////////////////////////////////////////////////////
// Implementation of LibFreeRDP.EventListener
- public void OnConnectionSuccess(int instance) {
+ public void OnConnectionSuccess(long instance) {
Log.v(TAG, "OnConnectionSuccess");
sendRDPNotification(FREERDP_EVENT_CONNECTION_SUCCESS, instance);
}
- public void OnConnectionFailure(int instance) {
+ public void OnConnectionFailure(long instance) {
Log.v(TAG, "OnConnectionFailure");
// send notification to session activity
sendRDPNotification(FREERDP_EVENT_CONNECTION_FAILURE, instance);
}
- public void OnDisconnecting(int instance) {
+ public void OnDisconnecting(long instance) {
Log.v(TAG, "OnDisconnecting");
// send disconnect notification
sendRDPNotification(FREERDP_EVENT_DISCONNECTED, instance);
}
- public void OnDisconnected(int instance) {
+ public void OnDisconnected(long instance) {
Log.v(TAG, "OnDisconnected");
}
}
public class SessionState implements Parcelable
{
- private int instance;
+ private long instance;
private BookmarkBase bookmark;
private Uri openUri;
private BitmapDrawable surface;
public SessionState(Parcel parcel)
{
- instance = parcel.readInt();
+ instance = parcel.readLong();
bookmark = parcel.readParcelable(null);
openUri = parcel.readParcelable(null);
surface = new BitmapDrawable(bitmap);
}
- public SessionState(int instance, BookmarkBase bookmark)
+ public SessionState(long instance, BookmarkBase bookmark)
{
this.instance = instance;
this.bookmark = bookmark;
this.uiEventListener = null;
}
- public SessionState(int instance, Uri openUri)
+ public SessionState(long instance, Uri openUri)
{
this.instance = instance;
this.bookmark = null;
LibFreeRDP.connect(instance);
}
- public int getInstance() {
+ public long getInstance() {
return instance;
}
@Override
public void writeToParcel(Parcel out, int flags) {
- out.writeInt(instance);
+ out.writeLong(instance);
out.writeParcelable(bookmark, flags);
out.writeParcelable(openUri, flags);
out.writeParcelable(surface.getBitmap(), flags);
return;
// is this event for the current session?
- if (session.getInstance() != intent.getExtras().getInt(
+ if (session.getInstance() != intent.getExtras().getLong(
GlobalApp.EVENT_PARAM, -1))
return;
private static native String freerdp_get_build_config();
- private static native int freerdp_new(Context context);
+ private static native long freerdp_new(Context context);
- private static native void freerdp_free(int inst);
+ private static native void freerdp_free(long inst);
- private static native boolean freerdp_parse_arguments(int inst, String[] args);
+ private static native boolean freerdp_parse_arguments(long inst, String[] args);
- private static native boolean freerdp_connect(int inst);
+ private static native boolean freerdp_connect(long inst);
- private static native boolean freerdp_disconnect(int inst);
+ private static native boolean freerdp_disconnect(long inst);
- private static native boolean freerdp_update_graphics(int inst,
+ private static native boolean freerdp_update_graphics(long inst,
Bitmap bitmap, int x, int y, int width, int height);
- private static native boolean freerdp_send_cursor_event(int inst, int x, int y, int flags);
+ private static native boolean freerdp_send_cursor_event(long inst, int x, int y, int flags);
- private static native boolean freerdp_send_key_event(int inst, int keycode, boolean down);
+ private static native boolean freerdp_send_key_event(long inst, int keycode, boolean down);
- private static native boolean freerdp_send_unicodekey_event(int inst, int keycode);
+ private static native boolean freerdp_send_unicodekey_event(long inst, int keycode);
- private static native boolean freerdp_send_clipboard_data(int inst, String data);
+ private static native boolean freerdp_send_clipboard_data(long inst, String data);
public static interface EventListener {
- void OnPreConnect(int instance);
+ void OnPreConnect(long instance);
- void OnConnectionSuccess(int instance);
+ void OnConnectionSuccess(long instance);
- void OnConnectionFailure(int instance);
+ void OnConnectionFailure(long instance);
- void OnDisconnecting(int instance);
+ void OnDisconnecting(long instance);
- void OnDisconnected(int instance);
+ void OnDisconnected(long instance);
}
public static interface UIEventListener {
listener = l;
}
- public static int newInstance(Context context) {
+ public static long newInstance(Context context) {
return freerdp_new(context);
}
- public static void freeInstance(int inst) {
+ public static void freeInstance(long inst) {
freerdp_free(inst);
}
- public static boolean connect(int inst) {
+ public static boolean connect(long inst) {
return freerdp_connect(inst);
}
- public static boolean disconnect(int inst) {
+ public static boolean disconnect(long inst) {
return freerdp_disconnect(inst);
}
- public static boolean cancelConnection(int inst) {
+ public static boolean cancelConnection(long inst) {
return freerdp_disconnect(inst);
}
return "-" + name;
}
- public static boolean setConnectionInfo(int inst, BookmarkBase bookmark) {
+ public static boolean setConnectionInfo(long inst, BookmarkBase bookmark) {
BookmarkBase.ScreenSettings screenSettings = bookmark.getActiveScreenSettings();
BookmarkBase.AdvancedSettings advanced = bookmark.getAdvancedSettings();
BookmarkBase.DebugSettings debug = bookmark.getDebugSettings();
return freerdp_parse_arguments(inst, arrayArgs);
}
- public static boolean setConnectionInfo(int inst, Uri openUri) {
+ public static boolean setConnectionInfo(long inst, Uri openUri) {
ArrayList<String> args = new ArrayList<String>();
// Parse URI from query string. Same key overwrite previous one
return freerdp_parse_arguments(inst, arrayArgs);
}
- public static boolean updateGraphics(int inst, Bitmap bitmap, int x, int y, int width, int height) {
+ public static boolean updateGraphics(long inst, Bitmap bitmap, int x, int y, int width, int height) {
return freerdp_update_graphics(inst, bitmap, x, y, width, height);
}
- public static boolean sendCursorEvent(int inst, int x, int y, int flags) {
+ public static boolean sendCursorEvent(long inst, int x, int y, int flags) {
return freerdp_send_cursor_event(inst, x, y, flags);
}
- public static boolean sendKeyEvent(int inst, int keycode, boolean down) {
+ public static boolean sendKeyEvent(long inst, int keycode, boolean down) {
return freerdp_send_key_event(inst, keycode, down);
}
- public static boolean sendUnicodeKeyEvent(int inst, int keycode) {
+ public static boolean sendUnicodeKeyEvent(long inst, int keycode) {
return freerdp_send_unicodekey_event(inst, keycode);
}
- public static boolean sendClipboardData(int inst, String data) {
+ public static boolean sendClipboardData(long inst, String data) {
return freerdp_send_clipboard_data(inst, data);
}
- private static void OnConnectionSuccess(int inst) {
+ private static void OnConnectionSuccess(long inst) {
if (listener != null)
listener.OnConnectionSuccess(inst);
}
- private static void OnConnectionFailure(int inst) {
+ private static void OnConnectionFailure(long inst) {
if (listener != null)
listener.OnConnectionFailure(inst);
}
- private static void OnPreConnect(int inst) {
+ private static void OnPreConnect(long inst) {
if (listener != null)
listener.OnPreConnect(inst);
}
- private static void OnDisconnecting(int inst) {
+ private static void OnDisconnecting(long inst) {
if (listener != null)
listener.OnDisconnecting(inst);
}
- private static void OnDisconnected(int inst) {
+ private static void OnDisconnected(long inst) {
if (listener != null)
listener.OnDisconnected(inst);
}
- private static void OnSettingsChanged(int inst, int width, int height, int bpp) {
+ private static void OnSettingsChanged(long inst, int width, int height, int bpp) {
SessionState s = GlobalApp.getSession(inst);
if (s == null)
return;
uiEventListener.OnSettingsChanged(width, height, bpp);
}
- private static boolean OnAuthenticate(int inst, StringBuilder username, StringBuilder domain, StringBuilder password) {
+ private static boolean OnAuthenticate(long inst, StringBuilder username, StringBuilder domain, StringBuilder password) {
SessionState s = GlobalApp.getSession(inst);
if (s == null)
return false;
return false;
}
- private static boolean OnGatewayAuthenticate(int inst, StringBuilder username, StringBuilder
+ private static boolean OnGatewayAuthenticate(long inst, StringBuilder username, StringBuilder
domain, StringBuilder password) {
SessionState s = GlobalApp.getSession(inst);
if (s == null)
return false;
}
- private static int OnVerifyCertificate(int inst, String commonName, String subject,
+ private static int OnVerifyCertificate(long inst, String commonName, String subject,
String issuer, String fingerprint, boolean
hostMismatch) {
SessionState s = GlobalApp.getSession(inst);
return 0;
}
- private static int OnVerifyChangedCertificate(int inst, String commonName, String subject,
+ private static int OnVerifyChangedCertificate(long inst, String commonName, String subject,
String issuer, String fingerprint, String oldSubject,
String oldIssuer, String oldFingerprint) {
SessionState s = GlobalApp.getSession(inst);
return 0;
}
- private static void OnGraphicsUpdate(int inst, int x, int y, int width, int height) {
+ private static void OnGraphicsUpdate(long inst, int x, int y, int width, int height) {
SessionState s = GlobalApp.getSession(inst);
if (s == null)
return;
uiEventListener.OnGraphicsUpdate(x, y, width, height);
}
- private static void OnGraphicsResize(int inst, int width, int height, int bpp) {
+ private static void OnGraphicsResize(long inst, int width, int height, int bpp) {
SessionState s = GlobalApp.getSession(inst);
if (s == null)
return;
uiEventListener.OnGraphicsResize(width, height, bpp);
}
- private static void OnRemoteClipboardChanged(int inst, String data) {
+ private static void OnRemoteClipboardChanged(long inst, String data) {
SessionState s = GlobalApp.getSession(inst);
if (s == null)
return;
y2 = MAX(y2, cinvalid[i].y + cinvalid[i].h);
}
- freerdp_callback("OnGraphicsUpdate", "(IIIII)V", context->instance,
+ freerdp_callback("OnGraphicsUpdate", "(JIIII)V", (jlong)context->instance,
x1, y1, x2 - x1, y2 - y1);
return TRUE;
}
if (!context || !context->instance || !context->settings)
return FALSE;
- freerdp_callback("OnGraphicsResize", "(IIII)V",
- context->instance, context->settings->DesktopWidth,
+ freerdp_callback("OnGraphicsResize", "(JIII)V",
+ (jlong)context->instance, context->settings->DesktopWidth,
context->settings->DesktopHeight, context->settings->ColorDepth);
return TRUE;
}
return FALSE;
}
- freerdp_callback("OnPreConnect", "(I)V", instance);
+ freerdp_callback("OnPreConnect", "(J)V", (jlong)instance);
return TRUE;
}
instance->update->EndPaint = android_end_paint;
instance->update->DesktopResize = android_desktop_resize;
pointer_cache_register_callbacks(update);
- freerdp_callback("OnSettingsChanged", "(IIII)V", instance,
+ freerdp_callback("OnSettingsChanged", "(JIII)V", (jlong)instance,
settings->DesktopWidth, settings->DesktopHeight,
settings->ColorDepth);
- freerdp_callback("OnConnectionSuccess", "(I)V", instance);
+ freerdp_callback("OnConnectionSuccess", "(J)V", (jlong)instance);
return TRUE;
}
static void android_post_disconnect(freerdp* instance)
{
- freerdp_callback("OnDisconnecting", "(I)V", instance);
+ freerdp_callback("OnDisconnecting", "(J)V", (jlong)instance);
gdi_free(instance);
}
jboolean res;
res = freerdp_callback_bool_result(
cb_name,
- "(ILjava/lang/StringBuilder;"
+ "(JLjava/lang/StringBuilder;"
"Ljava/lang/StringBuilder;"
"Ljava/lang/StringBuilder;)Z",
- instance, jstr1, jstr2, jstr3);
+ (jlong)instance, jstr1, jstr2, jstr3);
if (res == JNI_TRUE)
{
jstring jstr2 = (*env)->NewStringUTF(env, issuer);
jstring jstr3 = (*env)->NewStringUTF(env, fingerprint);
jint res = freerdp_callback_int_result("OnVerifyCertificate",
- "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)I",
- instance, jstr0, jstr1, jstr2, jstr3, host_mismatch);
+ "(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)I",
+ (jlong)instance, jstr0, jstr1, jstr2, jstr3, host_mismatch);
if (attached == JNI_TRUE)
jni_detach_thread();
jstring jstr5 = (*env)->NewStringUTF(env, old_issuer);
jstring jstr6 = (*env)->NewStringUTF(env, old_fingerprint);
jint res = freerdp_callback_int_result("OnVerifyChangedCertificate",
- "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;"
+ "(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;"
"Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I",
- instance, jstr0, jstr1, jstr2, jstr3, jstr4, jstr5, jstr6);
+ (jlong)instance, jstr0, jstr1, jstr2, jstr3, jstr4, jstr5, jstr6);
if (attached == JNI_TRUE)
jni_detach_thread();
WLog_DBG(TAG, "Session ended with %08lX", status);
if (status == CHANNEL_RC_OK)
- freerdp_callback("OnDisconnected", "(I)V", instance);
+ freerdp_callback("OnDisconnected", "(J)V", (jlong)instance);
else
- freerdp_callback("OnConnectionFailure", "(I)V", instance);
+ freerdp_callback("OnConnectionFailure", "(J)V", (jlong)instance);
WLog_DBG(TAG, "Quit.");
ExitThread(status);
return 0;
}
-static jint JNICALL jni_freerdp_new(JNIEnv* env, jclass cls, jobject context)
+static jlong JNICALL jni_freerdp_new(JNIEnv* env, jclass cls, jobject context)
{
jclass contextClass;
jclass fileClass;
{
WLog_FATAL(TAG, "Failed to load class references %s=%p, %s=%p",
JAVA_CONTEXT_CLASS, contextClass, JAVA_FILE_CLASS, fileClass);
- return (jint)NULL;
+ return (jlong)NULL;
}
getFilesDirID = (*env)->GetMethodID(env, contextClass, "getFilesDir",
if (!getFilesDirID)
{
WLog_FATAL(TAG, "Failed to find method ID getFilesDir ()L"JAVA_FILE_CLASS";");
- return (jint)NULL;
+ return (jlong)NULL;
}
getAbsolutePathID = (*env)->GetMethodID(env, fileClass, "getAbsolutePath",
{
WLog_FATAL(TAG,
"Failed to find method ID getAbsolutePath ()Ljava/lang/String;");
- return (jint)NULL;
+ return (jlong)NULL;
}
filesDirObj = (*env)->CallObjectMethod(env, context, getFilesDirID);
if (!filesDirObj)
{
WLog_FATAL(TAG, "Failed to call getFilesDir");
- return (jint)NULL;
+ return (jlong)NULL;
}
path = (*env)->CallObjectMethod(env, filesDirObj, getAbsolutePathID);
if (!path)
{
WLog_FATAL(TAG, "Failed to call getAbsolutePath");
- return (jint)NULL;
+ return (jlong)NULL;
}
raw = (*env)->GetStringUTFChars(env, path, 0);
if (!raw)
{
WLog_FATAL(TAG, "Failed to get C string from java string");
- return (jint)NULL;
+ return (jlong)NULL;
}
envStr = _strdup(raw);
if (!envStr)
{
WLog_FATAL(TAG, "_strdup(%s) failed", raw);
- return (jint)NULL;
+ return (jlong)NULL;
}
if (setenv("HOME", _strdup(envStr), 1) != 0)
{
WLog_FATAL(TAG, "Failed to set environemnt HOME=%s %s [%d]",
env, strerror(errno), errno);
- return (jint)NULL;
+ return (jlong)NULL;
}
RdpClientEntry(&clientEntryPoints);
ctx = freerdp_client_context_new(&clientEntryPoints);
if (!ctx)
- return (jint)NULL;
+ return (jlong)NULL;
- return (jint) ctx->instance;
+ return (jlong) ctx->instance;
}
-static void JNICALL jni_freerdp_free(JNIEnv* env, jclass cls, jint instance)
+static void JNICALL jni_freerdp_free(JNIEnv* env, jclass cls, jlong instance)
{
freerdp* inst = (freerdp*)instance;
}
static jboolean JNICALL jni_freerdp_parse_arguments(
- JNIEnv* env, jclass cls, jint instance, jobjectArray arguments)
+ JNIEnv* env, jclass cls, jlong instance, jobjectArray arguments)
{
freerdp* inst = (freerdp*)instance;
int i, count;
}
static jboolean JNICALL jni_freerdp_connect(JNIEnv* env, jclass cls,
- jint instance)
+ jlong instance)
{
freerdp* inst = (freerdp*)instance;
androidContext* ctx;
}
static jboolean JNICALL jni_freerdp_disconnect(JNIEnv* env, jclass cls,
- jint instance)
+ jlong instance)
{
freerdp* inst = (freerdp*)instance;
androidContext* ctx;
}
static jboolean JNICALL jni_freerdp_update_graphics(
- JNIEnv* env, jclass cls, jint instance, jobject bitmap,
+ JNIEnv* env, jclass cls, jlong instance, jobject bitmap,
jint x, jint y, jint width, jint height)
{
UINT32 DstFormat;
}
static jboolean JNICALL jni_freerdp_send_key_event(
- JNIEnv* env, jclass cls, jint instance,
+ JNIEnv* env, jclass cls, jlong instance,
jint keycode, jboolean down)
{
DWORD scancode;
}
static jboolean JNICALL jni_freerdp_send_unicodekey_event(
- JNIEnv* env, jclass cls, jint instance, jint keycode)
+ JNIEnv* env, jclass cls, jlong instance, jint keycode)
{
ANDROID_EVENT* event;
freerdp* inst = (freerdp*)instance;
}
static jboolean JNICALL jni_freerdp_send_cursor_event(
- JNIEnv* env, jclass cls, jint instance, jint x, jint y, jint flags)
+ JNIEnv* env, jclass cls, jlong instance, jint x, jint y, jint flags)
{
ANDROID_EVENT* event;
freerdp* inst = (freerdp*)instance;
static jboolean JNICALL jni_freerdp_send_clipboard_data(
JNIEnv* env, jclass cls,
- jint instance, jstring jdata)
+ jlong instance, jstring jdata)
{
ANDROID_EVENT* event;
freerdp* inst = (freerdp*)instance;
},
{
"freerdp_new",
- "(Landroid/content/Context;)I",
+ "(Landroid/content/Context;)J",
&jni_freerdp_new
},
{
"freerdp_free",
- "(I)V",
+ "(J)V",
&jni_freerdp_free
},
{
"freerdp_parse_arguments",
- "(I[Ljava/lang/String;)Z",
+ "(J[Ljava/lang/String;)Z",
&jni_freerdp_parse_arguments
},
{
"freerdp_connect",
- "(I)Z",
+ "(J)Z",
&jni_freerdp_connect
},
{
"freerdp_disconnect",
- "(I)Z",
+ "(J)Z",
&jni_freerdp_disconnect
},
{
"freerdp_update_graphics",
- "(ILandroid/graphics/Bitmap;IIII)Z",
+ "(JLandroid/graphics/Bitmap;IIII)Z",
&jni_freerdp_update_graphics
},
{
"freerdp_send_cursor_event",
- "(IIII)Z",
+ "(JIII)Z",
&jni_freerdp_send_cursor_event
},
{
"freerdp_send_key_event",
- "(IIZ)Z",
+ "(JIZ)Z",
&jni_freerdp_send_key_event
},
{
"freerdp_send_unicodekey_event",
- "(II)Z",
+ "(JI)Z",
&jni_freerdp_send_unicodekey_event
},
{
"freerdp_send_clipboard_data",
- "(ILjava/lang/String;)Z",
+ "(JLjava/lang/String;)Z",
&jni_freerdp_send_clipboard_data
}
};