Skip to content

Commit 53fc019

Browse files
authored
Split AOT Android Embedder and shell (flutter#22179)
1 parent 23a8e02 commit 53fc019

29 files changed

+1242
-3
lines changed

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ deps = {
482482
'packages': [
483483
{
484484
'package': 'flutter/android/embedding_bundle',
485-
'version': 'last_updated:2020-05-20T01:36:16-0700'
485+
'version': 'last_updated:2020-09-11T17:57:41-0700'
486486
}
487487
],
488488
'condition': 'download_android_deps',

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,8 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/Flutte
747747
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartExecutor.java
748748
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartMessenger.java
749749
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/dart/PlatformMessageHandler.java
750+
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/dynamicfeatures/DynamicFeatureManager.java
751+
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/dynamicfeatures/PlayStoreDynamicFeatureManager.java
750752
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/loader/ApplicationInfoLoader.java
751753
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterApplicationInfo.java
752754
FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java

shell/common/engine.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,4 +507,21 @@ const std::string& Engine::GetLastEntrypointLibrary() const {
507507
return last_entry_point_library_;
508508
}
509509

510+
// The Following commented out code connects into part 2 of the split AOT
511+
// feature. Left commented out until it lands:
512+
513+
// // |RuntimeDelegate|
514+
// void Engine::RequestDartDeferredLibrary(intptr_t loading_unit_id) {
515+
// return delegate_.RequestDartDeferredLibrary(loading_unit_id);
516+
// }
517+
518+
void Engine::LoadDartDeferredLibrary(intptr_t loading_unit_id,
519+
const uint8_t* snapshot_data,
520+
const uint8_t* snapshot_instructions) {
521+
if (runtime_controller_->IsRootIsolateRunning()) {
522+
// runtime_controller_->LoadDartDeferredLibrary(loading_unit_id,
523+
// snapshot_data, snapshot_instructions);
524+
}
525+
}
526+
510527
} // namespace flutter

shell/common/engine.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,21 @@ class Engine final : public RuntimeDelegate,
260260
virtual std::unique_ptr<std::vector<std::string>>
261261
ComputePlatformResolvedLocale(
262262
const std::vector<std::string>& supported_locale_data) = 0;
263+
264+
//--------------------------------------------------------------------------
265+
/// @brief Invoked when the Dart VM requests that a deferred library
266+
/// be loaded. Notifies the engine that the deferred library
267+
/// identified by the specified loading unit id should be
268+
/// downloaded and loaded into the Dart VM via
269+
/// `LoadDartDeferredLibrary`
270+
///
271+
/// @param[in] loading_unit_id The unique id of the deferred library's
272+
/// loading unit. This id is to be passed
273+
/// back into LoadDartDeferredLibrary
274+
/// in order to identify which deferred
275+
/// library to load.
276+
///
277+
virtual void RequestDartDeferredLibrary(intptr_t loading_unit_id) = 0;
263278
};
264279

265280
//----------------------------------------------------------------------------
@@ -767,6 +782,38 @@ class Engine final : public RuntimeDelegate,
767782
///
768783
const std::string& InitialRoute() const { return initial_route_; }
769784

785+
//--------------------------------------------------------------------------
786+
/// @brief Loads the Dart shared library into the Dart VM. When the
787+
/// Dart library is loaded successfully, the Dart future
788+
/// returned by the originating loadLibrary() call completes.
789+
///
790+
/// The Dart compiler may generate separate shared libraries
791+
/// files called 'loading units' when libraries are imported
792+
/// as deferred. Each of these shared libraries are identified
793+
/// by a unique loading unit id. Callers should dlopen the
794+
/// shared library file and use dlsym to resolve the dart
795+
/// symbols. These symbols can then be passed to this method to
796+
/// be dynamically loaded into the VM.
797+
///
798+
/// This method is paired with a RequestDartDeferredLibrary
799+
/// invocation that provides the embedder with the loading unit id
800+
/// of the deferred library to load.
801+
///
802+
///
803+
/// @param[in] loading_unit_id The unique id of the deferred library's
804+
/// loading unit, as passed in by
805+
/// RequestDartDeferredLibrary.
806+
///
807+
/// @param[in] snapshot_data Dart snapshot data of the loading unit's
808+
/// shared library.
809+
///
810+
/// @param[in] snapshot_data Dart snapshot instructions of the loading
811+
/// unit's shared library.
812+
///
813+
void LoadDartDeferredLibrary(intptr_t loading_unit_id,
814+
const uint8_t* snapshot_data,
815+
const uint8_t* snapshot_instructions);
816+
770817
private:
771818
Engine::Delegate& delegate_;
772819
const Settings settings_;
@@ -815,6 +862,12 @@ class Engine final : public RuntimeDelegate,
815862
std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocale(
816863
const std::vector<std::string>& supported_locale_data) override;
817864

865+
// The Following commented out code connects into part 2 of the split AOT
866+
// feature. Left commented out until it lands:
867+
868+
// // |RuntimeDelegate|
869+
// void RequestDartDeferredLibrary(intptr_t loading_unit_id) override;
870+
818871
void SetNeedsReportTimings(bool value) override;
819872

