From 4101b3d92da59ed639897c305d8dda487d1d27ae Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Fri, 13 Nov 2020 13:11:48 -0600 Subject: [PATCH] android: IPC/service-related cleanups. --- .../freedesktop/monado/ipc/MonadoImpl.java | 37 +++++++++++++------ src/xrt/targets/service-lib/CMakeLists.txt | 2 +- .../{lib.cpp => service_target.cpp} | 0 3 files changed, 26 insertions(+), 13 deletions(-) rename src/xrt/targets/service-lib/{lib.cpp => service_target.cpp} (100%) diff --git a/src/xrt/ipc/android/src/main/java/org/freedesktop/monado/ipc/MonadoImpl.java b/src/xrt/ipc/android/src/main/java/org/freedesktop/monado/ipc/MonadoImpl.java index fd6d49753..330661dbe 100644 --- a/src/xrt/ipc/android/src/main/java/org/freedesktop/monado/ipc/MonadoImpl.java +++ b/src/xrt/ipc/android/src/main/java/org/freedesktop/monado/ipc/MonadoImpl.java @@ -11,32 +11,47 @@ package org.freedesktop.monado.ipc; import android.os.ParcelFileDescriptor; +import android.util.Log; import android.view.Surface; import androidx.annotation.Keep; +import androidx.annotation.NonNull; + +import org.jetbrains.annotations.NotNull; /** * Java implementation of the IMonado IPC interface. *

* (This is the server-side code.) *

- * All this does is delegate calls to native JNI implementations + * All this does is delegate calls to native JNI implementations. + * The warning suppression is because Android Studio tends to have a hard time finding + * the (very real) implementations of these in service-lib. */ -@SuppressWarnings("JavaJniMissingFunction") @Keep public class MonadoImpl extends IMonado.Stub { + private static final String TAG = "MonadoImpl"; + static { // Load the shared library with the native parts of this class // This is the service-lib target. System.loadLibrary("monado-service"); } - public void connect(ParcelFileDescriptor parcelFileDescriptor) { + @Override + public void connect(@NotNull ParcelFileDescriptor parcelFileDescriptor) { + Log.i(TAG, "connect"); nativeAddClient(parcelFileDescriptor.detachFd()); } + @Override public void passAppSurface(Surface surface) { + Log.i(TAG, "passAppSurface"); + if (surface == null) { + Log.e(TAG, "Received a null Surface from the client!"); + return; + } nativeAppSurface(surface); } @@ -44,15 +59,14 @@ public class MonadoImpl extends IMonado.Stub { * Native handling of receiving a surface: should convert it to an ANativeWindow then do stuff * with it. *

- * Ignore Android Studio complaining that this function is missing: it is not, it is just in a - * different module. See `src/xrt/targets/service-lib/lib.cpp` for the implementation. - * (Ignore the warning saying that file isn't included in the build: it is, Android Studio - * is just confused.) + * Ignore warnings that this function is missing: it is not, it is just in a different module. + * See `src/xrt/targets/service-lib/service_target.cpp` for the implementation. * * @param surface The surface to pass to native code * @todo figure out a good way to make the MonadoImpl pointer a client ID */ - private native void nativeAppSurface(Surface surface); + @SuppressWarnings("JavaJniMissingFunction") + private native void nativeAppSurface(@NonNull Surface surface); /** * Native handling of receiving an FD for a new client: the FD should be used to start up the @@ -62,13 +76,12 @@ public class MonadoImpl extends IMonado.Stub { * running, this will be called in it. If it's not already running, a process will be created, * and this will be the first native code executed in that process. *

- * Ignore Android Studio complaining that this function is missing: it is not, it is just in a - * different module. See `src/xrt/targets/service-lib/lib.cpp` for the implementation. - * (Ignore the warning saying that file isn't included in the build: it is, Android Studio - * is just confused.) + * Ignore warnings that this function is missing: it is not, it is just in a different module. + * See `src/xrt/targets/service-lib/service_target.cpp` for the implementation. * * @param fd The incoming file descriptor: ownership is transferred to native code here. * @todo figure out a good way to make the MonadoImpl pointer a client ID */ + @SuppressWarnings("JavaJniMissingFunction") private native void nativeAddClient(int fd); } diff --git a/src/xrt/targets/service-lib/CMakeLists.txt b/src/xrt/targets/service-lib/CMakeLists.txt index 3ec84f530..8a0e03983 100644 --- a/src/xrt/targets/service-lib/CMakeLists.txt +++ b/src/xrt/targets/service-lib/CMakeLists.txt @@ -3,7 +3,7 @@ add_library(monado-service MODULE - lib.cpp + service_target.cpp ) target_link_libraries(monado-service PRIVATE diff --git a/src/xrt/targets/service-lib/lib.cpp b/src/xrt/targets/service-lib/service_target.cpp similarity index 100% rename from src/xrt/targets/service-lib/lib.cpp rename to src/xrt/targets/service-lib/service_target.cpp