[sim] Ensure that only the main Simulator window is recognised.

Ignoring other windows such as an external display.
This commit is contained in:
Eloy Durán
2014-08-15 16:55:28 +02:00
parent 8b0f0da9c5
commit 9e3b2e11dd

View File

@@ -258,10 +258,22 @@ locate_app_windows_ids(void)
validate(name, NSString);
#if defined(SIMULATOR_IOS)
// Don't recognise Simulator windows other than the main window (e.g. an
// external display window).
if ([name rangeOfString:sdk_version].location == NSNotFound) {
continue;
}
// Get the bundle ID for the process ID of this window and check if is
// indeed the iOS Simulator.
ProcessSerialNumber psn;
GetProcessForPID((pid_t)[[dict objectForKey:(NSString *)kCGWindowOwnerPID] intValue], &psn);
CFDictionaryRef processInfo = ProcessInformationCopyDictionary(&psn, kProcessDictionaryIncludeAllInformationMask);
NSString *bundleID = [(NSDictionary *)processInfo objectForKey:(NSString *)kCFBundleIdentifierKey];
NSNumber *processID = [dict objectForKey:(NSString *)kCGWindowOwnerPID];
GetProcessForPID((pid_t)[processID intValue], &psn);
NSDictionary *processInfo =
(NSDictionary *)ProcessInformationCopyDictionary(&psn,
kProcessDictionaryIncludeAllInformationMask);
NSString *bundleIDKey = (NSString *)kCFBundleIdentifierKey;
NSString *bundleID = [processInfo objectForKey:bundleIDKey];
if (![bundleID isEqualToString:@"com.apple.iphonesimulator"]) {
continue;
}