@@ -51,9 +51,33 @@ constexpr uint32_t OPEN_RIGHT_EXECUTABLE = 8u;
51
51
namespace flutter_runner {
52
52
53
53
constexpr char kDataKey [] = " data" ;
54
+ constexpr char kAssetsKey [] = " assets" ;
54
55
constexpr char kTmpPath [] = " /tmp" ;
55
56
constexpr char kServiceRootPath [] = " /svc" ;
56
57
58
+ // static
59
+ void Application::ParseProgramMetadata (
60
+ const fidl::VectorPtr<fuchsia::sys::ProgramMetadata>& program_metadata,
61
+ std::string* data_path,
62
+ std::string* assets_path) {
63
+ if (!program_metadata.has_value ()) {
64
+ return ;
65
+ }
66
+ for (const auto & pg : *program_metadata) {
67
+ if (pg.key .compare (kDataKey ) == 0 ) {
68
+ *data_path = " pkg/" + pg.value ;
69
+ } else if (pg.key .compare (kAssetsKey ) == 0 ) {
70
+ *assets_path = " pkg/" + pg.value ;
71
+ }
72
+ }
73
+
74
+ // assets_path defaults to the same as data_path if omitted.
75
+ if (assets_path->empty ()) {
76
+ *assets_path = *data_path;
77
+ }
78
+ }
79
+
80
+ // static
57
81
ActiveApplication Application::Create (
58
82
TerminationCallback termination_callback,
59
83
fuchsia::sys::Package package,
@@ -149,14 +173,11 @@ Application::Application(
149
173
settings_.dart_entrypoint_args = arguments.value ();
150
174
}
151
175
152
- // Determine /pkg/ data directory from StartupInfo .
176
+ // Determine where data and assets are stored within /pkg .
153
177
std::string data_path;
154
- for (size_t i = 0 ; i < startup_info.program_metadata ->size (); ++i) {
155
- auto pg = startup_info.program_metadata ->at (i);
156
- if (pg.key .compare (kDataKey ) == 0 ) {
157
- data_path = " pkg/" + pg.value ;
158
- }
159
- }
178
+ std::string assets_path;
179
+ ParseProgramMetadata (startup_info.program_metadata , &data_path, &assets_path);
180
+
160
181
if (data_path.empty ()) {
161
182
FML_DLOG (ERROR) << " Could not find a /pkg/data directory for "
162
183
<< package.resolved_url ;
@@ -189,11 +210,20 @@ Application::Application(
189
210
}
190
211
}
191
212
192
- application_directory_.reset (fdio_ns_opendir (fdio_ns_.get ()));
193
- FML_DCHECK (application_directory_.is_valid ());
213
+ {
214
+ fml::UniqueFD ns_fd (fdio_ns_opendir (fdio_ns_.get ()));
215
+ FML_DCHECK (ns_fd.is_valid ());
216
+
217
+ constexpr mode_t mode = O_RDONLY | O_DIRECTORY;
194
218
195
- application_assets_directory_.reset (openat (
196
- application_directory_.get (), data_path.c_str (), O_RDONLY | O_DIRECTORY));
219
+ application_assets_directory_.reset (
220
+ openat (ns_fd.get (), assets_path.c_str (), mode));
221
+ FML_DCHECK (application_assets_directory_.is_valid ());
222
+
223
+ application_data_directory_.reset (
224
+ openat (ns_fd.get (), data_path.c_str (), mode));
225
+ FML_DCHECK (application_data_directory_.is_valid ());
226
+ }
197
227
198
228
// TODO: LaunchInfo::out.
199
229
@@ -294,7 +324,7 @@ Application::Application(
294
324
std::string app_framework;
295
325
if (dart_utils::ReadFileToString (" pkg/data/runner.frameworkversion" ,
296
326
&runner_framework) &&
297
- dart_utils::ReadFileToStringAt (application_assets_directory_ .get (),
327
+ dart_utils::ReadFileToStringAt (application_data_directory_ .get (),
298
328
" app.frameworkversion" ,
299
329
&app_framework) &&
300
330
(runner_framework.compare (app_framework) == 0 )) {
@@ -509,7 +539,7 @@ void Application::AttemptVMLaunchWithCurrentSettings(
509
539
510
540
std::shared_ptr<dart_utils::ElfSnapshot> snapshot =
511
541
std::make_shared<dart_utils::ElfSnapshot>();
512
- if (snapshot->Load (application_assets_directory_ .get (),
542
+ if (snapshot->Load (application_data_directory_ .get (),
513
543
" app_aot_snapshot.so" )) {
514
544
const uint8_t * isolate_data = snapshot->IsolateData ();
515
545
const uint8_t * isolate_instructions = snapshot->IsolateInstrs ();
@@ -531,20 +561,16 @@ void Application::AttemptVMLaunchWithCurrentSettings(
531
561
hold_snapshot));
532
562
} else {
533
563
vm_snapshot = fml::MakeRefCounted<flutter::DartSnapshot>(
534
- CreateWithContentsOfFile (
535
- application_assets_directory_.get () /* /pkg/data */ ,
536
- " vm_snapshot_data.bin" , false ),
537
- CreateWithContentsOfFile (
538
- application_assets_directory_.get () /* /pkg/data */ ,
539
- " vm_snapshot_instructions.bin" , true ));
564
+ CreateWithContentsOfFile (application_data_directory_.get (),
565
+ " vm_snapshot_data.bin" , false ),
566
+ CreateWithContentsOfFile (application_data_directory_.get (),
567
+ " vm_snapshot_instructions.bin" , true ));
540
568
541
569
isolate_snapshot_ = fml::MakeRefCounted<flutter::DartSnapshot>(
542
- CreateWithContentsOfFile (
543
- application_assets_directory_.get () /* /pkg/data */ ,
544
- " isolate_snapshot_data.bin" , false ),
545
- CreateWithContentsOfFile (
546
- application_assets_directory_.get () /* /pkg/data */ ,
547
- " isolate_snapshot_instructions.bin" , true ));
570
+ CreateWithContentsOfFile (application_data_directory_.get (),
571
+ " isolate_snapshot_data.bin" , false ),
572
+ CreateWithContentsOfFile (application_data_directory_.get (),
573
+ " isolate_snapshot_instructions.bin" , true ));
548
574
}
549
575
550
576
auto vm = flutter::DartVMRef::Create (settings_, //
0 commit comments