Difference between revisions of "GSCapability"

From iPhone Development Wiki
Jump to: navigation, search
(Created page with '{{occlass|library=GraphicsServices.framework}} GSCapability is a group of C functions that checks the ''capability'' of the device. A capability can be a simple boolean valu…')
 
Line 13: Line 13:
 
</source>
 
</source>
  
== Header ==
+
== Extracting the capability dictionary ==
 +
The capabilities are stored as a plist in a shared memory region named "<tt>GSCapabilities</tt>". You can use this code to extract it:
 +
<source lang="c">
 +
#include <sys/mman.h>
 +
#include <sys/stat.h>
 +
#include <CoreFoundation/CoreFoundation.h>
 +
static CFDictionaryRef GSCopyCapababilities(void) {
 +
int shm = shm_open("GSCapabilities", 0);
 +
assert(shm != -1);
 +
 +
struct stat shm_stat;
 +
int fstat_ret = fstat(shm, &shm_stat);
 +
assert(fstat_ret == 0);
 +
 +
void* map = mmap(NULL, shm_stat.st_size, 1, 1, shm, 0);
 +
assert(map >= 0);
 +
 +
CFIndex len = *(CFIndex*)map;
 +
CFDataRef data = CFDataCreateWithBytesNoCopy(NULL, (const UInt8*)map + sizeof(len), len, kCFAllocatorNull);
 +
assert(data != NULL);
 +
 +
CFPropertyListRef propList = CFPropertyListCreateFromXMLData(NULL, data, kCFPropertyListImmutable, NULL);
 +
CFRelease(data);
 +
 +
munmap(map, len);
 +
close(shm);
 +
 +
return propList;
 +
}
 +
</source>
 +
 
 +
