@@ -51,9 +51,33 @@ constexpr uint32_t OPEN_RIGHT_EXECUTABLE = 8u;
5151namespace flutter_runner {
5252
5353constexpr char kDataKey [] = " data" ;
54+ constexpr char kAssetsKey [] = " assets" ;
5455constexpr char kTmpPath [] = " /tmp" ;
5556constexpr char kServiceRootPath [] = " /svc" ;
5657
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
5781ActiveApplication Application::Create (
5882 TerminationCallback termination_callback,
5983 fuchsia::sys::Package package,
@@ -149,14 +173,11 @@ Application::Application(
149173 settings_.dart_entrypoint_args = arguments.value ();
150174 }
151175
152- // Determine /pkg/ data directory from StartupInfo .
176+ // Determine where data and assets are stored within /pkg .
153177 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+
160181 if (data_path.empty ()) {
161182 FML_DLOG (ERROR) << " Could not find a /pkg/data directory for "
162183 << package.resolved_url ;
@@ -189,11 +210,20 @@ Application::Application(
189210 }
190211 }
191212
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;
194218
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+ }
197227
198228 // TODO: LaunchInfo::out.
199229
@@ -294,7 +324,7 @@ Application::Application(
294324 std::string app_framework;
295325 if (dart_utils::ReadFileToString (" pkg/data/runner.frameworkversion" ,
296326 &runner_framework) &&
297- dart_utils::ReadFileToStringAt (application_assets_directory_ .get (),
327+ dart_utils::ReadFileToStringAt (application_data_directory_ .get (),
298328 " app.frameworkversion" ,
299329 &app_framework) &&
300330 (runner_framework.compare (app_framework) == 0 )) {
@@ -509,7 +539,7 @@ void Application::AttemptVMLaunchWithCurrentSettings(
509539
510540 std::shared_ptr<dart_utils::ElfSnapshot> snapshot =
511541 std::make_shared<dart_utils::ElfSnapshot>();
512- if (snapshot->Load (application_assets_directory_ .get (),
542+ if (snapshot->Load (application_data_directory_ .get (),
513543 " app_aot_snapshot.so" )) {
514544 const uint8_t * isolate_data = snapshot->IsolateData ();
515545 const uint8_t * isolate_instructions = snapshot->IsolateInstrs ();
@@ -531,20 +561,16 @@ void Application::AttemptVMLaunchWithCurrentSettings(
531561 hold_snapshot));
532562 } else {
533563 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 ));
540568
541569 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 ));
548574 }
549575
550576 auto vm = flutter::DartVMRef::Create (settings_, //
0 commit comments