Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit e2c5858

Browse files
committed
Build on linux and fuchsia
Build Build Build Use string.format Const-ness, nits, codestyle Typo Formatting: Handle apk and so loading in android jni native Update docs Remove dart_handle return Refactor and rename methods Rename to LoadDartDeferredLibrary Additional renaming Add back moduleName to params Documentation Pass asset manager to persistent cache Fix license, cleanup, fix docs, rename methods Javadocs, API adjustments More docs, rename log tag remove extra import FlutterEngine constructor Improve docs, nits, renaming Documentation
1 parent f4a8708 commit e2c5858

20 files changed

+502
-318
lines changed

shell/common/engine.cc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -511,17 +511,16 @@ const std::string& Engine::GetLastEntrypointLibrary() const {
511511
// feature. Left commented out until it lands:
512512

513513
// // |RuntimeDelegate|
514-
// Dart_Handle Engine::OnDartLoadLibrary(intptr_t loading_unit_id) {
515-
// return delegate_.OnDartLoadLibrary(loading_unit_id);
514+
// void Engine::RequestDartDeferredLibrary(intptr_t loading_unit_id) {
515+
// return delegate_.RequestDartDeferredLibrary(loading_unit_id);
516516
// }
517517

518-
void Engine::CompleteDartLoadLibrary(intptr_t loading_unit_id,
519-
std::string lib_name,
520-
std::vector<std::string>& apkPaths,
521-
std::string abi) {
518+
void Engine::LoadDartDeferredLibrary(intptr_t loading_unit_id,
519+
const uint8_t* snapshot_data,
520+
const uint8_t* snapshot_instructions) {
522521
if (runtime_controller_->IsRootIsolateRunning()) {
523-
// runtime_controller_->CompleteDartLoadLibrary(loading_unit_id, lib_name,
524-
// apkPaths, abi);
522+
// runtime_controller_->LoadDartDeferredLibrary(loading_unit_id,
523+
// snapshot_data, snapshot_instructions);
525524
}
526525
}
527526

shell/common/engine.h

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "flutter/shell/common/rasterizer.h"
3131
#include "flutter/shell/common/run_configuration.h"
3232
#include "flutter/shell/common/shell_io_manager.h"
33-
#include "third_party/dart/runtime/include/dart_api.h"
3433
#include "third_party/skia/include/core/SkPicture.h"
3534

3635
namespace flutter {
@@ -270,10 +269,7 @@ class Engine final : public RuntimeDelegate,
270269
/// @param[in] loading_unit_id The unique id of the deferred library's
271270
/// loading unit.
272271
///
273-
/// @return A Dart_Handle that is Dart_Null on success, and a dart error
274-
/// on failure.
275-
///
276-
virtual Dart_Handle OnDartLoadLibrary(intptr_t loading_unit_id) = 0;
272+
virtual void RequestDartDeferredLibrary(intptr_t loading_unit_id) = 0;
277273
};
278274

279275
//----------------------------------------------------------------------------
@@ -782,26 +778,25 @@ class Engine final : public RuntimeDelegate,
782778
const std::string& InitialRoute() const { return initial_route_; }
783779

784780
//--------------------------------------------------------------------------
785-
/// @brief Loads the dart shared library from disk and into the dart VM
786-
/// based off of the search parameters. When the dart library is
787-
/// loaded successfully, the dart future returned by the
788-
/// originating loadLibrary() call completes.
781+
/// @brief Loads the dart shared library into the dart VM. When the
782+
/// dart library is loaded successfully, the dart future
783+
/// returned by the originating loadLibrary() call completes.
784+
/// Each shared library is a loading unit, which consists of
785+
/// deferred libraries that can be compiled split from the
786+
/// base dart library by gen_snapshot.
789787
///
790788
/// @param[in] loading_unit_id The unique id of the deferred library's
791789
/// loading unit.
792790
///
793-
/// @param[in] lib_name The file name of the .so shared library
794-
/// file.
795-
///
796-
/// @param[in] apkPaths The paths of the APKs that may or may not
797-
/// contain the lib_name file.
791+
/// @param[in] snapshot_data Dart snapshot data of the loading unit's
792+
/// shared library.
798793
///
799-
/// @param[in] abi The abi of the library, eg, arm64-v8a
794+
/// @param[in] snapshot_data Dart snapshot instructions of the loading
795+
/// unit's shared library.
800796
///
801-
void CompleteDartLoadLibrary(intptr_t loading_unit_id,
802-
std::string lib_name,
803-
std::vector<std::string>& apkPaths,
804-
std::string abi);
797+
void LoadDartDeferredLibrary(intptr_t loading_unit_id,
798+
const uint8_t* snapshot_data,
799+
const uint8_t* snapshot_instructions);
805800

806801
private:
807802
Engine::Delegate& delegate_;
@@ -855,7 +850,7 @@ class Engine final : public RuntimeDelegate,
855850
// feature. Left commented out until it lands:
856851

857852
// // |RuntimeDelegate|
858-
// Dart_Handle OnDartLoadLibrary(intptr_t loading_unit_id) override;
853+
// void RequestDartDeferredLibrary(intptr_t loading_unit_id) override;
859854

860855
void SetNeedsReportTimings(bool value) override;
861856

shell/common/engine_unittests.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "rapidjson/document.h"
1414
#include "rapidjson/stringbuffer.h"
1515
#include "rapidjson/writer.h"
16-
#include "third_party/dart/runtime/include/dart_api.h"
1716

1817
///\note Deprecated MOCK_METHOD macros used until this issue is resolved:
1918
// https://github.com/google/googletest/issues/2490
@@ -33,7 +32,7 @@ class MockDelegate : public Engine::Delegate {
3332
MOCK_METHOD1(ComputePlatformResolvedLocale,
3433
std::unique_ptr<std::vector<std::string>>(
3534
const std::vector<std::string>&));
36-
MOCK_METHOD1(OnDartLoadLibrary, Dart_Handle(intptr_t));
35+
MOCK_METHOD1(RequestDartDeferredLibrary, void(intptr_t));
3736
};
3837

3938
class MockResponse : public PlatformMessageResponse {
@@ -57,7 +56,7 @@ class MockRuntimeDelegate : public RuntimeDelegate {
5756
MOCK_METHOD1(ComputePlatformResolvedLocale,
5857
std::unique_ptr<std::vector<std::string>>(
5958
const std::vector<std::string>&));
60-
MOCK_METHOD1(OnDartLoadLibrary, Dart_Handle(intptr_t));
59+
MOCK_METHOD1(RequestDartDeferredLibrary, void(intptr_t));
6160
};
6261

6362
class MockRuntimeController : public RuntimeController {

shell/common/platform_view.cc

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

162-
Dart_Handle PlatformView::OnDartLoadLibrary(intptr_t loading_unit_id) {
163-
return Dart_Null();
164-
}
162+
void PlatformView::RequestDartDeferredLibrary(intptr_t loading_unit_id) {}
165163

166-
void PlatformView::CompleteDartLoadLibrary(intptr_t loading_unit_id,
167-
std::string lib_name,
168-
std::vector<std::string>& apkPaths,
169-
std::string abi) {}
164+
void PlatformView::LoadDartDeferredLibrary(
165+
intptr_t loading_unit_id,
166+
const uint8_t* snapshot_data,
167+
const uint8_t* snapshot_instructions) {}
170168

171169
void PlatformView::UpdateAssetManager(
172170
std::shared_ptr<AssetManager> asset_manager) {}

shell/common/platform_view.h

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -212,40 +212,28 @@ class PlatformView {
212212
int64_t texture_id) = 0;
213213

214214
//--------------------------------------------------------------------------
215-
/// @brief Invoked when the dart VM requests that a deferred library
216-
/// be loaded. Notifies the engine that the requested loading
217-
/// unit should be downloaded and loaded.
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+
/// Each shared library is a loading unit, which consists of
219+
/// deferred libraries that can be compiled split from the
220+
/// base dart library by gen_snapshot.
218221
///
219222
/// @param[in] loading_unit_id The unique id of the deferred library's
220-
/// loading unit.
223+
/// loading unit. This is the same id as the
224+
/// one passed in by the corresponding
225+
/// RequestDartDeferredLibrary.
221226
///
222-
/// @return A Dart_Handle that is Dart_Null on success, and a dart error
223-
/// on failure.
227+
/// @param[in] snapshot_data Dart snapshot data of the loading unit's
228+
/// shared library.
224229
///
225-
virtual Dart_Handle OnPlatformViewDartLoadLibrary(
226-
intptr_t loading_unit_id) = 0;
227-
228-
//--------------------------------------------------------------------------
229-
/// @brief Loads the dart shared library from disk and into the dart VM
230-
/// based off of the search parameters. When the dart library is
231-
/// loaded successfully, the dart future returned by the
232-
/// originating loadLibrary() call completes.
233-
///
234-
/// @param[in] loading_unit_id The unique id of the deferred library's
235-
/// loading unit.
236-
///
237-
/// @param[in] lib_name The file name of the .so shared library
238-
/// file.
239-
///
240-
/// @param[in] apkPaths The paths of the APKs that may or may not
241-
/// contain the lib_name file.
242-
///
243-
/// @param[in] abi The abi of the library, eg, arm64-v8a
230+
/// @param[in] snapshot_data Dart snapshot instructions of the loading
231+
/// unit's shared library.
244232
///
245-
virtual void CompleteDartLoadLibrary(intptr_t loading_unit_id,
246-
std::string lib_name,
247-
std::vector<std::string>& apkPaths,
248-
std::string abi) = 0;
233+
virtual void LoadDartDeferredLibrary(
234+
intptr_t loading_unit_id,
235+
const uint8_t* snapshot_data,
236+
const uint8_t* snapshot_instructions) = 0;
249237

250238
//--------------------------------------------------------------------------
251239
/// @brief Sets the asset manager of the engine to asset_manager
@@ -617,33 +605,38 @@ class PlatformView {
617605
/// @param[in] loading_unit_id The unique id of the deferred library's
618606
/// loading unit.
619607
///
620-
/// @return A Dart_Handle that is Dart_Null on success, and a dart error
621-
/// on failure.
622-
///
623-
virtual Dart_Handle OnDartLoadLibrary(intptr_t loading_unit_id);
608+
virtual void RequestDartDeferredLibrary(intptr_t loading_unit_id);
624609

625610
//--------------------------------------------------------------------------
626-
/// @brief Loads the dart shared library from disk and into the dart VM
627-
/// based off of the search parameters. When the dart library is
628-
/// loaded successfully, the dart future returned by the
629-
/// originating loadLibrary() call completes.
611+
/// @brief Loads the dart shared library into the dart VM. When the
612+
/// dart library is loaded successfully, the dart future
613+
/// returned by the originating loadLibrary() call completes.
614+
/// Each shared library is a loading unit, which consists of
615+
/// deferred libraries that can be compiled split from the
616+
/// base dart library by gen_snapshot.
630617
///
631618
/// @param[in] loading_unit_id The unique id of the deferred library's
632-
/// loading unit.
633-
///
634-
/// @param[in] lib_name The file name of the .so shared library
635-
/// file.
619+
/// loading unit. This is the same id as the
620+
/// one passed in by the corresponding
621+
/// RequestDartDeferredLibrary.
636622
///
637-
/// @param[in] apkPaths The paths of the APKs that may or may not
638-
/// contain the lib_name file.
623+
/// @param[in] snapshot_data Dart snapshot data of the loading unit's
624+
/// shared library.
639625
///
640-
/// @param[in] abi The abi of the library, eg, arm64-v8a
626+
/// @param[in] snapshot_data Dart snapshot instructions of the loading
627+
/// unit's shared library.
641628
///
642-
virtual void CompleteDartLoadLibrary(intptr_t loading_unit_id,
643-
std::string lib_name,
644-
std::vector<std::string>& apkPaths,
645-
std::string abi);
629+
virtual void LoadDartDeferredLibrary(intptr_t loading_unit_id,
630+
const uint8_t* snapshot_data,
631+
const uint8_t* snapshot_instructions);
646632

633+
// TODO(garyq): Implement a proper asset_resolver replacement instead of
634+
// overwriting the entire asset manager.
635+
//--------------------------------------------------------------------------
636+
/// @brief Sets the asset manager of the engine to asset_manager
637+
///
638+
/// @param[in] asset_manager The asset manager to use.
639+
///
647640
virtual void UpdateAssetManager(std::shared_ptr<AssetManager> asset_manager);
648641

649642
protected:

shell/common/shell.cc

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

1188-
void Shell::CompleteDartLoadLibrary(intptr_t loading_unit_id,
1189-
std::string lib_name,
1190-
std::vector<std::string>& apkPaths,
1191-
std::string abi) {
1192-
engine_->CompleteDartLoadLibrary(loading_unit_id, lib_name, apkPaths, abi);
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);
11931193
}
11941194

11951195
void Shell::UpdateAssetManager(std::shared_ptr<AssetManager> asset_manager) {
11961196
engine_->UpdateAssetManager(std::move(asset_manager));
11971197
}
11981198

11991199
// |Engine::Delegate|
1200-
Dart_Handle Shell::OnDartLoadLibrary(intptr_t loading_unit_id) {
1201-
return OnPlatformViewDartLoadLibrary(loading_unit_id);
1202-
}
1203-
1204-
// |PlatformView::Delegate|
1205-
Dart_Handle Shell::OnPlatformViewDartLoadLibrary(intptr_t loading_unit_id) {
1206-
return platform_view_->OnDartLoadLibrary(loading_unit_id);
1200+
void Shell::RequestDartDeferredLibrary(intptr_t loading_unit_id) {
1201+
platform_view_->RequestDartDeferredLibrary(loading_unit_id);
12071202
}
12081203

12091204
void Shell::ReportTimings() {

shell/common/shell.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "flutter/shell/common/platform_view.h"
3737
#include "flutter/shell/common/rasterizer.h"
3838
#include "flutter/shell/common/shell_io_manager.h"
39-
#include "third_party/dart/runtime/include/dart_api.h"
4039

4140
namespace flutter {
4241

@@ -509,13 +508,9 @@ class Shell final : public PlatformView::Delegate,
509508
void OnPlatformViewSetNextFrameCallback(const fml::closure& closure) override;
510509

511510
// |PlatformView::Delegate|
512-
Dart_Handle OnPlatformViewDartLoadLibrary(intptr_t loading_unit_id) override;
513-
514-
// |PlatformView::Delegate|
515-
void CompleteDartLoadLibrary(intptr_t loading_unit_id,
516-
std::string lib_name,
517-
std::vector<std::string>& apkPaths,
518-
std::string abi) override;
511+
void LoadDartDeferredLibrary(intptr_t loading_unit_id,
512+
const uint8_t* snapshot_data,
513+
const uint8_t* snapshot_instructions) override;
519514

520515
// |PlatformView::Delegate|
521516
void UpdateAssetManager(std::shared_ptr<AssetManager> asset_manager) override;
@@ -562,7 +557,7 @@ class Shell final : public PlatformView::Delegate,
562557
const std::vector<std::string>& supported_locale_data) override;
563558

564559
// |Engine::Delegate|
565-
Dart_Handle OnDartLoadLibrary(intptr_t loading_unit_id) override;
560+
void RequestDartDeferredLibrary(intptr_t loading_unit_id) override;
566561

567562
// |Rasterizer::Delegate|
568563
void OnFrameRasterized(const FrameTiming&) override;

shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,10 @@ public FlutterEngine(
261261
false);
262262
}
263263

264-
/** Fully configurable {@code FlutterEngine} constructor. */
264+
/**
265+
* Same as {@link #FlutterEngine(Context, FlutterLoader, FlutterJNI, String[], boolean, boolean)}, plus the
266+
* ability to control {@code waitForRestorationData}.
267+
*/
265268
public FlutterEngine(
266269
@NonNull Context context,
267270
@Nullable FlutterLoader flutterLoader,
@@ -270,6 +273,28 @@ public FlutterEngine(
270273
@Nullable String[] dartVmArgs,
271274
boolean automaticallyRegisterPlugins,
272275
boolean waitForRestorationData) {
276+
this(
277+
context,
278+
flutterLoader,
279+
flutterJNI,
280+
platformViewsController,
281+
dartVmArgs,
282+
automaticallyRegisterPlugins,
283+
waitForRestorationData,
284+
null);
285+
}
286+
287+
// TODO(garyq): Move this to a better injection system.
288+
/** Fully configurable {@code FlutterEngine} constructor. */
289+
public FlutterEngine(
290+
@NonNull Context context,
291+
@Nullable FlutterLoader flutterLoader,
292+
@NonNull FlutterJNI flutterJNI,
293+
@NonNull PlatformViewsController platformViewsController,
294+
@Nullable String[] dartVmArgs,
295+
boolean automaticallyRegisterPlugins,
296+
boolean waitForRestorationData,
297+
@Nullable DynamicFeatureManager dynamicFeatureManager) {
273298
AssetManager assetManager;
274299
try {
275300
assetManager = context.createPackageContext(context.getPackageName(), 0).getAssets();
@@ -304,9 +329,9 @@ public FlutterEngine(
304329
flutterJNI.setPlatformViewsController(platformViewsController);
305330
flutterJNI.setLocalizationPlugin(localizationPlugin);
306331

307-
dynamicFeatureManager = new PlayStoreDynamicFeatureManager(context, flutterJNI);
332+
this.dynamicFeatureManager = dynamicFeatureManager != null ?
333+
dynamicFeatureManager : new PlayStoreDynamicFeatureManager(context, flutterJNI);
308334
flutterJNI.setDynamicFeatureManager(dynamicFeatureManager);
309-
flutterJNI.setDynamicFeatureContext(context);
310335

311336
attachToJni();
312337

@@ -383,6 +408,7 @@ public void destroy() {
383408
platformViewsController.onDetachedFromJNI();
384409
dartExecutor.onDetachedFromJNI();
385410
flutterJNI.removeEngineLifecycleListener(engineLifecycleListener);
411+
flutterJNI.removeDynamicFeatureManager();
386412
flutterJNI.detachFromNativeAndReleaseResources();
387413
}
388414

0 commit comments

Comments
 (0)