Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/extensions/Variables/includes/ExtVariables.php on line 198
AppleProxShim: Difference between revisions - iPhone Development Wiki

AppleProxShim: Difference between revisions

From iPhone Development Wiki
mNo edit summary
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Infobox
| above = {{PAGENAME}}
| header1 = IOService
| label1 = Kernel Extension
| data1 = [[IOHIDFamily]]
| label2 = Parent Service
| data2 = AppleCT700
| label3 = IOProviderClass
| data3 = AppleARMIICDevice
| label4 = Primary Usage Page
| data4 = 65280
| label5 = Primary Usage
| data5 = 8
}}
'''AppleProxShim''' is the <tt>IOHIDService</tt> that controls the device's proximity sensor. By default, this service is enabled only from within applications that have called the high-level method {{ObjcCall|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 {{applink|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]]
=== General characteristics ===
=== General characteristics ===
{| class="wikitable"
{| class="wikitable"
|-
! Kernel Extension
| <tt>IOHIDFamily</tt>
|-
! Service name
| <tt>AppleProxShim</tt>
|-
! Parent Service
| <tt>AppleCT700</tt>
|-
! IOProviderClass
| <tt>AppleARMIICDevice</tt>
|-
|-
! HIDServiceSupport
! HIDServiceSupport
Line 19: Line 30:
! Default ReportInterval
! Default ReportInterval
| 0
| 0
|-
! PrimaryUsage
| 8
|-
! PrimaryUsagePage
| 65280
|}
|}


== Example ==
This example works only for the iPhone 4.


== Proximity Sensor ==
AppleProxShim is the <tt>IOHIDService</tt> 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 ==
<source lang="c">
<source lang="c">
#include <IOKit/hid/IOHIDEventSystem.h>
#include <IOKit/hid/IOHIDEventSystem.h>
#include <stdio.h>
#include <stdio.h>


void handle_event (void* target, void* refcon, IOHIDServiceRef service, IOHIDEventRef event) {
void handle_event(void* target, void* refcon, IOHIDServiceRef service, IOHIDEventRef event) {
 
if (IOHIDEventGetType(event) == kIOHIDEventTypeProximity) { // Proximity Event Received
  if (IOHIDEventGetType(event)==14){ // Proximity Event Received
int proximityValue=IOHIDEventGetIntegerValue(event, (IOHIDEventField)kIOHIDEventFieldProximityDetectionMask); // Get the value of the ProximityChanged Field (0 or 64)
 
                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
// 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 (*SBSSpringBoardServerPort)() = (int (*)())dlsym(RTLD_DEFAULT, "SBSSpringBoardServerPort");
int port = SBSSpringBoardServerPort();  
int port = SBSSpringBoardServerPort();  
void (*_SBDimScreen)(int port,BOOL shouldDim) = (void (*)(int port,BOOL shouldDim))dlsym(RTLD_DEFAULT, "SBDimScreen");
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;
_SBDimScreen(port, dim);  
_SBDimScreen(p,dim);  
}
  }
}
}


int main(int argc, char **argv) {
// 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;


int main () {
// Create a dictionary to match the service with
  // Create and open an event system.
CFStringRef keys[2];
  IOHIDEventSystemRef system = IOHIDEventSystemCreate(NULL);
CFNumberRef nums[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);
    
    
  // set the PrimaryUsagePage and PrimaryUsage that the AppleProxShim service uses
// Get the service
  int page = 65280;
IOHIDServiceRef serv = (IOHIDServiceRef)CFArrayGetValueAtIndex(srvs, 0);
  int usage = 8;
int interval = 1 ;
 
  // Create a dictionary to match the service with
// Set an interval of 1 , to activate the sensor 
  CFNumberRef nums[2];
IOHIDServiceSetProperty((IOHIDServiceRef)serv, CFSTR("ReportInterval"), CFNumberCreate(0, kCFNumberSInt32Type, &interval));
  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
IOHIDEventSystemOpen(system, handle_event, NULL, NULL, NULL);
  IOHIDServiceRef serv = (IOHIDServiceRef)CFArrayGetValueAtIndex(srvs, 0);
printf("HID Event system should now be running. Hit enter to quit any time.\n");
  int interval = 1 ;
getchar();
int defaultInterval = 0;
IOHIDServiceSetProperty((IOHIDServiceRef)serv, CFSTR("ReportInterval"), CFNumberCreate(0, kCFNumberSInt32Type, &defaultInterval));


  // Set an interval of 1 , to activate the sensor 
IOHIDEventSystemClose(system, NULL);
  IOHIDServiceSetProperty((IOHIDServiceRef)serv, CFSTR("ReportInterval"), CFNumberCreate(0, kCFNumberSInt32Type, &interval));
CFRelease(system);
 
return 0;
  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;
}</source>
}</source>


== Note ==
== 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 ==
The lockscreen has its own Dim Timer, so when in lockscreen the SBDimScreen event will only dim it, but will not undim. Test in {{applink|SpringBoard}}, unlocked, for better results.
<references/>
 
* Headers for IOHID: http://github.com/kennytm/iphone-private-frameworks/tree/master/IOKit/hid
== External links ==
 
* [http://github.com/kennytm/iphone-private-frameworks/tree/master/IOKit/hid Headers for IOHID].


{{occlass|library=IOKit.framework|navbox=1}}
{{occlass|library=IOKit.framework|navbox=1}}

Latest revision as of 04:34, 25 October 2014

AppleProxShim
IOService
Kernel Extension IOHIDFamily
Parent Service AppleCT700
IOProviderClass AppleARMIICDevice
Primary Usage Page 65280
Primary Usage 8

AppleProxShim is the IOHIDService that controls the device's proximity sensor. By default, this service is enabled only from within 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

General characteristics

HIDServiceSupport Yes
Default ReportInterval 0

Example

This example works only for the iPhone 4.

#include <IOKit/hid/IOHIDEventSystem.h>
#include <stdio.h>

void handle_event(void* target, void* refcon, IOHIDServiceRef service, IOHIDEventRef event) {
	if (IOHIDEventGetType(event) == kIOHIDEventTypeProximity) { // Proximity Event Received
		int proximityValue=IOHIDEventGetIntegerValue(event, (IOHIDEventField)kIOHIDEventFieldProximityDetectionMask); // 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(int argc, char **argv) {
	// 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
	CFStringRef keys[2];
	CFNumberRef nums[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();
	int defaultInterval = 0;
	IOHIDServiceSetProperty((IOHIDServiceRef)serv, CFSTR("ReportInterval"), CFNumberCreate(0, kCFNumberSInt32Type, &defaultInterval));

	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.

External links