Skip to content

Commit fde839a

Browse files
committed
make simulator work more or less
1 parent 650f974 commit fde839a

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

simulator/simulator.c

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
#include <pthread.h>
77
#include <android/bitmap.h>
88
#include <jni.h>
9+
#include <stdlib.h>
910

1011
static pthread_t t, t2;
1112
static bool s_simulator_running, s_simulator_vol_down_pressed, s_simulator_vol_up_pressed, s_simulator_pwr_pressed;
1213
static uint32_t last_pressed_key;
1314
static JavaVM* s_simulator_jvm;
1415
static jobject s_simulator_bitmap, s_simulator_thiz;
1516
static jint s_simulator_h, s_simulator_w;
17+
extern int droidboot_exit;
1618

1719
int droidboot_internal_get_display_height()
1820
{
@@ -26,15 +28,9 @@ int droidboot_internal_get_display_width()
2628

2729
JNIEXPORT void simulator_stop(JNIEnv* env)
2830
{
29-
s_simulator_running = false;
30-
pthread_join(t, NULL);
31-
pthread_join(t2, NULL);
32-
s_simulator_jvm = NULL;
33-
(*env)->DeleteGlobalRef(env, s_simulator_bitmap);
34-
s_simulator_bitmap = NULL;
35-
(*env)->DeleteGlobalRef(env, s_simulator_thiz);
36-
s_simulator_thiz = NULL;
37-
// TODO finish activity
31+
if (!s_simulator_running) return;
32+
__android_log_print(ANDROID_LOG_INFO, "droidboot", "closing");
33+
droidboot_exit = 0;
3834
}
3935

4036
JNIEXPORT void simulator_start(JNIEnv* env, jobject thiz, jobject bitmap, jint w, jint h)
@@ -47,6 +43,19 @@ JNIEXPORT void simulator_start(JNIEnv* env, jobject thiz, jobject bitmap, jint w
4743
droidboot_init();
4844
droidboot_show_dualboot_menu();
4945
simulator_stop(env);
46+
s_simulator_running = false;
47+
pthread_join(t, NULL);
48+
pthread_join(t2, NULL);
49+
(*env)->DeleteGlobalRef(env, s_simulator_bitmap);
50+
s_simulator_bitmap = NULL;
51+
__android_log_print(ANDROID_LOG_INFO, "droidboot", "goodbye");
52+
jclass cls = (*env)->GetObjectClass(env, s_simulator_thiz);
53+
jmethodID redraw = (*env)->GetMethodID(env, cls, "finish", "()V");
54+
(*env)->CallVoidMethod(env, s_simulator_thiz, redraw);
55+
(*env)->DeleteGlobalRef(env, s_simulator_thiz);
56+
s_simulator_thiz = NULL;
57+
s_simulator_jvm = NULL;
58+
exit(0);
5059
}
5160

5261
JNIEXPORT void simulator_key(jint key)
@@ -81,6 +90,10 @@ void droidboot_internal_fb_flush(lv_disp_drv_t * disp_drv, const lv_area_t * are
8190
__android_log_print(ANDROID_LOG_ERROR, "droidboot", "failed to unlock bitmap (%d), trying again", ret);
8291
usleep(10000);
8392
}
93+
94+
jclass cls = (*env)->GetObjectClass(env, s_simulator_thiz);
95+
jmethodID redraw = (*env)->GetMethodID(env, cls, "redraw", "()V");
96+
(*env)->CallVoidMethod(env, s_simulator_thiz, redraw);
8497
//__android_log_print(ANDROID_LOG_VERBOSE, "droidboot", "unlocked fb %p", addr);
8598
}
8699
// Inform the graphics library that we are ready with the flushing
@@ -218,7 +231,7 @@ void droidboot_internal_lvgl_threads_init()
218231

219232
void droidboot_internal_platform_on_screen_log(const char *buf)
220233
{
221-
__android_log_print(ANDROID_LOG_ERROR, "droidboot", "%s", buf); // TODO
234+
__android_log_print(ANDROID_LOG_INFO, "droidboot", "%s", buf); // TODO toast?
222235
}
223236

224237
void droidboot_internal_platform_system_log(const char *buf)

0 commit comments

Comments
 (0)