8223271: SplashScreen is still shown if defaulting to headless on MacOS
Reviewed-by: bpb, serb, kcr
--- a/make/lib/Awt2dLibraries.gmk Thu May 30 09:23:14 2019 -0700
+++ b/make/lib/Awt2dLibraries.gmk Thu May 30 11:52:23 2019 -0700
@@ -824,6 +824,7 @@
$(LIBM) -lpthread -liconv -losxapp \
-framework ApplicationServices \
-framework Foundation \
+ -framework Security \
-framework Cocoa \
-framework JavaNativeFoundation
else ifeq ($(call isTargetOs, windows), true)
--- a/src/java.base/share/native/libjli/java.c Thu May 30 09:23:14 2019 -0700
+++ b/src/java.base/share/native/libjli/java.c Thu May 30 11:52:23 2019 -0700
@@ -1169,13 +1169,13 @@
* Passing on splash screen info in environment variables
*/
if (splash_file_name && !headlessflag) {
- char* splash_file_entry = JLI_MemAlloc(JLI_StrLen(SPLASH_FILE_ENV_ENTRY "=")+JLI_StrLen(splash_file_name)+1);
+ splash_file_entry = JLI_MemAlloc(JLI_StrLen(SPLASH_FILE_ENV_ENTRY "=")+JLI_StrLen(splash_file_name)+1);
JLI_StrCpy(splash_file_entry, SPLASH_FILE_ENV_ENTRY "=");
JLI_StrCat(splash_file_entry, splash_file_name);
putenv(splash_file_entry);
}
if (splash_jar_name && !headlessflag) {
- char* splash_jar_entry = JLI_MemAlloc(JLI_StrLen(SPLASH_JAR_ENV_ENTRY "=")+JLI_StrLen(splash_jar_name)+1);
+ splash_jar_entry = JLI_MemAlloc(JLI_StrLen(SPLASH_JAR_ENV_ENTRY "=")+JLI_StrLen(splash_jar_name)+1);
JLI_StrCpy(splash_jar_entry, SPLASH_JAR_ENV_ENTRY "=");
JLI_StrCat(splash_jar_entry, splash_jar_name);
putenv(splash_jar_entry);
@@ -2241,6 +2241,11 @@
if (file_name == NULL){
return;
}
+
+ if (!DoSplashInit()) {
+ goto exit;
+ }
+
maxScaledImgNameLength = DoSplashGetScaledImgNameMaxPstfixLen(file_name);
scaled_splash_name = JLI_MemAlloc(
@@ -2261,13 +2266,13 @@
jar_name, file_name, &data_size);
}
if (image_data) {
- DoSplashInit();
DoSplashSetScaleFactor(scale_factor);
DoSplashLoadMemory(image_data, data_size);
JLI_MemFree(image_data);
+ } else {
+ DoSplashClose();
}
} else {
- DoSplashInit();
if (isImageScaled) {
DoSplashSetScaleFactor(scale_factor);
DoSplashLoadFile(scaled_splash_name);
@@ -2279,6 +2284,7 @@
DoSplashSetFileJarName(file_name, jar_name);
+ exit:
/*
* Done with all command line processing and potential re-execs so
* clean up the environment.
--- a/src/java.base/share/native/libjli/splashscreen.h Thu May 30 09:23:14 2019 -0700
+++ b/src/java.base/share/native/libjli/splashscreen.h Thu May 30 11:52:23 2019 -0700
@@ -26,7 +26,7 @@
int DoSplashLoadMemory(void* pdata, int size); /* requires preloading the file */
int DoSplashLoadFile(const char* filename);
-void DoSplashInit(void);
+int DoSplashInit(void);
void DoSplashClose(void);
void DoSplashSetFileJarName(const char* fileName, const char* jarName);
void DoSplashSetScaleFactor(float scaleFactor);
--- a/src/java.base/share/native/libjli/splashscreen_stubs.c Thu May 30 09:23:14 2019 -0700
+++ b/src/java.base/share/native/libjli/splashscreen_stubs.c Thu May 30 11:52:23 2019 -0700
@@ -33,7 +33,7 @@
*/
typedef int (*SplashLoadMemory_t)(void* pdata, int size);
typedef int (*SplashLoadFile_t)(const char* filename);
-typedef void (*SplashInit_t)(void);
+typedef int (*SplashInit_t)(void);
typedef void (*SplashClose_t)(void);
typedef void (*SplashSetFileJarName_t)(const char* fileName,
const char* jarName);
@@ -71,8 +71,8 @@
INVOKE(SplashLoadFile, 0)(filename);
}
-void DoSplashInit(void) {
- INVOKEV(SplashInit)();
+int DoSplashInit(void) {
+ INVOKE(SplashInit, 0)();
}
void DoSplashClose(void) {
--- a/src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m Thu May 30 09:23:14 2019 -0700
+++ b/src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m Thu May 30 11:52:23 2019 -0700
@@ -28,6 +28,7 @@
#import <Cocoa/Cocoa.h>
#import <objc/objc-auto.h>
+#include <Security/AuthSession.h>
#import <JavaNativeFoundation/JavaNativeFoundation.h>
#import "NSApplicationAWT.h"
@@ -184,8 +185,31 @@
return JNI_FALSE;
}
-void
+static int isInAquaSession() {
+ // environment variable to bypass the aqua session check
+ char *ev = getenv("AWT_FORCE_HEADFUL");
+ if (ev && (strncasecmp(ev, "true", 4) == 0)) {
+ // if "true" then tell the caller we're in
+ // an Aqua session without actually checking
+ return 1;
+ }
+ // Is the WindowServer available?
+ SecuritySessionId session_id;
+ SessionAttributeBits session_info;
+ OSStatus status = SessionGetInfo(callerSecuritySession, &session_id, &session_info);
+ if (status == noErr) {
+ if (session_info & sessionHasGraphicAccess) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+int
SplashInitPlatform(Splash * splash) {
+ if (!isInAquaSession()) {
+ return 0;
+ }
pthread_mutex_init(&splash->lock, NULL);
splash->maskRequired = 0;
@@ -206,6 +230,7 @@
[NSApplicationAWT runAWTLoopWithApp:[NSApplicationAWT sharedApplication]];
}];
}
+ return 1;
}
void
--- a/src/java.desktop/share/native/libsplashscreen/splashscreen_impl.c Thu May 30 09:23:14 2019 -0700
+++ b/src/java.desktop/share/native/libsplashscreen/splashscreen_impl.c Thu May 30 11:52:23 2019 -0700
@@ -57,7 +57,7 @@
splash->jarName = SplashConvertStringAlloc(jarName, &splash->jarNameLen);
}
-JNIEXPORT void
+JNIEXPORT int
SplashInit()
{
Splash *splash = SplashGetInstance();
@@ -67,7 +67,7 @@
splash->scaleFactor = 1;
initFormat(&splash->imageFormat, QUAD_RED_MASK, QUAD_GREEN_MASK,
QUAD_BLUE_MASK, QUAD_ALPHA_MASK);
- SplashInitPlatform(splash);
+ return SplashInitPlatform(splash);
}
JNIEXPORT void
@@ -263,6 +263,7 @@
Splash *splash = SplashGetInstance();
if (splash->isVisible < 0) {
+ stream->close(stream);
return 0;
}
--- a/src/java.desktop/share/native/libsplashscreen/splashscreen_impl.h Thu May 30 09:23:14 2019 -0700
+++ b/src/java.desktop/share/native/libsplashscreen/splashscreen_impl.h Thu May 30 11:52:23 2019 -0700
@@ -36,7 +36,7 @@
JNIEXPORT int
SplashLoadFile(const char *filename); // FIXME: range checking for SplashLoadMemory
-JNIEXPORT void
+JNIEXPORT int
SplashInit(void);
JNIEXPORT void
@@ -125,7 +125,7 @@
/* To be implemented in the platform-specific native code. */
-void SplashInitPlatform(Splash * splash);
+int SplashInitPlatform(Splash * splash);
void SplashCreateThread(Splash * splash);
void SplashCleanupPlatform(Splash * splash);
void SplashDonePlatform(Splash * splash);
--- a/src/java.desktop/unix/native/libsplashscreen/splashscreen_sys.c Thu May 30 09:23:14 2019 -0700
+++ b/src/java.desktop/unix/native/libsplashscreen/splashscreen_sys.c Thu May 30 11:52:23 2019 -0700
@@ -405,7 +405,7 @@
return 0;
}
-void
+int
SplashInitPlatform(Splash * splash) {
int shapeVersionMajor, shapeVersionMinor;
@@ -424,7 +424,7 @@
splash->display = XOpenDisplay(NULL);
if (!splash->display) {
splash->isVisible = -1;
- return;
+ return 0;
}
shapeSupported = XShapeQueryExtension(splash->display, &shapeEventBase,
@@ -474,7 +474,7 @@
splash->screen = NULL;
splash->visual = NULL;
fprintf(stderr, "Warning: unable to initialize the splashscreen. Not enough available color cells.\n");
- return;
+ return 0;
}
splash->cmap = AllocColors(splash->display, splash->screen,
numColors, colorIndex);
@@ -506,6 +506,7 @@
default:
; /* FIXME: should probably be fixed, but javaws splash screen doesn't support other visuals either */
}
+ return 1;
}
--- a/src/java.desktop/windows/native/libsplashscreen/splashscreen_sys.c Thu May 30 09:23:14 2019 -0700
+++ b/src/java.desktop/windows/native/libsplashscreen/splashscreen_sys.c Thu May 30 11:52:23 2019 -0700
@@ -437,7 +437,7 @@
LeaveCriticalSection(&splash->lock);
}
-void
+int
SplashInitPlatform(Splash * splash)
{
HDC hdc;
@@ -486,6 +486,7 @@
}
}
ReleaseDC(NULL, hdc);
+ return 1;
}
void