820873
void StopAnimator();

shell/common/engine_unittests.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class MockDelegate : public Engine::Delegate {
3232
MOCK_METHOD1(ComputePlatformResolvedLocale,
3333
std::unique_ptr<std::vector<std::string>>(
3434
const std::vector<std::string>&));
35+
MOCK_METHOD1(RequestDartDeferredLibrary, void(intptr_t));
3536
};
3637

3738
class MockResponse : public PlatformMessageResponse {
@@ -55,6 +56,7 @@ class MockRuntimeDelegate : public RuntimeDelegate {
5556
MOCK_METHOD1(ComputePlatformResolvedLocale,
5657
std::unique_ptr<std::vector<std::string>>(
5758
const std::vector<std::string>&));
59+
MOCK_METHOD1(RequestDartDeferredLibrary, void(intptr_t));
5860
};
5961

6062
class MockRuntimeController : public RuntimeController {

shell/common/platform_view.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,14 @@ PlatformView::ComputePlatformResolvedLocales(
159159
return out;
160160
}
161161

162+
void PlatformView::RequestDartDeferredLibrary(intptr_t loading_unit_id) {}
163+
164+
void PlatformView::LoadDartDeferredLibrary(
165+
intptr_t loading_unit_id,
166+
const uint8_t* snapshot_data,
167+
const uint8_t* snapshot_instructions) {}
168+
169+
void PlatformView::UpdateAssetManager(
170+
std::shared_ptr<AssetManager> asset_manager) {}
171+
162172
} // namespace flutter

shell/common/platform_view.h

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,43 @@ class PlatformView {
210210
///
211211
virtual void OnPlatformViewMarkTextureFrameAvailable(
212212
int64_t texture_id) = 0;
213+
214+
//--------------------------------------------------------------------------
215+
/// @brief Loads the dart shared library into the dart VM. When the
216+
/// dart library is loaded successfully, the dart future
217+
/// returned by the originating loadLibrary() call completes.
218+
///
219+
/// The Dart compiler may generate separate shared library .so
220+
/// files called 'loading units' when libraries are imported
221+
/// as deferred. Each of these shared libraries are identified
222+
/// by a unique loading unit id and can be dynamically loaded
223+
/// into the VM by dlopen-ing and resolving the data and
224+
/// instructions symbols.
225+
///
226+
///
227+
/// @param[in] loading_unit_id The unique id of the deferred library's
228+
/// loading unit.
229+
///
230+
/// @param[in] snapshot_data Dart snapshot data of the loading unit's
231+
/// shared library.
232+
///
233+
/// @param[in] snapshot_data Dart snapshot instructions of the loading
234+
/// unit's shared library.
235+
///
236+
virtual void LoadDartDeferredLibrary(
237+
intptr_t loading_unit_id,
238+
const uint8_t* snapshot_data,
239+
const uint8_t* snapshot_instructions) = 0;
240+
241+
// TODO(garyq): Implement a proper asset_resolver replacement instead of
242+
// overwriting the entire asset manager.
243+
//--------------------------------------------------------------------------
244+
/// @brief Sets the asset manager of the engine to asset_manager
245+
///
246+
/// @param[in] asset_manager The asset manager to use.
247+
///
248+
virtual void UpdateAssetManager(
249+
std::shared_ptr<AssetManager> asset_manager) = 0;
213250
};
214251

215252
//----------------------------------------------------------------------------
@@ -565,6 +602,62 @@ class PlatformView {
565602

566603
virtual std::shared_ptr<ExternalViewEmbedder> CreateExternalViewEmbedder();
567604

605+
//--------------------------------------------------------------------------
606+
/// @brief Invoked when the dart VM requests that a deferred library
607+
/// be loaded. Notifies the engine that the deferred library
608+
/// identified by the specified loading unit id should be
609+
/// downloaded and loaded into the Dart VM via
610+
/// `LoadDartDeferredLibrary`
611+
///
612+
/// @param[in] loading_unit_id The unique id of the deferred library's
613+
/// loading unit. This id is to be passed
614+
/// back into LoadDartDeferredLibrary
615+
/// in order to identify which deferred
616+
/// library to load.
617+
///
618+
virtual void RequestDartDeferredLibrary(intptr_t loading_unit_id);
619+
620+
//--------------------------------------------------------------------------
621+
/// @brief Loads the Dart shared library into the Dart VM. When the
622+
/// Dart library is loaded successfully, the Dart future
623+
/// returned by the originating loadLibrary() call completes.
624+
///
625+
/// The Dart compiler may generate separate shared libraries
626+
/// files called 'loading units' when libraries are imported
627+
/// as deferred. Each of these shared libraries are identified
628+
/// by a unique loading unit id. Callers should dlopen the
629+
/// shared library file and use dlsym to resolve the dart
630+
/// symbols. These symbols can then be passed to this method to
631+
/// be dynamically loaded into the VM.
632+
///
633+
/// This method is paired with a RequestDartDeferredLibrary
634+
/// invocation that provides the embedder with the loading unit id
635+
/// of the deferred library to load.
636+
///
637+
///
638+
/// @param[in] loading_unit_id The unique id of the deferred library's
639+
/// loading unit, as passed in by
640+
/// RequestDartDeferredLibrary.
641+
///
642+
/// @param[in] snapshot_data Dart snapshot data of the loading unit's
643+
/// shared library.
644+
///
645+
/// @param[in] snapshot_data Dart snapshot instructions of the loading
646+
/// unit's shared library.
647+
///
648+
virtual void LoadDartDeferredLibrary(intptr_t loading_unit_id,
649+
const uint8_t* snapshot_data,
650+
const uint8_t* snapshot_instructions);
651+
652+
// TODO(garyq): Implement a proper asset_resolver replacement instead of
653+
// overwriting the entire asset manager.
654+
//--------------------------------------------------------------------------
655+
/// @brief Sets the asset manager of the engine to asset_manager
656+
///
657+
/// @param[in] asset_manager The asset manager to use.
658+
///
659+
virtual void UpdateAssetManager(std::shared_ptr<AssetManager> asset_manager);
660+
568661
protected:
569662
PlatformView::Delegate& delegate_;
570663
const TaskRunners task_runners_;

shell/common/shell.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,22 @@ std::unique_ptr<std::vector<std::string>> Shell::ComputePlatformResolvedLocale(
11851185
return platform_view_->ComputePlatformResolvedLocales(supported_locale_data);
11861186
}
11871187

1188+
void Shell::LoadDartDeferredLibrary(intptr_t loading_unit_id,
1189+
const uint8_t* snapshot_data,
1190+
const uint8_t* snapshot_instructions) {
1191+
engine_->LoadDartDeferredLibrary(loading_unit_id, snapshot_data,
1192+
snapshot_instructions);
1193+
}
1194+
1195+
void Shell::UpdateAssetManager(std::shared_ptr<AssetManager> asset_manager) {
1196+
engine_->UpdateAssetManager(std::move(asset_manager));
1197+
}
1198+
1199+
// |Engine::Delegate|
1200+
void Shell::RequestDartDeferredLibrary(intptr_t loading_unit_id) {
1201+
platform_view_->RequestDartDeferredLibrary(loading_unit_id);
1202+
}
1203+
11881204
void Shell::ReportTimings() {
11891205
FML_DCHECK(is_setup_);
11901206
FML_DCHECK(task_runners_.GetRasterTaskRunner()->RunsTasksOnCurrentThread());

shell/common/shell.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,14 @@ class Shell final : public PlatformView::Delegate,
507507
// |PlatformView::Delegate|
508508
void OnPlatformViewSetNextFrameCallback(const fml::closure& closure) override;
509509

510+
// |PlatformView::Delegate|
511+
void LoadDartDeferredLibrary(intptr_t loading_unit_id,
512+
const uint8_t* snapshot_data,
513+
const uint8_t* snapshot_instructions) override;
514+
515+
// |PlatformView::Delegate|
516+
void UpdateAssetManager(std::shared_ptr<AssetManager> asset_manager) override;
517+
510518
// |Animator::Delegate|
511519
void OnAnimatorBeginFrame(fml::TimePoint frame_target_time) override;
512520

@@ -548,6 +556,9 @@ class Shell final : public PlatformView::Delegate,
548556
std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocale(
549557
const std::vector<std::string>& supported_locale_data) override;
550558

559+
// |Engine::Delegate|
560+
void RequestDartDeferredLibrary(intptr_t loading_unit_id) override;
561+
551562
// |Rasterizer::Delegate|
552563
void OnFrameRasterized(const FrameTiming&) override;
553564

shell/platform/android/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ android_java_sources = [
156156
"io/flutter/embedding/engine/dart/DartExecutor.java",
157157
"io/flutter/embedding/engine/dart/DartMessenger.java",
158158
"io/flutter/embedding/engine/dart/PlatformMessageHandler.java",
159+
"io/flutter/embedding/engine/dynamicfeatures/DynamicFeatureManager.java",
160+
"io/flutter/embedding/engine/dynamicfeatures/PlayStoreDynamicFeatureManager.java",
159161
"io/flutter/embedding/engine/loader/ApplicationInfoLoader.java",
160162
"io/flutter/embedding/engine/loader/FlutterApplicationInfo.java",
161163
"io/flutter/embedding/engine/loader/FlutterLoader.java",
@@ -462,6 +464,7 @@ action("robolectric_tests") {
462464
"test/io/flutter/embedding/engine/RenderingComponentTest.java",
463465
"test/io/flutter/embedding/engine/dart/DartExecutorTest.java",
464466
"test/io/flutter/embedding/engine/dart/DartMessengerTest.java",
467+
"test/io/flutter/embedding/engine/dynamicfeatures/PlayStoreDynamicFeatureManagerTest.java",
465468
"test/io/flutter/embedding/engine/loader/ApplicationInfoLoaderTest.java",
466469
"test/io/flutter/embedding/engine/loader/FlutterLoaderTest.java",
467470
"test/io/flutter/embedding/engine/mutatorsstack/FlutterMutatorViewTest.java",

0 commit comments

Comments
 (0)