== Default capabilities of various devices ==
 +
 
 +
 
 +
{| class="wikitable sortable"
 +
|-
 +
! Capabilities !! N45AP<br />(iPod Touch 1G) !! M68AP<br />(iPhone 2G)
 +
|-
 +
| kGSTelephonyCapability <br /> "<tt>telephony</tt>"
 +
| {{No}} || {{Yes}}
 +
|-
 +
| kGSCellularDataCapability <br /> "<tt>cellular-data</tt>"
 +
| {{No}} || {{Unk}}
 +
|-
 +
| kGSSMSCapability <br /> "<tt>sms</tt>"
 +
| {{No}} || {{Yes}}
 +
|-
 +
| kGSCameraCapability <br /> "<tt>still-camera</tt>"
 +
| {{No}} || {{Yes}}
 +
|-
 +
| kGSVideoCameraCapability <br /> "<tt>video-camera</tt>"
 +
| {{No}} || {{No}}
 +
|-
 +
| kGSAutoFocusCameraCapability <br /> "<tt>auto-focus-camera</tt>"
 +
| {{No}} || {{No}}
 +
|-
 +
| kGSH264EncoderCapability <br /> "<tt>h264-encoder</tt>"
 +
| {{No}} || {{No}}
 +
|-
 +
| kGSWiFiCapability <br /> "<tt>wifi</tt>"
 +
| {{Yes}} || {{Yes}}
 +
|-
 +
| kGSAccelerometerCapability <br /> "<tt>accelerometer</tt>"
 +
| {{Yes}} || {{Yes}}
 +
|-
 +
| kGSMagnetometerCapability <br /> "<tt>magnetometer</tt>"
 +
| {{No}} || {{No}}
 +
|-
 +
| kGSGPSCapability <br /> "<tt>gps</tt>"
 +
| {{No}} || {{Yes}}
 +
|-
 +
| kGSLocationServicesCapability <br /> "<tt>location-services</tt>"
 +
| {{Yes}} || {{Yes}}
 +
|-
 +
| kGSMicrophoneCapability <br /> "<tt>microphone</tt>"
 +
| {{No}} || {{Yes}}
 +
|-
 +
| kGSPeer2PeerCapability <br /> "<tt>peer-peer</tt>"
 +
| {{No}} || {{Unk}}
 +
|-
 +
| kGSOpenGLES1Capability <br /> "<tt>opengles-1</tt>"
 +
| {{Yes}} || {{Yes}}
 +
|-
 +
| kGSOpenGLES2Capability <br /> "<tt>opengles-2</tt>"
 +
| {{No}} || {{No}}
 +
|-
 +
| kGSARMV6ExecutionCapability <br /> "<tt>armv6</tt>"
 +
| {{Yes}} || {{Yes}}
 +
|-
 +
| kGSARMV7ExecutionCapability <br /> "<tt>armv7</tt>"
 +
| {{No}} || {{No}}
 +
|-
 +
| kGSDisplayPortCapability <br /> "<tt>display-port</tt>"
 +
| {{No}} || {{Unk}}
 +
|-
 +
| kGSContainsCellularRadioCapability <br /> "<tt>contains-cellular-radio</tt>"
 +
| {{No}} || {{Unk}}
 +
|-
 +
| kGSVolumeButtonCapability <br /> "<tt>volume-buttons</tt>"
 +
| {{No}} || {{Yes}}
 +
|-
 +
| kGSRingerSwitchCapability <br /> "<tt>ringer-switch</tt>"
 +
| {{No}} || {{Yes}}
 +
|-
 +
| kGSPiezoClickerCapability <br /> "<tt>piezo-clicker</tt>"
 +
| {{Yes}} || {{No}}
 +
|-
 +
| kGSBluetoothCapability <br /> "<tt>bluetooth</tt>"
 +
| {{No}} || {{Yes}}
 +
|-
 +
| kGSUnifiedIPodCapability <br /> "<tt>unified-ipod</tt>"
 +
| {{No}} || {{Yes}}
 +
|-
 +
| kGSYouTubeCapability <br /> "<tt>youtube</tt>"
 +
| {{Yes}} || {{Yes}}
 +
|-
 +
| kGSYouTubePluginCapability <br /> "<tt>youtubePlugin</tt>"
 +
| {{Yes}} || {{Yes}}
 +
|-
 +
| kGSGreenTeaDeviceCapability<ref name="green-tea">"Green-Tea" is a code name for devices sold in China. Green-Tea devices have restricted access to various applications e.g. Maps.</ref> <br /> "<tt>green-tea</tt>"
 +
| {{No}} || {{No}}
 +
|-
 +
| kGSNotGreenTeaDeviceCapability<ref name="green-tea"/> <br /> "<tt>not-green-tea</tt>"
 +
| {{Yes}} || {{Yes}}
 +
|-
 +
| kGSInternationalSettingsCapability <br /> "<tt>international-settings</tt>"
 +
| {{Yes}} || {{Yes}}
 +
|-
 +
| kGSPlatformStandAloneContactsCapability <br /> "<tt>stand-alone-contacts</tt>"
 +
| {{Yes}} || {{Yes}}
 +
|-
 +
| kGSDelaySleepForHeadsetClickCapability <br /> "<tt>delay-sleep-for-headset-click</tt>"
 +
| {{No}} || {{Unk}}
 +
|-
 +
| kGSLaunchApplicationsWhileAnimatingCapability <br /> "<tt>launch-applications-while-animating</tt>"
 +
| {{No}} || {{Unk}}
 +
|-
 +
| kGSLoadThumbnailsWhileScrollingCapability <br /> "<tt>load-thumbnails-while-scrolling</tt>"
 +
| {{No}} || {{Unk}}
 +
|-
 +
| kGSSensitiveUICapability <br /> "<tt>sensitive-ui</tt>"
 +
| {{No}} || {{Unk}}
 +
|-
 +
| kGSAppleInternalInstallCapability <br /> "<tt>apple-internal-install</tt>"
 +
| {{No}} || {{No}}
 +
|-
 +
| kGSHasAllFeaturesCapability <br /> "<tt>all-features</tt>"
 +
| {{Yes}} || {{Yes}}
 +
|-
 +
| kGSNikeIpodCapability <br /> "<tt>nike-ipod</tt>"
 +
| {{No}} || {{No}}
 +
|-
 +
| kGSApplicationInstallationCapability <br /> "<tt>applicationInstallation</tt>"
 +
| {{Yes}} || {{Yes}}
 +
|-
 +
| kGSVoiceControlCapability <br /> "<tt>voice-control</tt>"
 +
| {{No}} || {{No}}
 +
|-
 +
| kGSProximitySensorCapability <br /> "<tt>proximity-sensor</tt>"
 +
| {{No}} || {{Yes}}
 +
|-
 +
| kGSGasGaugeBatteryCapability<ref>Gas-gauge capability allows accurate monitoring of the battery level</ref> <br /> "<tt>gas-gauge-battery</tt>"
 +
| {{No}} || {{Unk}}
 +
|-
 +
| kGSAccessibilityCapability <br /> "<tt>accessibility</tt>"
 +
| {{No}} || {{No}}
 +
|-
 +
| kGSMMSCapability <br /> "<tt>mms</tt>"
 +
| {{No}} || {{No}}
 +
|-
 +
| kGSEncryptedDataPartitionCapability <br /> "<tt>encrypted-data-partition</tt>"
 +
| {{No}} || {{Unk}}
 +
|-
 +
| kGSEncodeAACCapability <br /> "<tt>encode-aac</tt>"
 +
| {{No}} || {{Unk}}
 +
|-
 +
| kGS720pPlaybackCapability <br /> "<tt>720p</tt>"
 +
| {{No}} || {{No}}
 +
|-
 +
| kGSDisplayFCCLogosViaSoftwareCapability <br /> "<tt>fcc-logos-via-software</tt>"
 +
| {{No}} || {{Unk}}
 +
|-
 +
| kGSHideNonDefaultApplicationsCapability <br /> "<tt>hide-non-default-apps</tt>"
 +
| {{No}} || {{Unk}}
 +
|-
 +
| kGSWildcatCapability<ref>"Wildcat" is the codename of iPad.</ref> <br /> "<tt>wildcat</tt>"
 +
| {{No}} || {{No}}
 +
|-
 +
| kGSDataPlanCapability <br /> "<tt>data-plan</tt>"
 +
| {{No}} || {{Unk}}
 +
|-
 +
| kGSTelephonyMaximumGeneration <br /> "<tt>telephony-maximum-generation</tt>"
 +
| 0  || 2.5
 +
|-
 +
| kGSDeviceNameString <br /> "<tt>device-name</tt>"
 +
| iPod || iPhone
 +
|-
 +
| kGSMarketingNameString <br /> "<tt>marketing-name</tt>"
 +
| iPod Touch || iPhone
 +
|-
 +
| kGSScreenDimensionsCapability<ref>This capability is a dictionary with 4 members. Only width and height are shown here.</ref> <br /> "<tt>screen-dimensions</tt>"
 +
| 320 &times; 480 || 320 &times; 480
 +
|}
 +
 
 +
 
 +
