diff options
Diffstat (limited to 'app/src')
| -rw-r--r-- | app/src/main/AndroidManifest.xml | 2 | ||||
| -rw-r--r-- | app/src/main/java/com/arslaancodes/mokuassistant/AssistantService.java | 73 | ||||
| -rw-r--r-- | app/src/main/jni/main.c | 11 |
3 files changed, 84 insertions, 2 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d80f2df..4eef0dd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -18,6 +18,6 @@ </intent-filter> </activity> - <!-- <service android:name=".AssistantService" android:foregroundServiceType="dataSync" android:exported="false" /> --> + <service android:name=".AssistantService" android:foregroundServiceType="dataSync" android:exported="false" /> </application> </manifest> diff --git a/app/src/main/java/com/arslaancodes/mokuassistant/AssistantService.java b/app/src/main/java/com/arslaancodes/mokuassistant/AssistantService.java new file mode 100644 index 0000000..d30ed2e --- /dev/null +++ b/app/src/main/java/com/arslaancodes/mokuassistant/AssistantService.java @@ -0,0 +1,73 @@ +package com.arslaancodes.mokuassistant; + +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.Service; +import android.content.Intent; +import android.os.Build; +import android.os.IBinder; +import android.util.Log; + +import androidx.core.app.NotificationCompat; + +public class AssistantService extends Service { + private static final String TAG = "moku"; + private static final String CHANNEL_ID = "moku_assistant_channel"; + private static final int NOTIFICATION_ID = 1001; + + @Override + public void onCreate() { + super.onCreate(); + createNotificationChannel(); + Log.i(TAG, "AssistantService created"); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + Log.i(TAG, "AssistantService started"); + + Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID).setContentTitle("moku Assistant").setContentText("listening...").setSmallIcon(android.R.drawable.ic_btn_speak_now).setPriority(NotificationCompat.PRIORITY_LOW).build(); + + startForeground(NOTIFICATION_ID, notification); + + startAssistant(); + + return START_STICKY; + } + + @Override + public void onDestroy() { + Log.i(TAG, "AssistantService destroyed"); + stopAssistant(); + super.onDestroy(); + } + + @Override + public IBinder onBind(Intent intent) { + return null; + } + + private void createNotificationChannel() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationChannel channel = new NotificationChannel( + CHANNEL_ID, + "moku Assistant", + NotificationManager.IMPORTANCE_LOW + ); + channel.setDescription("Shows when moku Assistant is running"); + NotificationManager manager = getSystemService(NotificationManager.class); + if (manager != null) { + manager.createNotificationChannel(channel); + } + } + } + + // JNI functions + private static native void startAssistant(); + private static native void stopAssistant(); + + static { + System.loadLibrary("moku"); + } +} diff --git a/app/src/main/jni/main.c b/app/src/main/jni/main.c index 864be54..47a1df0 100644 --- a/app/src/main/jni/main.c +++ b/app/src/main/jni/main.c @@ -1,4 +1,4 @@ -/* #include <vosk_api.h> */ +#include <vosk_api.h> #include <aaudio/AAudio.h> #include <android_native_app_glue.h> #include <android/log.h> @@ -12,6 +12,7 @@ #include <android/choreographer.h> #include <android/hardware_buffer.h> #include <time.h> +#include <jni.h> #define LOG_TAG "moku" @@ -23,6 +24,14 @@ #define LOGW(fmt, ...) _LOG(ANDROID_LOG_WARN, (fmt)__VA_OPT__(, ) __VA_ARGS__) #define LOGI(fmt, ...) _LOG(ANDROID_LOG_INFO, (fmt)__VA_OPT__(, ) __VA_ARGS__) +JNIEXPORT void JNICALL Java_com_arslaancodes_mokuassistant_AssistantService_startAssistant(JNIEnv *env, jclass clazz) { + LOGI("startAssistant called"); +} + +JNIEXPORT void JNICALL Java_com_arslaancodes_mokuassistant_AssistantService_stopAssistant(JNIEnv *env, jclass clazz) { + LOGI("stopAssistant called"); +} + enum Color { COLOR_RED = 0x000000ff, COLOR_GREEN = 0x0000ff00, |
