From 113801b790f7cf9a822e761c13ef359ec91756fc Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 5 Jun 2018 12:46:13 -0700 Subject: [PATCH] Added SDL_IsChromebook() to determine if we're running on a Chromebook. --- .../src/main/java/org/libsdl/app/SDLActivity.java | 7 +++++++ include/SDL_system.h | 5 +++++ src/core/android/SDL_android.c | 12 +++++++++++- src/dynapi/SDL_dynapi_overrides.h | 1 + src/dynapi/SDL_dynapi_procs.h | 3 +++ 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java index b1cd982c3..e505533da 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -695,6 +695,13 @@ public class SDLActivity extends Activity { return (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION); } + /** + * This method is called by SDL using JNI. + */ + public static boolean isChromebook() { + return getContext().getPackageManager().hasSystemFeature("org.chromium.arc.device_management"); + } + /** * This method is called by SDL using JNI. */ diff --git a/include/SDL_system.h b/include/SDL_system.h index 77186b597..6d6832d0f 100644 --- a/include/SDL_system.h +++ b/include/SDL_system.h @@ -125,6 +125,11 @@ extern DECLSPEC void * SDLCALL SDL_AndroidGetActivity(void); */ extern DECLSPEC SDL_bool SDLCALL SDL_IsAndroidTV(void); +/** + \brief Return true if the application is running on a Chromebook + */ +extern DECLSPEC SDL_bool SDLCALL SDL_IsChromebook(void); + /** See the official Android developer guide for more information: http://developer.android.com/guide/topics/data/data-storage.html diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index c4b342385..9405d6c2b 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -213,6 +213,7 @@ static jmethodID midSetWindowStyle; static jmethodID midSetOrientation; static jmethodID midGetContext; static jmethodID midIsAndroidTV; +static jmethodID midIsChromebook; static jmethodID midInputGetInputDeviceIds; static jmethodID midSendMessage; static jmethodID midShowTextInput; @@ -316,6 +317,8 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv* mEnv, jclass c "getContext","()Landroid/content/Context;"); midIsAndroidTV = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "isAndroidTV","()Z"); + midIsChromebook = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, + "isChromebook", "()Z"); midInputGetInputDeviceIds = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "inputGetInputDeviceIds", "(I)[I"); midSendMessage = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, @@ -349,7 +352,8 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv* mEnv, jclass c !midSendMessage || !midShowTextInput || !midIsScreenKeyboardShown || !midClipboardSetText || !midClipboardGetText || !midClipboardHasText || !midOpenAPKExpansionInputStream || !midGetManifestEnvironmentVariables || !midGetDisplayDPI || - !midCreateCustomCursor || !midSetCustomCursor || !midSetSystemCursor || !midSupportsRelativeMouse || !midSetRelativeMouseEnabled) { + !midCreateCustomCursor || !midSetCustomCursor || !midSetSystemCursor || !midSupportsRelativeMouse || !midSetRelativeMouseEnabled || + !midIsChromebook) { __android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLActivity.java?"); } @@ -2024,6 +2028,12 @@ SDL_bool SDL_IsAndroidTV(void) return (*env)->CallStaticBooleanMethod(env, mActivityClass, midIsAndroidTV); } +SDL_bool SDL_IsChromebook(void) +{ + JNIEnv *env = Android_JNI_GetEnv(); + return (*env)->CallStaticBooleanMethod(env, mActivityClass, midIsChromebook); +} + const char * SDL_AndroidGetInternalStoragePath(void) { static char *s_AndroidInternalFilesPath = NULL; diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h index 62de268b0..8d3223221 100644 --- a/src/dynapi/SDL_dynapi_overrides.h +++ b/src/dynapi/SDL_dynapi_overrides.h @@ -672,3 +672,4 @@ #define SDL_GameControllerMappingForDeviceIndex SDL_GameControllerMappingForDeviceIndex_REAL #define SDL_LinuxSetThreadPriority SDL_LinuxSetThreadPriority_REAL #define SDL_HasAVX512F SDL_HasAVX512F_REAL +#define SDL_IsChromebook SDL_IsChromebook_REAL diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 895b768a9..3d2a1a315 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -712,3 +712,6 @@ SDL_DYNAPI_PROC(char*,SDL_GameControllerMappingForDeviceIndex,(int a),(a),return SDL_DYNAPI_PROC(int,SDL_LinuxSetThreadPriority,(Sint64 a, int b),(a,b),return) #endif SDL_DYNAPI_PROC(SDL_bool,SDL_HasAVX512F,(void),(),return) +#ifdef __ANDROID__ +SDL_DYNAPI_PROC(SDL_bool,SDL_IsChromebook,(void),(),return) +#endif