== References ==
 +
<references/>
 
* http://github.com/kennytm/iphone-private-frameworks/blob/master/GraphicsServices/GSCapability.h
 
* http://github.com/kennytm/iphone-private-frameworks/blob/master/GraphicsServices/GSCapability.h

Revision as of 21:17, 3 February 2010


GSCapability is a group of C functions that checks the capability of the device. A capability can be a simple boolean value, e.g. whether the device can take pictures, to a complex structure e.g. the screen dimensions.

Example code

if (GSSystemHasCapability(kGSMagnetometerCapability)) {
  direction = get_direction();
} else {
  printf("This device has no compass\n");
}

Extracting the capability dictionary

The capabilities are stored as a plist in a shared memory region named "GSCapabilities". You can use this code to extract it:

#include <sys/mman.h>
#include <sys/stat.h>
#include <CoreFoundation/CoreFoundation.h>
static CFDictionaryRef GSCopyCapababilities(void) {
	int shm = shm_open("GSCapabilities", 0);
	assert(shm != -1);
	
	struct stat shm_stat;
	int fstat_ret = fstat(shm, &shm_stat);
	assert(fstat_ret == 0);
	
	void* map = mmap(NULL, shm_stat.st_size, 1, 1, shm, 0);
	assert(map >= 0);
	
	CFIndex len = *(CFIndex*)map;
	CFDataRef data = CFDataCreateWithBytesNoCopy(NULL, (const UInt8*)map + sizeof(len), len, kCFAllocatorNull);
	assert(data != NULL);
	
	CFPropertyListRef propList = CFPropertyListCreateFromXMLData(NULL, data, kCFPropertyListImmutable, NULL);
	CFRelease(data);
	
	munmap(map, len);
	close(shm);
	
	return propList;
}

Default capabilities of various devices

