danishjuzdan / jnativehook

Automatically exported from code.google.com/p/jnativehook
0 stars 0 forks source link

osx/NativeThread.c:666:6: error: 'AXAPIEnabled' is deprecated: first deprecated in OS X 10.9 [-Werror,-Wdeprecated-declarations] #75

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. try to build via "ant all" on Apple OS X Mavericks
2.
3.

What is the expected output? What do you see instead?

expected output = successful build

instead I see the following:

JNativeHook/src/native/osx/NativeThread.c:666:6: error: 'AXAPIEnabled' is 
deprecated: first deprecated in OS X 10.9 [-Werror,-Wdeprecated-declarations]
    [apply]         if (AXAPIEnabled() == true) {
    [apply]             ^
    [apply] /System/Library/Frameworks/ApplicationServices.framework/Frameworks/HIServices.framework/Headers/AXUIElement.h:49:16: note: 'AXAPIEnabled' declared here
    [apply] extern Boolean AXAPIEnabled (void) CF_DEPRECATED_MAC(10_0, 10_9);
    [apply]                ^
    [apply] 1 error generated.

BUILD FAILED

What version of the product are you using? On what operating system?

version 1.1.4 on Mac OS X 10.9 (Mavericks)

Please provide any additional information below.

Original issue reported on code.google.com by J...@joncrowell.org on 11 Dec 2013 at 6:18

GoogleCodeExporter commented 9 years ago
Looks like their is a large overhaul in the accessibility API for 10.9;  I will 
put in a patch shortly.  Updated code is now hosted on github, see 
https://github.com/kwhat 

Original comment by a...@1stleg.com on 11 Dec 2013 at 6:25

GoogleCodeExporter commented 9 years ago
Thanks - I'll follow the project on GitHub.  I cloned from GitHub and tried to 
build with ant and found that I had to run "brew install automake" to get past 
this:

bootstrap-libuiohook:
     [echo] Bootstrapping libUIOHook...
[autoreconf] autoreconf --verbose --force --install
[autoreconf] sh: autoreconf: command not found

once I had installed automake I ran into this:

[autoreconf] configure.ac:94: error: possibly undefined macro: 
AC_LIBTOOL_WIN32_DLL
[autoreconf]       If this token and others are legitimate, please use 
m4_pattern_allow.
[autoreconf]       See the Autoconf documentation.
[autoreconf] configure.ac:99: error: possibly undefined macro: AC_PROG_LIBTOOL
[autoreconf] autoreconf: /usr/local/Cellar/autoconf/2.69/bin/autoconf failed 
with exit status: 1

Original comment by J...@joncrowell.org on 11 Dec 2013 at 6:43

GoogleCodeExporter commented 9 years ago
Correct, version 1.2 (github) will require autoconf, libtool, pkgconfig and gcc 
to compile.  I have only tested the build system on Linux at this point.  Apple 
is next ;)

Original comment by a...@1stleg.com on 11 Dec 2013 at 7:17

GoogleCodeExporter commented 9 years ago
Something like this should do the trick if you would like to backport.

// Required to dynamically check for AXIsProcessTrustedWithOptions availability.
// FIXME Move to osx_input_helper.h after testing.
extern Boolean AXIsProcessTrustedWithOptions(CFDictionaryRef options) 
__attribute__((weak_import));
extern CFStringRef kAXTrustedCheckOptionPrompt __attribute__((weak_import));

