The tricky part here is that, once you start messing around with code running as root, there are multiple TCC databases to contend with, namely the one for your user account and the one for the system as a whole. That complicates matters.
Thanks for the insight. I didn't know that! Out of curiosity: would a
sudo tccutil reset All com.mycompany.myapp
reset the permissions for the app for the root user?
So, anyway, lemme clarify your actual setup. It sounds like you’re:
Using an IOHIDManager to discover HID devices.
That vends you various IOHIDDevice objects.
You choose one and call IOHIDDeviceOpen on it.
Is that right?
I'm doing it a bit differently:
Using IOServiceAddMatchingNotification() to look for IOKit services of IOHIDDevice class.
Match the properties of the IOKit services/devices I receive in the callback with the properties in the callback. And if it fulfills my criteria, proceed to the next step.
Use IORegistryEntryGetRegistryEntryID() to get the registry entry ID for the IOKit service of the HID device
Send that IOKit RegistryEntryID over XPC to my service running as root.
In the service running as root, use IOServiceGetMatchingServices(kIOMainPortDefault, IORegistryEntryIDMatching(entryID), …) to get the IOKit service for the HID device I want to open
Use IOHIDDeviceCreate(kCFAllocatorDefault, ioService) to get the IOHIDDeviceRef for the IOKit service
Pass that to IOHIDDeviceOpen() to open the device: via IOHIDDeviceOpen(hidDevice, kIOHIDOptionsTypeSeizeDevice)
Are you passing in kIOHIDOptionsTypeSeizeDevice?
Yes I do.
If it helps, I can provide a source code example via Feedback Assistant that's ready to run after adjusting the Team IDs.
Topic:
App & System Services
SubTopic:
Core OS
Tags: