Limneoselias (talk | contribs) |
Limneoselias (talk | contribs) |
||
Line 52: | Line 52: | ||
int (*SBSSpringBoardServerPort)() = (int (*)())dlsym(RTLD_DEFAULT, "SBSSpringBoardServerPort"); | int (*SBSSpringBoardServerPort)() = (int (*)())dlsym(RTLD_DEFAULT, "SBSSpringBoardServerPort"); | ||
int port = SBSSpringBoardServerPort(); | int port = SBSSpringBoardServerPort(); | ||
void (*_SBDimScreen)(int | void (*_SBDimScreen)(int _port,BOOL shouldDim) = (void (*)(int _port,BOOL shouldDim))dlsym(RTLD_DEFAULT, "SBDimScreen"); | ||
BOOL dim = proximityValue == 0 ? NO : YES; | BOOL dim = proximityValue == 0 ? NO : YES; |
Revision as of 21:33, 1 June 2011
General characteristics
Kernel Extension | IOHIDFamily |
---|---|
Service name | AppleProxShim |
Parent Service | AppleCT700 |
IOProviderClass | AppleARMIICDevice |
HIDServiceSupport | Yes |
Default ReportInterval | 0 |
PrimaryUsage | 8 |
PrimaryUsagePage | 65280 |
Proximity Sensor
AppleProxShim is the IOHIDService that controls the device's proximity sensor. By default, this service is enabled only from withing applications that have called the high-level method : UIApplication -setProximitySensingEnabled: .
You can intercept the service to manually enable the proximity sensor and assign a callback action for the proximity events, even when on SpringBoard.
To turn on the sensor, you need to change the service's default ReportInterval from 0 to a higher number. For more information about IOHID, see IOHIDFamily
Example
#include <IOKit/hid/IOHIDEventSystem.h>
#include <stdio.h>
void handle_event (void* target, void* refcon, IOHIDServiceRef service, IOHIDEventRef event) {
if (IOHIDEventGetType(event)==14){ // Proximity Event Received
int proximityValue=IOHIDEventGetIntegerValue(event, (IOHIDEventField)917504); // Get the value of the ProximityChanged Field (0 or 64)
// Call dimScreen on SpringBoard to simulate the original proximity effect, or use a reaction of your choice
int (*SBSSpringBoardServerPort)() = (int (*)())dlsym(RTLD_DEFAULT, "SBSSpringBoardServerPort");
int port = SBSSpringBoardServerPort();
void (*_SBDimScreen)(int _port,BOOL shouldDim) = (void (*)(int _port,BOOL shouldDim))dlsym(RTLD_DEFAULT, "SBDimScreen");
BOOL dim = proximityValue == 0 ? NO : YES;
_SBDimScreen(port,dim);
}
}
int main () {
// Create and open an event system.
IOHIDEventSystemRef system = IOHIDEventSystemCreate(NULL);
// set the PrimaryUsagePage and PrimaryUsage that the AppleProxShim service uses
int page = 65280;
int usage = 8;
// Create a dictionary to match the service with
CFNumberRef nums[2];
CFStringRef keys[2];
keys[0] = CFStringCreateWithCString(0, "PrimaryUsagePage", 0);
keys[1] = CFStringCreateWithCString(0, "PrimaryUsage", 0);
nums[0] = CFNumberCreate(0, kCFNumberSInt32Type, &page);
nums[1] = CFNumberCreate(0, kCFNumberSInt32Type, &usage);
CFDictionaryRef dict = CFDictionaryCreate(0, (const void**)keys, (const void**)nums, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
// Get the total of matching services with the above criteria
CFArrayRef srvs = (CFArrayRef)IOHIDEventSystemCopyMatchingServices(system, dict, 0, 0, 0,0);
// Get the service
IOHIDServiceRef serv = (IOHIDServiceRef)CFArrayGetValueAtIndex(srvs, 0);
int interval = 1 ;
// Set an interval of 1 , to activate the sensor
IOHIDServiceSetProperty((IOHIDServiceRef)serv, CFSTR("ReportInterval"), CFNumberCreate(0, kCFNumberSInt32Type, &interval));
IOHIDEventSystemOpen(system, handle_event, NULL, NULL, NULL);
printf("HID Event system should now be running. Hit enter to quit any time.\n");
getchar();
IOHIDEventSystemClose(system, NULL);
CFRelease(system);
return 0;
}
Note
The lockscreen has its own Dim Timer, so when in lockscreen the SBDimScreen event will only dim it, but will not undim. Test in SpringBoard , unlocked, for better results.
References
- Headers for IOHID: http://github.com/kennytm/iphone-private-frameworks/tree/master/IOKit/hid
|