Capabilities N45AP
(iPod Touch 1G)
M68AP
(iPhone 2G)
kGSTelephonyCapability
"telephony"
No Yes
kGSCellularDataCapability
"cellular-data"
No Unknown
kGSSMSCapability
"sms"
No Yes
kGSCameraCapability
"still-camera"
No Yes
kGSVideoCameraCapability
"video-camera"
No No
kGSAutoFocusCameraCapability
"auto-focus-camera"
No No
kGSH264EncoderCapability
"h264-encoder"
No No
kGSWiFiCapability
"wifi"
Yes Yes
kGSAccelerometerCapability
"accelerometer"
Yes Yes
kGSMagnetometerCapability
"magnetometer"
No No
kGSGPSCapability
"gps"
No Yes
kGSLocationServicesCapability
"location-services"
Yes Yes
kGSMicrophoneCapability
"microphone"
No Yes
kGSPeer2PeerCapability
"peer-peer"
No Unknown
kGSOpenGLES1Capability
"opengles-1"
Yes Yes
kGSOpenGLES2Capability
"opengles-2"
No No
kGSARMV6ExecutionCapability
"armv6"
Yes Yes
kGSARMV7ExecutionCapability
"armv7"
No No
kGSDisplayPortCapability
"display-port"
No Unknown
kGSContainsCellularRadioCapability
"contains-cellular-radio"
No Unknown
kGSVolumeButtonCapability
"volume-buttons"
No Yes
kGSRingerSwitchCapability
"ringer-switch"
No Yes
kGSPiezoClickerCapability
"piezo-clicker"
Yes No
kGSBluetoothCapability
"bluetooth"
No Yes
kGSUnifiedIPodCapability
"unified-ipod"
No Yes
kGSYouTubeCapability
"youtube"
Yes Yes
kGSYouTubePluginCapability
"youtubePlugin"
Yes Yes
kGSGreenTeaDeviceCapability[1]
"green-tea"
No No
kGSNotGreenTeaDeviceCapability[1]
"not-green-tea"
Yes Yes
kGSInternationalSettingsCapability
"international-settings"
Yes Yes
kGSPlatformStandAloneContactsCapability
"stand-alone-contacts"
Yes Yes
kGSDelaySleepForHeadsetClickCapability
"delay-sleep-for-headset-click"
No Unknown
kGSLaunchApplicationsWhileAnimatingCapability
"launch-applications-while-animating"
No Unknown
kGSLoadThumbnailsWhileScrollingCapability
"load-thumbnails-while-scrolling"
No Unknown
kGSSensitiveUICapability
"sensitive-ui"
No Unknown
kGSAppleInternalInstallCapability
"apple-internal-install"
No No
kGSHasAllFeaturesCapability
"all-features"
Yes Yes
kGSNikeIpodCapability
"nike-ipod"
No No
kGSApplicationInstallationCapability
"applicationInstallation"
Yes Yes
kGSVoiceControlCapability
"voice-control"
No No
kGSProximitySensorCapability
"proximity-sensor"
No Yes
kGSGasGaugeBatteryCapability[2]
"gas-gauge-battery"
No Unknown
kGSAccessibilityCapability
"accessibility"
No No
kGSMMSCapability
"mms"
No No
kGSEncryptedDataPartitionCapability
"encrypted-data-partition"
No Unknown
kGSEncodeAACCapability
"encode-aac"
No Unknown
kGS720pPlaybackCapability
"720p"
No No
kGSDisplayFCCLogosViaSoftwareCapability
"fcc-logos-via-software"
No Unknown
kGSHideNonDefaultApplicationsCapability
"hide-non-default-apps"
No Unknown
kGSWildcatCapability[3]
"wildcat"
No No
kGSDataPlanCapability
"data-plan"
No Unknown
kGSTelephonyMaximumGeneration
"telephony-maximum-generation"
0 2.5
kGSDeviceNameString
"device-name"
iPod iPhone
kGSMarketingNameString
"marketing-name"
iPod Touch iPhone
kGSScreenDimensionsCapability[4]
"screen-dimensions"
320 × 480 320 × 480


References

  1. 1.0 1.1 "Green-Tea" is a code name for devices sold in China. Green-Tea devices have restricted access to various applications e.g. Maps.
  2. Gas-gauge capability allows accurate monitoring of the battery level
  3. "Wildcat" is the codename of iPad.
  4. This capability is a dictionary with 4 members. Only width and height are shown here.