From 4ea3a6b031d059f757f110e2fa649d80d8604669 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Mon, 12 Aug 2019 21:20:59 -0700 Subject: [PATCH] Expose isolateId for engine (flutter/engine#10823) --- .../ios/framework/Headers/FlutterEngine.h | 7 +++++ .../ios/framework/Source/FlutterEngine.mm | 10 ++++++ .../Scenarios.xcodeproj/project.pbxproj | 4 +++ .../ScenariosTests/FlutterEngineTest.m | 31 +++++++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosTests/FlutterEngineTest.m diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h index 08f1058c2c..c65bef707b 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h @@ -242,6 +242,13 @@ FLUTTER_EXPORT */ @property(nonatomic, readonly) NSObject* binaryMessenger; +/** + * The UI Isolate ID of of the engine. + * + * This property will be nil if the engine is not running. + */ +@property(nonatomic, readonly, copy) NSString* isolateId; + @end #endif // FLUTTER_FLUTTERENGINE_H_ diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index efeb9cb212..aeb36b9cca 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -31,6 +31,8 @@ // Maintains a dictionary of plugin names that have registered with the engine. Used by // FlutterEngineRegistrar to implement a FlutterPluginRegistrar. @property(nonatomic, readonly) NSMutableDictionary* pluginPublications; + +@property(nonatomic, readwrite, copy) NSString* isolateId; @end @interface FlutterEngineRegistrar : NSObject @@ -171,6 +173,7 @@ - (void)destroyContext { [self resetChannels]; + self.isolateId = nil; _shell.reset(); _threadHost.Reset(); _platformViewsController.reset(); @@ -233,6 +236,13 @@ // Channels get a reference to the engine, and therefore need manual // cleanup for proper collection. - (void)setupChannels { + // This will be invoked once the shell is done setting up and the isolate ID + // for the UI isolate is available. + [_binaryMessenger setMessageHandlerOnChannel:@"flutter/isolate" + binaryMessageHandler:^(NSData* message, FlutterBinaryReply reply) { + self.isolateId = [[FlutterStringCodec sharedInstance] decode:message]; + }]; + _localizationChannel.reset([[FlutterMethodChannel alloc] initWithName:@"flutter/localization" binaryMessenger:self.binaryMessenger diff --git a/engine/src/flutter/testing/scenario_app/ios/Scenarios/Scenarios.xcodeproj/project.pbxproj b/engine/src/flutter/testing/scenario_app/ios/Scenarios/Scenarios.xcodeproj/project.pbxproj index 508809e031..5e76e5c433 100644 --- a/engine/src/flutter/testing/scenario_app/ios/Scenarios/Scenarios.xcodeproj/project.pbxproj +++ b/engine/src/flutter/testing/scenario_app/ios/Scenarios/Scenarios.xcodeproj/project.pbxproj @@ -23,6 +23,7 @@ 248D76DA22E388380012F0C1 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 248D76D922E388380012F0C1 /* main.m */; }; 248D76E422E388380012F0C1 /* ScenariosTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 248D76E322E388380012F0C1 /* ScenariosTests.m */; }; 248D76EF22E388380012F0C1 /* ScenariosUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 248D76EE22E388380012F0C1 /* ScenariosUITests.m */; }; + 248FDFC422FE7CD0009CC7CD /* FlutterEngineTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 248FDFC322FE7CD0009CC7CD /* FlutterEngineTest.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -95,6 +96,7 @@ 248D76EA22E388380012F0C1 /* ScenariosUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ScenariosUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 248D76EE22E388380012F0C1 /* ScenariosUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ScenariosUITests.m; sourceTree = ""; }; 248D76F022E388380012F0C1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 248FDFC322FE7CD0009CC7CD /* FlutterEngineTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FlutterEngineTest.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -162,6 +164,7 @@ 248D76E222E388380012F0C1 /* ScenariosTests */ = { isa = PBXGroup; children = ( + 248FDFC322FE7CD0009CC7CD /* FlutterEngineTest.m */, 0DB781FC22EA2C0300E9B371 /* FlutterViewControllerTest.m */, 248D76E322E388380012F0C1 /* ScenariosTests.m */, 248D76E522E388380012F0C1 /* Info.plist */, @@ -329,6 +332,7 @@ files = ( 248D76E422E388380012F0C1 /* ScenariosTests.m in Sources */, 0DB7820222EA493B00E9B371 /* FlutterViewControllerTest.m in Sources */, + 248FDFC422FE7CD0009CC7CD /* FlutterEngineTest.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosTests/FlutterEngineTest.m b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosTests/FlutterEngineTest.m new file mode 100644 index 0000000000..82c93a2033 --- /dev/null +++ b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosTests/FlutterEngineTest.m @@ -0,0 +1,31 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import +#import +#import "AppDelegate.h" + +@interface FlutterEngineTest : XCTestCase +@end + +@implementation FlutterEngineTest + +- (void)testIsolateId { + FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil]; + XCTAssertNil(engine.isolateId); + [self keyValueObservingExpectationForObject:engine keyPath:@"isolateId" handler:nil]; + + XCTAssertTrue([engine runWithEntrypoint:nil]); + + [self waitForExpectationsWithTimeout:30.0 handler:nil]; + + XCTAssertNotNil(engine.isolateId); + XCTAssertTrue([engine.isolateId hasPrefix:@"isolates/"]); + + [engine destroyContext]; + + XCTAssertNil(engine.isolateId); +} + +@end