A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Jonathan Gordon
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "config.h"
22
23#if (CONFIG_PLATFORM&PLATFORM_ANDROID)
24#include <jni.h>
25#include <stdbool.h>
26#include "string-extra.h"
27#include "kernel.h"
28#include "lang.h"
29
30extern JNIEnv *env_ptr;
31static jclass RockboxKeyboardInput_class;
32static jobject RockboxKeyboardInput_instance;
33static jmethodID kbd_inputfunc;
34static struct semaphore kbd_wakeup;
35static bool accepted;
36static jstring new_string;
37
38JNIEXPORT void JNICALL
39Java_org_rockbox_RockboxKeyboardInput_put_1result(JNIEnv *env, jobject this,
40 jboolean _accepted,
41 jstring _new_string)
42{
43 (void)env;(void)this;
44
45 accepted = (bool)_accepted;
46 if (accepted)
47 {
48 new_string = _new_string;
49 (*env)->NewGlobalRef(env, new_string); /* prevet GC'ing */
50 }
51 semaphore_release(&kbd_wakeup);
52}
53
54static void kdb_init(void)
55{
56 JNIEnv e = *env_ptr;
57 static jmethodID kbd_is_usable;
58 if (RockboxKeyboardInput_class == NULL)
59 {
60 semaphore_init(&kbd_wakeup, 1, 0);
61 /* get the class and its constructor */
62 RockboxKeyboardInput_class = e->FindClass(env_ptr,
63 "org/rockbox/RockboxKeyboardInput");
64 jmethodID constructor = e->GetMethodID(env_ptr,
65 RockboxKeyboardInput_class,
66 "<init>", "()V");
67 RockboxKeyboardInput_instance = e->NewObject(env_ptr,
68 RockboxKeyboardInput_class,
69 constructor);
70 kbd_inputfunc = e->GetMethodID(env_ptr, RockboxKeyboardInput_class,
71 "kbd_input",
72 "(Ljava/lang/String;"
73 "Ljava/lang/String;"
74 "Ljava/lang/String;)V");
75 kbd_is_usable = e->GetMethodID(env_ptr, RockboxKeyboardInput_class,
76 "is_usable", "()Z");
77 }
78
79 /* need to get it every time incase the activity died/restarted */
80 while (!e->CallBooleanMethod(env_ptr, RockboxKeyboardInput_instance,
81 kbd_is_usable))
82 sleep(HZ/10);
83}
84
85int kbd_input(char* text, int buflen, ucschar_t *kbd)
86{
87 (void)kbd;
88 JNIEnv e = *env_ptr;
89 jstring str = e->NewStringUTF(env_ptr, text);
90 jstring ok_text = e->NewStringUTF(env_ptr, str(LANG_KBD_OK));
91 jstring cancel_text = e->NewStringUTF(env_ptr, str(LANG_KBD_CANCEL));
92 const char *utf8_string;
93 kdb_init();
94
95 e->CallVoidMethod(env_ptr, RockboxKeyboardInput_instance,kbd_inputfunc,
96 str, ok_text, cancel_text);
97
98 semaphore_wait(&kbd_wakeup, TIMEOUT_BLOCK);
99
100 if (accepted)
101 {
102 utf8_string = e->GetStringUTFChars(env_ptr, new_string, 0);
103 strmemccpy(text, utf8_string, buflen);
104 e->ReleaseStringUTFChars(env_ptr, new_string, utf8_string);
105 e->DeleteGlobalRef(env_ptr, new_string);
106 }
107 e->DeleteLocalRef(env_ptr, str);
108 e->DeleteLocalRef(env_ptr, ok_text);
109 e->DeleteLocalRef(env_ptr, cancel_text);
110
111 return !accepted; /* return 0 on success */
112}
113
114int load_kbd(unsigned char* filename)
115{
116 (void)filename;
117 return 1;
118}
119
120#endif