Loading install/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -106,6 +106,7 @@ cc_library_static { srcs: [ "adb_install.cpp", "fuse_install.cpp", "virtiofs_install.cpp", "install.cpp", "snapshot_utils.cpp", "wipe_data.cpp", Loading install/fuse_install.cpp +16 −12 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #include <unistd.h> #include <algorithm> #include <filesystem> #include <functional> #include <memory> #include <string> Loading @@ -39,6 +40,8 @@ #include "install/install.h" #include "recovery_utils/roots.h" namespace fs = std::filesystem; using android::volmgr::VolumeInfo; using android::volmgr::VolumeManager; Loading @@ -57,9 +60,8 @@ static void SetSdcardUpdateBootloaderMessage() { } // Returns the selected filename, or an empty string. static std::string BrowseDirectory(const std::string& path, Device* device, RecoveryUI* ui) { std::unique_ptr<DIR, decltype(&closedir)> d(opendir(path.c_str()), closedir); if (!d) { std::string BrowseDirectory(const std::string& path, Device* device, RecoveryUI* ui) { if (access(path.c_str(), R_OK | X_OK)) { PLOG(ERROR) << "error opening " << path; return ""; } Loading @@ -67,19 +69,21 @@ static std::string BrowseDirectory(const std::string& path, Device* device, Reco std::vector<std::string> dirs; std::vector<std::string> entries{ "../" }; // "../" is always the first entry. dirent* de; while ((de = readdir(d.get())) != nullptr) { std::string name(de->d_name); for (const auto& entry : fs::directory_iterator(path)) { std::string name = entry.path().filename().string(); if (de->d_type == DT_DIR) { // Skip "." and ".." entries. if (name == "." || name == "..") continue; if (entry.is_directory()) { dirs.push_back(name + "/"); } else if (de->d_type == DT_REG && (android::base::EndsWithIgnoreCase(name, ".zip") || android::base::EndsWithIgnoreCase(name, ".map"))) { } else if (entry.is_regular_file()) { if (android::base::EndsWithIgnoreCase(name, ".zip") || android::base::EndsWithIgnoreCase(name, ".map")) { entries.push_back(name); } } } std::sort(dirs.begin(), dirs.end()); std::sort(entries.begin(), entries.end()); Loading install/include/install/fuse_install.h +2 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ using android::volmgr::VolumeInfo; std::string BrowseDirectory(const std::string& path, Device* device, RecoveryUI* ui); // Starts FUSE with the package from |path| as the data source. And installs the package from // |FUSE_SIDELOAD_HOST_PATHNAME|. The |path| can point to the location of a package zip file or a // block map file with the prefix '@'; e.g. /sdcard/package.zip, @/cache/recovery/block.map. Loading install/include/install/virtiofs_install.h 0 → 100644 +26 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include "install/install.h" #include "recovery_ui/device.h" #include "recovery_ui/ui.h" InstallResult ApplyFromVirtiofs(Device* device); // Returns true on success, or false on failure. bool InitializeVirtiofs(); install/virtiofs_install.cpp 0 → 100644 +57 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "install/fuse_install.h" #include "install/virtiofs_install.h" #include <string> #include "install/install.h" #include "recovery_utils/roots.h" static constexpr const char* VIRTIOFS_MOUNTPOINT = "/mnt/vendor/shared"; InstallResult ApplyFromVirtiofs(Device* device) { auto ui = device->GetUI(); std::string path = BrowseDirectory(VIRTIOFS_MOUNTPOINT, device, ui); if (path.empty()) { return INSTALL_NONE; } ui->Print("\n-- Install %s ...\n", path.c_str()); auto package = Package::CreateFilePackage(path, std::bind(&RecoveryUI::SetProgress, ui, std::placeholders::_1)); if (package == nullptr) { ui->Print("Failed to open package %s\n", path.c_str()); return INSTALL_ERROR; } auto result = InstallPackage(package.get(), path, false, 0 /* retry_count */, device); return result; } bool InitializeVirtiofs() { if (volume_for_mount_point(VIRTIOFS_MOUNTPOINT)) { if (ensure_path_mounted(VIRTIOFS_MOUNTPOINT) == 0) { return true; } } return false; } Loading
install/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -106,6 +106,7 @@ cc_library_static { srcs: [ "adb_install.cpp", "fuse_install.cpp", "virtiofs_install.cpp", "install.cpp", "snapshot_utils.cpp", "wipe_data.cpp", Loading
install/fuse_install.cpp +16 −12 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #include <unistd.h> #include <algorithm> #include <filesystem> #include <functional> #include <memory> #include <string> Loading @@ -39,6 +40,8 @@ #include "install/install.h" #include "recovery_utils/roots.h" namespace fs = std::filesystem; using android::volmgr::VolumeInfo; using android::volmgr::VolumeManager; Loading @@ -57,9 +60,8 @@ static void SetSdcardUpdateBootloaderMessage() { } // Returns the selected filename, or an empty string. static std::string BrowseDirectory(const std::string& path, Device* device, RecoveryUI* ui) { std::unique_ptr<DIR, decltype(&closedir)> d(opendir(path.c_str()), closedir); if (!d) { std::string BrowseDirectory(const std::string& path, Device* device, RecoveryUI* ui) { if (access(path.c_str(), R_OK | X_OK)) { PLOG(ERROR) << "error opening " << path; return ""; } Loading @@ -67,19 +69,21 @@ static std::string BrowseDirectory(const std::string& path, Device* device, Reco std::vector<std::string> dirs; std::vector<std::string> entries{ "../" }; // "../" is always the first entry. dirent* de; while ((de = readdir(d.get())) != nullptr) { std::string name(de->d_name); for (const auto& entry : fs::directory_iterator(path)) { std::string name = entry.path().filename().string(); if (de->d_type == DT_DIR) { // Skip "." and ".." entries. if (name == "." || name == "..") continue; if (entry.is_directory()) { dirs.push_back(name + "/"); } else if (de->d_type == DT_REG && (android::base::EndsWithIgnoreCase(name, ".zip") || android::base::EndsWithIgnoreCase(name, ".map"))) { } else if (entry.is_regular_file()) { if (android::base::EndsWithIgnoreCase(name, ".zip") || android::base::EndsWithIgnoreCase(name, ".map")) { entries.push_back(name); } } } std::sort(dirs.begin(), dirs.end()); std::sort(entries.begin(), entries.end()); Loading
install/include/install/fuse_install.h +2 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ using android::volmgr::VolumeInfo; std::string BrowseDirectory(const std::string& path, Device* device, RecoveryUI* ui); // Starts FUSE with the package from |path| as the data source. And installs the package from // |FUSE_SIDELOAD_HOST_PATHNAME|. The |path| can point to the location of a package zip file or a // block map file with the prefix '@'; e.g. /sdcard/package.zip, @/cache/recovery/block.map. Loading
install/include/install/virtiofs_install.h 0 → 100644 +26 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include "install/install.h" #include "recovery_ui/device.h" #include "recovery_ui/ui.h" InstallResult ApplyFromVirtiofs(Device* device); // Returns true on success, or false on failure. bool InitializeVirtiofs();
install/virtiofs_install.cpp 0 → 100644 +57 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "install/fuse_install.h" #include "install/virtiofs_install.h" #include <string> #include "install/install.h" #include "recovery_utils/roots.h" static constexpr const char* VIRTIOFS_MOUNTPOINT = "/mnt/vendor/shared"; InstallResult ApplyFromVirtiofs(Device* device) { auto ui = device->GetUI(); std::string path = BrowseDirectory(VIRTIOFS_MOUNTPOINT, device, ui); if (path.empty()) { return INSTALL_NONE; } ui->Print("\n-- Install %s ...\n", path.c_str()); auto package = Package::CreateFilePackage(path, std::bind(&RecoveryUI::SetProgress, ui, std::placeholders::_1)); if (package == nullptr) { ui->Print("Failed to open package %s\n", path.c_str()); return INSTALL_ERROR; } auto result = InstallPackage(package.get(), path, false, 0 /* retry_count */, device); return result; } bool InitializeVirtiofs() { if (volume_for_mount_point(VIRTIOFS_MOUNTPOINT)) { if (ensure_path_mounted(VIRTIOFS_MOUNTPOINT) == 0) { return true; } } return false; }