src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m
changeset 55189 fdaf7287ea3a
parent 47216 71c04702a3d5
child 55708 2b0acaf92ecc
--- 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