...

    bool accessibilityEnabled = false;
    // Check and make sure assistive devices is enabled.
    if (AXIsProcessTrustedWithOptions != NULL) {
        // 10.9 and later
        const void * keys[] = { kAXTrustedCheckOptionPrompt };
        const void * values[] = { kCFBooleanTrue };

        CFDictionaryRef options = CFDictionaryCreate(
                kCFAllocatorDefault,
                keys,
                values,
                sizeof(keys) / sizeof(*keys),
                &kCFCopyStringDictionaryKeyCallBacks,
                &kCFTypeDictionaryValueCallBacks);

        accessibilityEnabled = AXIsProcessTrustedWithOptions(options);
    }
    else {
        // 10.8 and older
        accessibilityEnabled = AXAPIEnabled();
    }

    if (accessibilityEnabled == true) {

Original comment by a...@1stleg.com on 11 Dec 2013 at 9:22

GoogleCodeExporter commented 9 years ago
Thanks.  I would like to backport.  I tried adding the code you provided in 
src/native/osx/NativeThread.c

You can see the modified file in this non-public gist: 
https://gist.github.com/jononomo/84e25d53a6b15bcd8217

Unfortunately, the "ant all" command still gives a compilation error.  So I 
adjusted the file to simply not include the problematic line, as can be seen in 
the comment on the gist.

Original comment by J...@joncrowell.org on 12 Dec 2013 at 2:00

GoogleCodeExporter commented 9 years ago
I figured it would probably still warn.  The only way to get rid of that would 
be to use something like dlopen() with dlsym() to try and dynamically check for 
and call the appropriate function.  The code above will work with the new 10.9 
method and fallback to the deprecated function only if it is unavailable.  To 
force it to compile modify the generated build.properties file and modify the 
native.cc.args line to either remove the -Werror flag or add either 
-Wno-deprecated or -Wno-deprecated-declarations after -Wextra.  Let me know 
which (if any) of those flags works for you.  I will look into a better 
solution in the near future.

Original comment by a...@1stleg.com on 12 Dec 2013 at 3:18

GoogleCodeExporter commented 9 years ago
One more thing;  Please let me know if you get prompted to allow for 
accessibility with the patch in place on 10.9.  You may need to disable it 
globally but I am not exactly sure.  I don't have a mac new enough to run 10.9 
so I have no way to test the AXIsProcessTrustedWithOptions function.  Thanks!

Original comment by a...@1stleg.com on 12 Dec 2013 at 3:38

GoogleCodeExporter commented 9 years ago
I have better patch in place now.  It doesnt quite work the way I would like it 
to but it will do for now.

#ifndef USE_WEAK_IMPORT
#include <dlfcn.h>
#endif

...

// FIXME Move to osx_input_helper.h after testing.
#ifdef USE_WEAK_IMPORT
// Required to dynamically check for AXIsProcessTrustedWithOptions availability.
extern Boolean AXIsProcessTrustedWithOptions(CFDictionaryRef options) 
__attribute__((weak_import));
extern CFStringRef kAXTrustedCheckOptionPrompt __attribute__((weak_import));
#else
typedef Boolean (*AXIsProcessTrustedWithOptions_t)(CFDictionaryRef options);
typedef Boolean (*AXAPIEnabled_t)(void);
#endif

...

    bool accessibilityEnabled = false;

    // FIXME Move to osx_input_helper.h after testing.
    #ifdef USE_WEAK_IMPORT
    // Check and make sure assistive devices is enabled.
    if (AXIsProcessTrustedWithOptions != NULL) {
        // New accessibility API 10.9 and later.
        const void * keys[] = { kAXTrustedCheckOptionPrompt };
        const void * values[] = { kCFBooleanTrue };

        CFDictionaryRef options = CFDictionaryCreate(
                kCFAllocatorDefault,
                keys,
                values,
                sizeof(keys) / sizeof(*keys),
                &kCFCopyStringDictionaryKeyCallBacks,
                &kCFTypeDictionaryValueCallBacks);

        accessibilityEnabled = AXIsProcessTrustedWithOptions(options);
    }
    else {
        // Old accessibility check 10.8 and older.
        accessibilityEnabled = AXAPIEnabled();
    }
    #else
    const char *dlError = NULL;
    void *libApplicaitonServices = dlopen("/System/Library/Frameworks/ApplicationServices.framework/ApplicationServices", RTLD_LAZY);
    dlError = dlerror();
    if (libApplicaitonServices != NULL && dlError == NULL) {
        // Check for the new function AXIsProcessTrustedWithOptions().
        AXIsProcessTrustedWithOptions_t fpAXIsProcessTrustedWithOptions = (AXIsProcessTrustedWithOptions_t) dlsym(libApplicaitonServices, "AXIsProcessTrustedWithOptions");
        dlError = dlerror();
        if (fpAXIsProcessTrustedWithOptions != NULL && dlError == NULL) {
            // New accessibility API 10.9 and later.
            const void * keys[] = { kAXTrustedCheckOptionPrompt };
            const void * values[] = { kCFBooleanTrue };

            CFDictionaryRef options = CFDictionaryCreate(
                    kCFAllocatorDefault,
                    keys,
                    values,
                    sizeof(keys) / sizeof(*keys),
                    &kCFCopyStringDictionaryKeyCallBacks,
                    &kCFTypeDictionaryValueCallBacks);

            accessibilityEnabled = (*fpAXIsProcessTrustedWithOptions)(options);
        }
        else {
            logger(LOG_LEVEL_DEBUG, "%s [%u]: Failed to locate AXIsProcessTrustedWithOptions(). (%s)\n",
                    __FUNCTION__, __LINE__, dlError);

            // Check for the fallback function AXAPIEnabled().
            AXAPIEnabled_t fpAXAPIEnabled = (AXAPIEnabled_t) dlsym(libApplicaitonServices, "AXAPIEnabled");
            dlError = dlerror();
            if (fpAXAPIEnabled != NULL && dlError == NULL) {
                // Old accessibility check 10.8 and older.
                accessibilityEnabled = (*fpAXAPIEnabled)();
            }
            else {
                // Could not load the AXAPIEnabled function!
                logger(LOG_LEVEL_ERROR, "%s [%u]: Failed to locate AXAPIEnabled()! (%s)\n",
                        __FUNCTION__, __LINE__, dlError);
            }
        }

        dlclose(libApplicaitonServices);
    }
    else {
        // Could not load the ApplicationServices framework!
        logger(LOG_LEVEL_ERROR, "%s [%u]: Failed to lazy load the ApplicationServices framework! (%s)\n",
                __FUNCTION__, __LINE__, dlError);
    }
    #endif

    if (accessibilityEnabled == true) {

Original comment by a...@1stleg.com on 13 Dec 2013 at 1:05

GoogleCodeExporter commented 9 years ago
Thanks for the improved patch.  I did get prompted to allow accessibility when 
I finally got the code to run on my computer.  It prompts you to open Security 
and Privacy settings in System Preferences and give the app access from there.  
Since I launched the java app from iTerm, I guess it thinks iTerm is the app 
that wants the access.  It automatically added iTerm to the list of apps that 
want to be able to "control your computer" and prompted me to grant it access. 
Screenshot attached.

Original comment by J...@joncrowell.org on 13 Dec 2013 at 1:52

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by a...@1stleg.com on 13 Dec 2013 at 1:56

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hi,

Can someone post a compiled version of all of this? at leats all the OSX lib.

Thx a lots!

Original comment by sebastie...@gmail.com on 13 Jan 2014 at 9:12

GoogleCodeExporter commented 9 years ago
Building on OS X is remarkably simple thanks to all the hard work done by the 
MacPorts project.  Start by installing MacPorts from 
http://www.macports.org/install.php
The run the following commands as root:

port -d sync
port -v selfupdate
port -v upgrade outdated 
port install autoconf automake gcc48 libtool pkgconfig apache-ant

Then switch back to your normal user, checkout the master branch from github 
and run ant compile jar

There maybe still be an issue running on 10.9 related to line 95 and 100 here:  
https://github.com/kwhat/libuiohook/blob/master/src/darwin/hook_thread.c#L95 

I am guessing that kAXTrustedCheckOptionPrompt_t just needs to be dereferenced 
but I cant check because I have very limited access to a mac capable of running 
OS X 10.9.

Original comment by a...@1stleg.com on 15 Jan 2014 at 2:03

GoogleCodeExporter commented 9 years ago
Perfect thx a lots for the informations.

Now i need to find a mac! ;)

Original comment by sebastie...@gmail.com on 15 Jan 2014 at 2:40

GoogleCodeExporter commented 9 years ago
Just a small update for those following this thread.  I am nearly ready to 
build 1.2-beta-1 however Apple has tried really hard to make cross compiling 
for their platform impossible.  If anyone has any tips for getting a gcc 
compatible compiler to build for apple targets on non-apple hardware running 
linux please contact me.  Until I can figure out a way to make this work, apple 
will not receive any binary support going forward.  I refuse to shell out more 
cash for additional hardware I don't need so I can support a platform I don't 
like and a development model I don't agree with.

Original comment by a...@1stleg.com on 15 Jan 2014 at 6:53

GoogleCodeExporter commented 9 years ago
LLVM/CLANG to the rescue!  I have successfully cross compiled some simple 
applications using clang.  Lots of build script support still needs to be added 
to make this a viable option, but it is looking promising.

Original comment by a...@1stleg.com on 19 Feb 2014 at 6:05

GoogleCodeExporter commented 9 years ago
The orignal issue should be solved as of 
https://github.com/kwhat/libuiohook/commit/26bef61d98a5ac16811f68788f2c4b4a60897
460

Additionally, the trunk should now support LLVM's clang compiler with minimal 
effort.  To compile using clang use `ant -Dant.build.native.toolchain=clang 
distclean compile jar`.  I have only tested on Linux and OS X.  Please open a 
new bug if it is related to LLVM.  Binaries for OS X will be available in 
1.2.0-beta2.

Original comment by a...@1stleg.com on 21 Mar 2014 at 6:23