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

Commit 47d9229

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
1 parent e10bb26 commit 47d9229

20 files changed

+482
-315
lines changed

shell/common/engine.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -511,17 +511,17 @@ 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::CompleteDartDeferredLibraryLoading(
519+
intptr_t loading_unit_id,
520+
const uint8_t* snapshot_data,
521+
const uint8_t* snapshot_instructions) {
522522
if (runtime_controller_->IsRootIsolateRunning()) {
523-
// runtime_controller_->CompleteDartLoadLibrary(loading_unit_id, lib_name,
524-
// apkPaths, abi);
523+
// runtime_controller_->CompleteDartDeferredLibraryLoading(loading_unit_id,
524+
// snapshot_data, snapshot_instructions);
525525
}
526526
}
527527

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 CompleteDartDeferredLibraryLoading(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::CompleteDartDeferredLibraryLoading(
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: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -212,40 +212,26 @@ 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
220223
/// loading unit.
221224
///
222-
/// @return A Dart_Handle that is Dart_Null on success, and a dart error
223-
/// on failure.
225+
/// @param[in] snapshot_data Dart snapshot data of the loading unit's
226+
/// shared library.
224227
///
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.
228+
/// @param[in] snapshot_data Dart snapshot instructions of the loading
229+
/// unit's shared library.
242230
///
243-
/// @param[in] abi The abi of the library, eg, arm64-v8a
244-
///
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;
231+
virtual void CompleteDartDeferredLibraryLoading(
232+
intptr_t loading_unit_id,
233+
const uint8_t* snapshot_data,
234+
const uint8_t* snapshot_instructions) = 0;
249235

250236
//--------------------------------------------------------------------------
251237
/// @brief Sets the asset manager of the engine to asset_manager
@@ -254,7 +240,6 @@ class PlatformView {
254240
///
255241
virtual void UpdateAssetManager(
256242
std::shared_ptr<AssetManager> asset_manager) = 0;
257-
>>>>>>> 4233d6879 (Initial code)
258243
};
259244

260245
//----------------------------------------------------------------------------
@@ -616,33 +601,35 @@ class PlatformView {
616601
/// @param[in] loading_unit_id The unique id of the deferred library's
617602
/// loading unit.
618603
///
619-
/// @return A Dart_Handle that is Dart_Null on success, and a dart error
620-
/// on failure.
621-
///
622-
virtual Dart_Handle OnDartLoadLibrary(intptr_t loading_unit_id);
604+
virtual void RequestDartDeferredLibrary(intptr_t loading_unit_id);
623605

624606
//--------------------------------------------------------------------------
625-
/// @brief Loads the dart shared library from disk and into the dart VM
626-
/// based off of the search parameters. When the dart library is
627-
/// loaded successfully, the dart future returned by the
628-
/// originating loadLibrary() call completes.
607+
/// @brief Loads the dart shared library into the dart VM. When the
608+
/// dart library is loaded successfully, the dart future
609+
/// returned by the originating loadLibrary() call completes.
610+
/// Each shared library is a loading unit, which consists of
611+
/// deferred libraries that can be compiled split from the
612+
/// base dart library by gen_snapshot.
629613
///
630614
/// @param[in] loading_unit_id The unique id of the deferred library's
631615
/// loading unit.
632616
///
633-
/// @param[in] lib_name The file name of the .so shared library
634-
/// file.
635-
///
636-
/// @param[in] apkPaths The paths of the APKs that may or may not
637-
/// contain the lib_name file.
617+
/// @param[in] snapshot_data Dart snapshot data of the loading unit's
618+
/// shared library.
638619
///
639-
/// @param[in] abi The abi of the library, eg, arm64-v8a
620+
/// @param[in] snapshot_data Dart snapshot instructions of the loading
621+
/// unit's shared library.
640622
///
641-
virtual void CompleteDartLoadLibrary(intptr_t loading_unit_id,
642-
std::string lib_name,
643-
std::vector<std::string>& apkPaths,
644-
std::string abi);
623+
virtual void CompleteDartDeferredLibraryLoading(
624+
intptr_t loading_unit_id,
625+
const uint8_t* snapshot_data,
626+
const uint8_t* snapshot_instructions);
645627

628+
//--------------------------------------------------------------------------
629+
/// @brief Sets the asset manager of the engine to asset_manager
630+
///
631+
/// @param[in] asset_manager The asset manager to use.
632+
///
646633
virtual void UpdateAssetManager(std::shared_ptr<AssetManager> asset_manager);
647634

648635
protected:

shell/common/shell.cc

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,25 +1181,21 @@ std::unique_ptr<std::vector<std::string>> Shell::ComputePlatformResolvedLocale(
11811181
return platform_view_->ComputePlatformResolvedLocales(supported_locale_data);
11821182
}
11831183

1184-
void Shell::CompleteDartLoadLibrary(intptr_t loading_unit_id,
1185-
std::string lib_name,
1186-
std::vector<std::string>& apkPaths,
1187-
std::string abi) {
1188-
engine_->CompleteDartLoadLibrary(loading_unit_id, lib_name, apkPaths, abi);
1184+
void Shell::CompleteDartDeferredLibraryLoading(
1185+
intptr_t loading_unit_id,
1186+
const uint8_t* snapshot_data,
1187+
const uint8_t* snapshot_instructions) {
1188+
engine_->CompleteDartDeferredLibraryLoading(loading_unit_id, snapshot_data,
1189+
snapshot_instructions);
11891190
}
11901191

11911192
void Shell::UpdateAssetManager(std::shared_ptr<AssetManager> asset_manager) {
11921193
engine_->UpdateAssetManager(std::move(asset_manager));
11931194
}
11941195

11951196
// |Engine::Delegate|
1196-
Dart_Handle Shell::OnDartLoadLibrary(intptr_t loading_unit_id) {
1197-
return OnPlatformViewDartLoadLibrary(loading_unit_id);
1198-
}
1199-
1200-
// |PlatformView::Delegate|
1201-
Dart_Handle Shell::OnPlatformViewDartLoadLibrary(intptr_t loading_unit_id) {
1202-
return platform_view_->OnDartLoadLibrary(loading_unit_id);
1197+
void Shell::RequestDartDeferredLibrary(intptr_t loading_unit_id) {
1198+
platform_view_->RequestDartDeferredLibrary(loading_unit_id);
12031199
}
12041200

12051201
void Shell::ReportTimings() {

shell/common/shell.h

Lines changed: 5 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,10 @@ 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 CompleteDartDeferredLibraryLoading(
512+
intptr_t loading_unit_id,
513+
const uint8_t* snapshot_data,
514+
const uint8_t* snapshot_instructions) override;
519515

520516
// |PlatformView::Delegate|
521517
void UpdateAssetManager(std::shared_ptr<AssetManager> asset_manager) override;
@@ -562,7 +558,7 @@ class Shell final : public PlatformView::Delegate,
562558
const std::vector<std::string>& supported_locale_data) override;
563559

564560
// |Engine::Delegate|
565-
Dart_Handle OnDartLoadLibrary(intptr_t loading_unit_id) override;
561+
void RequestDartDeferredLibrary(intptr_t loading_unit_id) override;
566562

567563
// |Rasterizer::Delegate|
568564
void OnFrameRasterized(const FrameTiming&) override;

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

Lines changed: 28 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

0 commit comments

Comments
 (0)