IOHIDRequestAccess() not working if accessibility status was previously checked via AXIsProcessTrustedWithOptions(NULL)

Originator:iospiritongt
Number:rdar://7381305 Date Originated:2019-10-15
Status:Open Resolved:
Product:macOS Product Version:10.15
Classification:bug Reproducible:always
 
# Filed as Feedback FB7381305

IOHIDRequestAccess() not working if accessibility status was previously checked via AXIsProcessTrustedWithOptions(NULL)

IOKit > 

# Steps to reproduce:
1) Check Accessibility API trust status via 
	Boolean isTruested = AXIsProcessTrustedWithOptions(NULL);

2) At a later point (not the same runloop pass), request input monitoring permission via IOHIDRequestAccess:
	bool accessGranted = IOHIDRequestAccess(kIOHIDRequestTypeListenEvent);
	
# Expected:
- the IOHIDRequestAccess(kIOHIDRequestTypeListenEvent) brings up a prompt, asking the user for permission to monitor keyboard events.
- the app making the call is listed under System Preferences > Security > Privacy > Input-Monitoring

# Actual:
- no prompt is shown
- the app making the call is not listed under System Preferences > Security > Privacy > Input-Monitoring

# Notes:
- the prompt is only shown if AXIsProcessTrustedWithOptions(NULL) has not been called previously, making it impossible to check for accessibility permissions and request input monitoring permission in the same app
- the issue affects usage with both kIOHIDRequestTypeListenEvent and kIOHIDRequestTypePostEvent

# Sample code
The issue is reproducable with this code:

```objc
Boolean isTrusted = AXIsProcessTrustedWithOptions(NULL);

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
	bool accessGranted = IOHIDRequestAccess(kIOHIDRequestTypeListenEvent);

	NSLog(@"Access granted: %d %d", accessGranted, isTrusted);
});
```

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!